📄 os_core.lst
字号:
ppdata = ppdata; /* Prevent compiler warning for not using 'pdata' *
-/
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 > 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
658 /*$PAGE*/
659 /*
660 *********************************************************************************************************
661 * INITIALIZE TCB
662 *
663 * Description: This function is internal to uC/OS-II and is used to initialize a Task Control Block when
664 * a task is created (see OSTaskCreate() and OSTaskCreateExt()).
665 *
666 * Arguments : prio is the priority of the task being created
667 *
668 * ptos is a pointer to the task's top-of-stack assuming that the CPU registers
669 * have been placed on the stack. Note that the top-of-stack corresponds to a
670 * 'high' memory location is OS_STK_GROWTH is set to 1 and a 'low' memory
C51 COMPILER V7.50 OS_CORE 12/12/2007 16:55:22 PAGE 12
671 * location if OS_STK_GROWTH is set to 0. Note that stack growth is CPU
672 * specific.
673 *
674 * pbos is a pointer to the bottom of stack. A NULL pointer is passed if called by
675 * 'OSTaskCreate()'.
676 *
677 * id is the task's ID (0..65535)
678 *
679 * stk_size is the size of the stack (in 'stack units'). If the stack units are INT8Us
680 * then, 'stk_size' contains the number of bytes for the stack. If the stack
681 * units are INT32Us then, the stack contains '4 * stk_size' bytes. The stack
682 * units are established by the #define constant OS_STK which is CPU
683 * specific. 'stk_size' is 0 if called by 'OSTaskCreate()'.
684 *
685 * pext is a pointer to a user supplied memory area that is used to extend the task
686 * control block. This allows you to store the contents of floating-point
687 * registers, MMU registers or anything else you could find useful during a
688 * context switch. You can even assign a name to each task and store this name
689 * in this TCB extension. A NULL pointer is passed if called by OSTaskCreate().
690 *
691 * opt options as passed to 'OSTaskCreateExt()' or,
692 * 0 if called from 'OSTaskCreate()'.
693 *
694 * Returns : OS_NO_ERR if the call was successful
695 * OS_NO_MORE_TCB if there are no more free TCBs to be allocated and thus, the task cannot
696 * be created.
697 *
698 * Note : This function is INTERNAL to uC/OS-II and your application should not call it.
699 *********************************************************************************************************
700 */
701
702 INT8U OSTCBInit (INT8U prio, OS_STK *ptos, OS_STK *pbos, INT16U id, INT16U stk_size, void *pext, INT16U op
-t) reentrant
703 {
704 1 OS_TCB *ptcb;
705 1
706 1
707 1 OS_ENTER_CRITICAL();
708 1 ptcb = OSTCBFreeList; /* Get a free TCB from the free TCB list */
709 1 if (ptcb != (OS_TCB *)0) {
710 2 OSTCBFreeList = ptcb->OSTCBNext; /* Update pointer to free TCB list */
711 2 OS_EXIT_CRITICAL();
712 2 ptcb->OSTCBStkPtr = ptos; /* Load Stack pointer in TCB */
713 2 ptcb->OSTCBPrio = (INT8U)prio; /* Load task priority into TCB */
714 2 ptcb->OSTCBStat = OS_STAT_RDY; /* Task is ready to run */
715 2 ptcb->OSTCBDly = 0; /* Task is not delayed */
716 2
717 2 #if OS_TASK_CREATE_EXT_EN
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
724 2 pext = pext; /* Prevent compiler warning if not used */
725 2 stk_size = stk_size;
726 2 pbos = pbos;
727 2 opt = opt;
728 2 id = id;
729 2 #endif
730 2
731 2 #if OS_TASK_DEL_EN
C51 COMPILER V7.50 OS_CORE 12/12/2007 16:55:22 PAGE 13
ptcb->OSTCBDelReq = OS_NO_ERR;
#endif
734 2
735 2 ptcb->OSTCBY = prio >> 3; /* Pre-compute X, Y, BitX and BitY */
736 2 ptcb->OSTCBBitY = OSMapTbl[ptcb->OSTCBY];
737 2 ptcb->OSTCBX = prio & 0x07;
738 2 ptcb->OSTCBBitX = OSMapTbl[ptcb->OSTCBX];
739 2
740 2 #if OS_MBOX_EN || (OS_Q_EN && (OS_MAX_QS >= 2)) || OS_SEM_EN
ptcb->OSTCBEventPtr = (OS_EVENT *)0; /* Task is not pending on an event */
#endif
743 2
744 2 #if OS_MBOX_EN || (OS_Q_EN && (OS_MAX_QS >= 2))
ptcb->OSTCBMsg = (void *)0; /* No message received */
#endif
747 2
748 2 OS_ENTER_CRITICAL();
749 2 OSTCBPrioTbl[prio] = ptcb;
750 2 ptcb->OSTCBNext = OSTCBList; /* Link into TCB chain */
751 2 ptcb->OSTCBPrev = (OS_TCB *)0;
752 2 if (OSTCBList != (OS_TCB *)0) {
753 3 OSTCBList->OSTCBPrev = ptcb;
754 3 }
755 2 OSTCBList = ptcb;
756 2 OSRdyGrp |= ptcb->OSTCBBitY; /* Make task ready to run */
757 2 OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
758 2 OS_EXIT_CRITICAL();
759 2 return (OS_NO_ERR);
760 2 } else {
761 2 OS_EXIT_CRITICAL();
762 2 return (OS_NO_MORE_TCB);
763 2 }
764 1 }
765 /*$PAGE*/
766 /*
767 *********************************************************************************************************
768 * PROCESS SYSTEM TICK
769 *
770 * Description: This function is used to signal to uC/OS-II the occurrence of a 'system tick' (also known
771 * as a 'clock tick'). This function should be called by the ticker ISR but, can also be
772 * called by a high priority task.
773 *
774 * Arguments : none
775 *
776 * Returns : none
777 *********************************************************************************************************
778 */
779
780 void OSTimeTick (void) reentrant
781 {
782 1 OS_TCB *ptcb;
783 1
784 1
785 1 OSTimeTickHook(); /* Call user definable hook */
786 1 ptcb = OSTCBList; /* Point at first TCB in TCB list */
787 1 while (ptcb->OSTCBPrio != OS_IDLE_PRIO) { /* Go through all TCBs in TCB list */
788 2 OS_ENTER_CRITICAL();
789 2 if (ptcb->OSTCBDly != 0) { /* Delayed or waiting for event with TO */
790 3 if (--ptcb->OSTCBDly == 0) { /* Decrement nbr of ticks to end of delay */
791 4 if (!(ptcb->OSTCBStat & OS_STAT_SUSPEND)) { /* Is task suspended? */
792 5 OSRdyGrp |= ptcb->OSTCBBitY; /* No, Make task Rdy to Run (timed out)*/
793 5 OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
C51 COMPILER V7.50 OS_CORE 12/12/2007 16:55:22 PAGE 14
794 5 } else { /* Yes, Leave 1 tick to prevent ... */
795 5 ptcb->OSTCBDly = 1; /* ... loosing the task when the ... */
796 5 } /* ... suspension is removed. */
797 4 }
798 3 }
799 2 ptcb = ptcb->OSTCBNext; /* Point at next TCB in TCB list */
800 2 OS_EXIT_CRITICAL();
801 2 }
802 1 OS_ENTER_CRITICAL(); /* Update the 32-bit tick counter */
803 1 OSTime++;
804 1 OS_EXIT_CRITICAL();
805 1 }
806 /*$PAGE*/
807 /*
808 *********************************************************************************************************
809 * GET VERSION
810 *
811 * Description: This function is used to return the version number of uC/OS-II. The returned value
812 * corresponds to uC/OS-II's version number multiplied by 100. In other words, version 2.00
813 * would be returned as 200.
814 *
815 * Arguments : none
816 *
817 * Returns : the version number of uC/OS-II multiplied by 100.
818 *********************************************************************************************************
819 */
820
821 INT16U OSVersion (void) reentrant
822 {
823 1 return (OS_VERSION);
824 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 2049 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 653 ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = 9 ----
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 + -