/** * @brief Selects timer clock source * * This function selects the clock source of the timer. * * @param source * - @ref TMR_CLK_SRC_DURING_TRX_SLEEP if clock source during sleep is to be selected, and * - @ref TMR_CLK_SRC_DURING_TRX_AWAKE if clock source while being awake is selected. */ void pal_timer_source_select(source_type_t source) { if (TMR_CLK_SRC_DURING_TRX_SLEEP == source) { TIMER_SRC_DURING_TRX_SLEEP(); } else { TIMER_SRC_DURING_TRX_AWAKE(); } }
/* * This function is called by timer_init() to perform the non-generic portion * of the initialization of the timer module. */ void timer_init_non_generic(void) { /* Select proper clock as timer clock source when radio is sleeping */ TIMER_SRC_DURING_TRX_SLEEP(); /* * Clear pending output compare matches of all the OCR1A, OCR1B and * OCR1C. */ TIFR1 = _BV(OCF1A); TIFR1 = _BV(OCF1B); TIFR1 = _BV(OCF1C); /* Enable the timer overflow interrupt */ TIMSK1 |= _BV(TOIE1); }
/* * This function is called by timer_init() to perform the non-generic portion * of the initialization of the timer module. * * sys_clk = 16MHz -> Will be used as source for Event Channel 0 with Prescaler 16 * * Timer usage * TCC0_CCA: Systime (software timer based on compare match) * TCC1_CCA: Input capture for time stamping */ void timer_init_non_generic(void) { /* Select proper clock as timer clock source when radio is sleeping */ TIMER_SRC_DURING_TRX_SLEEP(); /* * Clear pending output compare matches of all. */ TCC0_INTFLAGS = TC0_CCAIF_bm | TC0_CCBIF_bm | TC0_CCCIF_bm | TC0_CCDIF_bm; TCC1_INTFLAGS = TC1_CCAIF_bm | TC1_CCBIF_bm; /* Enable the timer overflow interrupt for TCC0 used for systime overflow. */ TCC0_INTCTRLA = TC_OVFINTLVL_HI_gc; /* Assign event channel 1 as input capture to TCC1_CCA */ TCC1_CTRLB |= TC1_CCAEN_bm; TCC1_CTRLD = TC1_EVACT0_bm | TC1_EVSEL3_bm | TC1_EVSEL0_bm; }