From ab1148d62d897a0262a803269254586699b82495 Mon Sep 17 00:00:00 2001 From: Moritz Fischer Date: Mon, 8 Jan 2018 14:17:51 -0800 Subject: mpm: Add code to drive the back panel LEDs Add code to drive back panel LEDs for GPS, Link (claim) and REF Signed-off-by: Moritz Fischer Reviewed-By: Martin Braun --- mpm/python/usrp_mpm/periph_manager/n310.py | 110 ++++++++++++++++++++++++++--- 1 file changed, 100 insertions(+), 10 deletions(-) (limited to 'mpm') diff --git a/mpm/python/usrp_mpm/periph_manager/n310.py b/mpm/python/usrp_mpm/periph_manager/n310.py index 5c0991559..f50e0b778 100644 --- a/mpm/python/usrp_mpm/periph_manager/n310.py +++ b/mpm/python/usrp_mpm/periph_manager/n310.py @@ -202,6 +202,79 @@ class FP_GPIO(object): assert index in range(self._gpiosize) return self._gpios.get(self._offset+index) +class BackpanelGPIO(object): + """ + Abstraction layer for the back panel GPIO + """ + EMIO_BASE = 54 + BP_GPIO_OFFSET = 45 + LED_LINK = 0 + LED_REF = 1 + LED_GPS = 2 + + def __init__(self): + self._gpiosize = 3 + self._offset = self.BP_GPIO_OFFSET + self.EMIO_BASE + self.ddr = 0x7 + self.usemask = 0x7 + self._gpios = SysFSGPIO( + 'zynq_gpio', + self.usemask << self._offset, + self.ddr << self._offset + ) + + def set_all(self, value): + """ + Set all pins to 'value'. + This method will convert value into binary and take the first 3 bits + assign to 3pins. + """ + bin_value = '{0:03b}'.format(value) + wr_value = bin_value[-(self._gpiosize):] + for i in range(self._gpiosize): + if (1 << i) & self.ddr: + self._gpios.set(self._offset + i, wr_value[i % 3]) + + def set(self, index, value=None): + """ + Set a pin by index + """ + assert index in range(self._gpiosize) + self._gpios.set(self._offset + index, value) + + def reset_all(self): + """ + Clear all pins + """ + for i in range(self._gpiosize): + self._gpios.reset(self._offset+i) + + def reset(self, index): + """ + Clear a pin by index + """ + assert index in range(self._gpiosize) + self._gpios.reset(self._offset + index) + + def get_all(self): + """ + Read back all pins + """ + result = 0 + for i in range(self._gpiosize): + if not (1<