//延迟指定时间长度
原型出自OS_TIME.C
INT8U OSTimeDlyHMSM (INT8U hours, INT8U minutes, INT8U seconds, INT16U milli)
{
INT32U ticks;
INT16U loops;
if (hours > 0 || minutes > 0 || seconds > 0 || milli > 0) {
if (minutes > 59) {
return (OS_TIME_INVALID_MINUTES); /* Validate arguments to be within range */
}
if (seconds > 59) {
return (OS_TIME_INVALID_SECONDS);
}
if (milli > 999) {
return (OS_TIME_INVALID_MILLI);
}
/* Compute the total number of clock ticks required.. */
/* .. (rounded to the nearest tick) */
//ucosii工作频率200hz,故1秒200次tick
//OS_CFG.H中定义 #define OS_TICKS_PER_SEC 200
//总tick=总秒*200 + [毫秒/1000]*200
//总秒*200=[hours * 3600L + minutes * 60L + seconds]*200
//[毫秒/1000]*200=tick数
//500/OS_TICKS_PER_SECOND的值基本上与0.5个节拍对应的毫秒数相同
ticks = ((INT32U)hours * 3600L + (INT32U)minutes * 60L + (INT32U)seconds) * OS_TICKS_PER_SEC
+ OS_TICKS_PER_SEC * ((INT32U)milli + 500L / OS_TICKS_PER_SEC) / 1000L;
loops = (INT16U)(ticks / 65536L); /* Compute the integral number of 65536 tick delays */
ticks = ticks % 65536L; /* Obtain the fractional number of ticks */
//loops延时会被分割成两次32768个节拍的延时(因为用户只能延时65535个节拍而不是65536个节拍)和一次ticks个节拍的延时.
//在这种情况下,OSTimeDlyHMSM()首先考虑ticks节拍,然后是超过65535的loops节拍数
OSTimeDly((INT16U)ticks);
while (loops > 0) {
OSTimeDly(32768);
OSTimeDly(32768);
loops--;
}
return (OS_NO_ERR);
}
return (OS_TIME_ZERO_DLY);
}