Skip to content

Commit

Permalink
restruct timer handler setter functions #49
Browse files Browse the repository at this point in the history
  • Loading branch information
akindyakov committed May 18, 2014
1 parent 1bf79a2 commit a0c4c82
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
4 changes: 2 additions & 2 deletions firmware/SatStepperBegin/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ void init() {
deviceInit();
initPwm();
stateInit();
timer0Init(&emptyTimerIntrHandler);
timer1Init(&emptyTimerIntrHandler);
timer0Init();
timer1Init();
setTimerPeriodByNum(0, 20000);

enableGlobalInterrupts();
Expand Down
22 changes: 14 additions & 8 deletions firmware/SatStepperBegin/timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down
12 changes: 7 additions & 5 deletions firmware/SatStepperBegin/timers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a0c4c82

Please sign in to comment.