📄 os_task.s43
字号:
NAME os_task(16)
RSEG CODE(1)
EXTERN OSIntNesting
EXTERN OSLockNesting
EXTERN OSMapTbl
EXTERN OSRdyGrp
EXTERN OSRdyTbl
EXTERN OSRunning
EXTERN OSTCBCur
EXTERN OSTCBFreeList
EXTERN OSTCBList
EXTERN OSTCBPrioTbl
PUBLIC OSTaskChangePrio
PUBLIC OSTaskCreate
PUBLIC OSTaskCreateExt
EXTERN OSTaskCtr
PUBLIC OSTaskDel
EXTERN OSTaskDelHook
PUBLIC OSTaskDelReq
PUBLIC OSTaskQuery
PUBLIC OSTaskResume
PUBLIC OSTaskStkChk
EXTERN OSTaskStkInit
PUBLIC OSTaskSuspend
EXTERN OS_Dummy
EXTERN OS_FlagUnlink
EXTERN OS_Sched
EXTERN OS_TCBInit
EXTERN memcpy
EXTERN memset
EXTERN ?CL430_1_26_L08
RSEG CODE
OSTaskChangePrio:
; 1. /*
; 2. *********************************************************************************************************
; 3. * uC/OS-II
; 4. * The Real-Time Kernel
; 5. * TASK MANAGEMENT
; 6. *
; 7. * (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
; 8. * All Rights Reserved
; 9. *
; 10. * File : OS_TASK.C
; 11. * By : Jean J. Labrosse
; 12. *********************************************************************************************************
; 13. */
; 14.
; 15. #ifndef OS_MASTER_FILE
; 16. #include "includes.h"
; 17. #endif
; 18.
; 19. /*
; 20. *********************************************************************************************************
; 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
; 40. INT8U OSTaskChangePrio (INT8U oldprio, INT8U newprio)
; 41. {
PUSH R10
PUSH R11
PUSH R8
PUSH R9
PUSH R6
; 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.
; 56.
; 57.
; 58. #if OS_ARG_CHK_EN > 0
; 59. if ((oldprio >= OS_LOWEST_PRIO && oldprio != OS_PRIO_SELF) ||
; 60. newprio >= OS_LOWEST_PRIO) {
CMP.B #12,R12
JNC (?0063)
CMP.B #255,R12
JNE (?0064)
?0063:
CMP.B #12,R14
JNC (?0061)
?0064:
; 61. return (OS_PRIO_INVALID);
MOV.B #42,R12
; 62. }
JMP (?0085)
?0061:
; 63. #endif
; 64. OS_ENTER_CRITICAL();
DINT
; 65. if (OSTCBPrioTbl[newprio] != (OS_TCB *)0) { /* New priority must not already exist */
MOV.B R14,R13
ADD R13,R13
CMP #0,OSTCBPrioTbl(R13)
JEQ (?0067)
; 66. OS_EXIT_CRITICAL();
EINT
; 67. return (OS_PRIO_EXIST);
MOV.B #40,R12
; 68. } else {
JMP (?0085)
?0067:
; 69. OSTCBPrioTbl[newprio] = (OS_TCB *)1; /* Reserve the entry to prevent others */
MOV.B R14,R13
ADD R13,R13
MOV #1,OSTCBPrioTbl(R13)
; 70. OS_EXIT_CRITICAL();
EINT
; 71. y = newprio >> 3; /* Precompute to reduce INT. latency */
MOV.B R14,R13
CLRC
RRC.B R13
RRA.B R13
RRA.B R13
; 72. bity = OSMapTbl[y];
MOV.B R13,R10
MOV.B OSMapTbl(R10),R15
; 73. x = newprio & 0x07;
MOV.B R14,R10
AND.B #7,R10
; 74. bitx = OSMapTbl[x];
MOV.B R10,R8
MOV.B OSMapTbl(R8),R11
; 75. OS_ENTER_CRITICAL();
DINT
; 76. if (oldprio == OS_PRIO_SELF) { /* See if changing self */
CMP.B #255,R12
JNE (?0069)
; 77. oldprio = OSTCBCur->OSTCBPrio; /* Yes, get priority */
MOV &OSTCBCur,R8
MOV.B 29(R8),R12
?0069:
; 78. }
; 79. ptcb = OSTCBPrioTbl[oldprio];
MOV.B R12,R9
ADD R9,R9
MOV OSTCBPrioTbl(R9),R8
; 80. if (ptcb != (OS_TCB *)0) { /* Task to change must exist */
CMP #0,R8
JEQ (?0071)
; 81. OSTCBPrioTbl[oldprio] = (OS_TCB *)0; /* Remove TCB from old priority */
AND.B #-1,R12
ADD R12,R12
MOV #0,OSTCBPrioTbl(R12)
; 82. if ((OSRdyTbl[ptcb->OSTCBY] & ptcb->OSTCBBitX) != 0x00) { /* If task is ready make it not */
MOV.B 31(R8),R12
BIT.B OSRdyTbl(R12),32(R8)
JEQ (?0073)
; 83. if ((OSRdyTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0x00) {
MOV.B 31(R8),R12
MOV.B 32(R8),R9
XOR.B #-1,R9
AND.B R9,OSRdyTbl(R12)
CMP.B #0,OSRdyTbl(R12)
JNE (?0075)
; 84. OSRdyGrp &= ~ptcb->OSTCBBitY;
MOV.B 33(R8),R12
XOR.B #-1,R12
AND.B R12,&OSRdyGrp
?0075:
; 85. }
; 86. OSRdyGrp |= bity; /* Make new priority ready to run */
BIS.B R15,&OSRdyGrp
; 87. OSRdyTbl[y] |= bitx;
MOV.B R13,R12
BIS.B R11,OSRdyTbl(R12)
; 88. #if OS_EVENT_EN > 0
; 89. } else {
JMP (?0082)
?0073:
; 90. pevent = ptcb->OSTCBEventPtr;
MOV 18(R8),R12
; 91. if (pevent != (OS_EVENT *)0) { /* Remove from event wait list */
CMP #0,R12
JEQ (?0082)
; 92. if ((pevent->OSEventTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0) {
MOV.B 31(R8),R9
ADD R12,R9
MOV.B 32(R8),R6
XOR.B #-1,R6
AND.B R6,6(R9)
CMP.B #0,6(R9)
JNE (?0084)
; 93. pevent->OSEventGrp &= ~ptcb->OSTCBBitY;
MOV.B 33(R8),R9
XOR.B #-1,R9
AND.B R9,1(R12)
?0084:
; 94. }
; 95. pevent->OSEventGrp |= bity; /* Add new priority to wait list */
BIS.B R15,1(R12)
; 96. pevent->OSEventTbl[y] |= bitx;
MOV.B R13,R9
ADD R12,R9
BIS.B R11,6(R9)
?0082:
; 97. }
; 98. #endif
; 99. }
; 100. OSTCBPrioTbl[newprio] = ptcb; /* Place pointer to TCB @ new priority */
MOV.B R14,R12
ADD R12,R12
MOV R8,OSTCBPrioTbl(R12)
; 101. ptcb->OSTCBPrio = newprio; /* Set new task priority */
MOV.B R14,29(R8)
; 102. ptcb->OSTCBY = y;
MOV.B R13,31(R8)
; 103. ptcb->OSTCBX = x;
MOV.B R10,30(R8)
; 104. ptcb->OSTCBBitY = bity;
MOV.B R15,33(R8)
; 105. ptcb->OSTCBBitX = bitx;
MOV.B R11,32(R8)
; 106. OS_EXIT_CRITICAL();
EINT
; 107. OS_Sched(); /* Run highest priority task ready */
CALL #OS_Sched
; 108. return (OS_NO_ERR);
MOV.B #0,R12
; 109. } else {
JMP (?0085)
?0071:
; 110. OSTCBPrioTbl[newprio] = (OS_TCB *)0; /* Release the reserved prio. */
AND.B #-1,R14
ADD R14,R14
MOV #0,OSTCBPrioTbl(R14)
; 111. OS_EXIT_CRITICAL();
EINT
; 112. return (OS_PRIO_ERR); /* Task to change didn't exist */
MOV.B #41,R12
; 113. }
?0085:
POP R6
POP R9
POP R8
POP R11
POP R10
RET
; 114. }
; 115. }
OSTaskCreate:
; 116. #endif
; 117. /*$PAGE*/
; 118. /*
; 119. *********************************************************************************************************
; 120. * CREATE A TASK
; 121. *
; 122. * Description: This function is used to have uC/OS-II manage the execution of a task. Tasks can either
; 123. * be created prior to the start of multitasking or by a running task. A task cannot be
; 124. * created by an ISR.
; 125. *
; 126. * Arguments : task is a pointer to the task's code
; 127. *
; 128. * pdata is a pointer to an optional data area which can be used to pass parameters to
; 129. * the task when the task first executes. Where the task is concerned it thinks
; 130. * it was invoked and passed the argument 'pdata' as follows:
; 131. *
; 132. * void Task (void *pdata)
; 133. * {
; 134. * for (;;) {
; 135. * Task code;
; 136. * }
; 137. * }
; 138. *
; 139. * ptos is a pointer to the task's top of stack. If the configuration constant
; 140. * OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
; 141. * memory to low memory). 'pstk' will thus point to the highest (valid) memory
; 142. * location of the stack. If OS_STK_GROWTH is set to 0, 'pstk' will point to the
; 143. * lowest memory location of the stack and the stack will grow with increasing
; 144. * memory locations.
; 145. *
; 146. * prio is the task's priority. A unique priority MUST be assigned to each task and the
; 147. * lower the number, the higher the priority.
; 148. *
; 149. * Returns : OS_NO_ERR if the function was successful.
; 150. * OS_PRIO_EXIT if the task priority already exist
; 151. * (each task MUST have a unique priority).
; 152. * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
; 153. * (i.e. >= OS_LOWEST_PRIO)
; 154. *********************************************************************************************************
; 155. */
; 156.
; 157. #if OS_TASK_CREATE_EN > 0
; 158. INT8U OSTaskCreate (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT8U prio)
; 159. {
PUSH R10
PUSH R11
MOV.B 8(SP),R11
; 160. #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
; 161. OS_CPU_SR cpu_sr;
; 162. #endif
; 163. OS_STK *psp;
; 164. INT8U err;
; 165.
; 166.
; 167. #if OS_ARG_CHK_EN > 0
; 168. if (prio > OS_LOWEST_PRIO) { /* Make sure priority is within allowable range */
CMP.B #13,R11
JNC (?0087)
; 169. return (OS_PRIO_INVALID);
MOV.B #42,R12
; 170. }
JMP (?0095)
?0087:
; 171. #endif
; 172. OS_ENTER_CRITICAL();
DINT
; 173. if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority */
MOV.B R11,R13
ADD R13,R13
CMP #0,OSTCBPrioTbl(R13)
JNE (?0089)
; 174. OSTCBPrioTbl[prio] = (OS_TCB *)1; /* Reserve the priority to prevent others from doing ... */
MOV.B R11,R13
ADD R13,R13
MOV #1,OSTCBPrioTbl(R13)
; 175. /* ... the same thing until task is created. */
; 176. OS_EXIT_CRITICAL();
EINT
; 177. psp = (OS_STK *)OSTaskStkInit(task, pdata, ptos, 0); /* Initialize the task's stack */
PUSH #0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -