diff --git a/platform/panduza_platform/connectors/boundary_scan_ftdi.py b/platform/panduza_platform/connectors/boundary_scan_ftdi.py index d02d184..b227c48 100644 --- a/platform/panduza_platform/connectors/boundary_scan_ftdi.py +++ b/platform/panduza_platform/connectors/boundary_scan_ftdi.py @@ -1,6 +1,5 @@ import asyncio import concurrent.futures -import threading from .boundary_scan_base import ConnectorBoundaryScanBase from panduza_platform.extlibs.bsdl import bsdl,bsdlJson,read_bsdlJson_files @@ -104,7 +103,7 @@ async def Get(**kwargs): jtag_frequency = kwargs["jtag_frequency"] if "jtag_bsdl_folder" in kwargs: - jtag_bsdl_folder = kwargs["jtag_bsdl_folder"] + jtag_bsdl_folder = kwargs["jtag_bsdl_folder"] else: raise Exception("no way to identify the informations given in the tree.json") @@ -239,6 +238,7 @@ async def async_read_number_of_devices(self): function that returns the number of devices detected in the jtag chain """ result = await self.run_async_function(self.scan) + print("Result:", result) return result @@ -249,6 +249,7 @@ async def async_get_idcodes(self): """ result = await self.run_async_function(self.idcode) + print("Result:", result) return result @@ -258,6 +259,7 @@ async def async_read_pin(self, device_number, pin, direction): function that reads the state of a pin """ result = await self.run_async_function(self.read,device_number, pin, direction) + print("Result:", result) return result @@ -280,11 +282,11 @@ async def run_async_function(self,function,*args): # Wait for the future to complete while not future.done(): await asyncio.sleep(0.1) - print(f"Waiting for the thread to complete...") + #print(f"Waiting for the thread to complete...") # Retrieve the result from the future result = future.result() - print("Result:", result) + #print("Result:", result) return result @@ -294,17 +296,7 @@ async def run_async_function(self,function,*args): ########################################################################### def scan(self): - number_of_devices = 0 - self.engine.reset() - self.engine.change_state('shift_dr') - idcode = self.engine._ctrl.read(32) - - while int(idcode) != 0: - number_of_devices += 1 - idcode = self.engine._ctrl.read(32) - - self.engine.change_state('update_dr') - self.engine.go_idle() + number_of_devices = len(self.idcode()) return number_of_devices diff --git a/platform/panduza_platform/connectors/test/test_boundary_scan_ftdi.py b/platform/panduza_platform/connectors/test/test_boundary_scan_ftdi.py new file mode 100644 index 0000000..bd09c10 --- /dev/null +++ b/platform/panduza_platform/connectors/test/test_boundary_scan_ftdi.py @@ -0,0 +1,98 @@ +import asyncio + +import time +from panduza_platform.connectors.boundary_scan_ftdi import ConnectorBoundaryScanFtdi + + +device_number_1 = 1 +device_number_3 = 3 +pin_PA5 = "PA5" +pin_PA10 = "PA10" +pin_PC5 = "PC5" + +async def nested(): + + print("42") + + + +async def blocking_io(): + print(f"start blocking_io at {time.strftime('%X')}") + # Note that time.sleep() can be replaced with any blocking + # IO-bound operation, such as file operations. + for i in range (500): + print("pok") + print(f"blocking_io complete at {time.strftime('%X')}") + + + +# Tâche pour l'écriture en boucle sur les broches +async def write_loop_task(connector): + + while True: + + # Écrire la valeur sur la broche + await connector.async_write_pin(device_number_1, pin_PA5, 1) + await connector.async_write_pin(device_number_1, pin_PA10, 1) + await connector.async_write_pin(device_number_3, pin_PA5, 1) + await connector.async_write_pin(device_number_3, pin_PA10, 1) + + +# Tâche pour la lecture de l'état des broches dès qu'une écriture est effectuée +async def read_on_write_task(connector): + + while True: + + await connector.async_read_pin(device_number_3,pin_PC5,"in") + # await connector.async_read_pin(device_number_3,pin_PA5,"out") + # await connector.async_read_pin(device_number_3,pin_PA10,"out") + # await connector.async_read_pin(device_number_1,pin_PA5,"out") + # await connector.async_read_pin(device_number_1,pin_PA10,"out") + + + + +async def main(): + print(f"started main at {time.strftime('%X')}") + # Schedule nested() to run soon concurrently + # with "main()". + + connector = ConnectorBoundaryScanFtdi() + write_task = asyncio.create_task(write_loop_task(connector)) + read_task = asyncio.create_task(read_on_write_task(connector)) + + #await asyncio.gather(write_task,read_task) + + # task1 = asyncio.create_task(connector.async_read_number_of_devices()) + # await task1 + + + # await asyncio.gather( + + # connector.async_read_number_of_devices(), + + # connector.async_get_idcodes(), + + # connector.async_write_pin(1,"PA10",1), + + # connector.async_write_pin(1,"PA5",1), + + # connector.async_write_pin(3,"PA10",1), + + # connector.async_write_pin(3,"PA5",1), + + # connector.async_read_pin(3,"PC5","in"), + + # connector.async_write_pin(1,"PA5",1), + + # connector.async_write_pin(1,"PA10",1), + + # ) + + print(f"finished main at {time.strftime('%X')}") + + + + +if __name__ == '__main__': + asyncio.run(main()) diff --git a/platform/panduza_platform/devices/ftdi/ft232h_jtag.py b/platform/panduza_platform/devices/ftdi/ft232h_jtag.py index fd708be..60ce5d0 100644 --- a/platform/panduza_platform/devices/ftdi/ft232h_jtag.py +++ b/platform/panduza_platform/devices/ftdi/ft232h_jtag.py @@ -26,18 +26,37 @@ def _PZA_DEV_interfaces(self): """ """ interfaces = [] - + jtag_frequency = self._initial_settings.get("jtag_frequency",6E6) jtag_bsdl_folder = self._initial_settings.get("jtag_bsdl_folder") - #number_of_devices = int(self._initial_settings.get("number_of_devices")) - pins = self.get_pins_from_idcode(jtag_bsdl_folder) # a list of pins from each device detected + pins_detected = self.get_pins_from_idcode(jtag_bsdl_folder) # a list of pins from each device detected + pins_wanted = self._initial_settings.get("pins_wanted",None) + number_of_devices = len(pins_detected) + + # print(pins_wanted) + # print(pins) + + pins = pins_detected.copy() + #pins = asyncio.run(get_pins_from_idcode(jtag_bsdl_folder,jtag_frequency)) #pins = run_async_function(jtag_bsdl_folder,jtag_frequency) - #print(pins) - number_of_devices = len(pins) - #print(pins) + if pins_wanted != None : + pins_list = set(pins_wanted) + + for i in range(number_of_devices): + if pins[i] is not None: + common_pins = pins_list.intersection(pins[i]) + if not common_pins: + pins[i] = None + else: + pins[i] = list(common_pins) + + + + + for device_number in range(0,number_of_devices): if pins[device_number] is not None: diff --git a/platform/panduza_platform/drivers/dio/drv_ftdi_boundary_scan_dio.py b/platform/panduza_platform/drivers/dio/drv_ftdi_boundary_scan_dio.py index 5b7490c..c59748b 100644 --- a/platform/panduza_platform/drivers/dio/drv_ftdi_boundary_scan_dio.py +++ b/platform/panduza_platform/drivers/dio/drv_ftdi_boundary_scan_dio.py @@ -33,6 +33,7 @@ async def _PZA_DRV_loop_init(self, loop, tree): assert_that(settings, has_key("jtag_bsdl_folder")) assert_that(settings, has_key("pin")) assert_that(settings, has_key("device_number")) + #assert_that(settings, has_key("pins_wanted")) self.pin = settings["pin"] @@ -107,7 +108,6 @@ async def _PZA_DRV_DIO_get_state_active(self): """ get the active state """ direction = self.__fakes["direction"]["value"] - self.__fakes["state"]["active"] = await self.jtag_connector.async_read_pin(self.device_number,self.pin,direction) self.log.info(f'the state of the device {self.device_number} {self.pin} ({direction}) is {self.__fakes["state"]["active"]}') @@ -122,7 +122,7 @@ async def _PZA_DRV_DIO_set_state_active(self,v): """ global previous_device_number,previous_pins #self.log.info(f' 1 pre : {previous_device_number} ; mtn : {self.device_number}') - self.log.info(f'1 pins : {previous_pins} ') + #self.log.info(f'1 pins : {previous_pins} ') if (previous_device_number != self.device_number): for pins in previous_pins : self.log.info(f'write on previous device {previous_device_number} {pins} with {not(v)}') @@ -130,7 +130,7 @@ async def _PZA_DRV_DIO_set_state_active(self,v): previous_pins.clear() - self.log.info(f'2 pins : {previous_pins} ') + #self.log.info(f'2 pins : {previous_pins} ') self.log.info(f'write on device {self.device_number} {self.pin} with {v}') self.__fakes["state"]["active"] = v @@ -143,7 +143,7 @@ async def _PZA_DRV_DIO_set_state_active(self,v): previous_pins.append(self.pin) #self.log.info(f'2 pre : {previous_device_number} ; mtn : {self.device_number}') - self.log.info(f'3 pins : {previous_pins} ') + #self.log.info(f'3 pins : {previous_pins} ') # --- diff --git a/platform/panduza_platform/meta_drivers/dio.py b/platform/panduza_platform/meta_drivers/dio.py index 50d5b06..2a5f90c 100644 --- a/platform/panduza_platform/meta_drivers/dio.py +++ b/platform/panduza_platform/meta_drivers/dio.py @@ -38,8 +38,8 @@ async def _PZA_DRV_loop_init(self, loop, tree): # first update await self.__update_attribute_initial() - # Start polling task - #self.__task_polling = loop.create_task(self.__polling_task()) + # trigger for polling task + self.trigger = False # Init Success await super()._PZA_DRV_loop_init(loop, tree) @@ -48,10 +48,13 @@ async def _PZA_DRV_loop_init(self, loop, tree): async def _PZA_DRV_loop_run(self, loop): # polls - # self.__poll_att_direction() - await asyncio.sleep(0.2) - #await self.__poll_att_state() + # await self.__poll_att_state() + # await asyncio.sleep(5) + # await self.__poll_att_direction() + # await asyncio.sleep(5) + + await self.__poll_trigger() # --- @@ -62,6 +65,10 @@ async def _PZA_DRV_cmds_set(self, loop, payload): for att in self.__cmd_handlers: if att in cmds: await self.__cmd_handlers[att](cmds[att]) + + self.trigger = True + + # ============================================================================= @@ -232,42 +239,49 @@ async def __att_state_full_update(self): }) + async def __poll_trigger(self): + + if self.trigger: + + v = await self._PZA_DRV_DIO_get_state_active() + await self._update_attribute("state", "active", v, 'always') + self.trigger = False - async def __poll_att_state(self): + + + # async def __poll_att_state(self): - polling_cycle = float(self._get_field("state", "polling_cycle")) + # polling_cycle = float(self._get_field("state", "polling_cycle")) - if polling_cycle < 0: - return - if (time.perf_counter() - self.__polling_cycle) > polling_cycle: - p = False - p = await self._update_attribute("state", "active_low", await self._PZA_DRV_DIO_get_state_activeLow(), False) or p - p = await self._update_attribute("state", "active", await self._PZA_DRV_DIO_get_state_active(), False) or p - print(f'dddddddd{p}') - if p: - await self._push_attribute("state") - self.__polling_cycle = time.perf_counter() + # if polling_cycle < 0: + # return + # if (time.perf_counter() - self.__polling_cycle) > polling_cycle: + # p = False + # p = await self._update_attribute("state", "active_low", await self._PZA_DRV_DIO_get_state_activeLow(), False) or p + # p = await self._update_attribute("state", "active", await self._PZA_DRV_DIO_get_state_active(), False) or p + + # if p: + # await self._push_attribute("state") + # self.__polling_cycle = time.perf_counter() - # def __poll_att_direction(self): + # async def __poll_att_direction(self): # polling_cycle = float(self._get_field("direction", "polling_cycle")) # if polling_cycle < 0: # return - # if (time.perf_counter() - self.polling_ref["direction"]) > polling_cycle: + # if (time.perf_counter() - self.__polling_cycle) > polling_cycle: # p = False - # p = await self._update_attribute("direction", "pull", self._PZA_DRV_DIO_get_direction_pull(), False) or p - # p = await self._update_attribute("direction", "value", self._PZA_DRV_DIO_get_direction_value(), False) or p + # p = await self._update_attribute("direction", "pull", await self._PZA_DRV_DIO_get_direction_pull(), False) or p + # p = await self._update_attribute("direction", "value", await self._PZA_DRV_DIO_get_direction_value(), False) or p + # if p: - # self._push_attribute("direction") - # self.polling_ref["direction"] = time.perf_counter() + # await self._push_attribute("direction") + # self.__polling_cycle = time.perf_counter() + - - - -