53 lines
969 B
C
53 lines
969 B
C
#include "Driver_Timer.h"
|
|
#include "stm32f10x.h"
|
|
#include "stdio.h"
|
|
/* Timer init function */
|
|
void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer)
|
|
{
|
|
/* Reset the selected Timer */
|
|
if(Timer->Timer == TIM1)
|
|
{
|
|
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
|
|
}
|
|
else if(Timer->Timer == TIM2)
|
|
{
|
|
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
|
|
}
|
|
else if(Timer->Timer == TIM3)
|
|
{
|
|
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
|
|
}
|
|
else if(Timer->Timer == TIM4)
|
|
{
|
|
RCC->APB1ENR |= RCC_APB1ENR_TIM4EN;
|
|
}
|
|
|
|
Timer->Timer->PSC = Timer->PSC;
|
|
Timer->Timer->ARR = Timer->ARR;
|
|
}
|
|
|
|
|
|
void MyTimer_ActiveIT (TIM_TypeDef * Timer, char Prio, void (*IT_function)(void))
|
|
{
|
|
Timer->DIER |= TIM_DIER_BIE;
|
|
if(Timer == TIM1)
|
|
{
|
|
|
|
}
|
|
if(Timer == TIM2)
|
|
{
|
|
NVIC_EnableIRQ(TIM2_IRQn);
|
|
NVIC_SetPriority(TIM2_IRQn, Prio);
|
|
}
|
|
if(Timer == TIM3)
|
|
{
|
|
NVIC_EnableIRQ(TIM3_IRQn);
|
|
NVIC_SetPriority(TIM3_IRQn, Prio);
|
|
}
|
|
if(Timer == TIM4)
|
|
{
|
|
NVIC_EnableIRQ(TIM4_IRQn);
|
|
NVIC_SetPriority(TIM4_IRQn, Prio);
|
|
}
|
|
}
|
|
|