📄 os_core.lst
字号:
pq->OSQOut = pq->OSQStart; /* ... wrap to queue start */
}
pq->OSQEntries--; /* Update number of queue entries */
*pevents_rdy++ = pevent; /* ... and return available queue event */
events_rdy = OS_TRUE;
events_rdy_nbr++;
} else {
events_stat |= OS_STAT_Q; /* Configure multi-pend for queue events */
}
break;
#endif
case OS_EVENT_TYPE_MUTEX:
case OS_EVENT_TYPE_FLAG:
default:
OS_EXIT_CRITICAL();
*pevents_rdy = (OS_EVENT *)0; /* NULL terminate return event array */
*perr = OS_ERR_EVENT_TYPE;
return (events_rdy_nbr);
}
pevents++;
pevent = *pevents;
}
if ( events_rdy == OS_TRUE) { /* Return any events already available */
*pevents_rdy = (OS_EVENT *)0; /* NULL terminate return event array */
OS_EXIT_CRITICAL();
*perr = OS_ERR_NONE;
return (events_rdy_nbr);
}
/*$PAGE*/
/* Otherwise, must wait until any event occurs */
OSTCBCur->OSTCBStat |= events_stat | /* Resource not available, ... */
OS_STAT_MULTI; /* ... pend on multiple events */
OSTCBCur->OSTCBStatPend = OS_STAT_PEND_OK;
OSTCBCur->OSTCBDly = timeout; /* Store pend timeout in TCB */
OS_EventTaskWaitMulti(pevents_pend); /* Suspend task until events or timeout occurs */
OS_EXIT_CRITICAL();
OS_Sched(); /* Find next highest priority task ready */
OS_ENTER_CRITICAL();
switch (OSTCBCur->OSTCBStatPend) { /* Handle event posted, aborted, or timed-out */
case OS_STAT_PEND_OK:
case OS_STAT_PEND_ABORT:
pevent = OSTCBCur->OSTCBEventPtr;
if (pevent != (OS_EVENT *)0) { /* If task event ptr != NULL, ... */
*pevents_rdy++ = pevent; /* ... return available event ... */
*pevents_rdy = (OS_EVENT *)0; /* ... & NULL terminate return event array */
events_rdy_nbr++;
} else { /* Else NO event available, handle as timeout */
OSTCBCur->OSTCBStatPend = OS_STAT_PEND_TO;
OS_EventTaskRemoveMulti(OSTCBCur, pevents_pend);
}
break;
case OS_STAT_PEND_TO:
default: /* ... remove task from events' wait lists */
OS_EventTaskRemoveMulti(OSTCBCur, pevents_pend);
break;
C51 COMPILER V8.17 OS_CORE 03/26/2009 14:24:24 PAGE 9
}
switch (OSTCBCur->OSTCBStatPend) {
case OS_STAT_PEND_OK:
switch (pevent->OSEventType) { /* Return event's message */
#if (OS_SEM_EN > 0)
case OS_EVENT_TYPE_SEM:
*pmsgs_rdy++ = (void *)0; /* NO message returned for semaphores */
break;
#endif
#if ((OS_MBOX_EN > 0) || \
((OS_Q_EN > 0) && (OS_MAX_QS > 0)))
case OS_EVENT_TYPE_MBOX:
case OS_EVENT_TYPE_Q:
*pmsgs_rdy++ = (void *)OSTCBCur->OSTCBMsg; /* Return received message */
break;
#endif
case OS_EVENT_TYPE_MUTEX:
case OS_EVENT_TYPE_FLAG:
default:
OS_EXIT_CRITICAL();
*pevents_rdy = (OS_EVENT *)0; /* NULL terminate return event array */
*perr = OS_ERR_EVENT_TYPE;
return (events_rdy_nbr);
}
*perr = OS_ERR_NONE;
break;
case OS_STAT_PEND_ABORT:
*pmsgs_rdy++ = (void *)0; /* NO message returned for abort */
*perr = OS_ERR_PEND_ABORT; /* Indicate that event aborted */
break;
case OS_STAT_PEND_TO:
default:
*pmsgs_rdy++ = (void *)0; /* NO message returned for timeout */
*perr = OS_ERR_TIMEOUT; /* Indicate that events timed out */
break;
}
OSTCBCur->OSTCBStat = OS_STAT_RDY; /* Set task status to ready */
OSTCBCur->OSTCBStatPend = OS_STAT_PEND_OK; /* Clear pend status */
OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0; /* Clear event pointers */
OSTCBCur->OSTCBEventMultiPtr = (OS_EVENT **)0;
OSTCBCur->OSTCBMsg = (void *)0; /* Clear task message */
OS_EXIT_CRITICAL();
return (events_rdy_nbr);
}
#endif
539
540 /*$PAGE*/
541 /*
542 *********************************************************************************************************
543 * INITIALIZATION
544 *
545 * Description: This function is used to initialize the internals of uC/OS-II and MUST be called prior to
546 * creating any uC/OS-II object and, prior to calling OSStart().
547 *
548 * Arguments : none
C51 COMPILER V8.17 OS_CORE 03/26/2009 14:24:24 PAGE 10
549 *
550 * Returns : none
551 *********************************************************************************************************
552 */
553
554 void OSInit (void) reentrant
555 {
556 1 OSInitHookBegin(); /* Call port specific initialization code
- */
557 1
558 1 OS_InitMisc(); /* Initialize miscellaneous variables
- */
559 1
560 1 OS_InitRdyList(); /* Initialize the Ready List
- */
561 1
562 1 OS_InitTCBList(); /* Initialize the free list of OS_TCBs
- */
563 1
564 1 OS_InitEventList(); /* Initialize the free list of OS_EVENTs
- */
565 1
566 1 #if (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
OS_FlagInit(); /* Initialize the event flag structures
- */
#endif
569 1
570 1 #if (OS_MEM_EN > 0) && (OS_MAX_MEM_PART > 0)
OS_MemInit(); /* Initialize the memory manager
- */
#endif
573 1
574 1 #if (OS_Q_EN > 0) && (OS_MAX_QS > 0)
OS_QInit(); /* Initialize the message queue structure
-s */
#endif
577 1
578 1 OS_InitTaskIdle(); /* Create the Idle Task
- */
579 1 #if OS_TASK_STAT_EN > 0
OS_InitTaskStat(); /* Create the Statistic Task
- */
#endif
582 1
583 1 #if OS_TMR_EN > 0
OSTmr_Init(); /* Initialize the Timer Manager
- */
#endif
586 1
587 1 OSInitHookEnd(); /* Call port specific init. code
- */
588 1
589 1 #if OS_DEBUG_EN > 0
OSDebugInit();
#endif
592 1 }
593 /*$PAGE*/
594 /*
595 *********************************************************************************************************
596 * ENTER ISR
597 *
598 * Description: This function is used to notify uC/OS-II that you are about to service an interrupt
C51 COMPILER V8.17 OS_CORE 03/26/2009 14:24:24 PAGE 11
599 * service routine (ISR). This allows uC/OS-II to keep track of interrupt nesting and thus
600 * only perform rescheduling at the last nested ISR.
601 *
602 * Arguments : none
603 *
604 * Returns : none
605 *
606 * Notes : 1) This function should be called ith interrupts already disabled
607 * 2) Your ISR can directly increment OSIntNesting without calling this function because
608 * OSIntNesting has been declared 'global'.
609 * 3) You MUST still call OSIntExit() even though you increment OSIntNesting directly.
610 * 4) You MUST invoke OSIntEnter() and OSIntExit() in pair. In other words, for every call
611 * to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
612 * end of the ISR.
613 * 5) You are allowed to nest interrupts up to 255 levels deep.
614 * 6) I removed the OS_ENTER_CRITICAL() and OS_EXIT_CRITICAL() around the increment because
615 * OSIntEnter() is always called with interrupts disabled.
616 *********************************************************************************************************
617 */
618
619 void OSIntEnter (void) reentrant
620 {
621 1 if (OSRunning == OS_TRUE) {
622 2 if (OSIntNesting < 255u) {
623 3 OSIntNesting++; /* Increment ISR nesting level */
624 3 }
625 2 }
626 1 }
627 /*$PAGE*/
628 /*
629 *********************************************************************************************************
630 * EXIT ISR
631 *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -