User guide

CIF Peripheral Model - SimpleTimer
102 CoMET Version 5.9 – Tutorial
Creating the Behavioral Functions
We will add all behavioral code for the SimpleTimer device to the SimpleTimer.c file. This
file can be found in the Workspace at SimpleTimer/Folders/Source
Files/SimpleTimer.c.
Double click on the SimpleTimer.c node to open the file for editing in the Document
window.
The steps involved are:
Create SetupNextMatch function
Create ClearMatchInterrupts function
Create Match callback function
Create Unmatch callback function
Modify Task Initialization function (AmpiTaskInitInstance)
Modify Reset function
Modify ReadRegister function and respond to various register reads
Modify WriteRegister function and respond to various register writes
On creating the SimpleTimer project, the CoMET new project wizard creates a number of
default functions, named according to the project name. We also add helper and callback
functions.
Creating the SetupNextMatch, ClearMatchInterrupts, Match and UnMatch functions
These functions are fully commented. See also Events and Responses in Behavioral Code,
page 97. Add the following to the end of the SimpleTimer.c file:
CODE BEGINS
/*
**************************************************************************
**
** Helper and Callback Functions
*/
/**
** SetupNextMatch(tInstanceData *IP, const tInt32 regMTRN)
**
** Sets up a callback for the next match on the given match register.
** Any existing callbacks are cancelled.
**
** Parameters
** IP
** A pointer to the instance data.
**
** regMTRN
** The match register number, or -1 for all match registers.
*/
static void SetupNextMatch(tInstanceData *IP, const tInt32 MTR_ix)
{
/*