winIDEA SDK
Loading...
Searching...
No Matches
test_soc_ctrl_bus_access_batch.py
1# This script is licensed under BSD License, see file LICENSE.txt, or search for `License` in the SDK online help.
2#
3# (c) TASKING Germany GmbH, 2023
4
5import isystem.connect as ic
6
7
8winidea_id = ''
9
10def test_soc_ctrl_bus_access_batch():
11 conn_mgr = ic.ConnectionMgr()
12 conn_mgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
13
14 sess_ctrl = ic.CSessionCtrl(conn_mgr)
15 sess_ctrl.begin_reset()
16 soc = sess_ctrl.get_SoC('')
17
18 access_batch = ic.CAccessBatch()
19
20 #! [accessbatch-base-snippet]
21 base_ai = ic.SAddressInfo()
22 base_ai.dest_bus(bus_index=0) # Destination is bus at index 0
23 base_ai.address(address=0xE0000000) # Base address is 0xE000'0000
24 access_batch.set_base(base_ai) # Set base address info for future accesses
25 #! [accessbatch-base-snippet]
26
27
32 write_data = ic.ByteVector([1, 2, 3, 4])
33 handle_write = access_batch.write(offset=0x04, data=write_data) # Add write to offset 0x4 from base_ai to queue
34 #! [accessbatch-write-snippet]
35
36 # Queue memory write based on custom address info
37 #! [accessbatch-write_a-snippet]
38 custom_ai = ic.SAddressInfo()
39 custom_ai.dest_bus(bus_index=0) # Destination is bus at index 0
40 custom_ai.address(address=0x80000004) # Address is 0x8000'0004
41 write_data = ic.ByteVector([1, 2, 3, 4])
42 # Add write to address 0x8000'0004 to queue
43 handle_write_a = access_batch.write_a(address_info=custom_ai, data=write_data)
44 #! [accessbatch-write_a-snippet]
45
46 # Queue memory write with code store
47 #! [accessbatch-write_CS_a-snippet]
48 cs_ai = ic.SAddressInfo()
49 cs_ai.dest_bus(bus_index=0) # Destination is bus at index 0
50 cs_ai.address(address=0x80000004) # Address is 0x8000'0004
51 code_store = ic.CCodeStore(conn_mgr)
52 code_store.insert(0x000, ic.ByteVector([0x01, 0x02, 0x03, 0x04])) # Write 4 bytes at offset 0x000
53 code_store.insert(0x100, ic.ByteVector([0x7E, 0x57, 0xDA, 0x7A])) # Write 4 bytes at offset 0x100
54 # Add write to address 0x8000'0004 to queue
55 handle_write_cs_a = access_batch.write_CS_a(address_info=cs_ai,
56 code_store=code_store)
57 #! [accessbatch-write_CS_a-snippet]
58
59
64 handle_read = access_batch.read(offset=0x04, num_MAUs=4) # Add read from offset 0x4 from base_ai to queue
65 #! [accessbatch-read-snippet]
66
67 # Queue memory read based on custom address info
68 #! [accessbatch-read_a-snippet]
69 custom_ai = ic.SAddressInfo()
70 custom_ai.dest_bus(bus_index=0) # Destination is bus at index 0
71 custom_ai.address(address=0x80000004) # Address is 0x8000'0004
72 handle_read_a = access_batch.read_a(address_info=custom_ai, num_MAUs=4) # Add read from address 0x8000'0004 to queue
73 #! [accessbatch-read_a-snippet]
74
75
80 data = ic.ByteVector([0x10, 0x22, 0x33, 0xAB]) # Data to be compared
81 mask = ic.ByteVector([0xFF, 0xF0, 0xFF, 0xFC]) # Mask to be applied when comparing data
82 handle_poll = access_batch.poll(offset=0x04, # Add test on offset 0x4 from base_ai with timeout 100 us to queue
83 data=data,
84 mask=mask,
85 timeout_us=100)
86 #! [accessbatch-poll-snippet]
87
88 # Queue memory test (poll) based on custom address info
89 #! [accessbatch-poll_a-snippet]
90 custom_ai = ic.SAddressInfo()
91 custom_ai.dest_bus(bus_index=0) # Destination is bus at index 0
92 custom_ai.address(address=0x80000004) # Address is 0x8000'0004
93 data = ic.ByteVector([0x10, 0x22, 0x33, 0xAB]) # Data to be compared
94 mask = ic.ByteVector([0xFF, 0xF0, 0xFF, 0xFC]) # Mask to be applied when comparing data
95 handle_poll_a = access_batch.poll_a(address_info=custom_ai, # Add test on offset 0x4 from base_ai with
96 data=data, # timeout 100 us to queue
97 mask=mask,
98 timeout_us=100)
99 #! [accessbatch-poll_a-snippet]
100
101
106 data = ic.ByteVector([0xCC]) # Data used for filling
107 handle_fill = access_batch.fill(offset=0x04, # Add fill on offset 0x4 from base_ai with size 0x100 to queue
108 num_MAUs=0x100,
109 data=data)
110 #! [accessbatch-fill-snippet]
111
112 # Queue memory fill based on custom address info
113 #! [accessbatch-fill_a-snippet]
114 custom_ai = ic.SAddressInfo()
115 custom_ai.dest_bus(bus_index=0) # Destination is bus at index 0
116 custom_ai.address(address=0x80000004) # Address is 0x8000'0004
117 handle_fill_a = access_batch.fill_a(address_info=custom_ai, # Add test on offset 0x4 from base_ai with
118 num_MAUs=0x100, # with size 0x100 to queue
119 data=data)
120 #! [accessbatch-fill_a-snippet]
121
122
127 handle_ftrig = access_batch.ftrig(n_trig=5) # Add generating of FNet trigger #5 to queue
128 #! [accessbatch-ftrig-snippet]
129
130
134 result = soc.access_batch(access_batch)
135 #! [accessbatch-execute-snippet]
136
137 # Dump results
138 #! [accessbatch-item-time-snippet]
139 item = access_batch.item(handle_write) # Retrieve item by handle
140 print('Time: ' + str(item.time_us)) # Print out item timestamp in us
141 #! [accessbatch-item-time-snippet]
142 #! [accessbatch-item-data-snippet]
143 item = access_batch.item(handle_read) # Retrieve item by handle
144 data_str = '0x' # Construct string containing all data bytes
145 for data_byte in item.data:
146 data_str += f'{data_byte:02X}'
147 print('Data: ' + data_str) # Print data in human-readable format
148 #! [accessbatch-item-data-snippet]
149 #! [accessbatch-item-access_info-snippet]
150 item = access_batch.item(handle_read) # Retrieve item by handle
151 for access_info_index in range(len(item.access_info)): # Print for each MAU if access failed or not
152 if item.access_info[access_info_index] == ic.ACCESS_FAIL:
153 print(f'Access to MAU at index {access_info_index} failed')
154 else:
155 print(f'Access to MAU at index {access_info_index} OK')
156 #! [accessbatch-item-access_info-snippet]
157 #! [accessbatch-item-poll_duration-snippet]
158 item = access_batch.item(handle_poll) # Retrieve item by handle
159 print('Poll duration: ' + str(item.poll_duration_us)) # Print out poll item duration in us
160 #! [accessbatch-item-poll_duration-snippet]
161
162 pass
163
164
165if __name__ == '__main__':
166 test_soc_ctrl_bus_access_batch()