📄 os_sem.lst
字号:
118 * Description: This function deletes a semaphore and readies all tasks pending on the semaphore.
119 *
120 * Arguments : pevent is a pointer to the event control block associated with the desired
121 * semaphore.
122 *
123 * opt determines delete options as follows:
124 * opt == OS_DEL_NO_PEND Delete semaphore ONLY if no task pending
125 * opt == OS_DEL_ALWAYS Deletes the semaphore even if tasks are waiting.
126 * In this case, all the tasks pending will be readied.
127 *
128 * err is a pointer to an error code that can contain one of the following values:
129 * OS_NO_ERR The call was successful and the semaphore was deleted
130 * OS_ERR_DEL_ISR If you attempted to delete the semaphore from an ISR
131 * OS_ERR_INVALID_OPT An invalid option was specified
132 * OS_ERR_TASK_WAITING One or more tasks were waiting on the semaphore
133 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a semaphore
134 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer.
135 *
136 * Returns : pevent upon error
137 * (OS_EVENT *)0 if the semaphore was successfully deleted.
138 *
139 * Note(s) : 1) This function must be used with care. Tasks that would normally expect the presence of
140 * the semaphore MUST check the return code of OSSemPend().
141 * 2) OSSemAccept() callers will not know that the intended semaphore has been deleted unless
142 * they check 'pevent' to see that it's a NULL pointer.
143 * 3) This call can potentially disable interrupts for a long time. The interrupt disable
144 * time is directly proportional to the number of tasks waiting on the semaphore.
145 * 4) Because ALL tasks pending on the semaphore will be readied, you MUST be careful in
146 * applications where the semaphore is used for mutual exclusion because the resource(s)
147 * will no longer be guarded by the semaphore.
148 *********************************************************************************************************
149 */
150
151 #if OS_SEM_DEL_EN > 0
\ In segment CODE, align 4, keep-with-next
152 OS_EVENT *OSSemDel (OS_EVENT *pevent, INT8U opt, INT8U *err)
153 {
\ OSSemDel:
\ 00000000 F2B5 PUSH {R1,R4-R7,LR}
\ 00000002 0400 MOVS R4,R0
\ 00000004 1500 MOVS R5,R2
154 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
155 OS_CPU_SR cpu_sr;
156 #endif
157 BOOLEAN tasks_waiting;
158
159
160 if (OSIntNesting > 0) { /* See if called from ISR ... */
\ 00000006 .... LDR R0,??DataTable10 ;; OSIntNesting
\ 00000008 0078 LDRB R0,[R0, #+0]
\ 0000000A 0128 CMP R0,#+1
\ 0000000C 03D3 BCC ??OSSemDel_0
161 *err = OS_ERR_DEL_ISR; /* ... can't DELETE from an ISR */
\ 0000000E 8C20 MOVS R0,#+140
\ 00000010 2870 STRB R0,[R5, #+0]
162 return (pevent);
\ 00000012 2000 MOVS R0,R4
\ 00000014 5FE0 B ??OSSemDel_1
163 }
164 #if OS_ARG_CHK_EN > 0
165 if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
\ ??OSSemDel_0:
\ 00000016 002C CMP R4,#+0
\ 00000018 03D1 BNE ??OSSemDel_2
166 *err = OS_ERR_PEVENT_NULL;
\ 0000001A 0420 MOVS R0,#+4
\ 0000001C 2870 STRB R0,[R5, #+0]
167 return (pevent);
\ 0000001E 2000 MOVS R0,R4
\ 00000020 59E0 B ??OSSemDel_1
168 }
169 #endif
170 if (pevent->OSEventType != OS_EVENT_TYPE_SEM) { /* Validate event block type */
\ ??OSSemDel_2:
\ 00000022 2078 LDRB R0,[R4, #+0]
\ 00000024 0328 CMP R0,#+3
\ 00000026 03D0 BEQ ??OSSemDel_3
171 *err = OS_ERR_EVENT_TYPE;
\ 00000028 0120 MOVS R0,#+1
\ 0000002A 2870 STRB R0,[R5, #+0]
172 return (pevent);
\ 0000002C 2000 MOVS R0,R4
\ 0000002E 52E0 B ??OSSemDel_1
173 }
174 OS_ENTER_CRITICAL();
\ ??OSSemDel_3:
\ 00000030 ........ _BLF OS_CPU_SR_Save,??OS_CPU_SR_Save??rT
\ 00000034 0600 MOVS R6,R0
175 if (pevent->OSEventGrp != 0x00) { /* See if any tasks waiting on semaphore */
\ 00000036 6078 LDRB R0,[R4, #+1]
\ 00000038 0028 CMP R0,#+0
\ 0000003A 01D0 BEQ ??OSSemDel_4
176 tasks_waiting = TRUE; /* Yes */
\ 0000003C 0127 MOVS R7,#+1
\ 0000003E 00E0 B ??OSSemDel_5
177 } else {
178 tasks_waiting = FALSE; /* No */
\ ??OSSemDel_4:
\ 00000040 0027 MOVS R7,#+0
179 }
180 switch (opt) {
\ ??OSSemDel_5:
\ 00000042 6846 MOV R0,SP
\ 00000044 0078 LDRB R0,[R0, #+0]
\ 00000046 0028 CMP R0,#+0
\ 00000048 02D0 BEQ ??OSSemDel_6
\ 0000004A 0128 CMP R0,#+1
\ 0000004C 22D0 BEQ ??OSSemDel_7
\ 0000004E 3CE0 B ??OSSemDel_8
181 case OS_DEL_NO_PEND: /* Delete semaphore only if no task waiting */
182 if (tasks_waiting == FALSE) {
\ ??OSSemDel_6:
\ 00000050 002F CMP R7,#+0
\ 00000052 13D1 BNE ??OSSemDel_9
183 #if OS_EVENT_NAME_SIZE > 1
184 pevent->OSEventName[0] = '?'; /* Unknown name */
\ 00000054 3F20 MOVS R0,#+63
\ 00000056 2074 STRB R0,[R4, #+16]
185 pevent->OSEventName[1] = OS_ASCII_NUL;
\ 00000058 0020 MOVS R0,#+0
\ 0000005A 6074 STRB R0,[R4, #+17]
186 #endif
187 pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
\ 0000005C 0020 MOVS R0,#+0
\ 0000005E 2070 STRB R0,[R4, #+0]
188 pevent->OSEventPtr = OSEventFreeList; /* Return Event Control Block to free list */
\ 00000060 .... LDR R0,??DataTable9 ;; OSEventFreeList
\ 00000062 0068 LDR R0,[R0, #+0]
\ 00000064 6060 STR R0,[R4, #+4]
189 pevent->OSEventCnt = 0;
\ 00000066 0020 MOVS R0,#+0
\ 00000068 6080 STRH R0,[R4, #+2]
190 OSEventFreeList = pevent; /* Get next free event control block */
\ 0000006A .... LDR R0,??DataTable9 ;; OSEventFreeList
\ 0000006C 0460 STR R4,[R0, #+0]
191 OS_EXIT_CRITICAL();
\ 0000006E 3000 MOVS R0,R6
\ 00000070 ........ _BLF OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
192 *err = OS_NO_ERR;
\ 00000074 0020 MOVS R0,#+0
\ 00000076 2870 STRB R0,[R5, #+0]
193 return ((OS_EVENT *)0); /* Semaphore has been deleted */
\ 00000078 0020 MOVS R0,#+0
\ 0000007A 2CE0 B ??OSSemDel_1
194 } else {
195 OS_EXIT_CRITICAL();
\ ??OSSemDel_9:
\ 0000007C 3000 MOVS R0,R6
\ 0000007E ........ _BLF OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
196 *err = OS_ERR_TASK_WAITING;
\ 00000082 0820 MOVS R0,#+8
\ 00000084 2870 STRB R0,[R5, #+0]
197 return (pevent);
\ 00000086 2000 MOVS R0,R4
\ 00000088 25E0 B ??OSSemDel_1
198 }
199
200 case OS_DEL_ALWAYS: /* Always delete the semaphore */
201 while (pevent->OSEventGrp != 0x00) { /* Ready ALL tasks waiting for semaphore */
202 OS_EventTaskRdy(pevent, (void *)0, OS_STAT_SEM);
\ ??OSSemDel_10:
\ 0000008A 0122 MOVS R2,#+1
\ 0000008C 0021 MOVS R1,#+0
\ 0000008E 2000 MOVS R0,R4
\ 00000090 ........ _BLF OS_EventTaskRdy,??OS_EventTaskRdy??rT
203 }
\ ??OSSemDel_7:
\ 00000094 6078 LDRB R0,[R4, #+1]
\ 00000096 0028 CMP R0,#+0
\ 00000098 F7D1 BNE ??OSSemDel_10
204 #if OS_EVENT_NAME_SIZE > 1
205 pevent->OSEventName[0] = '?'; /* Unknown name */
\ 0000009A 3F20 MOVS R0,#+63
\ 0000009C 2074 STRB R0,[R4, #+16]
206 pevent->OSEventName[1] = OS_ASCII_NUL;
\ 0000009E 0020 MOVS R0,#+0
\ 000000A0 6074 STRB R0,[R4, #+17]
207 #endif
208 pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
\ 000000A2 0020 MOVS R0,#+0
\ 000000A4 2070 STRB R0,[R4, #+0]
209 pevent->OSEventPtr = OSEventFreeList; /* Return Event Control Block to free list */
\ 000000A6 .... LDR R0,??DataTable9 ;; OSEventFreeList
\ 000000A8 0068 LDR R0,[R0, #+0]
\ 000000AA 6060 STR R0,[R4, #+4]
210 pevent->OSEventCnt = 0;
\ 000000AC 0020 MOVS R0,#+0
\ 000000AE 6080 STRH R0,[R4, #+2]
211 OSEventFreeList = pevent; /* Get next free event control block */
\ 000000B0 .... LDR R0,??DataTable9 ;; OSEventFreeList
\ 000000B2 0460 STR R4,[R0, #+0]
212 OS_EXIT_CRITICAL();
\ 000000B4 3000 MOVS R0,R6
\ 000000B6 ........ _BLF OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
213 if (tasks_waiting == TRUE) { /* Reschedule only if task(s) were waiting */
\ 000000BA 012F CMP R7,#+1
\ 000000BC 01D1 BNE ??OSSemDel_11
214 OS_Sched(); /* Find highest priority task ready to run */
\ 000000BE ........ _BLF OS_Sched,??OS_Sched??rT
215 }
216 *err = OS_NO_ERR;
\ ??OSSemDel_11:
\ 000000C2 0020 MOVS R0,#+0
\ 000000C4 2870 STRB R0,[R5, #+0]
217 return ((OS_EVENT *)0); /* Semaphore has been deleted */
\ 000000C6 0020 MOVS R0,#+0
\ 000000C8 05E0 B ??OSSemDel_1
218
219 default:
220 OS_EXIT_CRITICAL();
\ ??OSSemDel_8:
\ 000000CA 3000 MOVS R0,R6
\ 000000CC ........ _BLF OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
221 *err = OS_ERR_INVALID_OPT;
\ 000000D0 0720 MOVS R0,#+7
\ 000000D2 2870 STRB R0,[R5, #+0]
222 return (pevent);
\ 000000D4 2000 MOVS R0,R4
\ ??OSSemDel_1:
\ 000000D6 01B0 ADD SP,SP,#+4
\ 000000D8 F0BC POP {R4-R7}
\ 000000DA 02BC POP {R1}
\ 000000DC 0847 BX R1 ;; return
223 }
224 }
225 #endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -