From ae9cdc35829120419d2c2440d27093557095aff6 Mon Sep 17 00:00:00 2001 From: Steins7 Date: Mon, 21 Oct 2024 17:04:45 +0200 Subject: [PATCH] Fix majors bugs in tim module --- drv/tim.c | 49 +++++++++---------------------------------------- 1 file changed, 9 insertions(+), 40 deletions(-) diff --git a/drv/tim.c b/drv/tim.c index 7ebe184..832a75b 100644 --- a/drv/tim.c +++ b/drv/tim.c @@ -47,13 +47,12 @@ void tim_configure_master(enum TimPeriph periph, enum TimConfig config_mask, callbacks[periph] = callback; regs[periph]->dier.TIE = 1; - regs[periph]->dier.UIE = 1; + regs[periph]->dier.UIE = 0; enum NvicIrq irq = 0; switch (periph) { case TIM_PERIPH_1: - irq = NVIC_IRQ_TIM1_BRK | NVIC_IRQ_TIM1_UP - | NVIC_IRQ_TIM1_TRG_COM | NVIC_IRQ_TIM1_CC; + irq = NVIC_IRQ_TIM1_UP; break; case TIM_PERIPH_2: irq = NVIC_IRQ_TIM2; @@ -71,6 +70,12 @@ void tim_configure_master(enum TimPeriph periph, enum TimConfig config_mask, //trigger update to force application of the config regs[periph]->egr.UG = 1; + while (regs[periph]->sr.UIF == 0) {} + regs[periph]->sr.UIF = 0; + + if (callback != nullptr) { + regs[periph]->dier.UIE = 1; + } } @@ -144,48 +149,12 @@ static enum TimIRQSource computeIRQSource(enum TimPeriph periph) //--ISRs------------------------------------------------------------------------ -void hdr_tim1_brk(void) -{ - nvic_clear_pending(NVIC_IRQ_TIM1_BRK); - - enum TimIRQSource src = computeIRQSource(TIM_PERIPH_1); - - if (callbacks[TIM_PERIPH_1] != nullptr) { - callbacks[TIM_PERIPH_1](src); - } -} - void hdr_tim1_up(void) { nvic_clear_pending(NVIC_IRQ_TIM1_UP); enum TimIRQSource src = computeIRQSource(TIM_PERIPH_1); - - if (callbacks[TIM_PERIPH_1] != nullptr) { - callbacks[TIM_PERIPH_1](src); - } -} - -void hdr_tim1_trg_com(void) -{ - nvic_clear_pending(NVIC_IRQ_TIM1_TRG_COM); - - enum TimIRQSource src = computeIRQSource(TIM_PERIPH_1); - - if (callbacks[TIM_PERIPH_1] != nullptr) { - callbacks[TIM_PERIPH_1](src); - } -} - -void hdr_tim1_cc(void) -{ - nvic_clear_pending(NVIC_IRQ_TIM1_CC); - - enum TimIRQSource src = computeIRQSource(TIM_PERIPH_1); - - if (callbacks[TIM_PERIPH_1] != nullptr) { - callbacks[TIM_PERIPH_1](src); - } + callbacks[TIM_PERIPH_1](src); } void hdr_tim2(void)