User guide
CIF Peripheral Model - SimpleTimer
112 CoMET Version 5.9 – Tutorial
{
This function is called by the BusWrite and BusUntimedWrite functions. The WriteRegister
function is called each time there is a request to write data to a register from the bus. This
function returns the value put on the bus. Often writing a register signifies the start of some
event in the device. Callback functions are frequently scheduled from the WriteRegister
function.
As in the ReadRegister function, we need to add the case statements to the switch for the
offset of the register write.
The code below contains debug output statements which appear only when the SimpleTimer
module is built in Debug configuration.
Modify the switch (Offset) statement in the WriteRegister function to the following:
CODE BEGINS
switch (Offset)
{
/*
** Determine the register from offset and take appropriate action
*/
case GTR_OFFSET : // General Timer Register
{
tWord32 Count;
#ifdef _DEBUG
AmpiStreamPrintf(DEBUG_MSG, "%s: Write data %#06x to GTR\n",IP-
>pModulePathName,Data);
#endif
// Calculate current counter value.
Count = IP->regGTR + (tWord32)(AmpiClockGetTicks(IP->TimerClock, 0) -
IP->LastCounterUpdateTime);
// Nothing to do if it hasn't changed.
if (Count != Data)
{
// Save the new counter value.
IP->regGTR = Data;
IP->LastCounterUpdateTime = AmpiClockGetTicks(IP->TimerClock, 0);
// Reschedule the next match events.
SetupNextMatch(IP, -1);
}
}
break;
case TER_OFFSET: // Timer Enable Register
#ifdef _DEBUG
AmpiStreamPrintf(DEBUG_MSG, "%s: Write data %#06x to TER\n",IP-
>pModulePathName,Data);
#endif
if (IP->regTER != (Data & TER_ENABLE_ALL))
{
IP->regTER = Data & TER_ENABLE_ALL;
// Clear the match interrupts that are now disabled.
ClearMatchInterrupts(IP, ~Data);
// Reschedule the next match events.
SetupNextMatch(IP, -1);
}
break;
case TIER_OFFSET: // Timer Interrupt Enable Register