Making timers great again pahse 1 / to be tested and finished so that the timerInit() function works properly

interrupts
key 4 years ago
parent 7d85aa1c0f
commit 2c2d318217

@ -35,6 +35,7 @@ typedef enum {
} timerCountDirection_t;
typedef enum {
counter,
inputCapture,
outputCompare,
pwm,
@ -43,8 +44,8 @@ typedef enum {
void timerReset(timerNo_t timer);
void timerActivateBus(timerNo_t timer);
void timerEnableTimer(timerNo_t timer);
void timerDisableTimer(timerNo_t timer);
void timerEnable(timerNo_t timer);
void timerDisable(timerNo_t timer);
void timerSetMode(timerNo_t timer, timerMode_t mode);
void timerSetCountDirection(timerNo_t timer, timerCountDirection_t direction);
void timerSetPrescaler(timerNo_t timer, uint32_t prescaler);
@ -56,12 +57,14 @@ void timerClearCounter(timerNo_t timer);
/* Second stage configuration */
void timerInit(timerNo_t timer, uint32_t prescaler, uint32_t period, timerCountDirection_t direction, timerMode_t mode);
void timerSetHz(timerNo_t timer, uint16_t hz);
void timerSetMs(timerNo_t timer, uint16_t ms);
void timerSetNs(timerNo_t timer, uint16_t ns);
void timerSetPs(timerNo_t timer, uint16_t ps);
void timerSart(timerNo_t timer);
void timerHalt(timerNo_t timer);
void timerStop(timerNo_t timer);
uint32_t timerGetCount(timerNo_t timer);

@ -5,8 +5,7 @@
void timerReset(timerNo_t timer)
{
// reset via RCC_APBxRSTR Register
// To implement RM page 116
}
void timerActivateBus(timerNo_t timer)
@ -16,23 +15,22 @@ void timerActivateBus(timerNo_t timer)
RCC->APB1ENR |= (1<<timerBus_En_bitPos[timer]);
return;
}
RCC->APB2ENR |= (1<<timerBus_En_bitPos[timer]);
}
void timerEnableTimer(timerNo_t timer)
void timerEnable(timerNo_t timer)
{
BASE->CR1 |= 0x01; //all the timers have the same CEN bit in CR1 register pos 0
BASE->CR1 |= TIM_CR1_CEN; //all the timers have the same CEN bit in CR1 register pos 0
}
void timerDisableTimer(timerNo_t timer)
void timerDisable(timerNo_t timer)
{
BASE->CR1 &=~ 0x01; //all the timers have the same CEN bit in CR1 register pos 0
BASE->CR1 &=~ TIM_CR1_CEN; //all the timers have the same CEN bit in CR1 register pos 0
}
void timerSetMode(timerNo_t timer, timerMode_t mode)
{
//Implement
}
void timerSetCountDirection(timerNo_t timer, timerCountDirection_t direction)
@ -77,8 +75,21 @@ void timerClearUpdateInterrupt(timerNo_t timer)
BASE->SR &= ~1;
}
/* Second stage configuration */
/* Second stage configuration */
void timerInit( timerNo_t timer,
uint32_t prescaler,
uint32_t period,
timerCountDirection_t direction,
timerMode_t mode)
{
timerActivateBus(timer);
timerReset(timer);
timerSetMode(mode);
timerSetCountDirection(timer,direction);
timerSetPrescaler(timer, prescaler);
timerSetAutoReload(timer, period);
}
/* Bus Clock
* ------------------------------ = Duty (Hz)
@ -100,7 +111,6 @@ void timerSetHz(timerNo_t timer, uint16_t hz)
temp = 8000000/(prescaler*(period));
}while(temp >= hz);
timerActivateBus(timer);
timerSetPrescaler(timer, prescaler-1);
timerSetAutoReload(timer, period-1);
timerClearCounter(timer);
@ -124,12 +134,18 @@ void timerSetPs(timerNo_t timer, uint16_t ps)
void timerSart(timerNo_t timer)
{
timerEnable(timer);
}
void timerHalt(timerNo_t timer)
{
timerDisable(timer);
}
void timerStop(timerNo_t timer)
{
timerDisable(timer);
timerClearCounter(timer);
}
uint32_t timerGetCount(timerNo_t timer)

@ -15,9 +15,10 @@ int main(int argc, char *argv[])
delayInitMs(8000000, 1000);
//timerSetHz(timer_2,3);
timerSetHz(timer_2,10);
timerEnableTimer(timer_2);
timerInit(timer_2, 7999, 999, counter, downCounting);
timerSart(timer_2);
pinConfig(pinB3, output, pushPull, def_res, def_speed);
pinConfig(pinA0, input, def_stage, pullDown, def_speed);

Loading…
Cancel
Save