📄 os_core.lst
字号:
782 1
783 1
784 1 ppdata = ppdata; /* Prevent compiler warning for not using 'ppdata'
-*/
785 1 for (;;) {
786 2 OS_ENTER_CRITICAL();
787 2 OSIdleCtr++;
788 2 OS_EXIT_CRITICAL();
789 2 OSTaskIdleHook(); /* Call user definable HOOK */
790 2 }
791 1 }
792 /*$PAGE*/
793 /*
794 *********************************************************************************************************
795 * STATISTICS TASK
796 *
797 * Description: This task is internal to uC/OS-II and is used to compute some statistics about the
798 * multitasking environment. Specifically, OS_TaskStat() computes the CPU usage.
799 * CPU usage is determined by:
800 *
801 * OSIdleCtr
802 * OSCPUUsage = 100 * (1 - ------------) (units are in %)
803 * OSIdleCtrMax
804 *
805 * Arguments : ppdata this pointer is not used at this time.
806 *
807 * Returns : none
808 *
C51 COMPILER V7.02b OS_CORE 11/29/2006 14:48:11 PAGE 15
809 * Notes : 1) This task runs at a priority level higher than the idle task. In fact, it runs at the
810 * next higher priority, OS_IDLE_PRIO-1.
811 * 2) You can disable this task by setting the configuration #define OS_TASK_STAT_EN to 0.
812 * 3) We delay for 5 seconds in the beginning to allow the system to reach steady state and
813 * have all other tasks created before we do statistics. You MUST have at least a delay
814 * of 2 seconds to allow for the system to establish the maximum value for the idle
815 * counter.
816 *********************************************************************************************************
817 */
818
819 #if OS_TASK_STAT_EN > 0
void OS_TaskStat (void *ppdata) reentrant
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
INT32U run;
INT8S usage;
ppdata = ppdata; /* Prevent compiler warning for not using 'ppdata' */
while (OSStatRdy == FALSE) {
OSTimeDly(2 * OS_TICKS_PER_SEC); /* Wait until statistic task is ready */
}
for (;;) {
OS_ENTER_CRITICAL();
OSIdleCtrRun = OSIdleCtr; /* Obtain the of the idle counter for the past second */
run = OSIdleCtr;
OSIdleCtr = 0L; /* Reset the idle counter for the next second */
OS_EXIT_CRITICAL();
if (OSIdleCtrMax > 0L) {
usage = (INT8S)(100L - 100L * run / OSIdleCtrMax);
if (usage >= 0) { /* Make sure we don't have a negative percentage */
OSCPUUsage = usage;
} else {
OSCPUUsage = 0;
}
} else {
OSCPUUsage = 0;
}
OSTaskStatHook(); /* Invoke user definable hook */
OSTimeDly(OS_TICKS_PER_SEC); /* Accumulate OSIdleCtr for the next second */
}
}
#endif
854 /*$PAGE*/
855 /*
856 *********************************************************************************************************
857 * INITIALIZE TCB
858 *
859 * Description: This function is internal to uC/OS-II and is used to initialize a Task Control Block when
860 * a task is created (see OSTaskCreate() and OSTaskCreateExt()).
861 *
862 * Arguments : prio is the priority of the task being created
863 *
864 * ptos is a pointer to the task's top-of-stack assuming that the CPU registers
865 * have been placed on the stack. Note that the top-of-stack corresponds to a
866 * 'high' memory location is OS_STK_GROWTH is set to 1 and a 'low' memory
867 * location if OS_STK_GROWTH is set to 0. Note that stack growth is CPU
868 * specific.
869 *
870 * pbos is a pointer to the bottom of stack. A NULL pointer is passed if called by
C51 COMPILER V7.02b OS_CORE 11/29/2006 14:48:11 PAGE 16
871 * 'OSTaskCreate()'.
872 *
873 * id is the task's ID (0..65535)
874 *
875 * stk_size is the size of the stack (in 'stack units'). If the stack units are INT8Us
876 * then, 'stk_size' contains the number of bytes for the stack. If the stack
877 * units are INT32Us then, the stack contains '4 * stk_size' bytes. The stack
878 * units are established by the #define constant OS_STK which is CPU
879 * specific. 'stk_size' is 0 if called by 'OSTaskCreate()'.
880 *
881 * pext is a pointer to a user supplied memory area that is used to extend the task
882 * control block. This allows you to store the contents of floating-point
883 * registers, MMU registers or anything else you could find useful during a
884 * context switch. You can even assign a name to each task and store this name
885 * in this TCB extension. A NULL pointer is passed if called by OSTaskCreate().
886 *
887 * opt options as passed to 'OSTaskCreateExt()' or,
888 * 0 if called from 'OSTaskCreate()'.
889 *
890 * Returns : OS_NO_ERR if the call was successful
891 * OS_NO_MORE_TCB if there are no more free TCBs to be allocated and thus, the task cannot
892 * be created.
893 *
894 * Note : This function is INTERNAL to uC/OS-II and your application should not call it.
895 *********************************************************************************************************
896 */
897
898 INT8U OS_TCBInit (INT8U prio, OS_STK *ptos, OS_STK *pbos, INT16U id, INT32U stk_size, void *pext, INT16U
-opt) reentrant
899 {
900 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
903 1 OS_TCB *ptcb;
904 1
905 1
906 1 OS_ENTER_CRITICAL();
907 1 ptcb = OSTCBFreeList; /* Get a free TCB from the free TCB list */
908 1 if (ptcb != (OS_TCB *)0) {
909 2 OSTCBFreeList = ptcb->OSTCBNext; /* Update pointer to free TCB list */
910 2 OS_EXIT_CRITICAL();
911 2 ptcb->OSTCBStkPtr = ptos; /* Load Stack pointer in TCB */
912 2 ptcb->OSTCBPrio = (INT8U)prio; /* Load task priority into TCB */
913 2 ptcb->OSTCBStat = OS_STAT_RDY; /* Task is ready to run */
914 2 ptcb->OSTCBDly = 0; /* Task is not delayed */
915 2
916 2 #if OS_TASK_CREATE_EXT_EN > 0
ptcb->OSTCBExtPtr = pext; /* Store pointer to TCB extension */
ptcb->OSTCBStkSize = stk_size; /* Store stack size */
ptcb->OSTCBStkBottom = pbos; /* Store pointer to bottom of stack */
ptcb->OSTCBOpt = opt; /* Store task options */
ptcb->OSTCBId = id; /* Store task ID */
#else
923 2 pext = pext; /* Prevent compiler warning if not used */
924 2 stk_size = stk_size;
925 2 pbos = pbos;
926 2 opt = opt;
927 2 id = id;
928 2 #endif
929 2
930 2 #if OS_TASK_DEL_EN > 0
ptcb->OSTCBDelReq = OS_NO_ERR;
C51 COMPILER V7.02b OS_CORE 11/29/2006 14:48:11 PAGE 17
#endif
933 2
934 2 ptcb->OSTCBY = prio >> 3; /* Pre-compute X, Y, BitX and BitY */
935 2 ptcb->OSTCBBitY = OSMapTbl[ptcb->OSTCBY];
936 2 ptcb->OSTCBX = prio & 0x07;
937 2 ptcb->OSTCBBitX = OSMapTbl[ptcb->OSTCBX];
938 2
939 2 #if OS_EVENT_EN > 0
ptcb->OSTCBEventPtr = (OS_EVENT *)0; /* Task is not pending on an event */
#endif
942 2
943 2 #if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0) && (OS_TASK_DEL_EN > 0)
ptcb->OSTCBFlagNode = (OS_FLAG_NODE *)0; /* Task is not pending on an event flag */
#endif
946 2
947 2 #if (OS_MBOX_EN > 0) || ((OS_Q_EN > 0) && (OS_MAX_QS > 0))
ptcb->OSTCBMsg = (void *)0; /* No message received */
#endif
950 2
951 2 #if OS_VERSION >= 204
952 2 OSTCBInitHook(ptcb);
953 2 #endif
954 2
955 2 OSTaskCreateHook(ptcb); /* Call user defined hook */
956 2
957 2 OS_ENTER_CRITICAL();
958 2 OSTCBPrioTbl[prio] = ptcb;
959 2 ptcb->OSTCBNext = OSTCBList; /* Link into TCB chain */
960 2 ptcb->OSTCBPrev = (OS_TCB *)0;
961 2 if (OSTCBList != (OS_TCB *)0) {
962 3 OSTCBList->OSTCBPrev = ptcb;
963 3 }
964 2 OSTCBList = ptcb;
965 2 OSRdyGrp |= ptcb->OSTCBBitY; /* Make task ready to run */
966 2 OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
967 2 OS_EXIT_CRITICAL();
968 2 return (OS_NO_ERR);
969 2 }
970 1 OS_EXIT_CRITICAL();
971 1 return (OS_NO_MORE_TCB);
972 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1978 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 619 ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = 22 ----
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 + -