📄 os_task.s79
字号:
// 21 * CHANGE PRIORITY OF A TASK
// 22 *
// 23 * Description: This function allows you to change the priority of a task dynamically. Note that the new
// 24 * priority MUST be available.
// 25 *
// 26 * Arguments : oldp is the old priority
// 27 *
// 28 * newp is the new priority
// 29 *
// 30 * Returns : OS_NO_ERR is the call was successful
// 31 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
// 32 * (i.e. >= OS_LOWEST_PRIO)
// 33 * OS_PRIO_EXIST if the new priority already exist.
// 34 * OS_PRIO_ERR there is no task with the specified OLD priority (i.e. the OLD task does
// 35 * not exist.
// 36 *********************************************************************************************************
// 37 */
// 38
// 39 #if OS_TASK_CHANGE_PRIO_EN > 0
RSEG CODE:CODE:NOROOT(2)
CFI Block cfiBlock1 Using cfiCommon1
CFI Function OSTaskChangePrio
THUMB
// 40 INT8U OSTaskChangePrio (INT8U oldprio, INT8U newprio)
// 41 {
OSTaskChangePrio:
PUSH {R4-R7,LR}
CFI ?RET Frame(CFA, -4)
CFI R7 Frame(CFA, -8)
CFI R6 Frame(CFA, -12)
CFI R5 Frame(CFA, -16)
CFI R4 Frame(CFA, -20)
CFI CFA R13+20
SUB SP,SP,#+12
CFI CFA R13+32
MOVS R4,R0
MOVS R5,R1
// 42 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
// 43 OS_CPU_SR cpu_sr;
// 44 #endif
// 45
// 46 #if OS_EVENT_EN > 0
// 47 OS_EVENT *pevent;
// 48 #endif
// 49
// 50 OS_TCB *ptcb;
// 51 INT8U x;
// 52 INT8U y;
// 53 INT8U bitx;
// 54 INT8U bity;
// 55 INT8U y_old;
// 56
// 57
// 58 #if OS_ARG_CHK_EN > 0
// 59 if (oldprio >= OS_LOWEST_PRIO) {
CMP R4,#+63
BCC ??OSTaskChangePrio_0
// 60 if (oldprio != OS_PRIO_SELF) {
CMP R4,#+255
BEQ ??OSTaskChangePrio_0
// 61 return (OS_PRIO_INVALID);
??OSTaskChangePrio_1:
MOVS R0,#+42
B ??OSTaskChangePrio_2
// 62 }
// 63 }
// 64 if (newprio >= OS_LOWEST_PRIO) {
??OSTaskChangePrio_0:
CMP R5,#+63
BCS ??OSTaskChangePrio_1
// 65 return (OS_PRIO_INVALID);
// 66 }
// 67 #endif
// 68 OS_ENTER_CRITICAL();
_BLF OS_CPU_SR_Save,??OS_CPU_SR_Save??rT
// 69 if (OSTCBPrioTbl[newprio] != (OS_TCB *)0) { /* New priority must not already exist */
LSLS R1,R5,#+2
LDR R2,??DataTable23 ;; OSTCBPrioTbl
LDR R1,[R2, R1]
CMP R1,#+0
BEQ ??OSTaskChangePrio_3
// 70 OS_EXIT_CRITICAL();
_BLF OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
// 71 return (OS_PRIO_EXIST);
MOVS R0,#+40
B ??OSTaskChangePrio_2
// 72 }
// 73 if (oldprio == OS_PRIO_SELF) { /* See if changing self */
??OSTaskChangePrio_3:
CMP R4,#+255
BNE ??OSTaskChangePrio_4
// 74 oldprio = OSTCBCur->OSTCBPrio; /* Yes, get priority */
LDR R1,??DataTable1 ;; OSTCBCur
LDR R1,[R1, #+0]
ADDS R1,R1,#+45
LDRB R4,[R1, #+0]
// 75 }
// 76 ptcb = OSTCBPrioTbl[oldprio];
??OSTaskChangePrio_4:
LSLS R1,R4,#+2
LDR R1,[R2, R1]
// 77 if (ptcb == (OS_TCB *)0) { /* Does task to change exist? */
CMP R1,#+0
BNE ??OSTaskChangePrio_5
// 78 OS_EXIT_CRITICAL(); /* No, can't change its priority! */
_BLF OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
// 79 return (OS_PRIO_ERR);
MOVS R0,#+41
B ??OSTaskChangePrio_2
// 80 }
// 81 y = newprio >> 3; /* Yes, compute new TCB fields */
??OSTaskChangePrio_5:
LSRS R2,R5,#+3
// 82 bity = OSMapTbl[y];
LDR R6,??OSTaskChangePrio_6 ;; OSMapTbl
LDRB R3,[R6, R2]
STR R3,[SP, #+0]
// 83 x = newprio & 0x07;
LSLS R3,R5,#+29
LSRS R3,R3,#+29
STR R3,[SP, #+8]
// 84 bitx = OSMapTbl[x];
LDRB R3,[R6, R3]
STR R3,[SP, #+4]
// 85 OSTCBPrioTbl[oldprio] = (OS_TCB *)0; /* Remove TCB from old priority */
LSLS R3,R4,#+2
LDR R4,??DataTable23 ;; OSTCBPrioTbl
MOVS R6,#+0
STR R6,[R4, R3]
// 86 OSTCBPrioTbl[newprio] = ptcb; /* Place pointer to TCB @ new priority */
LSLS R3,R5,#+2
STR R1,[R4, R3]
// 87 y_old = ptcb->OSTCBY;
MOVS R3,#+47
LDRB R3,[R1, R3]
// 88 if ((OSRdyTbl[y_old] & ptcb->OSTCBBitX) != 0x00) { /* If task is ready make it not */
LDR R6,??DataTable11 ;; OSRdyTbl
LDRB R4,[R6, R3]
MOVS R6,#+48
LDRB R6,[R1, R6]
TST R4,R6
BEQ ??OSTaskChangePrio_7
// 89 OSRdyTbl[y_old] &= ~ptcb->OSTCBBitX;
LDR R7,??DataTable11 ;; OSRdyTbl
MOV R12,R3
LDR R4,??DataTable11 ;; OSRdyTbl
LDRB R4,[R4, R3]
MOVS R6,#+48
LDRB R6,[R1, R6]
BICS R4,R4,R6
MOV R6,R12
STRB R4,[R7, R6]
// 90 if (OSRdyTbl[y_old] == 0x00) {
LDR R4,??DataTable11 ;; OSRdyTbl
LDRB R3,[R4, R3]
CMP R3,#+0
BNE ??OSTaskChangePrio_8
// 91 OSRdyGrp &= ~ptcb->OSTCBBitY;
LDR R3,??DataTable10 ;; OSRdyGrp
LDR R4,??DataTable10 ;; OSRdyGrp
LDRB R4,[R4, #+0]
MOVS R6,#+49
LDRB R6,[R1, R6]
BICS R4,R4,R6
STRB R4,[R3, #+0]
// 92 }
// 93 OSRdyGrp |= bity; /* Make new priority ready to run */
??OSTaskChangePrio_8:
LDR R3,??DataTable10 ;; OSRdyGrp
LDR R4,??DataTable10 ;; OSRdyGrp
LDRB R4,[R4, #+0]
LDR R6,[SP, #+0]
ORRS R6,R6,R4
STRB R6,[R3, #+0]
// 94 OSRdyTbl[y] |= bitx;
LDR R4,??DataTable11 ;; OSRdyTbl
LDRB R6,[R7, R2]
LDR R7,[SP, #+4]
ORRS R7,R7,R6
STRB R7,[R4, R2]
B ??OSTaskChangePrio_9
// 95 #if OS_EVENT_EN > 0
// 96 } else { /* Task was not ready ... */
// 97 pevent = ptcb->OSTCBEventPtr;
??OSTaskChangePrio_7:
LDR R4,[R1, #+28]
// 98 if (pevent != (OS_EVENT *)0) { /* ... remove from event wait list */
CMP R4,#+0
BEQ ??OSTaskChangePrio_9
// 99 pevent->OSEventTbl[y_old] &= ~ptcb->OSTCBBitX;
ADDS R6,R4,R3
MOV R12,R6
LDRB R7,[R6, #+8]
MOVS R6,#+48
LDRB R6,[R1, R6]
BICS R7,R7,R6
MOV R6,R12
STRB R7,[R6, #+8]
// 100 if (pevent->OSEventTbl[y_old] == 0) {
ADDS R3,R4,R3
LDRB R3,[R3, #+8]
CMP R3,#+0
BNE ??OSTaskChangePrio_10
// 101 pevent->OSEventGrp &= ~ptcb->OSTCBBitY;
LDRB R3,[R4, #+1]
MOVS R6,#+49
LDRB R6,[R1, R6]
BICS R3,R3,R6
STRB R3,[R4, #+1]
// 102 }
// 103 pevent->OSEventGrp |= bity; /* Add new priority to wait list */
??OSTaskChangePrio_10:
LDRB R3,[R4, #+1]
LDR R6,[SP, #+0]
ORRS R6,R6,R3
STRB R6,[R4, #+1]
// 104 pevent->OSEventTbl[y] |= bitx;
ADDS R3,R4,R2
ADDS R4,R4,R2
LDRB R4,[R4, #+8]
LDR R6,[SP, #+4]
ORRS R6,R6,R4
STRB R6,[R3, #+8]
// 105 }
// 106 #endif
// 107 }
// 108 ptcb->OSTCBPrio = newprio; /* Set new task priority */
??OSTaskChangePrio_9:
MOVS R3,#+45
STRB R5,[R1, R3]
// 109 ptcb->OSTCBY = y;
MOVS R3,#+47
STRB R2,[R1, R3]
// 110 ptcb->OSTCBX = x;
MOVS R2,#+46
LDR R3,[SP, #+8]
STRB R3,[R1, R2]
// 111 ptcb->OSTCBBitY = bity;
MOVS R2,#+49
LDR R3,[SP, #+0]
STRB R3,[R1, R2]
// 112 ptcb->OSTCBBitX = bitx;
ADDS R1,R1,#+48
LDR R2,[SP, #+4]
STRB R2,[R1, #+0]
// 113 OS_EXIT_CRITICAL();
_BLF OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
// 114 OS_Sched(); /* Run highest priority task ready */
_BLF OS_Sched,??OS_Sched??rT
// 115 return (OS_NO_ERR);
MOVS R0,#+0
??OSTaskChangePrio_2:
ADD SP,SP,#+12
CFI CFA R13+20
POP {R4-R7}
POP {R1}
BX R1 ;; return
DATA
??OSTaskChangePrio_6:
DC32 OSMapTbl
CFI EndBlock cfiBlock1
// 116 }
RSEG CODE:CODE:NOROOT(2)
DATA
??DataTable1:
DC32 OSTCBCur
RSEG CODE:CODE:NOROOT(2)
DATA
??DataTable10:
DC32 OSRdyGrp
RSEG CODE:CODE:NOROOT(2)
DATA
??DataTable11:
DC32 OSRdyTbl
RSEG CODE:CODE:NOROOT(2)
CFI Block cfiBlock2 Using cfiCommon0
CFI NoFunction
ARM
??OSTaskCreate??rA:
ADD R12,PC,#+1
BX R12
CFI EndBlock cfiBlock2
REQUIRE OSTaskCreate
// 117 #endif
// 118
// 119 /*
// 120 *********************************************************************************************************
// 121 * CREATE A TASK
// 122 *
// 123 * Description: This function is used to have uC/OS-II manage the execution of a task. Tasks can either
// 124 * be created prior to the start of multitasking or by a running task. A task cannot be
// 125 * created by an ISR.
// 126 *
// 127 * Arguments : task is a pointer to the task's code
// 128 *
// 129 * p_arg is a pointer to an optional data area which can be used to pass parameters to
// 130 * the task when the task first executes. Where the task is concerned it thinks
// 131 * it was invoked and passed the argument 'p_arg' as follows:
// 132 *
// 133 * void Task (void *p_arg)
// 134 * {
// 135 * for (;;) {
// 136 * Task code;
// 137 * }
// 138 * }
// 139 *
// 140 * ptos is a pointer to the task's top of stack. If the configuration constant
// 141 * OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
// 142 * memory to low memory). 'pstk' will thus point to the highest (valid) memory
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -