24 #include "isr_manager.h" 30 #define TIMER_ID CONCAT_2(NRF_TIMER, US_TIMER_USED) 31 #define TIMER_IRQN CONCAT_3(TIMER, US_TIMER_USED, _IRQn) 32 #define TIMER_IRQ_Handler CONCAT_3(TIMER, US_TIMER_USED, _IRQHandler) 33 #define TIMER_SIZE CONCAT_3(NRF_TIMER, US_TIMER_USED, _MAX_SIZE) 38 #define TIMER_PRESCALER 4 41 #define TIMER_BITSIZE TIMER_BITMODE_BITMODE_32Bit 43 #define TIMER_BITSIZE TIMER_BITMODE_BITMODE_16Bit 48 static struct us_timer_t{
49 volatile uint32_t timer_mode;
50 void (*timer_handler)(void);
54 static volatile uint32_t us_timers_status;
59 us_timer[id].timer_handler = NULL;
63 TIMER_ID->TASKS_STOP = 1;
64 TIMER_ID->MODE = TIMER_MODE_MODE_Timer;
65 TIMER_ID->PRESCALER = TIMER_PRESCALER;
66 TIMER_ID->BITMODE = TIMER_BITSIZE;
67 TIMER_ID->TASKS_CLEAR = 1;
68 TIMER_ID->TASKS_START = 1;
70 NVIC_SetPriority(TIMER_IRQN, irq_priority);
71 NVIC_EnableIRQ(TIMER_IRQN);
75 us_timer[id].timer_handler = handler;
79 us_timer[id].timer_mode = time_us;
82 TIMER_ID->TASKS_CAPTURE[id] = 1;
83 TIMER_ID->CC[id] += time_us;
85 TIMER_ID->EVENTS_COMPARE[id] = 0;
86 TIMER_ID->INTENSET = 1 << (TIMER_INTENSET_COMPARE0_Pos + id);
89 if (us_timers_status == 0)
91 TIMER_ID->TASKS_START = 1;
94 us_timers_status |= 1 << id;
99 us_timers_status &= ~(1 << id);
101 TIMER_ID->INTENCLR = 1 << (TIMER_INTENSET_COMPARE0_Pos + id);
104 if (us_timers_status == 0)
106 TIMER_ID->TASKS_STOP = 1;
107 TIMER_ID->TASKS_SHUTDOWN = 1;
112 return ((us_timers_status & (1<<
id)) != 0);
119 void us_timer_timer_Handler ()
121 void TIMER_IRQ_Handler()
125 if(TIMER_ID->EVENTS_COMPARE[
id]){
127 TIMER_ID->EVENTS_COMPARE[id] = 0;
128 (void) TIMER_ID->EVENTS_COMPARE[
id];
130 void (*cb_handler)(void) = NULL;
131 if(us_timer[
id].timer_handler != NULL)
133 cb_handler = us_timer[id].timer_handler;
142 TIMER_ID->TASKS_CAPTURE[id] = 1;
143 TIMER_ID->CC[id] += us_timer[id].timer_mode;
146 if(cb_handler != NULL)
us_timer_num
Enumeration used for specifying the timers that can be used with this TIMER peripheral.
void us_timer_start(us_timer_num id, us_timer_mode mode, uint32_t time_us, void(*handler)(void))
void us_timer_init(uint32_t irq_priority)
Initialize the TIMER peripheral to use as a micro-second timer.
One shot call of the timer.
bool us_timer_get_on_status(us_timer_num id)
Not a timer, just used to find the number of timers.
void us_timer_stop(us_timer_num id)
us_timer_mode
Enumeration to specify the mode of operation of the timer.