added 2 functions for timer

interrupts
key 4 years ago
parent ee7d7e31ed
commit 8261d7fb6a

@ -31,8 +31,7 @@ typedef enum {
typedef enum {
upCounting,
downCounting,
centerAligned
downCounting
} timerCountDirection_t;
typedef enum {
@ -44,12 +43,15 @@ typedef enum {
void timerActivateBus(timerNo_t timer);
void timerEnableTimer(timerNo_t timer);
void timerDisableTimer(timerNo_t timer);
void timerSetClkSource(timerNo_t timer, clkSources_t clk);
void timerSetMode(timerNo_t timer, timerMode_t mode);
void timerSetCountDirection(timerNo_t timer, timerCountDirection_t direction);
void timerSetPrescaler(timerNo_t timer, uint32_t prescaler);
void timerSetPostscaler(timerNo_t timer, uint32_t postscaler);
void timerSetAutoReload(timerNo_t timer, uint32_t reload);
uint8_t timerGetUpdateInterrupt(timerNo_t timer);
void timerClearUpdateInterrupt(timerNo_t timer);
void timerClearCounter(timerNo_t timer);

@ -203,6 +203,15 @@ static const uint8_t timerBus_No[MAX_TIMER_CHANNEL_COUNT] = {
2
};
static const uint32_t timerMaxCounter[MAX_TIMER_CHANNEL_COUNT] = {
0xFFFF, /*!< Timer 1 has a 16 bit counter */
0xFFFFFFFF, /*!< Timer 2 has a 32 bit counter */
0xFFFF, /*!< Timer 3 has a 16 bit counter */
0xFFFF, /*!< Timer 14 has a 16 bit counter */
0xFFFF, /*!< Timer 16 has a 16 bit counter */
0xFFFF /*!< Timer 17 has a 16 bit counter */
};
#ifdef __cplusplus
}
#endif

@ -16,9 +16,13 @@ void timerActivateBus(timerNo_t timer)
void timerEnableTimer(timerNo_t timer)
{
//BASE->CR1 &= ~0x01; //all the timers have the same CEN bit in CR1 register pos 0
BASE->CR1 |= 0x01; //all the timers have the same CEN bit in CR1 register pos 0
}
void timerDisableTimer(timerNo_t timer)
{
BASE->CR1 &=~ 0x01; //all the timers have the same CEN bit in CR1 register pos 0
}
void timerSetClkSource(timerNo_t timer, clkSources_t clk)
{
@ -27,12 +31,18 @@ void timerSetClkSource(timerNo_t timer, clkSources_t clk)
void timerSetMode(timerNo_t timer, timerMode_t mode)
{
}
void timerSetCountDirection(timerNo_t timer, timerCountDirection_t direction)
{
if(direction == upCounting)
{
BASE->CR1 &=~ TIM_CR1_DIR;
return;
}
BASE->CR1 |= TIM_CR1_DIR;
}
void timerSetPrescaler(timerNo_t timer, uint32_t prescaler)
@ -55,11 +65,29 @@ void timerClearCounter(timerNo_t timer)
BASE->CNT = 0;
}
uint8_t timerGetUpdateInterrupt(timerNo_t timer)
{
return (BASE->SR & 1);
}
void timerClearUpdateInterrupt(timerNo_t timer)
{
BASE->SR &= ~1;
}
/* Second stage configuration */
void timerSetHz(timerNo_t timer, uint16_t hz)
{
uint32_t prescaler;
uint32_t period;
timerActivateBus(timer);
timerSetPrescaler(timer, 1599);
timerSetAutoReload(timer, 9999);
timerClearCounter(timer);
timerEnableTimer(timer);
}
void timerSetMs(timerNo_t timer, uint16_t ms)
@ -90,7 +118,7 @@ void timerStop(timerNo_t timer)
uint32_t timerGetCount(timerNo_t timer)
{
return BASE->CNT;
}

@ -16,8 +16,8 @@ int main(int argc, char *argv[])
delayInitMs(8000000, 1000);
timerActivateBus(timer_2);
timerSetPrescaler(timer_2, 159);
timerSetAutoReload(timer_2, 999);
timerSetPrescaler(timer_2, 8000-1);
timerSetAutoReload(timer_2, 1000-1);
timerClearCounter(timer_2);
timerEnableTimer(timer_2);
@ -50,8 +50,8 @@ int main(int argc, char *argv[])
while(1)
{
while(!(TIM2->SR & 1));
TIM2->SR &= ~1;
while(!timerGetUpdateInterrupt(timer_2));
timerClearUpdateInterrupt(timer_2);
pinToggle(pinB3);
}

Loading…
Cancel
Save