📄 os_task.lst
字号:
775 1 size = ptcb->OSTCBStkSize;
776 1 pchk = ptcb->OSTCBStkBottom;
777 1 OS_EXIT_CRITICAL();
778 1 #if OS_STK_GROWTH == 1
while (*pchk++ == (OS_STK)0) { /* Compute the number of zero entries on the stk */
free++;
}
#else
783 1 while (*pchk-- == (OS_STK)0) {
784 2 free++;
785 2 }
786 1 #endif
787 1 pdata->OSFree = free * sizeof(OS_STK); /* Compute number of free bytes on the stack */
788 1 pdata->OSUsed = (size - free) * sizeof(OS_STK); /* Compute number of bytes used on the stack */
789 1 return (OS_NO_ERR);
790 1 }
791 #endif
792 /*$PAGE*/
793 /*
794 *********************************************************************************************************
795 * SUSPEND A TASK
796 *
797 * Description: This function is called to suspend a task. The task can be the calling task if the
798 * priority passed to OSTaskSuspend() is the priority of the calling task or OS_PRIO_SELF.
C51 COMPILER V8.05a OS_TASK 04/11/2007 16:19:49 PAGE 14
799 *
800 * Arguments : prio is the priority of the task to suspend. If you specify OS_PRIO_SELF, the
801 * calling task will suspend itself and rescheduling will occur.
802 *
803 * Returns : OS_NO_ERR if the requested task is suspended
804 * OS_TASK_SUSPEND_IDLE if you attempted to suspend the idle task which is not allowed.
805 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
806 * (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
807 * OS_TASK_SUSPEND_PRIO if the task to suspend does not exist
808 *
809 * Note : You should use this function with great care. If you suspend a task that is waiting for
810 * an event (i.e. a message, a semaphore, a queue ...) you will prevent this task from
811 * running when the event arrives.
812 *********************************************************************************************************
813 */
814
815 #if OS_TASK_SUSPEND_EN > 0
816 INT8U OSTaskSuspend (INT8U prio) KCREENTRANT
817 {
818 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
821 1 BOOLEAN self;
822 1 OS_TCB *ptcb;
823 1 INT8U y;
824 1
825 1
826 1 #if OS_ARG_CHK_EN > 0
827 1 if (prio == OS_IDLE_PRIO) { /* Not allowed to suspend idle task */
828 2 return (OS_TASK_SUSPEND_IDLE);
829 2 }
830 1 if (prio >= OS_LOWEST_PRIO) { /* Task priority valid ? */
831 2 if (prio != OS_PRIO_SELF) {
832 3 return (OS_PRIO_INVALID);
833 3 }
834 2 }
835 1 #endif
836 1 OS_ENTER_CRITICAL();
837 1 if (prio == OS_PRIO_SELF) { /* See if suspend SELF */
838 2 prio = OSTCBCur->OSTCBPrio;
839 2 self = TRUE;
840 2 } else if (prio == OSTCBCur->OSTCBPrio) { /* See if suspending self */
841 2 self = TRUE;
842 2 } else {
843 2 self = FALSE; /* No suspending another task */
844 2 }
845 1 ptcb = OSTCBPrioTbl[prio];
846 1 if (ptcb == (OS_TCB *)0) { /* Task to suspend must exist */
847 2 OS_EXIT_CRITICAL();
848 2 return (OS_TASK_SUSPEND_PRIO);
849 2 }
850 1 y = ptcb->OSTCBY;
851 1 OSRdyTbl[y] &= ~ptcb->OSTCBBitX; /* Make task not ready */
852 1 if (OSRdyTbl[y] == 0x00) {
853 2 OSRdyGrp &= ~ptcb->OSTCBBitY;
854 2 }
855 1 ptcb->OSTCBStat |= OS_STAT_SUSPEND; /* Status of task is 'SUSPENDED' */
856 1 OS_EXIT_CRITICAL();
857 1 if (self == TRUE) { /* Context switch only if SELF */
858 2 OS_Sched();
859 2 }
860 1 return (OS_NO_ERR);
C51 COMPILER V8.05a OS_TASK 04/11/2007 16:19:49 PAGE 15
861 1 }
862 #endif
863 /*$PAGE*/
864 /*
865 *********************************************************************************************************
866 * QUERY A TASK
867 *
868 * Description: This function is called to obtain a copy of the desired task's TCB.
869 *
870 * Arguments : prio is the priority of the task to obtain information from.
871 *
872 * Returns : OS_NO_ERR if the requested task is suspended
873 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
874 * (i.e. > OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
875 * OS_PRIO_ERR if the desired task has not been created
876 *********************************************************************************************************
877 */
878
879 #if OS_TASK_QUERY_EN > 0
880 INT8U OSTaskQuery (INT8U prio, OS_TCB *pdata) KCREENTRANT
881 {
882 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
885 1 OS_TCB *ptcb;
886 1
887 1
888 1 #if OS_ARG_CHK_EN > 0
889 1 if (prio > OS_LOWEST_PRIO) { /* Task priority valid ? */
890 2 if (prio != OS_PRIO_SELF) {
891 3 return (OS_PRIO_INVALID);
892 3 }
893 2 }
894 1 #endif
895 1 OS_ENTER_CRITICAL();
896 1 if (prio == OS_PRIO_SELF) { /* See if suspend SELF */
897 2 prio = OSTCBCur->OSTCBPrio;
898 2 }
899 1 ptcb = OSTCBPrioTbl[prio];
900 1 if (ptcb == (OS_TCB *)0) { /* Task to query must exist */
901 2 OS_EXIT_CRITICAL();
902 2 return (OS_PRIO_ERR);
903 2 }
904 1 memcpy(pdata, ptcb, sizeof(OS_TCB)); /* Copy TCB into user storage area */
905 1 OS_EXIT_CRITICAL();
906 1 return (OS_NO_ERR);
907 1 }
908 #endif
909 /*$PAGE*/
910 /*
911 *********************************************************************************************************
912 * CLEAR TASK STACK
913 *
914 * Description: This function is used to clear the stack of a task (i.e. write all zeros)
915 *
916 * Arguments : pbos is a pointer to the task's bottom of stack. If the configuration constant
917 * OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
918 * memory to low memory). 'pbos' will thus point to the lowest (valid) memory
919 * location of the stack. If OS_STK_GROWTH is set to 0, 'pbos' will point to the
920 * highest memory location of the stack and the stack will grow with increasing
921 * memory locations. 'pbos' MUST point to a valid 'free' data item.
922 *
C51 COMPILER V8.05a OS_TASK 04/11/2007 16:19:49 PAGE 16
923 * size is the number of 'stack elements' to clear.
924 *
925 * opt contains additional information (or options) about the behavior of the task. The
926 * LOWER 8-bits are reserved by uC/OS-II while the upper 8 bits can be application
927 * specific. See OS_TASK_OPT_??? in uCOS-II.H.
928 *
929 * Returns : none
930 *********************************************************************************************************
931 */
932 #if OS_TASK_CREATE_EXT_EN > 0
933 void OS_TaskStkClr (OS_STK *pbos, INT32U size, INT16U opt) KCREENTRANT
934 {
935 1 if ((opt & OS_TASK_OPT_STK_CHK) != 0x0000) { /* See if stack checking has been enabled */
936 2 if ((opt & OS_TASK_OPT_STK_CLR) != 0x0000) { /* See if stack needs to be cleared */
937 3 #if OS_STK_GROWTH == 1
while (size > 0) { /* Stack grows from HIGH to LOW memory */
size--;
*pbos++ = (OS_STK)0; /* Clear from bottom of stack and up! */
}
#else
943 3 while (size > 0) { /* Stack grows from LOW to HIGH memory */
944 4 size--;
945 4 *pbos-- = (OS_STK)0; /* Clear from bottom of stack and down */
946 4 }
947 3 #endif
948 3 }
949 2 }
950 1 }
951
952 #endif
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 3830 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -