6.3.4. Special purpose behaviors

Certain behavior names have a special meaning in components. These special purpose behaviors are called implicitly and automatically in certain simulation phases. See Table 6.1 for a list.

Table 6.1. Special-purpose behaviors

behavior initThis behavior is called implicitly once when the simulation is started. The code in this behavior is executed only once. It is intended to allocate memory and other resources used during simulation.
behavior reset(int level)

This behavior is called whenever the simulation is reset by the user. Reset might be called multiple times. There are two reset levels:


all state variables must be reset to their reset value but memory contents must not be cleared.


all state variables must be reset to their reset value and memory contents must also be cleared.

Memory must not be allocated in this behavior since it might invoked several times.

behavior loadApplicationFile(const string& filename)This behavior is invoked whenever a user loads an application file into a component using a debugger. The implementation of this behavior must load the application file.
behavior terminateThis behavior is the counterpart to behavior init and is called when the simulation terminates. It is intended to free any allocated memory and resources that were allocated in behavior init.

Init behavior

At system startup, each component is called for several phases of the simulation. The first call is the init phase. The init behavior implements what the component must do at this stage.

The SerialCharDoubler component only requires setting the boolean flag that indicates that the component is just about to transmit an escape sequence. Place the code in Example 6.6 before the slave port definition in SerialCharDoubler.lisa:

Example 6.6. init behavior

     behavior init
          inEscape = false;

Reset behavior

The doubler component init phase performs everything that is required at startup. There is, therefore, no requirement for a reset behavior.

Terminate behavior

The terminate behavior is typically responsible for freeing all resources allocated in the init phase. The doubler component does not allocate any resources in the init phase, the terminate behavior can therefore be omitted.

A different component type, for example a memory component, might allocate memory structures to represent data or register storage. Allocated structures must be freed in this phase.

Copyright © 2007-2010 ARM Limited. All rights reserved.ARM DUI 0370K