static void _SYS_TMR_ProcessIsrClients(void) { int ix; SYS_TMR_CLIENT_OBJECT* pClient; bool isrLock; OSAL_CRITSECT_DATA_TYPE critSect; isrLock = _IsrTmrLock(&critSect); pClient = sClientObjects + 0; for ( ix = 0; ix < sizeof(sClientObjects)/sizeof(*sClientObjects); ix++, pClient++ ) { if ( pClient->isrState == SYS_TMR_CLIENT_ISR_MARK_DEL) { _SYS_TMR_ClientDelete(pClient); } else if(pClient->isrState == SYS_TMR_CLIENT_ISR_MARK_INACTIVE) { pClient->isrEnable = 0; pClient->currState = SYS_TMR_CLIENT_INACTIVE; } } _IsrTmrUnlock(isrLock, critSect); }
uint32_t SYS_TMR_ObjectCountGet ( SYS_TMR_HANDLE handle, uint32_t* pRateMs) { uint32_t obCount; SYS_TMR_CLIENT_OBJECT * timerObj = _SYS_TMR_ClientCheckSrvLock(handle); if(timerObj) { if(pRateMs) { // transform to ms *pRateMs = (timerObj->tuRate * 1000) / SYS_TMR_UNIT_RESOLUTION; } obCount = timerObj->tuCount; if(obCount == 0 && timerObj->flags.auto_del != 0) { // timed out, delete it _SYS_TMR_ClientDelete(timerObj); } _SYS_TMR_ClientSrvUnlock(); // round up so that don't return 0 if there are still counts return (obCount * 1000 + SYS_TMR_UNIT_RESOLUTION - 1) / SYS_TMR_UNIT_RESOLUTION; } return -1; }
void SYS_TMR_Deinitialize ( SYS_MODULE_OBJ object ) { int ix; // we're up and running // make sure no new clients are accepted _UserGblLock(); // now kill all clients DRV_TMR_Stop(sSysTmrObject.driverHandle); DRV_TMR_Alarm16BitDeregister ( sSysTmrObject.driverHandle); SYS_TMR_CLIENT_OBJECT* pClient = sClientObjects + 0; for ( ix = 0; ix < sizeof(sClientObjects)/sizeof(*sClientObjects); ix++, pClient++ ) { pClient->isrEnable = 0; if ( pClient->currState != SYS_TMR_CLIENT_FREE) { _SYS_TMR_ClientDelete(pClient); } } _UserGblLockDelete(); sSysTmrObject.status = SYS_STATUS_UNINITIALIZED; }
void SYS_TMR_ObjectDelete ( SYS_TMR_HANDLE handle) { SYS_TMR_CLIENT_OBJECT * timerObj = _SYS_TMR_ClientCheckSrvLock(handle); if(timerObj) { // valid client; lock other users access _SYS_TMR_ClientDelete(timerObj); _SYS_TMR_ClientSrvUnlock(); } }
// process timer alarm // occurs within TMR thread static void _SYS_TMR_ProcessTmrAlarm(void) { int ix; SYS_TMR_CLIENT_OBJECT* pClient; // get number of elapsed counts uint32_t nTicks = sSysTmrObject.sysTickCount - sSysTmrObject.sysTickPrevCount; sSysTmrObject.sysTickPrevCount = sSysTmrObject.sysTickCount; uint32_t nUnitsElapsed = (nTicks * sSysTmrObject.sysTickUnitCount); pClient = sClientObjects + 0; for ( ix = 0; ix < sizeof(sClientObjects)/sizeof(*sClientObjects); ix++, pClient++ ) { if ( pClient->currState == SYS_TMR_CLIENT_ACTIVE) { if( (pClient->tuCount -= nUnitsElapsed) <= 0 ) { // timeout /* invoke callback routine */ if ( pClient->callback != 0 ) { pClient->callback ( pClient->context, sSysTmrObject.sysTickCount); } if ( pClient->flags.periodic == true ) { // reload pClient->tuCount += pClient->tuRate; } else if (pClient->callback != 0 && pClient->flags.auto_del == true) { // client notified; delete this object _SYS_TMR_ClientDelete(pClient); } else { // non delete non periodic object; store the timeout condition pClient->currState = SYS_TMR_CLIENT_INACTIVE; pClient->tuCount = 0; } } } } }
bool SYS_TMR_ObjectReload ( SYS_TMR_HANDLE handle, uint32_t periodMs, uintptr_t context, SYS_TMR_CALLBACK callback) { SYS_TMR_CLIENT_OBJECT * timerObj = _SYS_TMR_ClientCheckSrvLock(handle); if(timerObj) { timerObj->isrEnable = 0; bool res = _SYS_TMR_ClientParamSet(timerObj, periodMs, context, callback); if(timerObj->isrState == SYS_TMR_CLIENT_ISR_MARK_DEL) { // client is too late _SYS_TMR_ClientDelete(timerObj); res = false; } timerObj->isrState = SYS_TMR_CLIENT_ISR_ACTIVE; timerObj->isrEnable = 1; _SYS_TMR_ClientSrvUnlock(); return res; } return false; }
void SYS_TMR_Deinitialize ( SYS_MODULE_OBJ object ) { int ix; if(!_SYS_TMR_ObjectCheck(object)) { return; } // we're up and running // make sure no new clients are accepted _UserGblLock(); // now kill all clients if ( sSysTmrObject.driverHandle != 0 && sSysTmrObject.driverHandle != DRV_HANDLE_INVALID ) { DRV_TMR_Close(sSysTmrObject.driverHandle); sSysTmrObject.driverHandle = 0; } // release all clients SYS_TMR_CLIENT_OBJECT* pClient = sClientObjects + 0; for ( ix = 0; ix < sizeof(sClientObjects)/sizeof(*sClientObjects); ix++, pClient++ ) { pClient->isrEnable = 0; if ( pClient->currState != SYS_TMR_CLIENT_FREE) { _SYS_TMR_ClientDelete(pClient); } } _UserGblLockDelete(); sSysTmrObject.status = SYS_STATUS_UNINITIALIZED; }