📄 os_q.lst
字号:
230 OSQFreeList = pq;
\ 0164 824C0000 MOV R12,&OSQFreeList
231 pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
\ 0168 CB430000 MOV.B #0,0(R11)
232 pevent->OSEventPtr = OSEventFreeList; /* Return Event Control Block to free list */
\ 016C 9B420000 MOV &OSEventFreeList,4(R11)
\ 0170 0400
233 OSEventFreeList = pevent; /* Get next free event control block */
\ 0172 824B0000 MOV R11,&OSEventFreeList
234 OS_EXIT_CRITICAL();
\ 0176 32D2 EINT
235 if (tasks_waiting == TRUE) { /* Reschedule only if task(s) were waiting */
\ 0178 5A93 CMP.B #1,R10
\ 017A 0220 JNE (?0096)
236 OS_Sched(); /* Find highest priority task ready to run */
\ 017C B0120000 CALL #OS_Sched
\ 0180 ?0096:
237 }
238 *err = OS_NO_ERR;
\ 0180 C8430000 MOV.B #0,0(R8)
239 return ((OS_EVENT *)0); /* Queue has been deleted */
\ 0184 0C43 MOV #0,R12
240
241 default:
\ 0186 053C JMP (?0098)
\ 0188 ?0097:
242 OS_EXIT_CRITICAL();
\ 0188 32D2 EINT
243 *err = OS_ERR_INVALID_OPT;
\ 018A F8400700 MOV.B #7,0(R8)
\ 018E 0000
244 return (pevent);
\ 0190 0C4B MOV R11,R12
245 }
\ 0192 ?0098:
\ 0192 3841 POP R8
\ 0194 3B41 POP R11
\ 0196 3A41 POP R10
\ 0198 3041 RET
\ 019A ?0087:
246 }
\ 019A OSQFlush:
247 #endif
248
249 /*$PAGE*/
250 /*
251 *********************************************************************************************************
252 * FLUSH QUEUE
253 *
254 * Description : This function is used to flush the contents of the message queue.
255 *
256 * Arguments : none
257 *
258 * Returns : OS_NO_ERR upon success
259 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a queue
260 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
261 *********************************************************************************************************
262 */
263
264 #if OS_Q_FLUSH_EN > 0
265 INT8U OSQFlush (OS_EVENT *pevent)
266 {
267 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
268 OS_CPU_SR cpu_sr;
269 #endif
270 OS_Q *pq;
271
272
273 #if OS_ARG_CHK_EN > 0
274 if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
\ 019A 0C93 CMP #0,R12
\ 019C 0220 JNE (?0100)
275 return (OS_ERR_PEVENT_NULL);
\ 019E 6C42 MOV.B #4,R12
276 }
\ 01A0 3041 RET
\ 01A2 ?0100:
277 if (pevent->OSEventType != OS_EVENT_TYPE_Q) { /* Validate event block type */
\ 01A2 6D43 MOV.B #2,R13
\ 01A4 6D9C CMP.B @R12,R13
\ 01A6 0224 JEQ (?0102)
278 return (OS_ERR_EVENT_TYPE);
\ 01A8 5C43 MOV.B #1,R12
279 }
\ 01AA 3041 RET
\ 01AC ?0102:
280 #endif
281 OS_ENTER_CRITICAL();
\ 01AC 32C2 DINT
282 pq = (OS_Q *)pevent->OSEventPtr; /* Point to queue storage structure */
\ 01AE 1D4C0400 MOV 4(R12),R13
283 pq->OSQIn = pq->OSQStart;
\ 01B2 9D4D0200 MOV 2(R13),6(R13)
\ 01B6 0600
284 pq->OSQOut = pq->OSQStart;
\ 01B8 9D4D0200 MOV 2(R13),8(R13)
\ 01BC 0800
285 pq->OSQEntries = 0;
\ 01BE 8D430C00 MOV #0,12(R13)
286 OS_EXIT_CRITICAL();
\ 01C2 32D2 EINT
287 return (OS_NO_ERR);
\ 01C4 4C43 MOV.B #0,R12
288 }
\ 01C6 3041 RET
\ 01C8 OSQPend:
289 #endif
290
291 /*$PAGE*/
292 /*
293 *********************************************************************************************************
294 * PEND ON A QUEUE FOR A MESSAGE
295 *
296 * Description: This function waits for a message to be sent to a queue
297 *
298 * Arguments : pevent is a pointer to the event control block associated with the desired queue
299 *
300 * timeout is an optional timeout period (in clock ticks). If non-zero, your task will
301 * wait for a message to arrive at the queue up to the amount of time
302 * specified by this argument. If you specify 0, however, your task will wait
303 * forever at the specified queue or, until a message arrives.
304 *
305 * err is a pointer to where an error message will be deposited. Possible error
306 * messages are:
307 *
308 * OS_NO_ERR The call was successful and your task received a
309 * message.
310 * OS_TIMEOUT A message was not received within the specified timeout
311 * OS_ERR_EVENT_TYPE You didn't pass a pointer to a queue
312 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
313 * OS_ERR_PEND_ISR If you called this function from an ISR and the result
314 * would lead to a suspension.
315 *
316 * Returns : != (void *)0 is a pointer to the message received
317 * == (void *)0 if no message was received or,
318 * if 'pevent' is a NULL pointer or,
319 * if you didn't pass a pointer to a queue.
320 *********************************************************************************************************
321 */
322
323 void *OSQPend (OS_EVENT *pevent, INT16U timeout, INT8U *err)
324 {
\ 01C8 0A12 PUSH R10
\ 01CA 0B12 PUSH R11
\ 01CC 0A4C MOV R12,R10
\ 01CE 1B410600 MOV 6(SP),R11
325 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
326 OS_CPU_SR cpu_sr;
327 #endif
328 void *msg;
329 OS_Q *pq;
330
331
332 if (OSIntNesting > 0) { /* See if called from ISR ... */
\ 01D2 C2930000 CMP.B #0,&OSIntNesting
\ 01D6 0424 JEQ (?0105)
333 *err = OS_ERR_PEND_ISR; /* ... can't PEND from an ISR */
\ 01D8 EB430000 MOV.B #2,0(R11)
334 return ((void *)0);
\ 01DC 0C43 MOV #0,R12
335 }
\ 01DE 523C JMP (?0116)
\ 01E0 ?0105:
336 #if OS_ARG_CHK_EN > 0
337 if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
\ 01E0 0A93 CMP #0,R10
\ 01E2 0420 JNE (?0107)
338 *err = OS_ERR_PEVENT_NULL;
\ 01E4 EB420000 MOV.B #4,0(R11)
339 return ((void *)0);
\ 01E8 0C43 MOV #0,R12
340 }
\ 01EA 4C3C JMP (?0116)
\ 01EC ?0107:
341 if (pevent->OSEventType != OS_EVENT_TYPE_Q) {/* Validate event block type */
\ 01EC 6C43 MOV.B #2,R12
\ 01EE 6C9A CMP.B @R10,R12
\ 01F0 0424 JEQ (?0109)
342 *err = OS_ERR_EVENT_TYPE;
\ 01F2 DB430000 MOV.B #1,0(R11)
343 return ((void *)0);
\ 01F6 0C43 MOV #0,R12
344 }
\ 01F8 453C JMP (?0116)
\ 01FA ?0109:
345 #endif
346 OS_ENTER_CRITICAL();
\ 01FA 32C2 DINT
347 pq = (OS_Q *)pevent->OSEventPtr; /* Point at queue control block */
\ 01FC 1D4A0400 MOV 4(R10),R13
348 if (pq->OSQEntries > 0) { /* See if any messages in the queue */
\ 0200 8D930C00 CMP #0,12(R13)
\ 0204 1224 JEQ (?0111)
349 msg = *pq->OSQOut++; /* Yes, extract oldest message from the queue */
\ 0206 1E4D0800 MOV 8(R13),R14
\ 020A AD530800 ADD #2,8(R13)
\ 020E 2C4E MOV @R14,R12
350 pq->OSQEntries--; /* Update the number of entries in the queue */
\ 0210 BD530C00 ADD #-1,12(R13)
351 if (pq->OSQOut == pq->OSQEnd) { /* Wrap OUT pointer if we are at the end of the queue */
\ 0214 9D9D0800 CMP 8(R13),4(R13)
\ 0218 0400
\ 021A 0320 JNE (?0113)
352 pq->OSQOut = pq->OSQStart;
\ 021C 9D4D0200 MOV 2(R13),8(R13)
\ 0220 0800
\ 0222 ?0113:
353 }
354 OS_EXIT_CRITICAL();
\ 0222 32D2 EINT
355 *err = OS_NO_ERR;
\ 0224 CB430000 MOV.B #0,0(R11)
356 return (msg); /* Return message received */
357 }
\ 0228 2D3C JMP (?0116)
\ 022A ?0111:
358 OSTCBCur->OSTCBStat |= OS_STAT_Q; /* Task will have to pend for a message to be posted */
\ 022A 1C420000 MOV &OSTCBCur,R12
\ 022E ECD21C00 BIS.B #4,28(R12)
359 OSTCBCur->OSTCBDly = timeout; /* Load timeout into TCB */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -