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