diff --git a/firmware/SatStepperBegin/main.c b/firmware/SatStepperBegin/main.c index 8fe66ca..ac6a386 100755 --- a/firmware/SatStepperBegin/main.c +++ b/firmware/SatStepperBegin/main.c @@ -22,8 +22,8 @@ void init() { deviceInit(); initPwm(); stateInit(); - timer0Init(&emptyTimerIntrHandler); - timer1Init(&emptyTimerIntrHandler); + timer0Init(); + timer1Init(); setTimerPeriodByNum(0, 20000); enableGlobalInterrupts(); diff --git a/firmware/SatStepperBegin/timers.c b/firmware/SatStepperBegin/timers.c index bc5d83f..43b3c20 100755 --- a/firmware/SatStepperBegin/timers.c +++ b/firmware/SatStepperBegin/timers.c @@ -58,9 +58,8 @@ static inline void setTimerSettingsToDefaultByNum(uint_fast8_t timerNum) { timerRegs[timerNum]->TPRH.bit.TDDRH = 0x0; } -void timer0Init(_controlTimerInterruptHandler handler) -{ - _tmr0Handler = handler; +void timer0Init() { + clearTimer0IntrHandler(); EALLOW; // This is needed to write to EALLOW protected registers PieVectTable.TINT0 = TMR0_Interrupt; @@ -73,9 +72,8 @@ void timer0Init(_controlTimerInterruptHandler handler) setTimerSettingsToDefaultByNum(0); } -void timer1Init(_controlTimerInterruptHandler handler) -{ - _tmr1Handler = handler; +void timer1Init() { + clearTimer1IntrHandler(); EALLOW; // This is needed to write to EALLOW protected registers PieVectTable.TINT1 = &TMR1_Interrupt; @@ -87,18 +85,26 @@ void timer1Init(_controlTimerInterruptHandler handler) setTimerSettingsToDefaultByNum(1); } -void swapTimer0IntrHandler(_controlTimerInterruptHandler handler) { +void setTimer0IntrHandler(_controlTimerInterruptHandler handler) { if (handler != NULL) { _tmr0Handler = handler; } } -void swapTimer1IntrHandler(_controlTimerInterruptHandler handler) { +void clearTimer0IntrHandler() { + _tmr0Handler = &emptyTimerIntrHandler; +} + +void setTimer1IntrHandler(_controlTimerInterruptHandler handler) { if (handler != NULL) { _tmr1Handler = handler; } } +void clearTimer1IntrHandler() { + _tmr1Handler = &emptyTimerIntrHandler; +} + void setTimerPeriodByNum(uint_fast8_t timerNum, uint32_t periodInUsec) { // The TIMH:TIM is loaded with the value in the PRDH:PRD, // and the prescaler counter (PSCH:PSC) is loaded with the diff --git a/firmware/SatStepperBegin/timers.h b/firmware/SatStepperBegin/timers.h index 56237cf..35e4fa4 100755 --- a/firmware/SatStepperBegin/timers.h +++ b/firmware/SatStepperBegin/timers.h @@ -13,13 +13,15 @@ #include "stdint.h" typedef void (* _controlTimerInterruptHandler)(void); -void emptyTimerIntrHandler(); -void timer0Init(_controlTimerInterruptHandler); -void timer1Init(_controlTimerInterruptHandler); +void timer0Init(); +void timer1Init(); -void swapTimer0IntrHandler(_controlTimerInterruptHandler); -void swapTimer1IntrHandler(_controlTimerInterruptHandler); +void setTimer0IntrHandler(_controlTimerInterruptHandler); +void clearTimer0IntrHandler(); + +void setTimer1IntrHandler(_controlTimerInterruptHandler); +void clearTimer1IntrHandler(); void setTimerPeriodByNum(uint_fast8_t timerNum, uint32_t periodInUsec); void stopTimerByNum(uint_fast8_t timerNum);