winIDEA SDK
test_batch_access.py
1# This script is licensed under BSD License, see file LICENSE.txt.
2#
3# (c) TASKING Germany GmbH, 2023
4
5from typing import List
6import isystem.connect as ic
7
8
9winidea_id = ''
10
11
12def test_batchAccess():
13 connMgr = ic.ConnectionMgr()
14 connMgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
15
16 dataCtrl = ic.CDataController(connMgr)
17 dbgCtrl = ic.CDebugFacade(connMgr)
18
19 ACCESS_FLAG = ic.SBatchAccessHeader.flStopResume
20 SYMBOL_NAMES = ["main_loop_counter", "g_char"]
21 VALUES_TO_WRITE = [6, 42]
22 NUM_ITEMS = len(SYMBOL_NAMES)
23 NUM_RUNS = 3
24 INTERVAL_US = 50000
25
26 baHeader = ic.SBatchAccessHeader()
27 baItemsRead = ic.VectorBatchAccessItem()
28 baItemsWrite = ic.VectorBatchAccessItem()
29 baResults = ic.VectorBatchAccessResult(NUM_ITEMS * NUM_RUNS)
30
31 baHeader.m_dwFlags = ACCESS_FLAG
32 baHeader.m_dwNumItems = NUM_ITEMS
33 baHeader.m_dwNumRuns = NUM_RUNS
34 baHeader.m_qwRunInterval = INTERVAL_US
35
36 # Determine BA memory locations we are interested in
37 symbolsInfo: List[ic.CSymbolInfo] = []
38 for index, symName in enumerate(SYMBOL_NAMES):
39 symbolInfo = dbgCtrl.getSymbolInfo(ic.IConnectDebug.fRealTime, symName)
40 symbolsInfo.append(symbolInfo)
41
42 # prepare BA read items
43 item = ic.SBatchAccessItem()
44 item.m_byFlags = ic.SBatchAccessItem.flRead
45 item.m_bySize = symbolInfo.getSizeMAUs()
46 item.m_byMemArea = symbolInfo.getMemArea()
47 item.m_aAddress = symbolInfo.getAddress()
48 baItemsRead.push_back(item)
49
50 # prepare BA write items
51 item = ic.SBatchAccessItem()
52 item.m_byFlags = ic.SBatchAccessItem.flWrite
53 item.m_bySize = symbolInfo.getSizeMAUs()
54 item.m_byMemArea = symbolInfo.getMemArea()
55 item.m_aAddress = symbolInfo.getAddress()
56 # set item data (write) values
57 ic.CDataController.setByte(item.m_abyData, 0, VALUES_TO_WRITE[index])
58 ic.CDataController.setByte(item.m_abyData, 1, 0)
59 ic.CDataController.setByte(item.m_abyData, 2, 0)
60 ic.CDataController.setByte(item.m_abyData, 3, 0)
61 baItemsWrite.push_back(item)
62
63 print(f"Performing batch access write...")
64 # we are not interested in batch access timestamps, hence ignore `batchAccess` return value
65 dataCtrl.batchAccess(ACCESS_FLAG,
66 baHeader,
67 baItemsWrite,
68 baResults)
69 for index, baResult in enumerate(baResults):
70 baResult: ic.SBatchAccessItemResult
71 if baResult.m_byResult != ic.SBatchAccessItemResult.resOK:
72 print(f"WARNING: Batch write {index} failed!")
73
74 print(f"Performing batch access read...")
75 baResults = ic.VectorBatchAccessResult(NUM_ITEMS * NUM_RUNS)
76 dataCtrl.batchAccess(ACCESS_FLAG,
77 baHeader,
78 baItemsRead,
79 baResults)
80 for index, baResult in enumerate(baResults):
81 baResult: ic.SBatchAccessItemResult
82 if baResult.m_byResult != ic.SBatchAccessItemResult.resOK:
83 print(f"WARNING: Batch read {index} failed!")
84 else:
85 print(f"\tItem {index} ('{SYMBOL_NAMES[index % NUM_ITEMS]}): "
86 f"data: {ic.CDataController.getByte(baResult.m_abyData, 0)}")
87
88
89if __name__ == "__main__":
90 test_batchAccess()