diff options
Diffstat (limited to 'mpm/python')
| -rwxr-xr-x | mpm/python/usrp_hwd.py | 18 | ||||
| -rw-r--r-- | mpm/python/usrp_mpm/dboard_manager/base.py | 30 | ||||
| -rw-r--r-- | mpm/python/usrp_mpm/dboard_manager/eiscat.py | 8 | ||||
| -rw-r--r-- | mpm/python/usrp_mpm/dboard_manager/magnesium.py | 14 | ||||
| -rw-r--r-- | mpm/python/usrp_mpm/periph_manager/base.py | 41 | ||||
| -rw-r--r-- | mpm/python/usrp_mpm/periph_manager/n310.py | 35 | 
6 files changed, 84 insertions, 62 deletions
diff --git a/mpm/python/usrp_hwd.py b/mpm/python/usrp_hwd.py index 863c59396..27c2870df 100755 --- a/mpm/python/usrp_hwd.py +++ b/mpm/python/usrp_hwd.py @@ -50,6 +50,12 @@ def setup_arg_parser():               "used instead of whatever else the code may find",          default=None      ) +    parser.add_argument( +        '--default-args', +        help="Provide a comma-separated list of key=value pairs that are" \ +             "used as defaults for device initialization.", +        default=None +    )      return parser  def parse_args(): @@ -59,6 +65,15 @@ def parse_args():      args = setup_arg_parser().parse_args()      if args.override_db_pids is not None:          args.override_db_pids = [int(x, 0) for x in args.override_db_pids.split(",")] +    args.default_args = args.default_args or '' +    try: +        args.default_args = { +            x.split('=')[0].strip(): x.split('=')[1].strip() if x.find('=') != -1 else '' +            for x in args.default_args.split(',') +            if len(x) +        } +    except IndexError: +        log.error("Could not parse default device args: `{}'".format(args.default_args))      return args @@ -100,8 +115,10 @@ def main():          "type": mgr._get_device_info()["type"],          "serial": mgr._get_device_info()["serial"]      } +    mgr.init(args.default_args) # TODO really this should be called by the UHD session      if args.init_only:          log.info("Terminating on user request before launching RPC server.") +        mgr.deinit()          return True      log.info("Spawning discovery process...")      _PROCESSES.append( @@ -113,6 +130,7 @@ def main():      signal.signal(signal.SIGTERM, kill_time)      signal.signal(signal.SIGINT, kill_time)      signal.pause() +    mgr.deinit() # TODO Really this should be called when a device is unclaimed      return True  if __name__ == '__main__': diff --git a/mpm/python/usrp_mpm/dboard_manager/base.py b/mpm/python/usrp_mpm/dboard_manager/base.py index 5bf31784f..c7e116fc0 100644 --- a/mpm/python/usrp_mpm/dboard_manager/base.py +++ b/mpm/python/usrp_mpm/dboard_manager/base.py @@ -42,12 +42,16 @@ class DboardManagerBase(object):      def __init__(self, slot_idx, **kwargs):          self.log = get_logger('dboardManager')          self.slot_idx = slot_idx +        self.device_info = {}          self._init_spi_nodes(kwargs.get('spi_nodes', []))      def _init_spi_nodes(self, spi_devices):          """ -        docstring for _init_spi_nodes +        Populates the self._spi_nodes dictionary. +        Note that this won't instantiate any spidev objects, it'll just map +        keys from self.spi_chipselect to spidev nodes, and do a sanity check +        that enough nodes are available.          """          if len(spi_devices) < len(self.spi_chipselect):              self.log.error("Expected {0} spi devices, found {1} spi devices".format( @@ -59,8 +63,30 @@ class DboardManagerBase(object):              self._spi_nodes[k] = spi_devices[v]          self.log.debug("spidev device node map: {}".format(self._spi_nodes)) +    def init(self, args): +        """ +        Run the dboard initialization. This typically happens at the beginning +        of a UHD session. + +        Must be overridden. + +        args -- A dictionary of arbitrary settings that can be used by the +                dboard code. Similar to device args for UHD. +        """ +        raise NotImplementedError("DboardManagerBase::init() not implemented!") + +    def deinit(self): +        """ +        Power down the dboard. Does not have be implemented. If it does, it +        needs to be safe to call multiple times. +        """ +        self.log.info("deinit() called, but not implemented.") +      def get_serial(self): -        return self._eeprom.get("serial", "") +        """ +        Return this daughterboard's serial number as a dictionary. +        """ +        return self.device_info.get("serial", "")      def update_ref_clock_freq(self, freq):          """ diff --git a/mpm/python/usrp_mpm/dboard_manager/eiscat.py b/mpm/python/usrp_mpm/dboard_manager/eiscat.py index 7a930af79..78d5d0e18 100644 --- a/mpm/python/usrp_mpm/dboard_manager/eiscat.py +++ b/mpm/python/usrp_mpm/dboard_manager/eiscat.py @@ -30,7 +30,7 @@ N_CHANS = 8 # Chans per dboard  # Power enable pins  POWER_ENB = 0x200C # Address of the power enable register -PWR_CHAN_EN_2V5 = [(1<<x) for x in xrange(8)] +PWR_CHAN_EN_2V5 = [(1<<chan_en) for chan_en in xrange(8)]  PWR2_5V_DC_CTRL_ENB = 1<<8  PWR2_5V_DC_PWR_EN = 1<<9  PWR2_5V_LNA_CTRL_EN = 1<<10 @@ -382,12 +382,15 @@ class EISCAT(DboardManagerBase):          self.mmcm = None          self._spi_ifaces = None -    def init_device(self): +    def init(self, args):          """          Execute necessary actions to bring up the daughterboard          This assumes that an appropriate overlay was loaded.          """ +        self.log.info("init() called with args `{}'".format( +            ",".join(['{}={}'.format(x, args[x]) for x in args]) +        ))          self.log.trace("Getting uio...")          self.radio_regs = UIO(label="jesd204b-regs", read_only=False)          # Create JESD cores. They will also test the UIO regs on initialization. @@ -456,6 +459,7 @@ class EISCAT(DboardManagerBase):          for i in xrange(2):              if not self.jesd_cores[i].check_deframer_status():                  raise RuntimeError("JESD Core {}: Deframer status not lookin' so good!".format(i)) +        self.log.info("JESD core initialized, link up!")          self.phase_dac = self._spi_ifaces['phase_dac']          ## END OF THE JEPSON SEQUENCE ## diff --git a/mpm/python/usrp_mpm/dboard_manager/magnesium.py b/mpm/python/usrp_mpm/dboard_manager/magnesium.py index edb9a24db..9edfe497c 100644 --- a/mpm/python/usrp_mpm/dboard_manager/magnesium.py +++ b/mpm/python/usrp_mpm/dboard_manager/magnesium.py @@ -65,12 +65,14 @@ class Magnesium(DboardManagerBase):      def __init__(self, slot_idx, **kwargs):          super(Magnesium, self).__init__(*args, **kwargs)          self.log = get_logger("Magnesium") -        # eeprom_data is a tuple (head_dict, raw_data) -    def init_device(self): +    def init(self, args):          """          Execute necessary init dance to bring up dboard          """ +        self.log.info("init() called with args `{}'".format( +            ",".join(['{}={}'.format(x, args[x]) for x in args]) +        ))          self.clock_regs = create_spidev_iface(self._spi_nodes['lmk'])          self.log.debug("Loading C++ drivers...")          self._device = lib.dboards.magnesium_manager( @@ -144,11 +146,3 @@ class Magnesium(DboardManagerBase):                  print("%08X" % self.radio_regs.peek32(i + j)),              print("") -    def read_eeprom_v1(self, data): -        """ -        read eeprom data version 1 -        """ -        # magnesium eeprom contains -        # nothing -        return struct.unpack_from("x", data) - diff --git a/mpm/python/usrp_mpm/periph_manager/base.py b/mpm/python/usrp_mpm/periph_manager/base.py index a6f69fd6d..ec0e4ed79 100644 --- a/mpm/python/usrp_mpm/periph_manager/base.py +++ b/mpm/python/usrp_mpm/periph_manager/base.py @@ -336,19 +336,34 @@ class PeriphManagerBase(object):          self.log.info("Found {} daughterboard(s).".format(len(self.dboards)))          # self.overlays = "" -        # self._dboard_eeproms = {} -        # self.log.debug("Initializing dboards") -        # # for dboard_slot, eeprom_addr in self.dboard_eeprom_addrs.iteritems(): -            # # self.log.debug("Adding dboard for slot {0}".format(dboard_slot)) -            # # spi_devices = [] -            # # # I know EEPROM adresses for my dboard slots -            # # eeprom_data = EEPROM().read_eeprom(get_eeprom_paths(eeprom_addr)) -            # # # I know spidev masters on the dboard slots -            # # hw_pid = eeprom_data[0].get("hw_pid", 0) -            # # if hw_pid in dboard_manager.HW_PIDS: -                # # spi_devices = get_spidev_nodes(self.dboard_spimaster_addrs.get(dboard_slot)) -            # # dboard = dboard_manager.HW_PIDS.get(hw_pid, dboard_manager.unknown) -            # # self.dboards.update({dboard_slot: dboard(spi_devices, eeprom_data)}) + +    def init(self, args): +        """ +        Run the mboard initialization. This is typically done at the beginning +        of a UHD session. +        Default behaviour is to call init() on all the daughterboards.`args' is +        passed to the daughterboard's init calls.  For additional features, +        this needs to be overridden. + +        args -- A dictionary of args for initialization. Similar to device args +                in UHD. +        """ +        self.log.info("Mboard init() called with device args `{}'.".format( +            ",".join(['{}={}'.format(x, args[x]) for x in args]) +        )) +        self.log.debug("Initializing dboards...") +        for dboard in self.dboards: +            dboard.init(args) + +    def deinit(self): +        """ +        Power down a device after a UHD session. +        This must be safe to call multiple times. The default behaviour is to +        call deinit() on all the daughterboards. +        """ +        self.log.info("Mboard deinit() called.") +        for dboard in self.dboards: +            dboard.deinit()      def safe_list_updateable_components(self):          """ diff --git a/mpm/python/usrp_mpm/periph_manager/n310.py b/mpm/python/usrp_mpm/periph_manager/n310.py index 59eb7da94..1d2e23b91 100644 --- a/mpm/python/usrp_mpm/periph_manager/n310.py +++ b/mpm/python/usrp_mpm/periph_manager/n310.py @@ -126,46 +126,11 @@ class n310(PeriphManagerBase):          self.set_clock_source(N3XX_DEFAULT_CLOCK_SOURCE) -        # data = self._read_eeprom_v1(self._eeprom_rawdata) -        # mac 0: mgmt port, mac1: sfp0, mac2: sfp1 -        # self.interfaces["mgmt"] = { -        #     "mac_addr": byte_to_mac(data[0]), -        #     "addrs": get_iface_addrs(byte_to_mac(data[0])) -        # } -        # self.interfaces["sfp0"] = { -        #     "mac_addr": byte_to_mac(data[1]), -        #     "addrs": get_iface_addrs(byte_to_mac(data[1])) -        # } -        # self.interfaces["sfp1"] = { -        #     "mac_addr": byte_to_mac(data[2]), -        #     "addrs": get_iface_addrs(byte_to_mac(data[2])) -        # } -        # self.mboard_info["serial"] = data[0]  # some format          self.mboard_info["serial"] = '123'  # some format          with open("/sys/class/rfnoc_crossbar/crossbar0/local_addr", "w") as xbar:              xbar.write("0x2")          # if header.get("dataversion", 0) == 1: -        # Initialize our daughterboards: -        self.log.debug("Initializing dboards...") -        for dboard in self.dboards: -            dboard.init_device() - -    def _read_eeprom_v1(self, data): -        """ -        read eeprom with data version 1 -        """ -        # data contains -        # 24 bytes header -> ignore them here -        # 8 bytes serial -        # 6 bytes mac_addr0 -        # 2 bytes pad -        # 6 bytes mac_addr1 -        # 2 bytes pad -        # 6 bytes mac_addr2 -        # 2 bytes pad -        # 4 bytes CRC -        return struct.unpack_from("!28x 8s 6s 2x 6s 2x 6s 2x I", data)      def get_interfaces(self):          """  | 
