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