From 4e873a4cb19552f6903f69739f0a6818c8a5e263 Mon Sep 17 00:00:00 2001
From: Martin Braun <martin.braun@ettus.com>
Date: Fri, 12 Jan 2018 18:17:54 -0800
Subject: mpm: n310: Check all periphs for initialization status

---
 mpm/python/usrp_mpm/periph_manager/base.py |  4 ++++
 mpm/python/usrp_mpm/periph_manager/n310.py | 25 ++++++++++++++++++-------
 2 files changed, 22 insertions(+), 7 deletions(-)

(limited to 'mpm')

diff --git a/mpm/python/usrp_mpm/periph_manager/base.py b/mpm/python/usrp_mpm/periph_manager/base.py
index 4db74e8dd..265d286e5 100644
--- a/mpm/python/usrp_mpm/periph_manager/base.py
+++ b/mpm/python/usrp_mpm/periph_manager/base.py
@@ -334,6 +334,10 @@ class PeriphManagerBase(object):
         This must be safe to call multiple times. The default behaviour is to
         call deinit() on all the daughterboards.
         """
+        if not self._device_initialized:
+            self.log.error(
+                "Cannot run deinit(), device was never fully initialized!")
+            return
         self.log.trace("Mboard deinit() called.")
         for dboard in self.dboards:
             dboard.deinit()
diff --git a/mpm/python/usrp_mpm/periph_manager/n310.py b/mpm/python/usrp_mpm/periph_manager/n310.py
index f16dbc2b6..d24526792 100644
--- a/mpm/python/usrp_mpm/periph_manager/n310.py
+++ b/mpm/python/usrp_mpm/periph_manager/n310.py
@@ -581,6 +581,10 @@ class n310(PeriphManagerBase):
         Calls init() on the parent class, and then programs the Ethernet
         dispatchers accordingly.
         """
+        if not self._device_initialized:
+            self.log.warning(
+                "Cannot run init(), device was never fully initialized!")
+            return
         result = super(n310, self).init(args)
         for xport_mgr in itervalues(self._xport_mgrs):
             xport_mgr.init(args)
@@ -590,6 +594,10 @@ class n310(PeriphManagerBase):
         """
         Clean up after a UHD session terminates.
         """
+        if not self._device_initialized:
+            self.log.warning(
+                "Cannot run deinit(), device was never fully initialized!")
+            return
         super(n310, self).deinit()
         for xport_mgr in itervalues(self._xport_mgrs):
             xport_mgr.deinit()
@@ -604,9 +612,10 @@ class n310(PeriphManagerBase):
         """
         self.log.trace("Tearing down N3xx device...")
         self._tear_down = True
-        self._status_monitor_thread.join(3 * N3XX_MONITOR_THREAD_INTERVAL)
-        if self._status_monitor_thread.is_alive():
-            self.log.error("Could not terminate monitor thread!")
+        if self._device_initialized:
+            self._status_monitor_thread.join(3 * N3XX_MONITOR_THREAD_INTERVAL)
+            if self._status_monitor_thread.is_alive():
+                self.log.error("Could not terminate monitor thread!")
         active_overlays = self.list_active_overlays()
         self.log.trace("N310 has active device tree overlays: {}".format(
             active_overlays
@@ -1115,14 +1124,16 @@ class n310(PeriphManagerBase):
         This is called when the device is claimed, in case the device needs to
         run any actions on claiming (e.g., light up an LED).
         """
-        # Light up LINK
-        self._bp_leds.set(self._bp_leds.LED_LINK, 1)
+        if self._device_initialized:
+            # Light up LINK
+            self._bp_leds.set(self._bp_leds.LED_LINK, 1)
 
     def unclaim(self):
         """
         This is called when the device is unclaimed, in case the device needs
         to run any actions on claiming (e.g., turn off an LED).
         """
-        # Turn off LINK
-        self._bp_leds.set(self._bp_leds.LED_LINK, 0)
+        if self._device_initialized:
+            # Turn off LINK
+            self._bp_leds.set(self._bp_leds.LED_LINK, 0)
 
-- 
cgit v1.2.3