/**************************************************************************** * * NAME: vTickTimerISR * * DESCRIPTION Timer interrupt service routine. * * Flash LED so we can see software is running. * * Check for data ready for transmission and initiate. * * PARAMETERS Name RW Usage * None. * * RETURNS: * None. * * NOTES: * None. * * ****************************************************************************/ PUBLIC void vDongleInitTickTimer(void) { DBG_vPrintf(DEBUG_DEVICE_CONFIG,"vDongleInitTickTimer\n"); /* Initialise tick timer to give 10ms interrupt */ vAHI_TickTimerConfigure(E_AHI_TICK_TIMER_DISABLE); vAHI_TickTimerWrite(0); vAHI_TickTimerInterval(DONGLE_TICK_PERIOD_COUNT); vAHI_TickTimerIntEnable(TRUE); vAHI_TickTimerConfigure(E_AHI_TICK_TIMER_RESTART); }
/**************************************************************************** * * NAME: SetTickCompare * * DESCRIPTION: * Set the tick timer compare register * * RETURNS: * True if the compare register value is in the future * ****************************************************************************/ OS_HWCOUNTER_SET_CALLBACK(APP_cbSetTickTimerCompare, u32CompareValue) { /* calculations are relative to the last compare register value to account for counter wrap around */ int32 s32NextDelta = u32CompareValue - s_u32LastExpiredTime; uint32 u32CurDelta = u32AHI_TickTimerRead() - s_u32LastExpiredTime; /* * Race condition here. If the tick counter has incremented passed the compare point * in the time between reading it and loading the compare register the interrupt will be missed. * Increase the delta to take account of this time. To minimise this time, the number of * instructions between the register read and write to the interval register should be minimised. */ u32CurDelta += 100; if (s32NextDelta > 0 && u32CurDelta < s32NextDelta) { vAHI_TickTimerInterval(u32CompareValue); s_u32CompareTime = u32CompareValue; return TRUE; } return FALSE; }