Skip to content

Commit

Permalink
boundary scan without polling task
Browse files Browse the repository at this point in the history
  • Loading branch information
Rethusan committed Jul 17, 2023
1 parent 30dc1d3 commit 2dd7679
Show file tree
Hide file tree
Showing 10 changed files with 480 additions and 127 deletions.
8 changes: 4 additions & 4 deletions platform/panduza_platform/connectors/boundary_scan_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ class ConnectorBoundaryScanBase(metaclass=abc.ABCMeta):
"""

@abc.abstractmethod
async def read_number_of_devices(self):
async def async_read_number_of_devices(self):
"""
"""
pass

@abc.abstractmethod
async def get_idcodes(self):
async def async_get_idcodes(self):
"""
"""
pass

@abc.abstractmethod
async def read_pin(self, device_number, pin, direction):
async def async_read_pin(self, device_number, pin, direction):
"""
"""
pass

@abc.abstractmethod
async def write_pin(self, device_number, pin, value):
async def async_write_pin(self, device_number, pin, value):
"""
"""
pass
151 changes: 50 additions & 101 deletions platform/panduza_platform/connectors/boundary_scan_ftdi.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import asyncio
import concurrent.futures
import os
import threading

from .boundary_scan_base import ConnectorBoundaryScanBase
from panduza_platform.extlibs.bsdl import bsdl,bsdlJson
from panduza_platform.extlibs.bsdl import bsdl,bsdlJson,read_bsdlJson_files
from panduza_platform.log.driver import driver_logger

from pyftdi.ftdi import Ftdi
Expand Down Expand Up @@ -41,31 +41,6 @@ def get_bit_settings(bit_state_dict, boundary_reg):
return BitSequence(byte_array)


def get_bsdl_file(bsdl_folder):
list_bsdl_files = os.listdir(bsdl_folder)
bsdl_file_directory = []
bsdl_file = []
for i in range(len(list_bsdl_files)):
bsdl_file_directory.append(os.path.join(bsdl_folder,list_bsdl_files[i]))
f = open(bsdl_file_directory[i],"r")
bsdl_file.append(f.read())

return bsdl_file

def get_idcode_from_bsdl(bsdl_folder):
parser = bsdl.bsdlParser()
list_bsdl_files = os.listdir(bsdl_folder)
bsdl_file = get_bsdl_file(bsdl_folder)

idcode_bsdl= []

for i in range(len(list_bsdl_files)):
json = parser.parse(bsdl_file[i], "bsdl_description", semantics=BsdlSemantics(), parseinfo=False).asjson()
json_bsdl = bsdlJson.BsdlJson(json)

idcode_bsdl.append(json_bsdl.idcode)

return idcode_bsdl

###########################################################################
###########################################################################
Expand Down Expand Up @@ -117,18 +92,22 @@ async def Get(**kwargs):


if "usb_vendor" in kwargs:
usb_vendor = kwargs["usb_vendor"]
elif "usb_model" in kwargs:
usb_vendor = kwargs["usb_vendor"]

if "usb_model" in kwargs:
usb_model = kwargs["usb_model"]
elif "usb_serial_short" in kwargs:
usb_serial_short = kwargs["usb_serial_short"]
elif "jtag_frequency" in kwargs:

if "usb_serial_short" in kwargs:
usb_serial_short = kwargs["usb_serial_short"]

if "jtag_frequency" in kwargs:
jtag_frequency = kwargs["jtag_frequency"]
elif "jtag_bsdl_folder" in kwargs:

if "jtag_bsdl_folder" in kwargs:
jtag_bsdl_folder = kwargs["jtag_bsdl_folder"]

else:
raise Exception("no way to identify the informations given in tre tree.json")
raise Exception("no way to identify the informations given in the tree.json")

instance_name = str(f"{usb_vendor}_{usb_model}_{usb_serial_short}")

Expand Down Expand Up @@ -167,9 +146,7 @@ def __init__(self,**kwargs):

parser = bsdl.bsdlParser()

# Init thread
self.executor = concurrent.futures.ThreadPoolExecutor() ####################### it doesn't work


# Get parameters
usb_vendor = kwargs.get('usb_vendor', "0403")
usb_model = kwargs.get('usb_model', "6014")
Expand All @@ -182,25 +159,23 @@ def __init__(self,**kwargs):
self.engine.reset()

# Get idcodes
idcode_bsdl = get_idcode_from_bsdl(jtag_bsdl_folder)
idcode_bsdl = read_bsdlJson_files.get_idcode_from_bsdl(jtag_bsdl_folder)
idcode_detected = self.idcode() # retrieve the idcodes in order and store them in a dictionnary (key = device_number ; value = idcode)

# Get number of devices
self.total_devices = self.scan()

# Get bsdl files
bsdl_file = get_bsdl_file(jtag_bsdl_folder)
bsdl_file = read_bsdlJson_files.get_bsdl_file(jtag_bsdl_folder)

# list of idcode
idcode = []
# list for idcode without version number
idcode_modified = []

# Dictionnary for BSDL files
self.bsdl_dict = {}

# Remove the first 4 bits of the idcodes (= idcode without 4-bit version number)
for n in range (len(idcode_detected)):
idcode.append(idcode_detected[n])
idcode_modified.append(hex(int(idcode_detected[n][-7:],16)))

# Store the correct bsdl files in order
Expand Down Expand Up @@ -259,81 +234,61 @@ def __init__(self,**kwargs):
###########################################################################


async def read_number_of_devices(self):
async def async_read_number_of_devices(self):
"""
function that returns the number of devices detected in the jtag chain
"""
async with self._mutex:
result = await self.run_async_function(self.scan)
return result

with concurrent.futures.ThreadPoolExecutor() as executor:
# Submit the scan function to the executor
future = executor.submit(self.scan)

# Wait for the future to complete
while not future.done():
await asyncio.sleep(0.1)
print("Waiting for the thread scan to complete...")

# Retrieve the result from the future
result = future.result()
print("Result:", result)



async def get_idcodes(self):
async def async_get_idcodes(self):
"""
function that returns the differnts idcodes of devices in order in the jtag chain
"""
async with self._mutex:

result = await self.run_async_function(self.idcode)
return result

with concurrent.futures.ThreadPoolExecutor() as executor:
# Submit the idcode function to the executor
future = executor.submit(self.idcode)

# Wait for the future to complete
while not future.done():
await asyncio.sleep(0.1)
print("Waiting for the thread idcode to complete...")

# Retrieve the result from the future
result = future.result()
print("Result:", result)


async def read_pin(self, device_number, pin, direction):
"""
async def async_read_pin(self, device_number, pin, direction):
"""
async with self._mutex:
with concurrent.futures.ThreadPoolExecutor() as executor:
# Submit the read function to the executor
future = executor.submit(self.read,device_number, pin, direction)

# Wait for the future to complete
while not future.done():
await asyncio.sleep(0.1)
print("Waiting for the thread read to complete...")

# Retrieve the result from the future
result = future.result()
print("Result:", result)
function that reads the state of a pin
"""
result = await self.run_async_function(self.read,device_number, pin, direction)
return result



async def write_pin(self, device_number, pin, value):
async def async_write_pin(self, device_number, pin, value):
"""
function that writes on a pin
"""
result = await self.run_async_function(self.write,device_number,pin,value)
return result



async def run_async_function(self,function,*args):
async with self._mutex:
with concurrent.futures.ThreadPoolExecutor() as executor:
# Submit the write function to the executor
future = executor.submit(self.write,device_number, pin, value)
# Submit the function to the executor
future = executor.submit(function, *args)

# Wait for the future to complete
while not future.done():
await asyncio.sleep(0.1)
print("Waiting for the thread write 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





###########################################################################
###########################################################################
Expand Down Expand Up @@ -377,22 +332,18 @@ def read(self,device_number,pin,direction):
global bit_settings

boundary_scan = self.sample(device_number)
#print(boundary_scan)
for bit in range(0, self.boundary_length[device_number]):
cell = self.json_bsdl[device_number].boundary_register[str(bit)]
cell_spec = cell["cell_spec"]
if cell_spec["port_id"] == pin:
if direction == "in" and cell_spec["function"].upper() == "INPUT":

byte_array_scan = list(boundary_scan)
#print(byte_array_scan)

if byte_array_scan[bit] == 1 :
#print(pin + " (input) is turn on ")
self.extest(bit_settings,device_number)
return True
else :
#print(pin + " (input) is turn off")
self.extest(bit_settings,device_number)
return False

Expand All @@ -403,11 +354,9 @@ def read(self,device_number,pin,direction):
byte_array = list(bit_settings)

if byte_array[bit] == 1 :
#print(pin + " (output) is turn on")
self.extest(bit_settings,device_number)
return True
else :
#print(pin + " (output) is turn off")
self.extest(bit_settings,device_number)
return False

Expand Down Expand Up @@ -458,7 +407,7 @@ def check_device(self,device_number):


def sample(self,device_number):
"""fonction qui permet d'effectuer le BoundaryScan et qui renvoi le bitstream"""
"""function that performs the BoundaryScan and returns the bitstream"""

instruction = self.instruction(device_number,"sample")
self.engine.capture_ir()
Expand All @@ -475,7 +424,7 @@ def sample(self,device_number):
return bit_sequence

def extest(self,bit_settings,device_number):
""" fonction qui permet d'effectuer le BoundaryScan et d'écrire sur les registres """
""" function that performs the BoundaryScan and writes to the registers """

instruction = self.instruction(device_number,"extest")
self.engine.capture_ir()
Expand Down
4 changes: 3 additions & 1 deletion platform/panduza_platform/devices/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from .hanmatek import PZA_DEVICES_LIST as HANMATEK_DEVICES
from .panduza import PZA_DEVICES_LIST as PANDUZA_DEVICES
from .ftdi import PZA_DEVICES_LIST as FTDI_DEVICES

PZA_DEVICES_LIST = [] \
+ HANMATEK_DEVICES \
+ PANDUZA_DEVICES
+ PANDUZA_DEVICES \
+ FTDI_DEVICES
5 changes: 5 additions & 0 deletions platform/panduza_platform/devices/ftdi/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .ft232h_jtag import DeviceFtdiFt232h_jtag

PZA_DEVICES_LIST= [
DeviceFtdiFt232h_jtag
]
Loading

0 comments on commit 2dd7679

Please sign in to comment.