tim #6

Merged
Steins7 merged 16 commits from tim into dev 2024-11-03 12:07:39 +00:00
Showing only changes of commit ae9cdc3582 - Show all commits

View File

@ -47,13 +47,12 @@ void tim_configure_master(enum TimPeriph periph, enum TimConfig config_mask,
callbacks[periph] = callback; callbacks[periph] = callback;
regs[periph]->dier.TIE = 1; regs[periph]->dier.TIE = 1;
regs[periph]->dier.UIE = 1; regs[periph]->dier.UIE = 0;
enum NvicIrq irq = 0; enum NvicIrq irq = 0;
switch (periph) { switch (periph) {
case TIM_PERIPH_1: case TIM_PERIPH_1:
irq = NVIC_IRQ_TIM1_BRK | NVIC_IRQ_TIM1_UP irq = NVIC_IRQ_TIM1_UP;
| NVIC_IRQ_TIM1_TRG_COM | NVIC_IRQ_TIM1_CC;
break; break;
case TIM_PERIPH_2: case TIM_PERIPH_2:
irq = NVIC_IRQ_TIM2; 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 //trigger update to force application of the config
regs[periph]->egr.UG = 1; 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------------------------------------------------------------------------ //--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) void hdr_tim1_up(void)
{ {
nvic_clear_pending(NVIC_IRQ_TIM1_UP); nvic_clear_pending(NVIC_IRQ_TIM1_UP);
enum TimIRQSource src = computeIRQSource(TIM_PERIPH_1); 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_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);
}
} }
void hdr_tim2(void) void hdr_tim2(void)