Page MenuHomec4science

callback_timers.h
No OneTemporary

File Metadata

Created
Sat, May 18, 21:22

callback_timers.h

#ifndef __CALLBACK_TIMERS_H
#define __CALLBACK_TIMERS_H
#include "../main.h"
typedef void (*cbt_PeriodicTaskFunc)(void);
// TIMX_PERIOD is the clock divider at the input of the timers.
// So, the timer will increment its counter, every TIMX_PERIOD ticks of the system clock (168 MHz).
// For example, current loop: TIM1_PRESCALER=168 => TIM1 will have a frequency of (168MHz/168=) 1MHz => 1 us.
#define TIM1_PRESCALER ((uint16_t)(SystemCoreClock/APB2_PRESCALER*TIM_MULTIPLIER/1000000-1)) // CLK_CNT = 1[us] (current loop)
#define TIM6_PRESCALER ((uint16_t)(SystemCoreClock/APB1_PRESCALER*TIM_MULTIPLIER/1000000-1)) // CLK_CNT = 1[us] (control loop)
#define TIM7_PRESCALER ((uint16_t)(SystemCoreClock/APB1_PRESCALER*TIM_MULTIPLIER/1000000-1)) // CLK_CNT = 1[us] (data loop)
/** @defgroup CallbackTimers Driver / Callback timers
* @brief Driver to call functions at a fixed rate.
*
* This driver setups three timers of the STM32, in order to call at a precise
* rate the control functions: the current regulation loop, the position
* regulation loop and the communication loop (data streaming part only).
*
* In the initialization code, first call cbt_Init(). Then call each
* cbt_Set*LoopTimer() function, giving the pointer to the function to call as
* an argument.
*
* @addtogroup CallbackTimers
* @{
*/
void cbt_Init(void);
void cbt_SetCurrentLoopTimer(cbt_PeriodicTaskFunc f, uint32_t period);
void cbt_SetPositionLoopTimer(cbt_PeriodicTaskFunc f, uint32_t period);
void cbt_SetCommLoopTimer(cbt_PeriodicTaskFunc f, uint32_t period);
void cbt_SetPositionLoopPeriod(uint32_t period);
void cbt_SetCommLoopPeriod(uint32_t period);
uint32_t cbt_GetCurrentLoopPeriod(void);
uint32_t cbt_GetPositionLoopPeriod(void);
uint32_t cbt_GetCommLoopPeriod(void);
/**
* @}
*/
#endif

Event Timeline