void TC0_Handler(void) { volatile uint32_t ul_dummy, TC_value; /* Get the current timer counter value from a 32-bit register*/ TC_value = tc_read_tc(TC0,0); /* Clear status bit to acknowledge interrupt */ ul_dummy = tc_get_status(TC0, 0); if ((ul_dummy & TC_SR_CPCS) == TC_SR_CPCS) { #if DEBUG printf("%08x OV \n",TC_value); #endif time_msb++; rtimer_clock_t now = ((rtimer_clock_t)time_msb << 32)|tc_read_tc(TC0,0); rtimer_clock_t clock_to_wait = next_rtimer_time - now; if(clock_to_wait <= 0x100000000 && clock_to_wait > 0) { // We must set now the Timer Compare Register. // Set the auxiliary timer (TC0,1) at the write time interrupt tc_write_rc(TC0,1,(uint32_t)clock_to_wait); // Set and enable interrupt on RC compare tc_enable_interrupt(TC0,1,TC_IER_CPCS); // Start the auxiliary timer tc_start(TC0,1); } } else { printf("ERROR: TC: Unknown interrupt.\n"); } }
/*! \brief read the actual timer count from register */ uint16_t tmr_read_count(void) { return tc_read_tc(TIMER, TIMER_CHANNEL_ID); }
/*---------------------------------------------------------------------------*/ rtimer_clock_t rtimer_arch_now(void) { /* Modified, as now time is 64 bit */ return ((rtimer_clock_t)time_msb << 32)|(uint64_t)tc_read_tc(TC0,0); }