oscilloscope/User/Delay/delay.c

33 lines
601 B
C
Raw Normal View History

2020-12-19 09:26:30 +08:00
#include "delay.h"
2020-12-19 10:57:22 +08:00
#include "rtthread.h"
2020-12-19 09:26:30 +08:00
#include "stm32f10x.h"
2020-12-19 10:57:22 +08:00
void rt_hw_us_delay(unsigned int us)
2020-12-19 09:26:30 +08:00
{
2020-12-19 10:57:22 +08:00
rt_uint32_t delta, current_delay, tick;
if(us == 0)
return;
2020-12-19 10:57:22 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>tick<63><6B>
tick = us * (SysTick->LOAD/(1000000/RT_TICK_PER_SECOND));
//<2F><><EFBFBD>õ<EFBFBD>ǰʱ<C7B0><CAB1>
delta = SysTick->VAL;
//ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰʱ<C7B0>䣬ֱ<E4A3AC><D6B1><EFBFBD>ﵽָ<EFB5BD><D6B8>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD>ѭ<EFBFBD><D1AD>
do
{
if(delta > SysTick->VAL)
{
current_delay = delta - SysTick->VAL;
}
else
{
//<2F><>ʱ<EFBFBD><CAB1>Խ<EFBFBD><D4BD>һ<EFBFBD><D2BB>OS tick<63>ı߽<C4B1>
current_delay = SysTick->LOAD + delta - SysTick->VAL;
}
}while(current_delay < tick);
2020-12-19 09:26:30 +08:00
}