📄 os_core.lst
字号:
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
591 /*$PAGE*/
592 /*
593 *********************************************************************************************************
594 * INITIALIZE TCB
595 *
596 * Description: This function is internal to uC/OS-II and is used to initialize a Task Control Block when
597 * a task is created (see OSTaskCreate() and OSTaskCreateExt()).
598 *
599 * Arguments : prio is the priority of the task being created
600 *
601 * ptos is a pointer to the task's top-of-stack assuming that the CPU registers
602 * have been placed on the stack. Note that the top-of-stack corresponds to a
603 * 'high' memory location is OS_STK_GROWTH is set to 1 and a 'low' memory
604 * location if OS_STK_GROWTH is set to 0. Note that stack growth is CPU
605 * specific.
606 *
607 * pbos is a pointer to the bottom of stack. A NULL pointer is passed if called by
608 * 'OSTaskCreate()'.
609 *
610 * id is the task's ID (0..65535)
C51 COMPILER V7.20 OS_CORE 12/29/2004 11:50:53 PAGE 11
611 *
612 * stk_size is the size of the stack (in 'stack units'). If the stack units are INT8Us
613 * then, 'stk_size' contains the number of bytes for the stack. If the stack
614 * units are INT32Us then, the stack contains '4 * stk_size' bytes. The stack
615 * units are established by the #define constant OS_STK which is CPU
616 * specific. 'stk_size' is 0 if called by 'OSTaskCreate()'.
617 *
618 * pext is a pointer to a user supplied memory area that is used to extend the task
619 * control block. This allows you to store the contents of floating-point
620 * registers, MMU registers or anything else you could find useful during a
621 * context switch. You can even assign a name to each task and store this name
622 * in this TCB extension. A NULL pointer is passed if called by OSTaskCreate().
623 *
624 * opt options as passed to 'OSTaskCreateExt()' or,
625 * 0 if called from 'OSTaskCreate()'.
626 *
627 * Returns : OS_NO_ERR if the call was successful
628 * OS_NO_MORE_TCB if there are no more free TCBs to be allocated and thus, the task cannot
629 * be created.
630 *
631 * Note : This function is INTERNAL to uC/OS-II and your application should not call it.
632 *********************************************************************************************************
633 */
634 static OS_TCB *ptcb11;
635 INT8U OSTCBInit (INT8U prio,
636 OS_STK *ptos,
637 OS_STK *pbos,
638 INT16U id,
639 INT16U stk_size,
640 void *pext,
641 INT16U opt)reentrant
642 {
643 1 OS_ENTER_CRITICAL();
644 1 ptcb11 = OSTCBFreeList; /* Get a free TCB from the free TCB list *
-/
645 1 if (ptcb11 != (OS_TCB *)0) {
646 2 OSTCBFreeList = ptcb11->OSTCBNext; /* Update pointer to free TCB list *
-/
647 2 OS_EXIT_CRITICAL();
648 2 ptcb11->OSTCBStkPtr = ptos; /* Load Stack pointer in TCB *
-/
649 2 ptcb11->OSTCBPrio = (INT8U)prio; /* Load task priority into TCB *
-/
650 2 ptcb11->OSTCBStat = OS_STAT_RDY; /* Task is ready to run *
-/
651 2 ptcb11->OSTCBDly = 0; /* Task is not delayed *
-/
652 2
653 2 #if OS_TASK_CREATE_EXT_EN
ptcb11->OSTCBExtPtr = pext; /* Store pointer to TCB extension *
-/
ptcb11->OSTCBStkSize = stk_size; /* Store stack size *
-/
ptcb11->OSTCBStkBottom = pbos; /* Store pointer to bottom of stack *
-/
ptcb11->OSTCBOpt = opt; /* Store task options *
-/
ptcb11->OSTCBId = id; /* Store task ID *
-/
#else
660 2 pext = pext; /* Prevent compiler warning if not used */
661 2 stk_size = stk_size;
C51 COMPILER V7.20 OS_CORE 12/29/2004 11:50:53 PAGE 12
662 2 pbos = pbos;
663 2 opt = opt;
664 2 id = id;
665 2 #endif
666 2
667 2 #if OS_TASK_DEL_EN
ptcb11->OSTCBDelReq = OS_NO_ERR;
#endif
670 2
671 2 ptcb11->OSTCBY = prio >> 3; /* Pre-compute X, Y, BitX and BitY *
-/
672 2 ptcb11->OSTCBBitY = OSMapTbl[ptcb11->OSTCBY];
673 2 ptcb11->OSTCBX = prio & 0x07;
674 2 ptcb11->OSTCBBitX = OSMapTbl[ptcb11->OSTCBX];
675 2
676 2 #if OS_MBOX_EN || (OS_Q_EN && (OS_MAX_QS >= 2)) || OS_Sem_EN
677 2 ptcb11->OSTCBEventPtr = (OS_EVENT *)0; /* Task is not pending on an event *
-/
678 2 #endif
679 2
680 2 #if OS_MBOX_EN || (OS_Q_EN && (OS_MAX_QS >= 2))
ptcb11->OSTCBMsg = (void *)0; /* No message received *
-/
#endif
683 2
684 2 OS_ENTER_CRITICAL();
685 2 OSTCBPrioTbl[prio] = ptcb11;
686 2 ptcb11->OSTCBNext = OSTCBList; /* Link into TCB chain *
-/
687 2 ptcb11->OSTCBPrev = (OS_TCB *)0;
688 2 if (OSTCBList != (OS_TCB *)0) {
689 3 OSTCBList->OSTCBPrev = ptcb11;
690 3 }
691 2 OSTCBList = ptcb11;
692 2 OSRdyGrp |= ptcb11->OSTCBBitY; /* Make task ready to run *
-/
693 2 OSRdyTbl[ptcb11->OSTCBY] |= ptcb11->OSTCBBitX;
694 2 OS_EXIT_CRITICAL();
695 2 return (OS_NO_ERR);
696 2 } else {
697 2 OS_EXIT_CRITICAL();
698 2 return (OS_NO_MORE_TCB);
699 2 }
700 1 }
701 /*$PAGE*/
702 /*
703 *********************************************************************************************************
704 * PROCESS SYSTEM TICK
705 *
706 * Description: This function is used to signal to uC/OS-II the occurrence of a 'system tick' (also known
707 * as a 'clock tick'). This function should be called by the ticker ISR but, can also be
708 * called by a high priority task.
709 *
710 * Arguments : none
711 *
712 * Returns : none
713 *********************************************************************************************************
714 */
715
716 void OSTimeTick (void)
717 {
718 1 OS_TCB *ptcb;
C51 COMPILER V7.20 OS_CORE 12/29/2004 11:50:53 PAGE 13
719 1
720 1
721 1 OSTimeTickHook(); /* Call user definable hook */
722 1 ptcb = OSTCBList; /* Point at first TCB in TCB list */
723 1 while (ptcb->OSTCBPrio != OS_IDLE_PRIO) { /* Go through all TCBs in TCB list */
724 2 OS_ENTER_CRITICAL();
725 2 if (ptcb->OSTCBDly != 0) { /* Delayed or waiting for event with TO */
726 3 if (--ptcb->OSTCBDly == 0) { /* Decrement nbr of ticks to end of delay */
727 4 if (!(ptcb->OSTCBStat & OS_STAT_SUSPEND)) { /* Is task suspended? */
728 5 OSRdyGrp |= ptcb->OSTCBBitY; /* No, Make task Rdy to Run (timed out)*/
729 5 OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
730 5 } else { /* Yes, Leave 1 tick to prevent ... */
731 5 ptcb->OSTCBDly = 1; /* ... loosing the task when the ... */
732 5 } /* ... suspension is removed. */
733 4 }
734 3 }
735 2 ptcb = ptcb->OSTCBNext; /* Point at next TCB in TCB list */
736 2 OS_EXIT_CRITICAL();
737 2 }
738 1 OS_ENTER_CRITICAL(); /* Update the 32-bit tick counter */
739 1 OSTime++;
740 1 OS_EXIT_CRITICAL();
741 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 2805 ----
CONSTANT SIZE = 264 ----
XDATA SIZE = 245 5
PDATA SIZE = ---- ----
DATA SIZE = 3 ----
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 + -