The target interface system uses CrossStudio's JavaScript (ECMAScript) interpreter to support board and target specific behaviour. The main use for this is to support non-standard target and board reset schemes and also to configure the target after reset.

## Reset Script

The Reset Script property held in the Target Options project property group is used to define a script to execute to reset and configure the target. In order to reduce script duplication a file of type "Reset Script" can be placed in the project and used to specify a script file common to the target type. Items defined in this file can be referenced by the reset script.

The aim of the reset script is to get the processor into a known state. When the script has executed the processor should be reset, stopped on the first instruction and configured appropriately.

As an example, the following script demonstrates the reset script for an Evaluator 7T target board with a memory configuration that re-maps SRAM to start from 0x00000000. The Evaluator7T_Reset function carries out the standard ARM reset and stops the processor prior to executing the first instruction. The Evaluator7T_ResetWithRamAtZero function calls this reset function and then configures the target memory by accessing the configuration registers directly. See TargetInterface Object for a description of the TargetInterface object which is used by the reset script to access the target hardware.

> function Evaluator7T_Reset()
> {
> TargetInterface.setNSRST(0);
> TargetInterface.setICEBreakerBreakpoint(0, 0x00000000, 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x100, 0xF7);
> TargetInterface.setNSRST(1);
> TargetInterface.waitForDebugState(1000);
> TargetInterface.trst();
> }
> function Evaluator7T_ResetWithRamAtZero()
> {
> Evaluator7T_Reset();
> /***************************************************************************
> * Register settings for the following memory configuration: *
> * *
> * ---------------------- *
> * | ROMCON0 - 512K FLASH | 0x01800000 - 0x0187FFFF *
> * |----------------------| *
> * | ROMCON2 - 256K SRAM | 0x00040000 - 0x0007FFFF *
> * |----------------------| *
> * | ROMCON1 - 256K SRAM | 0x00000000 - 0x0003FFFF *
> * ---------------------- *
> * *
> ***************************************************************************/
> TargetInterface.pokeWord(0x03FF0000, 0x07FFFFA0); // SYSCFG
> TargetInterface.pokeWord(0x03FF3000, 0x00000000); // CLKCON
> TargetInterface.pokeWord(0x03FF3008, 0x00000000); // EXTACON0
> TargetInterface.pokeWord(0x03FF300C, 0x00000000); // EXTACON1
> TargetInterface.pokeWord(0x03FF3010, 0x0000003E); // EXTDBWIDTH
> TargetInterface.pokeWord(0x03FF3014, 0x18860030); // ROMCON0
> TargetInterface.pokeWord(0x03FF3018, 0x00400010); // ROMCON1
> TargetInterface.pokeWord(0x03FF301C, 0x00801010); // ROMCON2
> TargetInterface.pokeWord(0x03FF3020, 0x08018020); // ROMCON3
> TargetInterface.pokeWord(0x03FF3024, 0x0A020040); // ROMCON4
> TargetInterface.pokeWord(0x03FF3028, 0x0C028040); // ROMCON5
> TargetInterface.pokeWord(0x03FF302C, 0x00000000); // DRAMCON0
> TargetInterface.pokeWord(0x03FF3030, 0x00000000); // DRAMCON1
> TargetInterface.pokeWord(0x03FF3034, 0x00000000); // DRAMCON2
> TargetInterface.pokeWord(0x03FF3038, 0x00000000); // DRAMCON3
> TargetInterface.pokeWord(0x03FF303C, 0x9C218360); // REFEXTCON
> }

## TargetInterface Object

The TargetInterface object is used to access the currently connected target interface. The following section describes the TargetInterface object's member functions.

### TargetInterface.peekByte

TargetInterface.peekByte(address)
Reads a byte of target memory.
Parameters
address | The address from which to read.
Returns
The byte peeked from the specified address.

### TargetInterface.pokeByte

TargetInterface.pokeByte(address, data)
Writes a byte of target memory.
Parameters
address | The target address to write to.
data | The data byte to write.

### TargetInterface.peekUint16

TargetInterface.peekUint16(address)
Reads a 16 bit unsigned integer from target memory.
Parameters
address | The address from which to read.
Returns
The 16 bit unsigned integer peeked from the specified address.

### TargetInterface.pokeUint16

TargetInterface.pokeUint16(address, data)
Writes a 16 bit unsigned integer to target memory.
Parameters
address | The target address to write to.
data | The data to write.

### TargetInterface.peekUint32

TargetInterface.peekUint32(address)
Reads a 32 bit unsigned integer from target memory.
Parameters
address | The address from which to read.
Returns
The 32 bit unsigned integer peeked from the specified address.

### TargetInterface.pokeUint32

TargetInterface.pokeUint32(address, data)
Writes a 32 bit unsigned integer to target memory.
Parameters
address | The target address to write to.
data | The data to write.

### TargetInterface.peekWord

TargetInterface.peekWord(address)
Reads a word of data from target memory.
Parameters
address | The address from which to read.
Returns
The word peeked from the specified address.

### TargetInterface.pokeWord

TargetInterface.pokeWord(address, data)
Writes a word of data to target memory.
Parameters
address | The target address to write to.
data | The data word to write.

### TargetInterface.peekBytes

TargetInterface.peekBytes(address, length)
Reads a block of bytes from target memory.
Parameters
address | The start address from which to read.
length | The number of bytes to read.
Returns
An array containing the bytes read.

### TargetInterface.pokeBytes

TargetInterface.pokeBytes(address, length)
Writes a block of bytes to target memory.
Parameters
address | The start address to write to.
data | An array containing the bytes to write.

### TargetInterface.eraseBytes

TargetInterface.eraseBytes(address, length)
Erase a block of erasable memory.
Parameters
address | The start address to erase..
length | The number of bytes to erase.

### TargetInterface.delay

TargetInterface.delay(milliseconds)
Wait for a specified period of time.
Parameters
milliseconds | The number of milliseconds to wait..

### TargetInterface.setICEBreakerBreakpoint

TargetInterface.setICEBreakerBreakpoint(n, addressValue, addressMask, dataValue, dataMask controlValue, controlMask)
Set an ICEBreaker breakpoint.
Parameters
n | The number of the watchpoint unit to use.
addressValue | The address value.
addressMask | The address mask.
dataValue | The data value.
dataMask | The data mask.
controlValue | The control value.
controlMask | The control mask.

### TargetInterface.waitForDebugState

TargetInterface.waitForDebugState(timeout)
Wait for the target to enter debug state. If the timeout period expires and exception will be thrown which will be caught by the debugger.
Parameters
timeout | The maximum time in milliseconds to wait for the target to enter debug state.

### TargetInterface.setNSRST

TargetInterface.setNSRST(value)
Set the level of the target's nSRST reset signal.
Parameters
value | Set nSRST high if value does not equal zero.

### TargetInterface.beginDebugAccess

TargetInterface.beginDebugAccess()
Put target into debug state if it is not already in order to carry out a number of debug operations. The idea behind beginDebugAccess and endDebugAccess is to minimize the number of times the target enters and exits debug state when carrying out a number of debug operations. Target interface functions that require the target to be in debug state (such as peek and poke) also use beginDebugAccess and endDebugAccess to get the target into the correct state. A nesting count is maintained, incremented by beginDebugAccess and decremented by endDebugAccess. The initial processor state is recorded on the first nested call to beginDebugAccess and this state is restored when the final endDebugAccess is called causing the count to return to it initial state.

### TargetInterface.endDebugAccess

TargetInterface.endDebugAccess(alwaysRun)
Restore the target run state recorded at the first nested call to beginDebugAccess. See beginDebugAccess for more information.
Parameters
alwaysRun | If non-zero the processor will always exit debug state on the last nested call to endDebugAccess.

### TargetInterface.trst

TargetInterface.trst()
Perform a JTAG TAP reset.