📄 os_task.lst
字号:
575 #endif
576 /*$PAGE*/
577 /*
578 *********************************************************************************************************
579 * STACK CHECKING
580 *
581 * Description: This function is called to check the amount of free memory left on the specified task's
582 * stack.
583 *
584 * Arguments : prio is the task priority
585 *
586 * pdata is a pointer to a data structure of type OS_STK_DATA.
587 *
588 * Returns : OS_NO_ERR upon success
589 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
590 * (i.e. > OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
591 * OS_TASK_NOT_EXIST if the desired task has not been created
592 * OS_TASK_OPT_ERR if you did NOT specified OS_TASK_OPT_STK_CHK when the task was created
593 *********************************************************************************************************
594 */
595 #if OS_TASK_CREATE_EXT_EN > 0
596 INT8U OSTaskStkChk (INT8U prio, OS_STK_DATA *pdata) KCREENTRANT
597 {
598 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
601 1 OS_TCB *ptcb;
602 1 OS_STK *pchk;
603 1 INT32U free;
604 1 INT32U size;
605 1
606 1
607 1 #if OS_ARG_CHK_EN > 0
608 1 if (prio > OS_LOWEST_PRIO && prio != OS_PRIO_SELF) { /* Make sure task priority is valid */
609 2 return (OS_PRIO_INVALID);
610 2 }
611 1 #endif
C51 COMPILER V6.23a OS_TASK 12/09/2004 16:50:26 PAGE 11
612 1 pdata->OSFree = 0; /* Assume failure, set to 0 size */
613 1 pdata->OSUsed = 0;
614 1 OS_ENTER_CRITICAL();
615 1 if (prio == OS_PRIO_SELF) { /* See if check for SELF */
616 2 prio = OSTCBCur->OSTCBPrio;
617 2 }
618 1 ptcb = OSTCBPrioTbl[prio];
619 1 if (ptcb == (OS_TCB *)0) { /* Make sure task exist */
620 2 OS_EXIT_CRITICAL();
621 2 return (OS_TASK_NOT_EXIST);
622 2 }
623 1 if ((ptcb->OSTCBOpt & OS_TASK_OPT_STK_CHK) == 0) { /* Make sure stack checking option is set */
624 2 OS_EXIT_CRITICAL();
625 2 return (OS_TASK_OPT_ERR);
626 2 }
627 1 free = 0;
628 1 size = ptcb->OSTCBStkSize;
629 1 pchk = ptcb->OSTCBStkBottom;
630 1 OS_EXIT_CRITICAL();
631 1 #if OS_STK_GROWTH == 1
632 1 while (*pchk++ == (OS_STK)0) { /* Compute the number of zero entries on the stk */
633 2 free++;
634 2 }
635 1 #else
while (*pchk-- == (OS_STK)0) {
free++;
}
#endif
640 1 pdata->OSFree = free * sizeof(OS_STK); /* Compute number of free bytes on the stack */
641 1 pdata->OSUsed = (size - free) * sizeof(OS_STK); /* Compute number of bytes used on the stack */
642 1 return (OS_NO_ERR);
643 1 }
644 #endif
645 /*$PAGE*/
646 /*
647 *********************************************************************************************************
648 * SUSPEND A TASK
649 *
650 * Description: This function is called to suspend a task. The task can be the calling task if the
651 * priority passed to OSTaskSuspend() is the priority of the calling task or OS_PRIO_SELF.
652 *
653 * Arguments : prio is the priority of the task to suspend. If you specify OS_PRIO_SELF, the
654 * calling task will suspend itself and rescheduling will occur.
655 *
656 * Returns : OS_NO_ERR if the requested task is suspended
657 * OS_TASK_SUSPEND_IDLE if you attempted to suspend the idle task which is not allowed.
658 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
659 * (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
660 * OS_TASK_SUSPEND_PRIO if the task to suspend does not exist
661 *
662 * Note : You should use this function with great care. If you suspend a task that is waiting for
663 * an event (i.e. a message, a semaphore, a queue ...) you will prevent this task from
664 * running when the event arrives.
665 *********************************************************************************************************
666 */
667
668 #if OS_TASK_SUSPEND_EN > 0
669 INT8U OSTaskSuspend (INT8U prio) KCREENTRANT
670 {
671 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
C51 COMPILER V6.23a OS_TASK 12/09/2004 16:50:26 PAGE 12
674 1 BOOLEAN self;
675 1 OS_TCB *ptcb;
676 1
677 1
678 1 #if OS_ARG_CHK_EN > 0
679 1 if (prio == OS_IDLE_PRIO) { /* Not allowed to suspend idle task */
680 2 return (OS_TASK_SUSPEND_IDLE);
681 2 }
682 1 if (prio >= OS_LOWEST_PRIO && prio != OS_PRIO_SELF) { /* Task priority valid ? */
683 2 return (OS_PRIO_INVALID);
684 2 }
685 1 #endif
686 1 OS_ENTER_CRITICAL();
687 1 if (prio == OS_PRIO_SELF) { /* See if suspend SELF */
688 2 prio = OSTCBCur->OSTCBPrio;
689 2 self = TRUE;
690 2 } else if (prio == OSTCBCur->OSTCBPrio) { /* See if suspending self */
691 2 self = TRUE;
692 2 } else {
693 2 self = FALSE; /* No suspending another task */
694 2 }
695 1 ptcb = OSTCBPrioTbl[prio];
696 1 if (ptcb == (OS_TCB *)0) { /* Task to suspend must exist */
697 2 OS_EXIT_CRITICAL();
698 2 return (OS_TASK_SUSPEND_PRIO);
699 2 }
700 1 if ((OSRdyTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0x00) { /* Make task not ready */
701 2 OSRdyGrp &= ~ptcb->OSTCBBitY;
702 2 }
703 1 ptcb->OSTCBStat |= OS_STAT_SUSPEND; /* Status of task is 'SUSPENDED' */
704 1 OS_EXIT_CRITICAL();
705 1 if (self == TRUE) { /* Context switch only if SELF */
706 2 OS_Sched();
707 2 }
708 1 return (OS_NO_ERR);
709 1 }
710 #endif
711 /*$PAGE*/
712 /*
713 *********************************************************************************************************
714 * QUERY A TASK
715 *
716 * Description: This function is called to obtain a copy of the desired task's TCB.
717 *
718 * Arguments : prio is the priority of the task to obtain information from.
719 *
720 * Returns : OS_NO_ERR if the requested task is suspended
721 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
722 * (i.e. > OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
723 * OS_PRIO_ERR if the desired task has not been created
724 *********************************************************************************************************
725 */
726
727 #if OS_TASK_QUERY_EN > 0
728 INT8U OSTaskQuery (INT8U prio, OS_TCB *pdata) KCREENTRANT
729 {
730 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
733 1 OS_TCB *ptcb;
734 1
735 1
C51 COMPILER V6.23a OS_TASK 12/09/2004 16:50:26 PAGE 13
736 1 #if OS_ARG_CHK_EN > 0
737 1 if (prio > OS_LOWEST_PRIO && prio != OS_PRIO_SELF) { /* Task priority valid ? */
738 2 return (OS_PRIO_INVALID);
739 2 }
740 1 #endif
741 1 OS_ENTER_CRITICAL();
742 1 if (prio == OS_PRIO_SELF) { /* See if suspend SELF */
743 2 prio = OSTCBCur->OSTCBPrio;
744 2 }
745 1 ptcb = OSTCBPrioTbl[prio];
746 1 if (ptcb == (OS_TCB *)0) { /* Task to query must exist */
747 2 OS_EXIT_CRITICAL();
748 2 return (OS_PRIO_ERR);
749 2 }
750 1 memcpy(pdata, ptcb, sizeof(OS_TCB)); /* Copy TCB into user storage area */
751 1 OS_EXIT_CRITICAL();
752 1 return (OS_NO_ERR);
753 1 }
754 #endif
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 4207 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 1 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -