winIDEA SDK
ws_cfg.py
1# This script is licensed under BSD License, see file LICENSE.txt.
2#
3# (c) TASKING Germany GmbH, 2023
4
5import isystem.connect as ic
6import os
7
8class WorkspaceConfigurator():
9 def __init__(self, cmgr: ic.ConnectionMgr):
10 self.cmgr = cmgr
11 self.wsCtrl = ic.CWorkspaceController(cmgr)
12 self.configCtrl = ic.CConfigurationController(cmgr)
13
14 def create_workspace(self, workspaceFileName: str, workspaceDir:str = None):
15 """
16 Creates a new workspace.
17 @param workspaceFileName: Name for the created workspace.
18 @param workspaceDir: Directory where the new workspace gets generated.
19 """
20 # Create Workspace Controller instance
21 if workspaceDir is None:
22 workspaceDir = os.getcwd()
23 wsPath=os.path.join(workspaceDir, workspaceFileName)
24
25 # Create a new workspace
26 self.wsCtrl.newWS(wsPath)
27 self.wsCtrl.save()
28
29 def save_workspace(self):
30 """
31 Saves the workspace.
32 """
33 self.wsCtrl.save()
34
35 def close_workspace(self):
36 """
37 Closes the workspace.
38 """
39 self.wsCtrl.close()
40
41
42 def set_emulator_type(self, Type: str):
43 """
44 Sets the emulator type used.
45 @param Type: Type of emulator used.
46 Options available are iC5000, iC5500, iC5700, iC6000 and XCP
47 """
48 # Create hardware option controller instance
49 optHardware = ic.COptionController(self.cmgr, '/iOPEN/Hardware')
50
51 # Set the emulator used.
52 optHardware.set('Emulator', Type)
53
54 def set_USB_comm(self, device: str = ''):
55 """
56 Sets the emulator to use USB connection.
57 @param device: USB device name composed from emulator type and the
58 emulator serial number. Used when there are more than 1 emulator
59 connected to your PC, otherwise it can remain empty.
60 More information: https://www.isystem.com/downloads/winIDEA/help/winidea-configuration-communication-type.html
61 """
62 optCommunication = ic.COptionController(self.cmgr, '/iOPEN/Communication')
63 inParams = {}
64 inParams['Mode'] = 'USB'
65 inParams['USBDeviceName'] = device
66
67 # Set the communication options.
68 optCommunication.set_multi(inParams)
69
70
71 def set_TCP_comm(self, IP: str, port: str, useGlobalDiscoveryPort: bool=True):
72 """
73 Sets the emulator to use TCP connection.
74 @param port: Selects which TCP port to use.
75 @param ipAddress: Device description. This option can be host name,
76 device ip address or 'localhost'.
77 More information: https://www.isystem.com/downloads/winIDEA/help/winidea-configuration-communication-type.html
78 @param useGlobalDiscoveryPort: Switches on or off global discovery port.
79 This parameter is used for emulator discovery on the network.
80 """
81
82 # Create communication option controller instance
83 optCommunication = ic.COptionController(self.cmgr, '/iOPEN/Communication')
84
85 # For TCP
86 inParams = {}
87
88 inParams['Mode'] = 'TCP'
89 inParams['TCPPortNumber'] = port
90 inParams['IPAddress'] = IP
91 if useGlobalDiscoveryPort:
92 inParams['IPUseGlobalDiscoveryPort'] = 'true'
93 else:
94 inParams['IPUseGlobalDiscoveryPort'] = 'false'
95
96 # Set the communication options.
97 optCommunication.set_multi(inParams)
98
99 def set_SoC(self, name: str):
100 """
101 Selects which target is connected.
102 @param name: Name of the target device. List of devices is available
103 in the device drop down menu: https://www.isystem.com/downloads/winIDEA/help/advanced-soc-configuration.html.
104 """
105 # Create a option controller instance for SoC using the configuration controller.
106 # MCU is the default SoC[0] name.
107 optSoC = self.configCtrl.ide_SoC('MCU')
108 # Select the target device used
109 optSoC.set('SFRName', name)
110
111 def add_application(self, name: str):
112 """
113 Adds a new application.
114 @param name: Name of the created application.
115 """
116 # Create new application
117 optApps = self.configCtrl.ide_apps()
118 optApp = optApps.add()
119
120 # Set application name
121 optApp.set('Name', name)
122
123
124 def add_symbol_file(self, appName: str, path: str, Type: str):
125 """
126 Adds a symbol file to the application.
127 @param appName: Name of the application to which the symbol file is added.
128 @param path: Path to the symbol file.
129 @param Type: Type of the symbol file.
130 Options available are BIN, ELF, HEX, OMF51,
131 25(OFM2 251/MX51), SIT(SLO text), TMSCOFF, UBROF and S37.
132 """
133 optApps = self.configCtrl.ide_apps()
134 appIndex = optApps.index_of("Name", appName)
135 optApp = optApps.at(appIndex)
136
137 # Create a new SymbolsFile instance for the application
138 optSymbolFile = optApp.opt('SymbolFiles.File').add()
139
140 # Set the symbol file path
141 optSymbolFile.set('Path', path)
142
143 # Set the symbol file type to ELF
144 optSymbolFile.set('Options.Type', Type)
145
146
147 def add_memory_space(self, name: str, coreName: str, appName: str,
148 isEnabled: bool = True, useMsid: bool = False, msidLevel: str = ''):
149 """
150 Adds a new memory space.
151 @param name: Name for the created memory space.
152 @param coreName: Name of the core which is associated with
153 the created memory space.
154 @param appName: Name of the application which
155 is associated with the created memory space.
156 @param isEnabled: Selects if the memory space is enabled.
157 @param useMsid: Selects if MSID is used.
158 @param msidLevel: Selects which MSID level is used.
159
160 """
161 # Create memory space Option controller instance
162 optSoC = self.configCtrl.ide_SoC('MCU')
163 optMemSpace = optSoC.opt("MemorySpaces")
164
165 # Add a new memory space
166 optMyMemSpace = optMemSpace.add()
167
168 # Configure the memory space
169 inParams = {}
170 if isEnabled:
171 inParams['Enabled'] = 'true' # Enable the memory space
172 else:
173 inParams['Enabled'] = 'false' # Enable the memory space
174 inParams['UserName'] = name # Name for this memory space
175 inParams['Cores'] = coreName # CPU core associated to this memory space
176 inParams['Application'] = appName # Application associated to this core
177
178 # Enable MSID
179 if useMsid:
180 inParams['MSID.Use'] = 'true'
181 inParams['MSID.Level'] = msidLevel
182 else:
183 inParams['MSID.Use'] = 'false'
184
185 # Set the memory space parameters
186 optMyMemSpace.set_multi(inParams)
187
188 def add_program_file(self, path: str, Type: str,
189 offset: int = 0):
190 """
191 Adds a program file.
192 @param path: Path of the program file.
193 @param programFileType: Type of the program file.
194 Options available are BIN, ELF, HEX and S37.
195 @param offset: Download offset of the program file.
196 """
197 optSoC = self.configCtrl.ide_SoC('MCU')
198 optProgFile = optSoC.opt("DLFs_Program.File")
199 optProgFile = optProgFile.add()
200
201 inParams = {}
202 inParams['Path'] = path
203 inParams['Options.Type'] = Type
204 inParams['Options.CodeOffset'] = str(offset)
205
206 optProgFile.set_multi(inParams)
207
208 def set_demo_mode(self, isDemoModeOn: bool):
209 """
210 Enables demo mode for winIDEA.
211 @param cmgr: ConnectionMgr instance.
212 @param isDemoModeOn: Enables or disables demo mode.
213 """
214
215 ideCtrl = ic.CIDEController(self.cmgr)
216 params = ic.StrStrMap()
217 if isDemoModeOn:
218 params["Demo"] = "TRUE"
219 ideCtrl.invoke("/IDE/Demo", params)
220 else:
221 params["Demo"] = "FALSE"
222 ideCtrl.invoke("/IDE/Demo", params)
223
224
225 def create_analyzer_trigger(self, profilerCtrl: ic.CProfilerController2, triggerName: str) -> int:
226 """
227 Creates a new Analyzer trigger and returns index.
228 @param profilerCtrl: Profiler controller instance.
229 @param triggerName: Trigger name
230 """
231 # Remove all existing triggers with triggerName
232 profilerCtrl.removeTrigger(triggerName)
233
234 # Create and use new trigger
235 triggerIdx = profilerCtrl.createTrigger(triggerName)
236 profilerCtrl.select(triggerIdx)
237 return triggerIdx
238
239 def remove_existing_process_triggers(self, optProcessTrigger: ic.COptionController):
240 """
241 Removes all existing process triggers.
242 @param optProcessTrigger: Process trigger option controller instance.
243 """
244 while optProcessTrigger.size():
245 optProcessTrigger.remove(0)
246
247 def add_new_process_trigger(self, optProcessTrigger: ic.COptionController, appName: str,
248 memorySpaceName: str) -> ic.COptionController:
249 """
250 Adds a new process trigger.
251 @param optProcessTrigger: Process trigger option controller instance.
252 @param appName: Name of the application.
253 @param MemorySpaceName: Name of the memory space.
254 """
255 optProcessTriggerInstance = optProcessTrigger.add()
256 optProcessTriggerInstance.set('ProcessURL', appName + '/' + memorySpaceName)
257 return optProcessTriggerInstance
258
259 def add_new_profiler_data_area(self, optProfilerData: ic.COptionController, variableName: str,
260 appName: str, memorySpaceName: str, interpretationType: str, accessType: str):
261 """
262 Adds a new profiler data area.
263 @param optProfilerData: Profiler data option controller instance.
264 @param variableName: Name of the variable to profile.
265 @param interpretationType: Profiler data interpretation type.
266 Available types are State, Function, Regular and Sampling.
267 @param accessType: Type of data access.
268 Available types are Write, Read and WriteAndRead.
269 """
270 # Add a new profiler data area
271 optProfilerDataArea = optProfilerData.add()
272
273 # Configure the new data area
274 inParams = {}
275 inParams['Name'] = f'{variableName},,,{appName}/{memorySpaceName}'
276 inParams['Type'] = interpretationType
277 inParams['DataType'] = 'Variable'
278 inParams['AccessType'] = accessType
279
280 optProfilerDataArea.set_multi(inParams)