You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

64 lines
1.1 KiB

#include "time.h"
#include "stm32f10x_tim.h"
#include "Parameter.h"
#define SysTickReLoadValue (SYSTEM_FREQUENCY / 1000)
uint16_t w1MsTickCnt = 0;
void SYSTICK_INIT(void)
{
SysTick->LOAD = SysTickReLoadValue - 1;
SysTick->VAL = SysTickReLoadValue - 1;
SysTick->CTRL = 0x00;
SysTick->CTRL |= 0x07;
}
void SysTick_Handler(void)
{
w1MsTickCnt++;
if (w1MsTickCnt >= MAX_TICK_VALUE)
{
w1MsTickCnt = 0;
}
}
uint16_t Get1MsTickVal(void)
{
return w1MsTickCnt;
}
uint16_t Get1MsTickInterval(uint16_t wLastTickVal)
{
uint16_t wCurTickVal;
uint16_t wTickInterval;
if (FOREMOST_TIME == wLastTickVal)
{
return MAX_INTERVAL;
}
if (LATTERMOST_TIME == wLastTickVal)
{
return MIN_INTERVAL;
}
wCurTickVal = w1MsTickCnt;
if (wCurTickVal >= wLastTickVal)
{
wTickInterval = wCurTickVal - wLastTickVal;
}
else
{
wTickInterval = (MAX_TICK_VALUE - wLastTickVal) + wCurTickVal;
}
return wTickInterval;
}
void Delay_ms(uint16_t ms)
{
uint16_t time = Get1MsTickVal();
while (Get1MsTickInterval(time) < ms);
}