📄 os_core.lst
字号:
653 * Description: This function is called by other uC/OS-II services and is used to ready a task that was
654 * waiting for an event to occur.
655 *
656 * Arguments : pevent is a pointer to the event control block corresponding to the event.
657 *
658 * pmsg is a pointer to a message. This pointer is used by message oriented services
659 * such as MAILBOXEs and QUEUEs. The pointer is not used when called by other
660 * service functions.
661 *
662 * msk is a mask that is used to clear the status byte of the TCB. For example,
663 * OSSemPost() will pass OS_STAT_SEM, OSMboxPost() will pass OS_STAT_MBOX etc.
664 *
665 * pend_stat is used to indicate the readied task's pending status:
666 *
667 * OS_STAT_PEND_OK Task ready due to a post (or delete), not a timeout or
668 * an abort.
669 * OS_STAT_PEND_ABORT Task ready due to an abort.
670 *
671 * Returns : none
672 *
673 * Note : This function is INTERNAL to uC/OS-II and your application should not call it.
674 *********************************************************************************************************
675 */
676 #if OS_EVENT_EN
677 INT8U OS_EventTaskRdy (OS_EVENT *pevent, void *pmsg, INT8U msk, INT8U
678 pend_stat) reentrant
679 {
680 1 OS_TCB *ptcb;
681 1 INT8U x;
682 1 INT8U y;
683 1 INT8U prio;
684 1 #if OS_LOWEST_PRIO <= 63
685 1 INT8U bitx;
686 1 INT8U bity;
687 1 #else
INT16U bitx;
INT16U bity;
INT16U *ptbl;
#endif
692 1
693 1
694 1 #if OS_LOWEST_PRIO <= 63
695 1 y = OSUnMapTbl[pevent->OSEventGrp]; /* Find HPT waiting for message */
696 1 bity = (INT8U)(1 << y);
697 1 x = OSUnMapTbl[pevent->OSEventTbl[y]];
698 1 bitx = (INT8U)(1 << x);
699 1 prio = (INT8U)((y << 3) + x); /* Find priority of task getting the msg */
700 1 #else
if ((pevent->OSEventGrp & 0xFF) != 0) { /* Find HPT waiting for message */
y = OSUnMapTbl[pevent->OSEventGrp & 0xFF];
} else {
C51 COMPILER V7.50 OS_CORE 12/14/2007 08:25:29 PAGE 13
y = OSUnMapTbl[(pevent->OSEventGrp >> 8) & 0xFF] + 8;
}
bity = (INT16U)(1 << y);
ptbl = &pevent->OSEventTbl[y];
if ((*ptbl & 0xFF) != 0) {
x = OSUnMapTbl[*ptbl & 0xFF];
} else {
x = OSUnMapTbl[(*ptbl >> 8) & 0xFF] + 8;
}
bitx = (INT16U)(1 << x);
prio = (INT8U)((y << 4) + x); /* Find priority of task getting the msg */
#endif
716 1
717 1 pevent->OSEventTbl[y] &= ~bitx; /* Remove this task from the waiting list */
718 1 if (pevent->OSEventTbl[y] == 0) {
719 2 pevent->OSEventGrp &= ~bity; /* Clr group bit if this was only task pending */
720 2 }
721 1 ptcb = OSTCBPrioTbl[prio]; /* Point to this task's OS_TCB */
722 1 ptcb->OSTCBDly = 0; /* Prevent OSTimeTick() from readying task */
723 1 ptcb->OSTCBEventPtr = (OS_EVENT *)0; /* Unlink ECB from this task */
724 1 #if ((OS_Q_EN > 0) && (OS_MAX_QS > 0)) || (OS_MBOX_EN > 0)
725 1 ptcb->OSTCBMsg = pmsg; /* Send message directly to waiting task */
726 1 #else
pmsg = pmsg; /* Prevent compiler warning if not used */
#endif
729 1 ptcb->OSTCBStatPend = pend_stat; /* Set pend status of post or abort */
730 1 ptcb->OSTCBStat &= ~msk; /* Clear bit associated with event type */
731 1 if (ptcb->OSTCBStat == OS_STAT_RDY) { /* See if task is ready (could be susp'd) */
732 2 OSRdyGrp |= bity; /* Put task in the ready to run list */
733 2 OSRdyTbl[y] |= bitx;
734 2 }
735 1 return (prio);
736 1 }
737 #endif
738 /*$PAGE*/
739 /*
740 *********************************************************************************************************
741 * MAKE TASK WAIT FOR EVENT TO OCCUR
742 *
743 * Description: This function is called by other uC/OS-II services to suspend a task because an event has
744 * not occurred.
745 *
746 * Arguments : pevent is a pointer to the event control block for which the task will be waiting for.
747 *
748 * Returns : none
749 *
750 * Note : This function is INTERNAL to uC/OS-II and your application should not call it.
751 *********************************************************************************************************
752 */
753 #if OS_EVENT_EN
754 void OS_EventTaskWait (OS_EVENT *pevent) reentrant
755 {
756 1 INT8U y;
757 1
758 1
759 1 OSTCBCur->OSTCBEventPtr = pevent; /* Store pointer to event control block in TCB */
760 1 y = OSTCBCur->OSTCBY; /* Task no longer ready */
761 1 OSRdyTbl[y] &= ~OSTCBCur->OSTCBBitX;
762 1 if (OSRdyTbl[y] == 0) {
763 2 OSRdyGrp &= ~OSTCBCur->OSTCBBitY; /* Clear event grp bit if this was only task pending */
764 2 }
765 1 pevent->OSEventTbl[OSTCBCur->OSTCBY] |= OSTCBCur->OSTCBBitX; /* Put task in waiting list */
C51 COMPILER V7.50 OS_CORE 12/14/2007 08:25:29 PAGE 14
766 1 pevent->OSEventGrp |= OSTCBCur->OSTCBBitY;
767 1 }
768 #endif
769 /*$PAGE*/
770 /*
771 *********************************************************************************************************
772 * MAKE TASK READY TO RUN BASED ON EVENT TIMEOUT OR ABORT
773 *
774 * Description: This function is called by other uC/OS-II services to make a task ready to run because a
775 * timeout or abort occurred.
776 *
777 * Arguments : pevent is a pointer to the event control block which is readying a task.
778 *
779 * Returns : none
780 *
781 * Note : This function is INTERNAL to uC/OS-II and your application should not call it.
782 *********************************************************************************************************
783 */
784 #if OS_EVENT_EN
785 void OS_EventTOAbort (OS_EVENT *pevent) reentrant
786 {
787 1 INT8U y;
788 1
789 1
790 1 y = OSTCBCur->OSTCBY;
791 1 pevent->OSEventTbl[y] &= ~OSTCBCur->OSTCBBitX; /* Remove task from wait list */
792 1 if (pevent->OSEventTbl[y] == 0x00) {
793 2 pevent->OSEventGrp &= ~OSTCBCur->OSTCBBitY;
794 2 }
795 1 OSTCBCur->OSTCBStatPend = OS_STAT_PEND_OK; /* Clear pend status */
796 1 OSTCBCur->OSTCBStat = OS_STAT_RDY; /* Set status to ready */
797 1 OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0; /* No longer waiting for event */
798 1 }
799 #endif
800 /*$PAGE*/
801 /*
802 *********************************************************************************************************
803 * INITIALIZE EVENT CONTROL BLOCK'S WAIT LIST
804 *
805 * Description: This function is called by other uC/OS-II services to initialize the event wait list.
806 *
807 * Arguments : pevent is a pointer to the event control block allocated to the event.
808 *
809 * Returns : none
810 *
811 * Note : This function is INTERNAL to uC/OS-II and your application should not call it.
812 *********************************************************************************************************
813 */
814 #if OS_EVENT_EN
815 void OS_EventWaitListInit (OS_EVENT *pevent) reentrant
816 {
817 1 #if OS_LOWEST_PRIO <= 63
818 1 INT8U *ptbl;
819 1 #else
INT16U *ptbl;
#endif
822 1 INT8U i;
823 1
824 1
825 1 pevent->OSEventGrp = 0; /* No task waiting on event */
826 1 ptbl = &pevent->OSEventTbl[0];
827 1
C51 COMPILER V7.50 OS_CORE 12/14/2007 08:25:29 PAGE 15
828 1 for (i = 0; i < OS_EVENT_TBL_SIZE; i++) {
829 2 *ptbl++ = 0;
830 2 }
831 1 }
832 #endif
833 /*$PAGE*/
834 /*
835 *********************************************************************************************************
836 * INITIALIZATION
837 * INITIALIZE THE FREE LIST OF EVENT CONTROL BLOCKS
838 *
839 * Description: This function is called by OSInit() to initialize the free list of event control blocks.
840 *
841 * Arguments : none
842 *
843 * Returns : none
844 *********************************************************************************************************
845 */
846
847 static void OS_InitEventList (void) reentrant
848 {
849 1 #if OS_EVENT_EN && (OS_MAX_EVENTS > 0)
850 1 #if (OS_MAX_EVENTS > 1)
851 1 INT16U i;
852 1 OS_EVENT *pevent1;
853 1 OS_EVENT *pevent2;
854 1
855 1
856 1 OS_MemClr((INT8U *)&OSEventTbl[0], sizeof(OSEventTbl)); /* Clear the event table */
857 1 pevent1 = &OSEventTbl[0];
858 1 pevent2 = &OSEventTbl[1];
859 1 for (i = 0; i < (OS_MAX_EVENTS - 1); i++) { /* Init. list of free EVENT control blocks */
860 2 pevent1->OSEventType = OS_EVENT_TYPE_UNUSED;
861 2 pevent1->OSEventPtr = pevent2;
862 2 #if OS_EVENT_NAME_SIZE > 1
863 2 pevent1->OSEventName[0] = '?'; /* Unknown name */
864 2 pevent1->OSEventName[1] = OS_ASCII_NUL;
865 2 #endif
866 2 pevent1++;
867 2 pevent2++;
868 2 }
869 1 pevent1->OSEventType = OS_EVENT_TYPE_UNUSED;
870 1 pevent1->OSEventPtr = (OS_EVENT *)0;
871 1 #if OS_EVENT_NAME_SIZE > 1
872 1 pevent1->OSEventName[0] = '?';
873 1 pevent1->OSEventName[1] = OS_ASCII_NUL;
874 1 #endif
875 1 OSEventFreeList = &OSEventTbl[0];
876 1 #else
OSEventFreeList = &OSEventTbl[0]; /* Only have ONE event control block */
OSEventFreeList->OSEventType = OS_EVENT_TYPE_UNUSED;
OSEventFreeList->OSEventPtr = (OS_EVENT *)0;
#if OS_EVENT_NAME_SIZE > 1
OSEventFreeList->OSEventName[0] = '?'; /* Unknown name */
OSEventFreeList->OSEventName[1] = OS_ASCII_NUL;
#endif
#endif
885 1 #endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -