#include "utimers.h" #include "libdsp.h" #include "erlcommon.h" volatile unsigned int ulLastCounterValue = 0UL, ulOverflows = 0; inline universal_timer_t* getUTimerHandler(int num) { if ((num<0) ||(num>7)) return 0; return (universal_timer_t*)(TIMERS_BASE + (num*0x14)); } enum ERL_ERROR initUTimer(int num, int load_val, int enable_int) { universal_timer_t* timer = getUTimerHandler(num); if (timer==0) return ERL_PROGRAM_ERROR; //Disable timer timer->CntrlReg = 0; //Set Load Value timer->LoadReg = load_val; //Start timer if (enable_int) timer->CntrlReg = 1; else timer->CntrlReg = 5; return ERL_NO_ERROR; } unsigned int getUTimerCounter(int num) { universal_timer_t* timer = getUTimerHandler(num); if (timer==0) return 0; return timer->ValReg; } void resetUTimerInt(int num) { universal_timer_t* timer = getUTimerHandler(num); if (timer==0) return; volatile unsigned int read_int = timer->EOIReg; } void disableUTimer(int num) { universal_timer_t* timer = getUTimerHandler(num); if (timer==0) return; timer->CntrlReg = 0; volatile unsigned int read_int = timer->EOIReg; } enum ERL_ERROR start_utimer(int num) { int ret = initUTimer(num, 0xFFFFFFFF, 0); ulLastCounterValue = 0UL; ulOverflows = 0UL; return ret; } unsigned long long utimer_tics_get(int num) { if ((num<0) ||(num>7)) return 0; unsigned int valueNow = 0xFFFFFFFF - getUTimerCounter(num) ; if( valueNow < ulLastCounterValue ) { ulOverflows++; } ulLastCounterValue = valueNow; return valueNow + (((unsigned long long)ulOverflows) << 32); }