123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- #ifndef OS_MASTER_FILE
- #include <ucos_ii.h>
- #endif
- void OSTimeDly (INT32U ticks)
- {
- INT8U y;
- #if OS_CRITICAL_METHOD == 3u
- OS_CPU_SR cpu_sr = 0u;
- #endif
- if (OSIntNesting > 0u) {
- return;
- }
- if (OSLockNesting > 0u) {
- return;
- }
- if (ticks > 0u) {
- OS_ENTER_CRITICAL();
- y = OSTCBCur->OSTCBY;
- OSRdyTbl[y] &= (OS_PRIO)~OSTCBCur->OSTCBBitX;
- if (OSRdyTbl[y] == 0u) {
- OSRdyGrp &= (OS_PRIO)~OSTCBCur->OSTCBBitY;
- }
- OSTCBCur->OSTCBDly = ticks;
- OS_EXIT_CRITICAL();
- OS_Sched();
- }
- }
- #if OS_TIME_DLY_HMSM_EN > 0u
- INT8U OSTimeDlyHMSM (INT8U hours,
- INT8U minutes,
- INT8U seconds,
- INT16U ms)
- {
- INT32U ticks;
- if (OSIntNesting > 0u) {
- return (OS_ERR_TIME_DLY_ISR);
- }
- if (OSLockNesting > 0u) {
- return (OS_ERR_SCHED_LOCKED);
- }
- #if OS_ARG_CHK_EN > 0u
- if (hours == 0u) {
- if (minutes == 0u) {
- if (seconds == 0u) {
- if (ms == 0u) {
- return (OS_ERR_TIME_ZERO_DLY);
- }
- }
- }
- }
- if (minutes > 59u) {
- return (OS_ERR_TIME_INVALID_MINUTES);
- }
- if (seconds > 59u) {
- return (OS_ERR_TIME_INVALID_SECONDS);
- }
- if (ms > 999u) {
- return (OS_ERR_TIME_INVALID_MS);
- }
- #endif
-
-
- ticks = ((INT32U)hours * 3600uL + (INT32U)minutes * 60uL + (INT32U)seconds) * OS_TICKS_PER_SEC
- + OS_TICKS_PER_SEC * ((INT32U)ms + 500uL / OS_TICKS_PER_SEC) / 1000uL;
- OSTimeDly(ticks);
- return (OS_ERR_NONE);
- }
- #endif
- #if OS_TIME_DLY_RESUME_EN > 0u
- INT8U OSTimeDlyResume (INT8U prio)
- {
- OS_TCB *ptcb;
- #if OS_CRITICAL_METHOD == 3u
- OS_CPU_SR cpu_sr = 0u;
- #endif
- if (prio >= OS_LOWEST_PRIO) {
- return (OS_ERR_PRIO_INVALID);
- }
- OS_ENTER_CRITICAL();
- ptcb = OSTCBPrioTbl[prio];
- if (ptcb == (OS_TCB *)0) {
- OS_EXIT_CRITICAL();
- return (OS_ERR_TASK_NOT_EXIST);
- }
- if (ptcb == OS_TCB_RESERVED) {
- OS_EXIT_CRITICAL();
- return (OS_ERR_TASK_NOT_EXIST);
- }
- if (ptcb->OSTCBDly == 0u) {
- OS_EXIT_CRITICAL();
- return (OS_ERR_TIME_NOT_DLY);
- }
- ptcb->OSTCBDly = 0u;
- if ((ptcb->OSTCBStat & OS_STAT_PEND_ANY) != OS_STAT_RDY) {
- ptcb->OSTCBStat &= ~OS_STAT_PEND_ANY;
- ptcb->OSTCBStatPend = OS_STAT_PEND_TO;
- } else {
- ptcb->OSTCBStatPend = OS_STAT_PEND_OK;
- }
- if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) == OS_STAT_RDY) {
- OSRdyGrp |= ptcb->OSTCBBitY;
- OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
- OS_EXIT_CRITICAL();
- OS_Sched();
- } else {
- OS_EXIT_CRITICAL();
- }
- return (OS_ERR_NONE);
- }
- #endif
- #if OS_TIME_GET_SET_EN > 0u
- INT32U OSTimeGet (void)
- {
- INT32U ticks;
- #if OS_CRITICAL_METHOD == 3u
- OS_CPU_SR cpu_sr = 0u;
- #endif
- OS_ENTER_CRITICAL();
- ticks = OSTime;
- OS_EXIT_CRITICAL();
- return (ticks);
- }
- #endif
- #if OS_TIME_GET_SET_EN > 0u
- void OSTimeSet (INT32U ticks)
- {
- #if OS_CRITICAL_METHOD == 3u
- OS_CPU_SR cpu_sr = 0u;
- #endif
- OS_ENTER_CRITICAL();
- OSTime = ticks;
- OS_EXIT_CRITICAL();
- }
- #endif
-
|