6 void (*irq_handler)(
void *);
14 const uint16_t _twr_timer_prescaler_lut[3] =
21 static int _twr_timer_lock_count = 0;
25 RCC->APB2ENR |= RCC_APB2ENR_TIM22EN;
30 if (_twr_timer_lock_count++ == 0)
32 TIM22->PSC = _twr_timer_prescaler_lut[twr_system_clock_get()];
36 TIM22->EGR = TIM_EGR_UG;
38 TIM22->CR1 |= TIM_CR1_CEN;
44 if (_twr_timer_lock_count < 1) twr_error(TWR_ERROR_ERROR_UNLOCK);
46 if (_twr_timer_lock_count == 1)
48 TIM22->CR1 &= ~TIM_CR1_CEN;
51 _twr_timer_lock_count--;
78 twr_timer_tim3_irq.irq_handler = NULL;
82 twr_timer_tim6_irq.irq_handler = NULL;
90 if (twr_timer_tim3_irq.irq_handler == NULL)
92 twr_timer_tim3_irq.irq_handler = irq_handler;
93 twr_timer_tim3_irq.irq_param = irq_param;
99 if (twr_timer_tim6_irq.irq_handler == NULL)
101 twr_timer_tim6_irq.irq_handler = irq_handler;
102 twr_timer_tim6_irq.irq_param = irq_param;
109 if (twr_timer_tim2_irq.irq_handler == NULL)
111 twr_timer_tim2_irq.irq_handler = irq_handler;
112 twr_timer_tim2_irq.irq_param = irq_param;
120 void TIM3_IRQHandler(
void)
122 if (twr_timer_tim3_irq.irq_handler)
124 twr_timer_tim3_irq.irq_handler(twr_timer_tim3_irq.irq_param);
128 void TIM2_IRQHandler(
void)
130 if (twr_timer_tim2_irq.irq_handler)
132 twr_timer_tim2_irq.irq_handler(twr_timer_tim2_irq.irq_param);
136 void TIM6_IRQHandler()
138 if (twr_timer_tim6_irq.irq_handler)
140 twr_timer_tim6_irq.irq_handler(twr_timer_tim6_irq.irq_param);
void twr_timer_clear(void)
Clear timer counter.
void twr_timer_init(void)
Initialize timer.
void twr_timer_clear_irq_handler(TIM_TypeDef *tim)
Unregister timer IRQ handler.
void twr_timer_delay(uint16_t microseconds)
Relative delay.
void twr_timer_stop(void)
Stop timer.
void twr_timer_start(void)
Start timer.
bool twr_timer_set_irq_handler(TIM_TypeDef *tim, void(*irq_handler)(void *), void *irq_param)
Register timer IRQ handler.
uint16_t twr_timer_get_microseconds(void)
Get actual tick of timer.