📄 os_core.lst
字号:
546 1 if (OSRunning == FALSE) {
547 2 y = OSUnMapTbl[OSRdyGrp]; /* Find highest priority's task priority number */
548 2 x = OSUnMapTbl[OSRdyTbl[y]];
549 2 OSPrioHighRdy = (INT8U)((y << 3) + x);
550 2 OSPrioCur = OSPrioHighRdy;
551 2 OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy]; /* Point to highest priority task ready to run */
552 2 OSTCBCur = OSTCBHighRdy;
553 2 OSStartHighRdy(); /* Execute target specific code to start task */
554 2 }
555 1 }
556 /*$PAGE*/
557 /*
558 *********************************************************************************************************
559 * STATISTICS INITIALIZATION
560 *
561 * Description: This function is called by your application to establish CPU usage by first determining
562 * how high a 32-bit counter would count to in 1 second if no other tasks were to execute
563 * during that time. CPU usage is then determined by a low priority task which keeps track
564 * of this 32-bit counter every second but this time, with other tasks running. CPU usage is
565 * determined by:
566 *
567 * OSIdleCtr
568 * CPU Usage (%) = 100 * (1 - ------------)
569 * OSIdleCtrMax
570 *
571 * Arguments : none
572 *
573 * Returns : none
574 *********************************************************************************************************
575 */
576
577 #if OS_TASK_STAT_EN
void OSStatInit (void) REENTRANT
{
OSTimeDly(2); /* 下一个为统计任务,但OSStatRdy为false所以延时,进入IDLE任
-务 */
OS_ENTER_CRITICAL();
OSIdleCtr = 0L; /* Clear idle counter
- */
OS_EXIT_CRITICAL();
OSTimeDly(OS_TICKS_PER_SEC); /* 延时一秒,直接进入IDLE任务中,统计1秒空闲时间有多少计数
- */
OS_ENTER_CRITICAL();
OSIdleCtrMax = OSIdleCtr; /* Store maximum idle counter count in 1 second
- */
OSStatRdy = TRUE;
C51 COMPILER V7.06 OS_CORE 07/30/2008 11:19:14 PAGE 11
OS_EXIT_CRITICAL(); /* 初始化得到OSIdleCtr在一秒内就大计数,用些值可计百分比 */
}
#endif
591 /*$PAGE*/
592 /*
593 *********************************************************************************************************
594 * IDLE TASK
595 *
596 * Description: This task is internal to uC/OS-II and executes whenever no other higher priority tasks
597 * executes because they are waiting for event(s) to occur.
598 *
599 * Arguments : none
600 *
601 * Returns : none
602 *********************************************************************************************************
603 */
604
605 void OSTaskIdle (void DT_XDATA * ppdata) REENTRANT
606 {
607 1 ppdata = ppdata; /* Prevent compiler warning for not using 'ppdata'
-*/
608 1 for (;;) {
609 2 OS_ENTER_CRITICAL();
610 2 OSIdleCtr++;
611 2 OS_EXIT_CRITICAL();
612 2 }
613 1 }
614 /*$PAGE*/
615 /*
616 *********************************************************************************************************
617 * STATISTICS TASK
618 *
619 * Description: This task is internal to uC/OS-II and is used to compute some statistics about the
620 * multitasking environment. Specifically, OSTaskStat() computes the CPU usage.
621 * CPU usage is determined by:
622 *
623 * OSIdleCtr
624 * OSCPUUsage = 100 * (1 - ------------) (units are in %)
625 * OSIdleCtrMax
626 *
627 * Arguments : ppdata this pointer is not used at this time.
628 *
629 * Returns : none
630 *
631 * Notes : 1) This task runs at a priority level higher than the idle task. In fact, it runs at the
632 * next higher priority, OS_IDLE_PRIO-1.
633 * 2) You can disable this task by setting the configuration #define OS_TASK_STAT_EN to 0.
634 * 3) We delay for 5 seconds in the beginning to allow the system to reach steady state and
635 * have all other tasks created before we do statistics. You MUST have at least a delay
636 * of 2 seconds to allow for the system to establish the maximum value for the idle
637 * counter.
638 *********************************************************************************************************
639 */
640
641 #if OS_TASK_STAT_EN
void OSTaskStat (void DT_XDATA * ppdata) REENTRANT
{
INT32U run;
INT8S usage;
ppdata = ppdata; /* Prevent compiler warning for not using 'ppdata'
C51 COMPILER V7.06 OS_CORE 07/30/2008 11:19:14 PAGE 12
-*/
while (OSStatRdy == FALSE) {
OSTimeDly(2 * OS_TICKS_PER_SEC); /* 统计任务还没有准备好继续延时 */
}
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 > 100) {
OSCPUUsage = 100;
} else if (usage < 0) {
OSCPUUsage = 0;
} else {
OSCPUUsage = usage;
}
} else {
OSCPUUsage = 0;
}
OSTaskStatHook(); /* Invoke user definable hook */
OSTimeDly(OS_TICKS_PER_SEC); /* Accumulate OSIdleCtr for the next second */
}
}
#endif
675 /*$PAGE*/
676 /*
677 *********************************************************************************************************
678 * INITIALIZE TCB
679 *
680 * Description: This function is internal to uC/OS-II and is used to initialize a Task Control Block when
681 * a task is created (see OSTaskCreate() and OSTaskCreateExt()).
682 *
683 * Arguments : prio is the priority of the task being created
684 *
685 * ptos is a pointer to the task's top-of-stack assuming that the CPU registers
686 * have been placed on the stack. Note that the top-of-stack corresponds to a
687 * 'high' memory location is OS_STK_GROWTH is set to 1 and a 'low' memory
688 * location if OS_STK_GROWTH is set to 0. Note that stack growth is CPU
689 * specific.
690 *
691 * pbos is a pointer to the bottom of stack. A NULL pointer is passed if called by
692 * 'OSTaskCreate()'.
693 *
694 * id is the task's ID (0..65535)
695 *
696 * stk_size is the size of the stack (in 'stack units'). If the stack units are INT8Us
697 * then, 'stk_size' contains the number of bytes for the stack. If the stack
698 * units are INT32Us then, the stack contains '4 * stk_size' bytes. The stack
699 * units are established by the #define constant OS_STK which is CPU
700 * specific. 'stk_size' is 0 if called by 'OSTaskCreate()'.
701 *
702 * pext is a pointer to a user supplied memory area that is used to extend the task
703 * control block. This allows you to store the contents of floating-point
704 * registers, MMU registers or anything else you could find useful during a
705 * context switch. You can even assign a name to each task and store this name
706 * in this TCB extension. A NULL pointer is passed if called by OSTaskCreate().
707 *
C51 COMPILER V7.06 OS_CORE 07/30/2008 11:19:14 PAGE 13
708 * opt options as passed to 'OSTaskCreateExt()' or,
709 * 0 if called from 'OSTaskCreate()'.
710 *
711 * Returns : OS_NO_ERR if the call was successful
712 * OS_NO_MORE_TCB if there are no more free TCBs to be allocated and thus, the task cannot
713 * be created.
714 *
715 * Note : This function is INTERNAL to uC/OS-II and your application should not call it.
716 *********************************************************************************************************
717 */
718
719 INT8U OSTCBInit (INT8U prio, OS_STK DT_XDATA * ptos, OS_STK DT_XDATA * pbos, INT16U id, INT16U stk_size, v
-oid DT_XDATA * pext, INT16U opt) REENTRANT
720 {
721 1 OS_TCB DT_XDATA * ptcb;
722 1
723 1
724 1 OS_ENTER_CRITICAL();
725 1
726 1 ptcb = OSTCBFreeList; /* 从OSTCBFreeList中拿出一个TCB,如果OSTCBFreeList为空,则
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -