#include "interrupt_interface.h"
|
#include "cpu.h"
|
#include "wtd.h"
|
|
static __IO uint32_t g_tick = 0;
|
|
static void Interrupt()
|
{
|
g_tick = 1;
|
}
|
|
/*!
|
* @brief 时钟节拍
|
* @param [in] void
|
* @note null
|
*/
|
void TickTime()
|
{
|
// WatchDogService();
|
while (!g_tick)
|
;
|
g_tick = 0;
|
}
|
|
/*!
|
* @brief 时钟配置
|
* @param [in] void
|
* @note null
|
*/
|
void CLK_Config(void)
|
{
|
/* Initialization of the clock */
|
/* Clock divider to HSI/1 */
|
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
|
// CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSE, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
|
|
CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER1, ENABLE);
|
CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER2, ENABLE);
|
CLK_PeripheralClockConfig(CLK_PERIPHERAL_ADC, ENABLE);
|
CLK_PeripheralClockConfig(CLK_PERIPHERAL_UART2, ENABLE);
|
}
|
|
/*!
|
* @brief 定时器4配置
|
* @param [in] void
|
* @note null
|
*/
|
static void TIM4_Config(void)
|
{
|
/* TIM4 configuration:
|
- TIM4CLK is set to 16 MHz, the TIM4 Prescaler is equal to 128 so the TIM1 counter
|
clock used is 16 MHz / 128 = 125 000 Hz
|
- With 125 000 Hz we can generate time base:
|
max time base is 2.048 ms if TIM4_PERIOD = 255 --> (255 + 1) / 125000 = 2.048 ms
|
min time base is 0.016 ms if TIM4_PERIOD = 1 --> ( 1 + 1) / 125000 = 0.016 ms
|
- In this example we need to generate a time base equal to 1 ms
|
so TIM4_PERIOD = (0.001 * 125000 - 1) = 124 */
|
|
/* Time base configuration */
|
TIM4_DeInit();
|
TIM4_TimeBaseInit(TIM4_PRESCALER_128, 124);
|
/* Clear TIM4 update flag */
|
TIM4_ClearFlag(TIM4_FLAG_UPDATE);
|
/* Enable update interrupt */
|
TIM4_ITConfig(TIM4_IT_UPDATE, ENABLE);
|
TIM4_Cmd(ENABLE);
|
}
|
|
void OSTimer_Config(void)
|
{
|
TIM4_Config();
|
RegInterruptFunc(Interrupt, 4);
|
}
|