User guide

CIF Peripheral Model - SimpleTimer
CoMET Version 5.9 – Tutorial 93
Adding Behavioral Code
We now implement the behavioral code associated with the Simple Timer device. In this
section we discuss the recommended methodology and implementation details for the
behavioral code.
General Modeling Guidelines
In designing VaST models we aim for speed and accuracy. The model should accurately
model the hardware. It should execute as efficiently as possible, to save real time when
simulating. A model should display the behavior of the modeled hardware device only at the
times when it is observed. When it is not observed, it should do as little as possible. This
improves efficiency and performance without sacrificing accuracy.
The times when the model is observed are at events such as the following:
Register reads - when a register is read, its value must correspond to the expected register
value. For example, the GTR (General Timer Register) should indicate the correct tick count.
Register writes - when we write to a register, the result should correspond to the expected
result. For example, writing a zero to bit 0 or 1 in the TER (Timer Enable Register) should
disable the corresponding MTR (Match Timer Register).
Events - when an event takes place, such as a change in a Net or Port, or a specified time
event, the model should behave as expected. For example, a Match event should result in the
MatchInterrupt port going high.
Events and Callback Functions
It is efficient to use CIF callback functions to respond to events. An event callback function
executes only when the corresponding event takes place.
Below we show the Event and Response table prepared from the specification. We add a
column describing the associated behavioral code function.
State and Instance Data
The model state is managed in an instance data structure. Typically the instance data structure
is defined in the projectName.h file and initialized in the task initialization function in the
projectName.c file.
How the SimpleTimer Behavior is Implemented
The SimpleTimer follows the above modeling guidelines. The implementation may differ
from expectation based on hardware experience.
Determining General Timer Register Value
While it may be traditional for a hardware timer to respond to each clock tick, updating the
counter for each tick, this is inefficient in a model. We need to know the correct value for the
counter only when we read it or write to it. We can use a function call to determine how
many ticks have elapsed since the TimerClock started, so there is no need to count ticks.