winIDEA SDK
Loading...
Searching...
No Matches
test_soc_ctrl_bus_access_batch.py
# This script is licensed under BSD License, see file LICENSE.txt, or search for `License` in the SDK online help.
#
# (c) TASKING Germany GmbH, 2023
import isystem.connect as ic
winidea_id = ''
def test_soc_ctrl_bus_access_batch():
conn_mgr = ic.ConnectionMgr()
conn_mgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
sess_ctrl = ic.CSessionCtrl(conn_mgr)
sess_ctrl.begin_reset()
soc = sess_ctrl.get_SoC('')
access_batch = ic.CAccessBatch()
#! [accessbatch-base-snippet]
base_ai = ic.SAddressInfo()
base_ai.dest_bus(bus_index=0) # Destination is bus at index 0
base_ai.address(address=0xE0000000) # Base address is 0xE000'0000
access_batch.set_base(base_ai) # Set base address info for future accesses
#! [accessbatch-base-snippet]
write_data = ic.ByteVector([1, 2, 3, 4])
handle_write = access_batch.write(offset=0x04, data=write_data) # Add write to offset 0x4 from base_ai to queue
#! [accessbatch-write-snippet]
# Queue memory write based on custom address info
#! [accessbatch-write_a-snippet]
custom_ai = ic.SAddressInfo()
custom_ai.dest_bus(bus_index=0) # Destination is bus at index 0
custom_ai.address(address=0x80000004) # Address is 0x8000'0004
write_data = ic.ByteVector([1, 2, 3, 4])
# Add write to address 0x8000'0004 to queue
handle_write_a = access_batch.write_a(address_info=custom_ai, data=write_data)
#! [accessbatch-write_a-snippet]
# Queue memory write with code store
#! [accessbatch-write_CS_a-snippet]
cs_ai = ic.SAddressInfo()
cs_ai.dest_bus(bus_index=0) # Destination is bus at index 0
cs_ai.address(address=0x80000004) # Address is 0x8000'0004
code_store = ic.CCodeStore(conn_mgr)
code_store.insert(0x000, ic.ByteVector([0x01, 0x02, 0x03, 0x04])) # Write 4 bytes at offset 0x000
code_store.insert(0x100, ic.ByteVector([0x7E, 0x57, 0xDA, 0x7A])) # Write 4 bytes at offset 0x100
# Add write to address 0x8000'0004 to queue
handle_write_cs_a = access_batch.write_CS_a(address_info=cs_ai,
code_store=code_store)
#! [accessbatch-write_CS_a-snippet]
handle_read = access_batch.read(offset=0x04, num_MAUs=4) # Add read from offset 0x4 from base_ai to queue
#! [accessbatch-read-snippet]
# Queue memory read based on custom address info
#! [accessbatch-read_a-snippet]
custom_ai = ic.SAddressInfo()
custom_ai.dest_bus(bus_index=0) # Destination is bus at index 0
custom_ai.address(address=0x80000004) # Address is 0x8000'0004
handle_read_a = access_batch.read_a(address_info=custom_ai, num_MAUs=4) # Add read from address 0x8000'0004 to queue
#! [accessbatch-read_a-snippet]
data = ic.ByteVector([0x10, 0x22, 0x33, 0xAB]) # Data to be compared
mask = ic.ByteVector([0xFF, 0xF0, 0xFF, 0xFC]) # Mask to be applied when comparing data
handle_poll = access_batch.poll(offset=0x04, # Add test on offset 0x4 from base_ai with timeout 100 us to queue
data=data,
mask=mask,
timeout_us=100)
#! [accessbatch-poll-snippet]
# Queue memory test (poll) based on custom address info
#! [accessbatch-poll_a-snippet]
custom_ai = ic.SAddressInfo()
custom_ai.dest_bus(bus_index=0) # Destination is bus at index 0
custom_ai.address(address=0x80000004) # Address is 0x8000'0004
data = ic.ByteVector([0x10, 0x22, 0x33, 0xAB]) # Data to be compared
mask = ic.ByteVector([0xFF, 0xF0, 0xFF, 0xFC]) # Mask to be applied when comparing data
handle_poll_a = access_batch.poll_a(address_info=custom_ai, # Add test on offset 0x4 from base_ai with
data=data, # timeout 100 us to queue
mask=mask,
timeout_us=100)
#! [accessbatch-poll_a-snippet]
data = ic.ByteVector([0xCC]) # Data used for filling
handle_fill = access_batch.fill(offset=0x04, # Add fill on offset 0x4 from base_ai with size 0x100 to queue
num_MAUs=0x100,
data=data)
#! [accessbatch-fill-snippet]
# Queue memory fill based on custom address info
#! [accessbatch-fill_a-snippet]
custom_ai = ic.SAddressInfo()
custom_ai.dest_bus(bus_index=0) # Destination is bus at index 0
custom_ai.address(address=0x80000004) # Address is 0x8000'0004
handle_fill_a = access_batch.fill_a(address_info=custom_ai, # Add test on offset 0x4 from base_ai with
num_MAUs=0x100, # with size 0x100 to queue
data=data)
#! [accessbatch-fill_a-snippet]
handle_ftrig = access_batch.ftrig(n_trig=5) # Add generating of FNet trigger #5 to queue
#! [accessbatch-ftrig-snippet]
result = soc.access_batch(access_batch) # Execute batch access
if result == ic.CAccessBatch.EAccessBatchResult_OK: # Check if batch access was successful
print('Access batch OK')
else:
print(f'Access batch failed with error: {result}')
#! [accessbatch-execute-snippet]
# Dump results
#! [accessbatch-item-time-snippet]
item = access_batch.item(handle_write) # Retrieve item by handle
print('Time: ' + str(item.time_us)) # Print out item timestamp in us
#! [accessbatch-item-time-snippet]
#! [accessbatch-item-data-snippet]
item = access_batch.item(handle_read) # Retrieve item by handle
data_str = '0x' # Construct string containing all data bytes
for data_byte in item.data:
data_str += f'{data_byte:02X}'
print('Data: ' + data_str) # Print data in human-readable format
#! [accessbatch-item-data-snippet]
#! [accessbatch-item-access_info-snippet]
item = access_batch.item(handle_read) # Retrieve item by handle
for access_info_index in range(len(item.access_info)): # Print for each MAU if access failed or not
if item.access_info[access_info_index] == ic.ACCESS_FAIL:
print(f'Access to MAU at index {access_info_index} failed')
else:
print(f'Access to MAU at index {access_info_index} OK')
#! [accessbatch-item-access_info-snippet]
#! [accessbatch-item-poll_duration-snippet]
item = access_batch.item(handle_poll) # Retrieve item by handle
print('Poll duration: ' + str(item.poll_duration_us)) # Print out poll item duration in us
#! [accessbatch-item-poll_duration-snippet]
#! [accessbatch-item-access_duration-snippet]
item = access_batch.item(handle_read) # Retrieve item by handle
print('Read duration: ' + str(item.memory_access_duration)) # Print out memory access duration in us
#! [accessbatch-item-access_duration-snippet]
pass
if __name__ == '__main__':
test_soc_ctrl_bus_access_batch()