/*---------------------------------------------------------------------------*/ void RTC_IRQHandler(void) { // Find reason of IRQ if(RTC_IntGet() & RTC_IF_COMP0) { // Update second counters //_u32_seconds_since_epoch += DAY_VALUE_IN_SEC; //_u32_uptime += DAY_VALUE_IN_SEC; // Update alarm (alarm or second values may be updated) // Get about 100us to take into account Interrupt scheduling time //SI32_RTC_0->ALARM0.U32 = (_u32_alarm0_secvalue * _rtc_second) - 2; // Reset Counter RTC_CounterReset(); } else if(RTC_IntGet() & RTC_IF_COMP1) { if(alarm_callback != NULL) alarm_callback(); // Disable handler alarm_callback = NULL; } else { printf("%s: unknown reason for RTC interrupt\r\n",__func__); } // Clear interrupts RTC_IntClear(_RTC_IF_MASK); }
void RTC_IRQHandler(void) { uint32_t flags; flags = RTC_IntGet(); if ((flags & RTC_IF_COMP0) && rtc_inited) { RTC_IntClear(RTC_IF_COMP0); lp_ticker_irq_handler(); } }
bool hw_timer_is_interrupt_pending(hwtimer_id_t timer_id) { if(timer_id >= HWTIMER_NUM) return false; start_atomic(); bool is_pending = !!((RTC_IntGet() & RTC->IEN) & RTC_IFS_COMP1); end_atomic(); return is_pending; }
bool hw_timer_is_overflow_pending(hwtimer_id_t timer_id) { if(timer_id >= HWTIMER_NUM) return false; start_atomic(); //COMP0 is used to limit thc RTC to 16 bits -> use this one to check bool is_pending = !!((RTC_IntGet() & RTC->IEN) & RTC_IFS_COMP0); end_atomic(); return is_pending; }
/**************************************************************************//** * @brief Delay function, does not depend on interrupts. *****************************************************************************/ static void Delay( uint32_t msec ) { /* RTC frequency is LFXO divided by 32 (prescaler) */ #define RTC_FREQ (32768 / 32) RTC_IntDisable( RTC_IF_COMP0 ); RTC_IntClear( RTC_IF_COMP0 ); RTC_CompareSet( 0, (RTC_FREQ * msec ) / 1000 ); /* Calculate trigger value */ RTC_Enable( true ); while ( !( RTC_IntGet() & RTC_IF_COMP0 ) ); /* Wait for trigger */ RTC_Enable( false ); }
void isr_rtc(void) { if ((RTC_IntGet() & RTC_IF_COMP0)) { if (rtt_state.alarm_cb != NULL) { rtt_state.alarm_cb(rtt_state.alarm_arg); } /* clear interrupt */ RTC_IntClear(RTC_IFC_COMP0); } if (RTC_IntGet() & RTC_IF_OF) { if (rtt_state.overflow_cb != NULL) { rtt_state.overflow_cb(rtt_state.overflow_arg); } /* clear interrupt */ RTC_IntClear(RTC_IFC_OF); } if (sched_context_switch_request) { thread_yield(); } }
/***************************************************************************//** * @brief RTC Interrupt Handler * ******************************************************************************/ void RTC_IRQHandler(void) { /* Interrupt source: compare match 0 */ /* Increment compare value and update TFT display */ if ( RTC_IntGet() & RTC_IF_COMP0 ) { RTC_CompareSet(0,RTC->COMP0 + RTC_COUNTS_BETWEEN_DISPLAY); RTC_IntClear(RTC_IFC_COMP0); /* Set flag for display update */ doDisplayUpdate = true; } /* Interrupt source: compare match 1 */ /* Increment compare value and compensate for temperature drift */ if ( RTC_IntGet() & RTC_IF_COMP1 ) { RTC_CompareSet(1,RTC->COMP1 + RTC_COUNTS_BETWEEN_TC); RTC_IntClear(RTC_IFC_COMP1); /* Set flag for temperature compensation */ doTemperatureCompensation = true; } /* Interrupt source: counter overflow */ /* Increase overflow counter and update display */ if ( RTC_IntGet() & RTC_IF_OF ) { clockOverflow( ); RTC_IntClear(RTC_IFC_OF); /* Set flag for display update */ doDisplayUpdate = true; } }
/**************************************************************************//** * @brief RTC_IRQHandler * Interrupt Service Routine for RTC Interrupt Line *****************************************************************************/ void RTC_IRQHandler(void) { uint32_t flags; flags = RTC_IntGet(); /* if comp0 interrupt flag is set */ if(((flags & _RTC_IFS_COMP0_MASK)& RTC->IEN) == RTC_IFS_COMP0) { sensorCalib(); } /* Clear interrupt flag */ RTC_IntClear(flags); }
void RTC_IRQHandler(void) { ENERGEST_ON(ENERGEST_TYPE_IRQ); // Find reason of IRQ if(RTC_IntGet() & RTC_IF_COMP0) { watchdog_start(); rtimer_run_next(); watchdog_stop(); // disable interrupt RTC_IntDisable(RTC_IF_COMP0); } else { PRINTF("%s: unknown reason for RTC interrupt\r\n",__func__); } // Clear interrupts RTC_IntClear(_RTC_IF_MASK); ENERGEST_OFF(ENERGEST_TYPE_IRQ); }
const hwtimer_info_t* hw_timer_get_info(hwtimer_id_t timer_id) { if(timer_id >= HWTIMER_NUM) return NULL; static const hwtimer_info_t timer_info = { .min_delay_ticks = 0, }; return &timer_info; } hwtimer_tick_t hw_timer_getvalue(hwtimer_id_t timer_id) { if(timer_id >= HWTIMER_NUM || (!timer_inited)) return 0; else { uint32_t value =(uint16_t)(RTC->CNT & 0xFFFF); return value; } } error_t hw_timer_schedule(hwtimer_id_t timer_id, hwtimer_tick_t tick ) { if(timer_id >= HWTIMER_NUM) return ESIZE; if(!timer_inited) return EOFF; start_atomic(); RTC_IntDisable(RTC_IEN_COMP1); RTC_CompareSet( 1, tick ); RTC_IntClear(RTC_IEN_COMP1); RTC_IntEnable(RTC_IEN_COMP1); end_atomic(); } error_t hw_timer_cancel(hwtimer_id_t timer_id) { if(timer_id >= HWTIMER_NUM) return ESIZE; if(!timer_inited) return EOFF; start_atomic(); RTC_IntDisable(RTC_IEN_COMP1); RTC_IntClear(RTC_IEN_COMP1); end_atomic(); } error_t hw_timer_counter_reset(hwtimer_id_t timer_id) { if(timer_id >= HWTIMER_NUM) return ESIZE; if(!timer_inited) return EOFF; start_atomic(); RTC_IntDisable(RTC_IEN_COMP0 | RTC_IEN_COMP1); RTC_IntClear(RTC_IEN_COMP0 | RTC_IEN_COMP1); RTC_CounterReset(); RTC_IntEnable(RTC_IEN_COMP0); end_atomic(); } bool hw_timer_is_overflow_pending(hwtimer_id_t timer_id) { if(timer_id >= HWTIMER_NUM) return false; start_atomic(); //COMP0 is used to limit thc RTC to 16 bits -> use this one to check bool is_pending = !!((RTC_IntGet() & RTC->IEN) & RTC_IFS_COMP0); end_atomic(); return is_pending; } bool hw_timer_is_interrupt_pending(hwtimer_id_t timer_id) { if(timer_id >= HWTIMER_NUM) return false; start_atomic(); bool is_pending = !!((RTC_IntGet() & RTC->IEN) & RTC_IFS_COMP1); end_atomic(); return is_pending; } INT_HANDLER(RTC_IRQHandler) { //retrieve flags. We 'OR' this with the enabled interrupts //since the COMP1 flag may be set if it wasn't used before (compare register == 0 -> ifs flag set regardless of whether interrupt is enabled) //by AND ing with the IEN we make sure we only consider the flags of the ENABLED interrupts uint32_t flags = (RTC_IntGet() & RTC->IEN); RTC_IntClear(RTC_IFC_OF | RTC_IFC_COMP0 | RTC_IFC_COMP1); //evaluate flags to see which one(s) fired: if((flags & RTC_IFS_COMP0) && (overflow_f != 0x0)) overflow_f(); if((flags & RTC_IFS_COMP1)) { RTC_IntDisable(RTC_IEN_COMP1); if(compare_f != 0x0) compare_f(); } }