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