📄 os_q.ls1
字号:
310 ; if (pevent->OSEventType != OS_EVENT_TYPE_Q) { /* Validate event block type
*/
311 ; *err = OS_ERR_EVENT_TYPE;
312 ; return (pevent);
313 ; }
314 ; #endif
315 ; OS_ENTER_CRITICAL();
316 ; if (pevent->OSEventGrp != 0x00) { /* See if any tasks waiting on
queue */
317 ; tasks_waiting = TRUE; /* Yes
*/
318 ; } else {
319 ; tasks_waiting = FALSE; /* No
*/
320 ; }
A51 MACRO ASSEMBLER OS_Q 05/17/2005 11:19:56 PAGE 7
321 ; switch (opt) {
322 ; case OS_DEL_NO_PEND: /* Delete queue only if no tas
k waiting */
323 ; if (tasks_waiting == FALSE) {
324 ; pq = (OS_Q *)pevent->OSEventPtr; /* Return OS_Q to fre
e list */
325 ; pq->OSQPtr = OSQFreeList;
326 ; OSQFreeList = pq;
327 ; pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
328 ; pevent->OSEventPtr = OSEventFreeList; /* Return Event Control Block
to free list */
329 ; OSEventFreeList = pevent; /* Get next free event control
block */
330 ; OS_EXIT_CRITICAL();
331 ; *err = OS_NO_ERR;
332 ; return ((OS_EVENT *)0); /* Queue has been deleted
*/
333 ; } else {
334 ; OS_EXIT_CRITICAL();
335 ; *err = OS_ERR_TASK_WAITING;
336 ; return (pevent);
337 ; }
338 ;
339 ; case OS_DEL_ALWAYS: /* Always delete the queue
*/
340 ; while (pevent->OSEventGrp != 0x00) { /* Ready ALL tasks waiting for
queue */
341 ; OS_EventTaskRdy(pevent, (void *)0, OS_STAT_Q);
342 ; }
343 ; pq = (OS_Q *)pevent->OSEventPtr; /* Return OS_Q to fre
e list */
344 ; pq->OSQPtr = OSQFreeList;
345 ; OSQFreeList = pq;
346 ; pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
347 ; pevent->OSEventPtr = OSEventFreeList; /* Return Event Control Block
to free list */
348 ; OSEventFreeList = pevent; /* Get next free event control
block */
349 ; OS_EXIT_CRITICAL();
350 ; if (tasks_waiting == TRUE) { /* Reschedule only if task(s)
were waiting */
351 ; OS_Sched(); /* Find highest priority task
ready to run */
352 ; }
353 ; *err = OS_NO_ERR;
354 ; return ((OS_EVENT *)0); /* Queue has been deleted
*/
355 ;
356 ; default:
357 ; OS_EXIT_CRITICAL();
358 ; *err = OS_ERR_INVALID_OPT;
359 ; return (pevent);
360 ; }
361 ; }
362 ; #endif
363 ;
364 ; /*$PAGE*/
365 ; /*
366 ; *****************************************************************************************
****************
367 ; * FLUSH QUEUE
368 ; *
369 ; * Description : This function is used to flush the contents of the message queue.
370 ; *
371 ; * Arguments : none
372 ; *
A51 MACRO ASSEMBLER OS_Q 05/17/2005 11:19:56 PAGE 8
373 ; * Returns : OS_NO_ERR upon success
374 ; * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a queue
375 ; * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
376 ; *****************************************************************************************
****************
377 ; */
378 ;
379 ; #if OS_Q_FLUSH_EN > 0
380 ; INT8U OSQFlush (OS_EVENT *pevent)LG_REENTRANT
381 ; {
382 ; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status
register */
383 ; OS_CPU_SR cpu_sr;
384 ; #endif
385 ; OS_Q *pq;
386 ;
387 ;
388 ; #if OS_ARG_CHK_EN > 0
389 ; if (pevent == (OS_EVENT *)0) { /* Validate 'pevent'
*/
390 ; return (OS_ERR_PEVENT_NULL);
391 ; }
392 ; if (pevent->OSEventType != OS_EVENT_TYPE_Q) { /* Validate event block type
*/
393 ; return (OS_ERR_EVENT_TYPE);
394 ; }
395 ; #endif
396 ; OS_ENTER_CRITICAL();
397 ; pq = (OS_Q *)pevent->OSEventPtr; /* Point to queue storage structure
*/
398 ; pq->OSQIn = pq->OSQStart;
399 ; pq->OSQOut = pq->OSQStart;
400 ; pq->OSQEntries = 0;
401 ; OS_EXIT_CRITICAL();
402 ; return (OS_NO_ERR);
403 ; }
404 ; #endif
405 ;
406 ; /*$PAGE*/
407 ; /*
408 ; *****************************************************************************************
****************
409 ; * PEND ON A QUEUE FOR A MESSAGE
410 ; *
411 ; * Description: This function waits for a message to be sent to a queue
412 ; *
413 ; * Arguments : pevent is a pointer to the event control block associated with the
desired queue
414 ; *
415 ; * timeout is an optional timeout period (in clock ticks). If non-zero
, your task will
416 ; * wait for a message to arrive at the queue up to the amount o
f time
417 ; * specified by this argument. If you specify 0, however, your
task will wait
418 ; * forever at the specified queue or, until a message arrives.
419 ; *
420 ; * err is a pointer to where an error message will be deposited. P
ossible error
421 ; * messages are:
422 ; *
423 ; * OS_NO_ERR The call was successful and your task re
ceived a
424 ; * message.
425 ; * OS_TIMEOUT A message was not received within the sp
ecified timeout
A51 MACRO ASSEMBLER OS_Q 05/17/2005 11:19:56 PAGE 9
426 ; * OS_ERR_EVENT_TYPE You didn't pass a pointer to a queue
427 ; * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
428 ; * OS_ERR_PEND_ISR If you called this function from an ISR
and the result
429 ; * would lead to a suspension.
430 ; *
431 ; * Returns : != (void *)0 is a pointer to the message received
432 ; * == (void *)0 if no message was received or,
433 ; * if 'pevent' is a NULL pointer or,
434 ; * if you didn't pass a pointer to a queue.
435 ; *****************************************************************************************
****************
436 ; */
437 ;
438 ; void *OSQPend (OS_EVENT *pevent, INT16U timeout, INT8U *err)LG_REENTRANT
439 ; {
440 ; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status regis
ter */
441 ; OS_CPU_SR cpu_sr;
442 ; #endif
443 ; void *msg;
444 ; OS_Q *pq;
445 ;
446 ;
447 ; if (OSIntNesting > 0) { /* See if called from ISR ...
*/
448 ; *err = OS_ERR_PEND_ISR; /* ... can't PEND from an ISR
*/
449 ; return ((void *)0);
450 ; }
451 ; #if OS_ARG_CHK_EN > 0
452 ; if (pevent == (OS_EVENT *)0) { /* Validate 'pevent'
*/
453 ; *err = OS_ERR_PEVENT_NULL;
454 ; return ((void *)0);
455 ; }
456 ; if (pevent->OSEventType != OS_EVENT_TYPE_Q) {/* Validate event block type
*/
457 ; *err = OS_ERR_EVENT_TYPE;
458 ; return ((void *)0);
459 ; }
460 ; #endif
461 ; OS_ENTER_CRITICAL();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -