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.

265 lines
7.5 KiB

#include "delay.h"
//////////////////////////////////////////////////////////////////////////////////
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫʹ<EFBFBD><EFBFBD>OS,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
#if SYSTEM_SUPPORT_OS
#include "includes.h" //ucos ʹ<EFBFBD><EFBFBD>
#endif
//////////////////////////////////////////////////////////////////////////////////
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><EFBFBD>ѧϰʹ<EFBFBD>ã<EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><EFBFBD><EFBFBD>;
//ALIENTEK STM32<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//ʹ<EFBFBD><EFBFBD>SysTick<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ<EFBFBD><EFBFBD><EFBFBD>ӳٽ<EFBFBD><EFBFBD>й<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʺ<EFBFBD>STM32F10xϵ<EFBFBD>У<EFBFBD>
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>delay_us,delay_ms
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><EFBFBD>@ALIENTEK
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳:www.openedv.com
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:2010/1/1
//<EFBFBD><EFBFBD><EFBFBD>V1.8
//<EFBFBD><EFBFBD>Ȩ<EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؾ<EFBFBD><EFBFBD><EFBFBD>
//Copyright(C) <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿƼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>޹<EFBFBD>˾ 2009-2019
//All rights reserved
//********************************************************************************
//V1.2<EFBFBD>޸<EFBFBD>˵<EFBFBD><EFBFBD>
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>ó<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>
//<EFBFBD><EFBFBD>ֹ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>׼ȷ,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>do while<EFBFBD>ṹ!
//V1.3<EFBFBD>޸<EFBFBD>˵<EFBFBD><EFBFBD>
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD>UCOSII<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>.
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>ucosII,delay_init<EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBF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ʽ,<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>OS(<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>UCOSII<EFBFBD><EFBFBD>UCOSIII,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>OS<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>)
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:delay_osrunning/delay_ostickspersec/delay_osintnesting<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:delay_osschedlock/delay_osschedunlock/delay_ostimedly<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//V1.8<EFBFBD>޸<EFBFBD>˵<EFBFBD><EFBFBD> 20150519
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>UCOSIII֧<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>2<EFBFBD><EFBFBD>bug<EFBFBD><EFBFBD>
//delay_tickspersec<EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>delay_ostickspersec
//delay_intnesting<EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>delay_osintnesting
//////////////////////////////////////////////////////////////////////////////////
static u8 fac_us=0; //us<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
static u16 fac_ms=0; //ms<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD>ucos<EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD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EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>systick
// delay_osintnesting:<EFBFBD><EFBFBD><EFBFBD>ڱ<EFBFBD>ʾOS<EFBFBD>ж<EFBFBD>Ƕ<EFBFBD>׼<EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD>Ϊ<EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ե<EFBFBD><EFBFBD><EFBFBD>,delay_msʹ<EFBFBD>øò<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//Ȼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
// delay_osschedlock:<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>OS<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD>ֹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//delay_osschedunlock:<EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD><EFBFBD><EFBFBD>OS<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD>¿<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// delay_ostimedly:<EFBFBD><EFBFBD><EFBFBD><EFBFBD>OS<EFBFBD><EFBFBD>ʱ,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̽<EFBFBD><EFBFBD><EFBFBD>UCOSII<EFBFBD><EFBFBD>UCOSIII<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>OS,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>вο<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֲ
//֧<EFBFBD><EFBFBD>UCOSII
#ifdef OS_CRITICAL_METHOD //OS_CRITICAL_METHOD<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ֧<EFBFBD><EFBFBD>UCOSII
#define delay_osrunning OSRunning //OS<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><EFBFBD><EFBFBD>,0,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;1,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define delay_ostickspersec OS_TICKS_PER_SEC //OSʱ<EFBFBD>ӽ<EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD>ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><EFBFBD><EFBFBD>
#define delay_osintnesting OSIntNesting //<EFBFBD>ж<EFBFBD>Ƕ<EFBFBD>׼<EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>Ƕ<EFBFBD>״<EFBFBD><EFBFBD><EFBFBD>
#endif
//֧<EFBFBD><EFBFBD>UCOSIII
#ifdef CPU_CFG_CRITICAL_METHOD //CPU_CFG_CRITICAL_METHOD<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ֧<EFBFBD><EFBFBD>UCOSIII
#define delay_osrunning OSRunning //OS<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><EFBFBD><EFBFBD>,0,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;1,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define delay_ostickspersec OSCfg_TickRate_Hz //OSʱ<EFBFBD>ӽ<EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD>ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><EFBFBD><EFBFBD>
#define delay_osintnesting OSIntNestingCtr //<EFBFBD>ж<EFBFBD>Ƕ<EFBFBD>׼<EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>Ƕ<EFBFBD>״<EFBFBD><EFBFBD><EFBFBD>
#endif
//us<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱʱ,<EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD>ֹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>us<EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD>)
void delay_osschedlock(void)
{
#ifdef CPU_CFG_CRITICAL_METHOD //ʹ<EFBFBD><EFBFBD>UCOSIII
OS_ERR err;
OSSchedLock(&err); //UCOSIII<EFBFBD>ķ<EFBFBD>ʽ,<EFBFBD><EFBFBD>ֹ<EFBFBD><EFBFBD><EFBFBD>ȣ<EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>us<EFBFBD><EFBFBD>ʱ
#else //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>UCOSII
OSSchedLock(); //UCOSII<EFBFBD>ķ<EFBFBD>ʽ,<EFBFBD><EFBFBD>ֹ<EFBFBD><EFBFBD><EFBFBD>ȣ<EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>us<EFBFBD><EFBFBD>ʱ
#endif
}
//us<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱʱ,<EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void delay_osschedunlock(void)
{
#ifdef CPU_CFG_CRITICAL_METHOD //ʹ<EFBFBD><EFBFBD>UCOSIII
OS_ERR err;
OSSchedUnlock(&err); //UCOSIII<EFBFBD>ķ<EFBFBD>ʽ,<EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#else //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>UCOSII
OSSchedUnlock(); //UCOSII<EFBFBD>ķ<EFBFBD>ʽ,<EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#endif
}
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>OS<EFBFBD>Դ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ
//ticks:<EFBFBD><EFBFBD>ʱ<EFBFBD>Ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void delay_ostimedly(u32 ticks)
{
#ifdef CPU_CFG_CRITICAL_METHOD
OS_ERR err;
OSTimeDly(ticks,OS_OPT_TIME_PERIODIC,&err); //UCOSIII<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
#else
OSTimeDly(ticks); //UCOSII<EFBFBD><EFBFBD>ʱ
#endif
}
//systick<EFBFBD>жϷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ucosʱ<EFBFBD>õ<EFBFBD>
void SysTick_Handler(void)
{
if(delay_osrunning==1) //OS<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><EFBFBD>ȴ<EFBFBD><EFBFBD><EFBFBD>
{
OSIntEnter(); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
OSTimeTick(); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ucos<EFBFBD><EFBFBD>ʱ<EFBFBD>ӷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
OSIntExit(); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
}
}
#endif
//<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>ӳٺ<EFBFBD><EFBFBD><EFBFBD>
//<EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>OS<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>,<EFBFBD>˺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>OS<EFBFBD><EFBFBD>ʱ<EFBFBD>ӽ<EFBFBD><EFBFBD><EFBFBD>
//SYSTICK<EFBFBD><EFBFBD>ʱ<EFBFBD>ӹ̶<EFBFBD>ΪHCLKʱ<EFBFBD>ӵ<EFBFBD>1/8
//SYSCLK:ϵͳʱ<EFBFBD><EFBFBD>
void delay_init()
{
#if SYSTEM_SUPPORT_OS //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ֧<EFBFBD><EFBFBD>OS.
u32 reload;
#endif
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); //ѡ<EFBFBD><EFBFBD><EFBFBD>ⲿʱ<EFBFBD><EFBFBD> HCLK/8
fac_us=SystemCoreClock/8000000; //Ϊϵͳʱ<EFBFBD>ӵ<EFBFBD>1/8
#if SYSTEM_SUPPORT_OS //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ֧<EFBFBD><EFBFBD>OS.
reload=SystemCoreClock/8000000; //ÿ<EFBFBD><EFBFBD><EFBFBD>ӵļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>λΪM
reload*=1000000/delay_ostickspersec; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>delay_ostickspersec<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
//reloadΪ24λ<EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ:16777216,<EFBFBD><EFBFBD>72M<EFBFBD><EFBFBD><EFBFBD><EFBFBD>1.86s<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
fac_ms=1000/delay_ostickspersec; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>OS<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٵ<EFBFBD>λ
SysTick->CTRL|=SysTick_CTRL_TICKINT_Msk; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>SYSTICK<EFBFBD>ж<EFBFBD>
SysTick->LOAD=reload; //ÿ1/delay_ostickspersec<EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>һ<EFBFBD><EFBFBD>
SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>SYSTICK
#else
fac_ms=(u16)fac_us*1000; //<EFBFBD><EFBFBD>OS<EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><EFBFBD>ms<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>systickʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#endif
}
#if SYSTEM_SUPPORT_OS //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ֧<EFBFBD><EFBFBD>OS.
//<EFBFBD><EFBFBD>ʱnus
//nusΪҪ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>us<EFBFBD><EFBFBD>.
void delay_us(u32 nus)
{
u32 ticks;
u32 told,tnow,tcnt=0;
u32 reload=SysTick->LOAD; //LOAD<EFBFBD><EFBFBD>ֵ
ticks=nus*fac_us; //<EFBFBD><EFBFBD>Ҫ<EFBFBD>Ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
tcnt=0;
delay_osschedlock(); //<EFBFBD><EFBFBD>ֹOS<EFBFBD><EFBFBD><EFBFBD>ȣ<EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>us<EFBFBD><EFBFBD>ʱ
told=SysTick->VAL; //<EFBFBD>ս<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
while(1)
{
tnow=SysTick->VAL;
if(tnow!=told)
{
if(tnow<told)tcnt+=told-tnow; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>SYSTICK<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
else tcnt+=reload-tnow+told;
told=tnow;
if(tcnt>=ticks)break; //ʱ<EFBFBD><EFBFBD><EFBFBD>/<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ӳٵ<EFBFBD>ʱ<EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD>.
}
};
delay_osschedunlock(); //<EFBFBD>ָ<EFBFBD>OS<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
//<EFBFBD><EFBFBD>ʱnms
//nms:Ҫ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>ms<EFBFBD><EFBFBD>
void delay_ms(u16 nms)
{
if(delay_osrunning&&delay_osintnesting==0) //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>OS<EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
{
if(nms>=fac_ms) //<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>OS<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
delay_ostimedly(nms/fac_ms); //OS<EFBFBD><EFBFBD>ʱ
}
nms%=fac_ms; //OS<EFBFBD>Ѿ<EFBFBD><EFBFBD>޷<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ôС<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ʱ
}
delay_us((u32)(nms*1000)); //<EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ʱ
}
#else //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>OSʱ
//<EFBFBD><EFBFBD>ʱnus
//nusΪҪ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>us<EFBFBD><EFBFBD>.
void delay_us(u32 nus)
{
u32 temp;
SysTick->LOAD=nus*fac_us; //ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SysTick->VAL=0x00; //<EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
do
{
temp=SysTick->CTRL;
}while((temp&0x01)&&!(temp&(1<<16))); //<EFBFBD>ȴ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>
SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //<EFBFBD>رռ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SysTick->VAL =0X00; //<EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
//<EFBFBD><EFBFBD>ʱnms
//ע<EFBFBD><EFBFBD>nms<EFBFBD>ķ<EFBFBD>Χ
//SysTick->LOADΪ24λ<EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱΪ:
//nms<=0xffffff*8*1000/SYSCLK
//SYSCLK<EFBFBD><EFBFBD>λΪHz,nms<EFBFBD><EFBFBD>λΪms
//<EFBFBD><EFBFBD>72M<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,nms<=1864
void delay_ms(u16 nms)
{
u32 temp;
SysTick->LOAD=(u32)nms*fac_ms; //ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(SysTick->LOADΪ24bit)
SysTick->VAL =0x00; //<EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
do
{
temp=SysTick->CTRL;
}while((temp&0x01)&&!(temp&(1<<16))); //<EFBFBD>ȴ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>
SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //<EFBFBD>رռ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SysTick->VAL =0X00; //<EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
#endif