-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable new timer to manage a new thread
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef __TASKTIMER_H | ||
#define __TASKTIMER_H | ||
|
||
/* Includes ------------------------------------------------------------------*/ | ||
#include "stm32f0xx.h" | ||
#include "stm32f0xx_tim.h" | ||
#include "stm32f0xx_rcc.h" | ||
#include "stm32f0xx_misc.h" | ||
|
||
void TaskTimerInit(uint32_t TaskRate); | ||
|
||
void TaskTimerCallback(void); | ||
|
||
#endif /* __TASKTIMER_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "TaskTImer.h" | ||
|
||
void TaskTimerInit(uint32_t TaskRate) | ||
{ | ||
NVIC_InitTypeDef NVIC_InitStructure; | ||
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; | ||
/* TIM2 clock enable */ | ||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); | ||
|
||
/* Time base configuration */ | ||
TIM_TimeBaseStructure.TIM_Period = (1000 / TaskRate) - 1; | ||
TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t) ((SystemCoreClock) / 1000) - 1; | ||
TIM_TimeBaseStructure.TIM_ClockDivision = 0; | ||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; | ||
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); | ||
|
||
/* NVIC configuration *******************************************************/ | ||
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; | ||
NVIC_InitStructure.NVIC_IRQChannelPriority = 0x3; | ||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; | ||
NVIC_Init(&NVIC_InitStructure); | ||
|
||
/* Clear TIM2 Counter */ | ||
TIM_SetCounter(TIM2, 0); | ||
|
||
/* TIM Interrupts enable */ | ||
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE); | ||
|
||
/* TIM2 counter enable */ | ||
TIM_Cmd(TIM2, ENABLE); | ||
} | ||
|
||
/** | ||
* @brief This function handles the TIM2 interrupt request. | ||
* @param None | ||
* @retval None | ||
*/ | ||
void TIM2_IRQHandler(void) | ||
{ | ||
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET) { | ||
TIM_ClearITPendingBit(TIM2, TIM_IT_Update); | ||
TaskTimerCallback(); | ||
} | ||
} |