📄 os_task.lst
字号:
555: }
556: }
557: }
558: #endif
559: /*$PAGE*/
560: /*
561: *********************************************************************************************************
562: * STACK CHECKING
563: *
564: * Description: This function is called to check the amount of free memory left on the specified task's
565: * stack.
566: *
567: * Arguments : prio is the task priority
568: *
569: * pdata is a pointer to a data structure of type OS_STK_DATA.
570: *
571: * Returns : OS_NO_ERR upon success
572: * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
573: * (i.e. > OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
574: * OS_TASK_NOT_EXIST if the desired task has not been created
575: * OS_TASK_OPT_ERR if you did NOT specified OS_TASK_OPT_STK_CHK when the task was created
576: *********************************************************************************************************
577: */
578: #if OS_TASK_CREATE_EXT_EN
579: INT8U OSTaskStkChk (INT8U prio, OS_STK_DATA *pdata)
580: {
581: OS_TCB *ptcb;
582: OS_STK *pchk;
583: INT32U free;
584: INT32U size;
585:
586:
587: pdata->OSFree = 0; /* Assume failure, set to 0 size */
588: pdata->OSUsed = 0;
589: if (prio > OS_LOWEST_PRIO && prio != OS_PRIO_SELF) { /* Make sure task priority is valid */
590: return (OS_PRIO_INVALID);
591: }
592: OS_ENTER_CRITICAL();
593: if (prio == OS_PRIO_SELF) { /* See if check for SELF */
594: prio = OSTCBCur->OSTCBPrio;
595: }
596: ptcb = OSTCBPrioTbl[prio];
597: if (ptcb == (OS_TCB *)0) { /* Make sure task exist */
598: OS_EXIT_CRITICAL();
599: return (OS_TASK_NOT_EXIST);
600: }
601: if ((ptcb->OSTCBOpt & OS_TASK_OPT_STK_CHK) == 0) { /* Make sure stack checking option is set */
602: OS_EXIT_CRITICAL();
603: return (OS_TASK_OPT_ERR);
604: }
605: free = 0;
606: size = ptcb->OSTCBStkSize;
607: pchk = ptcb->OSTCBStkBottom;
608: OS_EXIT_CRITICAL();
609: #if OS_STK_GROWTH == 1
610: while (*pchk++ == 0) { /* Compute the number of zero entries on the stk */
611: free++;
612: }
613: #else
614: while (*pchk-- == 0) {
615: free++;
616: }
617: #endif
618: pdata->OSFree = free * sizeof(OS_STK); /* Compute number of free bytes on the stack */
619: pdata->OSUsed = (size - free) * sizeof(OS_STK); /* Compute number of bytes used on the stack */
620: return (OS_NO_ERR);
621: }
622: #endif
623: /*$PAGE*/
624: /*
625: *********************************************************************************************************
626: * SUSPEND A TASK
627: *
628: * Description: This function is called to suspend a task. The task can be the calling task if the
629: * priority passed to OSTaskSuspend() is the priority of the calling task or OS_PRIO_SELF.
630: *
631: * Arguments : prio is the priority of the task to suspend. If you specify OS_PRIO_SELF, the
632: * calling task will suspend itself and rescheduling will occur.
633: *
634: * Returns : OS_NO_ERR if the requested task is suspended
635: * OS_TASK_SUSPEND_IDLE if you attempted to suspend the idle task which is not allowed.
636: * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
637: * (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
638: * OS_TASK_SUSPEND_PRIO if the task to suspend does not exist
639: *
640: * Note : You should use this function with great care. If you suspend a task that is waiting for
641: * an event (i.e. a message, a semaphore, a queue ...) you will prevent this task from
642: * running when the event arrives.
643: *********************************************************************************************************
644: */
645:
646: #if OS_TASK_SUSPEND_EN
647: INT8U OSTaskSuspend (INT8U prio)
648: {
649: BOOLEAN self;
650: OS_TCB *ptcb;
651:
652:
653: if (prio == OS_IDLE_PRIO) { /* Not allowed to suspend idle task */
654: return (OS_TASK_SUSPEND_IDLE);
655: }
656: if (prio >= OS_LOWEST_PRIO && prio != OS_PRIO_SELF) { /* Task priority valid ? */
657: return (OS_PRIO_INVALID);
658: }
659: OS_ENTER_CRITICAL();
660: if (prio == OS_PRIO_SELF) { /* See if suspend SELF */
661: prio = OSTCBCur->OSTCBPrio;
662: self = TRUE;
663: } else if (prio == OSTCBCur->OSTCBPrio) { /* See if suspending self */
664: self = TRUE;
665: } else {
666: self = FALSE; /* No suspending another task */
667: }
668: if ((ptcb = OSTCBPrioTbl[prio]) == (OS_TCB *)0) { /* Task to suspend must exist */
669: OS_EXIT_CRITICAL();
670: return (OS_TASK_SUSPEND_PRIO);
671: } else {
672: if ((OSRdyTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0) { /* Make task not ready */
673: OSRdyGrp &= ~ptcb->OSTCBBitY;
674: }
675: ptcb->OSTCBStat |= OS_STAT_SUSPEND; /* Status of task is 'SUSPENDED' */
676: OS_EXIT_CRITICAL();
677: if (self == TRUE) { /* Context switch only if SELF */
678: OSSched();
679: }
680: return (OS_NO_ERR);
681: }
682: }
683: #endif
684: /*$PAGE*/
685: /*
686: *********************************************************************************************************
687: * QUERY A TASK
688: *
689: * Description: This function is called to obtain a copy of the desired task's TCB.
690: *
691: * Arguments : prio is the priority of the task to obtain information from.
692: *
693: * Returns : OS_NO_ERR if the requested task is suspended
694: * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
695: * (i.e. > OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
696: * OS_PRIO_ERR if the desired task has not been created
697: *********************************************************************************************************
698: */
699:
700: INT8U OSTaskQuery (INT8U prio, OS_TCB *pdata)
701: {
Function: OSTaskQuery
Source : C:\motoctest\ucos1\sources\os_task.c
Options : -Cc -EnvGENPATH=C:\motoctest\ucos1;C:\motoctest\ucos1\bin;C:\motoctest\ucos1\cmd;C:\motoctest\ucos1\prm;C:\motoctest\ucos1\sources;C:\Metrowerks\lib\HC08c\LIB;C:\Metrowerks\lib\HC08c\src;C:\Metrowerks\lib\HC08c\INCLUDE -EnvLIBPATH=C:\Metrowerks\lib\HC08c\INCLUDE -EnvOBJPATH=C:\motoctest\ucos1\bin -EnvTEXTPATH=C:\motoctest\ucos1\bin -La=%f.inc -Lasm=%n.lst -ObjN=C:\motoctest\ucos1\ucos1_Data\MMDS-MMEVS\ObjectCode\os_task.c.o
0000 87 PSHA
0001 89 PSHX
0002 a7fe AIS #-2
702: OS_TCB *ptcb;
703:
704:
705: if (prio > OS_LOWEST_PRIO && prio != OS_PRIO_SELF) { /* Task priority valid ? */
0004 9ee607 LDA 7,SP
0007 a103 CMP #3
0009 2308 BLS L13 ;abs = 0013
000b a1ff CMP #-1
000d 2704 BEQ L13 ;abs = 0013
706: return (OS_PRIO_INVALID);
000f a62a LDA #42
0011 203b BRA L4E ;abs = 004e
0013 L13:
707: }
708: OS_ENTER_CRITICAL();
0013 9b SEI
709: if (prio == OS_PRIO_SELF) { /* See if suspend SELF */
0014 9ee607 LDA 7,SP
0017 4c INCA
0018 2607 BNE L21 ;abs = 0021
710: prio = OSTCBCur->OSTCBPrio;
001a 5500 LDHX OSTCBCur
001c e609 LDA 9,X
001e 9ee707 STA 7,SP
0021 L21:
711: }
712: if ((ptcb = OSTCBPrioTbl[prio]) == (OS_TCB *)0) { /* Task to query must exist */
0021 9eee07 LDX 7,SP
0024 58 LSLX
0025 8c CLRH
0026 e601 LDA @OSTCBPrioTbl:1,X
0028 9ee702 STA 2,SP
002b e600 LDA @OSTCBPrioTbl,X
002d 9ee701 STA 1,SP
0030 e601 LDA @OSTCBPrioTbl:1,X
0032 ea00 ORA @OSTCBPrioTbl,X
0034 2605 BNE L3B ;abs = 003b
713: OS_EXIT_CRITICAL();
0036 9a CLI
714: return (OS_PRIO_ERR);
0037 a629 LDA #41
0039 2013 BRA L4E ;abs = 004e
003b L3B:
715: }
716: *pdata = *ptcb; /* Copy TCB into user storage area */
003b 95 TSX
003c e603 LDA 3,X
003e 87 PSHA
003f e602 LDA 2,X
0041 87 PSHA
0042 f6 LDA ,X
0043 87 PSHA
0044 ee01 LDX 1,X
0046 8a PULH
0047 a60e LDA #14
0049 cd0000 JSR _COPY
717: OS_EXIT_CRITICAL();
004c 9a CLI
718: return (OS_NO_ERR);
004d 4f CLRA
004e L4E:
719: }
004e a704 AIS #4
0050 81 RTS
720:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -