Skip to content

Commit

Permalink
enable new timer to manage a new thread
Browse files Browse the repository at this point in the history
  • Loading branch information
WSCKY committed Nov 30, 2018
1 parent 4f9176a commit 59bdcc5
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Projects/ds_twr_Responder/inc/TaskTimer.h
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 */
44 changes: 44 additions & 0 deletions Projects/ds_twr_Responder/src/TaskTimer.c
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();
}
}

0 comments on commit 59bdcc5

Please sign in to comment.