15.6.6 Option change notification example walk-through

These Jython code snippets are from the Keil MCBSTM32E platform Jython script and the DSTREAMDebugAndTrace class:
1.     def optionValuesChanged(self):
2.         '''Callback to update the configuration state after options are changed.
3.            This will be called:
4.               * after construction but before device connection
5.               * during a debug session should the user change the DTSL options
6.         '''
7.         obase = "options"
8.         if self.isConnected():
9.             self.updateDynamicOptions(obase)
10.        else:
11.            self.setInitialOptions(obase)
Line 1 declares the optionValuesChanged method, which is called to tell the DTSL components that the options have changed. Line 7 assigns the top level options name path value. Lines 8 to 11 call one of two methods depending on whether the configuration is connected yet.
1.     def setInitialOptions(self, obase):
2.         '''Takes the configuration options and configures the
3.            DTSL objects prior to target connection
4.            Param: obase the option path string to top level options
5.         '''
6.         if self.traceDeviceIsDSTREAM(obase):
7.             self.setDSTREAMTraceEnabled(True)
8.             self.setDSTREAMOptions(obase+".traceBuffer")
9.             obaseETM = obase+".ETM"
10.            obaseITM = obase+".ITM"
11.            self.setETMEnabled(self.getOptionValue(
12.                                 obaseETM+".cortexM3coreTraceEnabled"))
13.            self.reservedATBIDs = {}
14.            self.setITMEnabled(self.getOptionValue(obaseITM+".itmTraceEnabled"))
15.            obaseITMOwner = obaseITM+".itmTraceEnabled.itmowner"
16.            if self.debuggerOwnsITM(obaseITMOwner):
17.                self.setITMOwnedByDebugger(True);
18.                self.setITMOptions(obaseITMOwner+".debugger")
19.            else:
20.                self.setITMOwnedByDebugger(False);
21.                self.reservedATBIDs["ITM"] =
22.                self.getOptionValue(obaseITMOwner+".target.targetITMATBID")
23.            self.updateATBIDAssignments()
24.        else:
25.            self.setDSTREAMTraceEnabled(False)
26.            self.setETMEnabled(False)
27.            self.setITMEnabled(False)
In this code example, note the following:
For completeness, the following shows the dynamic option update method:
1.     def updateDynamicOptions(self, obase):
2.         '''Takes any changes to the dynamic options and
3.            applies them. Note that some trace options may
4.            not take effect until trace is (re)started
5.            Param: obase the option path string to top level options
6.         '''
7.         if self.traceDeviceIsDSTREAM(obase):
8.             obaseETM = obase+".ETM"
9.             self.setETMEnabled(self.getOptionValue(
10.                obaseETM+".cortexM3coreTraceEnabled"))
11.            obaseITM = obase+".ITM"
12.            if self.getOptionValue(obaseITM+".itmTraceEnabled"):
13.                self.setITMEnabled(True)
14.                obaseITMOwner = obaseITM+".itmTraceEnabled.itmowner"
15.                if self.debuggerOwnsITM(obaseITMOwner):
16.                    self.setITMOptions(obaseITMOwner+".debugger")
17.            else:
18.                self.setITMEnabled(False)
For the dynamic option changes, only the options marked as dynamic need inspecting.

Note

The option values are passed on to the corresponding DTSL objects, but the option changes might not be applied immediately. In many cases, the change only applies when execution or trace is next started. Whether the option change is applied immediately is determined by the implementation of the DTSL object.
Non-ConfidentialPDF file icon PDF versionARM DUI0446W
Copyright © 2010-2015 ARM. All rights reserved.