- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] This function execute long delay function.
- * @param[in] us Delay time.
- * [url=home.php?mod=space&uid=266161]@return[/url] None
- * [url=home.php?mod=space&uid=1543424]@Details[/url] Use the SysTick to generate the long delay time and the UNIT is in us.
- * The SysTick clock source is from HCLK, i.e the same as system core clock.
- * User can use SystemCoreClockUpdate() to calculate CyclesPerUs automatically before using this function.
- */
- __STATIC_INLINE void CLK_SysTickLongDelay(uint32_t us)
- {
- uint32_t delay;
-
- /* It should <= 335544us for each delay loop */
- delay = 335544UL;
- do
- {
- if(us > delay)
- {
- us -= delay;
- }
- else
- {
- delay = us;
- us = 0UL;
- }
-
- SysTick->LOAD = delay * CyclesPerUs;
- SysTick->VAL = (0x0UL);
- SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;
- /* Waiting for down-count to zero */
- while((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == 0UL);
- /* Disable SysTick counter */
- SysTick->CTRL = 0UL;
-
- }while(us > 0UL);
-
- }
通过
do
{
if(us > delay)
{
us -= delay;
}
else
{
delay = us;
us = 0UL;
}
实现了任意数值的延时。当大于最大限制时候,就先执行限制,并扣掉该值,循环,直到小于最大计量。
|