User guide

CIF Peripheral Model - SimpleTimer
98 CoMET Version 5.9 – Tutorial
Declarations, Definitions and Instance Data
Instance data stores the state of a particular instance of a model. Each instance of a Simple
Timer device needs to maintain its own state, while all instances of a device share behavioral
code. State is maintained in the instance data structure. This structure is defined in the header
file SimpleTimer.h. This file can be found in the CoMET workspace:
SimpleTimer/Folders/Header Files/SimpleTimer.h
CoMET creates a default SimpleTimer.h file from a template when the project is created.
The SimpleTimer.h is the appropriate file in which to create #defines for register address
offsets and bit masks for manipulating registers.
In the SimpleTimer.h file we perform the following steps:
Define macros
Define Callback Data Structure
Declare Callback and Helper Function prototypes
In Instance data structure:
o Declare Port handles
o Declare Registers
o Declare Callback Handles and Callback Data Structure
o Declare state variables
Defining Macros
In the CoMET workspace, open the SimpleTimer/Folders/Header Files/SimpleTimer.h
file. To open the file in the Document window, double click on the workspace file name.
Add the following definitions, after the line:
#include "config.h"
and before the line
typedef struct sInstanceData tInstanceData;
CODE BEGINS
#define NUM_MATCH_REGISTERS 2
/* SimpleTimer register offsets */
#define GTR_OFFSET 0x00000000 /* General Timer Register */
#define TER_OFFSET 0x00000008 /* Timer Enable Register */
#define TIER_OFFSET 0x00000010 /* Timer Interrupt Enable Register */
#define MTR1_OFFSET 0x00000028 /* Match Timer Register 1 */
#define MTR2_OFFSET 0x00000030 /* Match Timer Register 2 */
#define TIFR_OFFSET 0x00000018 /* Timer Interrupt Flag Register */
#define TER_ENABLE_1 0x01
#define TER_ENABLE_2 0x02
#define TER_ENABLE_ALL (TER_ENABLE_1 | TER_ENABLE_2)
#define TIER_ENABLE_1 0x01
#define TIER_ENABLE_2 0x02
#define TIER_ENABLE_ALL (TIER_ENABLE_1 | TIER_ENABLE_2)