15.9.1 Hooking device reset behavior

For a DSTREAM class device, the default operation for a System Reset request is to drive nSRST on the JTAG connector. On some platforms, this pin is not present on the JTAG connector, and so some other method must be used to perform the reset. Sometimes, the reset is performed by writing to some other system component, such as a System Reset Controller device. If this is not available, another approach is to cause a system watchdog timeout, which in turn causes a system reset. Whichever approach is taken, the default reset behavior must be modified.
The following code sequence is an example of this:
1. from com.arm.debug.dtsl.components import ConnectableDevice
2. [snip]
3. class ResetHookedDevice(ConnectableDevice):
4.     def __init__(self, root, devNo, name):
5.         ConnectableDevice.__init__(self, root, devNo, name)
6.         self.parent = root
8.     def systemReset(self, resetType):
9.         ConnectableDevice.systemReset(self, resetType)
10.        # Notify root configuration
11.        self.parent.postReset()
13. class DSTREAMDebugAndTrace(DTSLv1):
15.     '''A top level configuration class which supports debug and trace'''
17.  [snip]    
19.     def setupPinMUXForTrace(self):
20.         '''Sets up the IO Pin MUX to select 4 bit TPIU trace'''
21.         addrDBGMCU_CR = 0xE0042004
22.         value = self.readMem(addrDBGMCU_CR)
23.         value |=  0xE0 # TRACE_MODE=11 (4 bit port), TRACE_IOEN=1
24.         self.writeMem(addrDBGMCU_CR, value)
26.     def enableSystemTrace(self):
27.         '''Sets up the system to enable trace
28.            For a Cortex-M3 system we must make sure that the
29.            TRCENA bit (24) in the DEMCR registers is set.
30.            NOTE: This bit is normally set by the DSTREAM Cortex-M3
31.                  template - but we set it ourselves here in case
32.                  no one connects to the Cortex-M3 device.
33.         '''
34.         addrDEMCR = 0xE000EDFC
35.         bitTRCENA = 0x01000000
36.         value = self.readMem(addrDEMCR)
37.         value |= bitTRCENA
38.         self.writeMem(addrDEMCR, value)
40.     def postReset(self):
41.         '''Makes sure the debug configuration is re-instated
42.            following a reset event
43.         '''
44.         if self.getOptionValue("options.traceBuffer.traceCaptureDevice") == "DSTREAM":
45.             self.setupPinMUXForTrace()
46.         self.enableSystemTrace()
Line 3 declares a Jython class called ResetHookedDevice, which is derived from the standard DTSL Java Device class. The ConnectableDevice class implements the IDevice interface. One of the methods in the IDevice interface is systemReset():
 * Reset system
 * @param resetType
 *            one of the following values
 *            <ul>
 *              <li>{@link RDDI#RDDI_RST_PERFORM}</li>
 *              <li>{@link RDDI#RDDI_RST_ASSERT}</li>
 *              <li>{@link RDDI#RDDI_RST_DEASSERT}</li>
 *            </ul>
 * @throws DTSLException On error
public abstract void systemReset(int resetType) throws DTSLException;
The ResetHookedDevice class provides a new implementation for the systemReset method. If the DTSL configuration class gives DTSL an instance of the ResetHookedDevice class, instead of an instance of the ConnectableDevice class, then when DS-5 Debugger calls the systemReset method, the new method is called instead of the old one:
# create core
devID = self.findDevice("Cortex-M3")
self.cortexM3 = ResetHookedDevice(self, devID, "Cortex-M3")
The code sequence creates a ResetHookedDevice instance and gives it the name “Cortex-M3”. When the debugger asks DTSL for the “Cortex-M3” device, it gives it the ResetHookedDevice instance. This device was derived from Device, so it gets all the methods that the Device class implements, but the old systemReset method is replaced with the new one.
When deriving a new class from an existing one, you can replace as many of its IDevice methods as you want. Your new implementation of an IDevice method can call the existing implementation within the ConnectableDevice object by calling ConnectableDevice.<method-name>().
See the DTSL Java docs for full IDevice documentation.
The constructor for the ResetHookedDevice class stores a reference to the DTSL configuration which created it. When a reset is requested, it calls the existing ConnectableDevice reset code and tells the parent configuration that a reset has taken place. In this case, the configuration reconfigures the pin mux settings of the device to make sure that external trace is enabled.
Related concepts
15.5.2 DTSL device objects
Non-ConfidentialPDF file icon PDF versionARM DUI0446W
Copyright © 2010-2015 ARM. All rights reserved.