#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; } /* Start function */ void MyTimer_Start(TIM_TypeDef * Timer) { Timer->CR1 |=1<<0 ;// TIM_CR1_CEN } /* Stop function*/ void MyTimer_Stop(TIM_TypeDef * Timer) { Timer->CR1 &=~(1<<0) ;// TIM_CR1_CEN } void Bug (void) { while(1); } void (*TIM2_fx) (void) = &Bug; void (*TIM3_fx) (void) = &Bug; void (*TIM4_fx) (void) = &Bug; /* Interrupt function */ void MyTimer_ActiveIT (TIM_TypeDef * Timer, char Prio, void (*IT_function)(void)) { Timer->DIER |= TIM_DIER_UIE; if(Timer == TIM1) { } if(Timer == TIM2) { NVIC_EnableIRQ(TIM2_IRQn); NVIC_SetPriority(TIM2_IRQn, Prio); TIM2_fx = IT_function; } if(Timer == TIM3) { NVIC_EnableIRQ(TIM3_IRQn); NVIC_SetPriority(TIM3_IRQn, Prio); TIM3_fx = IT_function; } if(Timer == TIM4) { NVIC_EnableIRQ(TIM4_IRQn); NVIC_SetPriority(TIM4_IRQn, Prio); TIM4_fx = IT_function; } } void TIM2_IRQHandler (void) { TIM2->SR &= ~TIM_SR_UIF; (*TIM2_fx)(); } void TIM3_IRQHandler (void) { TIM3->SR &= ~TIM_SR_UIF; (*TIM3_fx)(); } void TIM4_IRQHandler (void) { TIM3->SR &= ~TIM_SR_UIF; (*TIM4_fx)(); }