Hi,
(SDK v14.2, nRF52832)
I'm developing a Timeout Timer functionality, and was wandering if the following scenario is a good practice:
I don't want to have a interrupt at all, but I want my timer to stop automatically if it has been timeout. So, is using Timer Shortcut with Compare Event (while interrupts are disabled) reasonable?
(for some reason, i feel like something wrong here)
Timer Init:
void TIMEOUT_T1_Init(void)
{
NRF_TIMER1->TASKS_STOP = 1;
NRF_TIMER1->TASKS_CLEAR = 1;
NRF_TIMER1->MODE = 0; /* 'Timer' mode */
NRF_TIMER1->BITMODE = 3; /* 32 bit timer bith width*/
NRF_TIMER1->PRESCALER = 4; /* 1us timer --> f(timer) = 16Mhz / (2^PRESCALER)*/
NRF_TIMER1->INTENCLR = (0x3F << 16U); /* disabling all interupts for Timer 1*/
}
Timer Timeout Start:
/*
* TIMEOUT_T1_Start
*
* MCU HARDWARE:
* NRF52 Timer 1.
*
* PARAMETERS:
* timeout_us(uint32_t): timeout in microsecond.
*/
void TIMEOUT_T1_Start(uint32_t timeout_us)
{
NRF_TIMER1->TASKS_STOP = 1;
NRF_TIMER1->TASKS_CLEAR = 1;
NRF_TIMER1->EVENTS_COMPARE[TIMER_SHORTS_COMPARE1] = 0;
NRF_TIMER1->CC[TIMER_SHORTS_COMPARE1] = timeout_us;
NRF_TIMER1->SHORTS = TIMER_SHORTS_COMPARE1_STOP_Msk; /* shortcut between COMPARE[Channel 1] and STOP task*/
NRF_TIMER1->TASKS_START = 1;
}
Thanks.