📄 os_q.lst
字号:
436 1 OS_EXIT_CRITICAL();
437 1 OS_Sched(); /* Find next highest priority task ready to run */
438 1 OS_ENTER_CRITICAL();
439 1 if (OSTCBCur->OSTCBStatPend != OS_STAT_PEND_OK) { /* Was task readied because timed-out or aborted?*/
440 2 pend_stat = OSTCBCur->OSTCBStatPend;
441 2 OS_EventTOAbort(pevent);
442 2 OS_EXIT_CRITICAL();
443 2 switch (pend_stat) {
444 3 case OS_STAT_PEND_TO:
445 3 default:
446 3 *perr = OS_ERR_TIMEOUT; /* Indicate a timeout occured */
447 3 break;
448 3
449 3 case OS_STAT_PEND_ABORT:
450 3 *perr = OS_ERR_PEND_ABORT; /* Indicate that we aborted */
451 3 break;
452 3 }
453 2 return ((void *)0); /* No message received */
454 2 }
455 1 pmsg = OSTCBCur->OSTCBMsg;/* No, Extract message from TCB (Put there by QPost) */
456 1 OSTCBCur->OSTCBMsg = (void *)0;
457 1 OSTCBCur->OSTCBStat = OS_STAT_RDY;
458 1 OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0; /* No longer waiting for event */
459 1 OS_EXIT_CRITICAL();
460 1 *perr = OS_ERR_NONE;
461 1 return (pmsg); /* Return message received */
462 1 }
463 /*$PAGE*/
464 /*
465 *********************************************************************************************************
466 * ABORT WAITING ON A MESSAGE QUEUE
467 *
468 * Description: This function aborts & readies any tasks currently waiting on a queue. This function
469 * should be used to fault-abort the wait on the queue, rather than to normally signal
470 * the queue via OSQPost(), OSQPostFront() or OSQPostOpt().
471 *
472 * Arguments : pevent is a pointer to the event control block associated with the desired queue.
473 *
474 * opt determines the type of ABORT performed:
475 * OS_PEND_OPT_NONE ABORT wait for a single task (HPT) waiting on the
476 * queue
477 * OS_PEND_OPT_BROADCAST ABORT wait for ALL tasks that are waiting on the
478 * queue
479 *
480 * perr is a pointer to where an error message will be deposited. Possible error
481 * messages are:
482 *
483 * OS_ERR_NONE No tasks were waiting on the queue.
484 * OS_ERR_PEND_ABORT At least one task waiting on the queue was readied
485 * and informed of the aborted wait; check return value
486 * for the number of tasks whose wait on the queue
487 * was aborted.
C51 COMPILER V7.50 OS_Q 12/14/2007 08:25:37 PAGE 9
488 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a queue.
489 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer.
490 *
491 * Returns : == 0 if no tasks were waiting on the queue, or upon error.
492 * > 0 if one or more tasks waiting on the queue are now readied and informed.
493 *********************************************************************************************************
494 */
495
496 #if OS_Q_PEND_ABORT_EN > 0
497 INT8U OSQPendAbort (OS_EVENT *pevent, INT8U opt, INT8U *perr) reentrant
498 {
499 1 INT8U nbr_tasks;
500 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
503 1
504 1
505 1
506 1 #if OS_ARG_CHK_EN > 0
if (perr == (INT8U *)0) { /* Validate 'perr' */
return (0);
}
if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
*perr = OS_ERR_PEVENT_NULL;
return (0);
}
#endif
515 1 if (pevent->OSEventType != OS_EVENT_TYPE_Q) { /* Validate event block type */
516 2 *perr = OS_ERR_EVENT_TYPE;
517 2 return (0);
518 2 }
519 1 OS_ENTER_CRITICAL();
520 1 if (pevent->OSEventGrp != 0) { /* See if any task waiting on queue? */
521 2 nbr_tasks = 0;
522 2 switch (opt) {
523 3 case OS_PEND_OPT_BROADCAST: /* Do we need to abort ALL waiting tasks? */
524 3 while (pevent->OSEventGrp != 0) { /* Yes, ready ALL tasks waiting on queue */
525 4 (void)OS_EventTaskRdy(pevent, (void *)0, OS_STAT_Q, OS_STAT_PEND_ABORT);
526 4 nbr_tasks++;
527 4 }
528 3 break;
529 3
530 3 case OS_PEND_OPT_NONE: /* No, ready HPT waiting on queue */
531 3 default:
532 3 (void)OS_EventTaskRdy(pevent, (void *)0, OS_STAT_Q, OS_STAT_PEND_ABORT);
533 3 nbr_tasks++;
534 3 break;
535 3 }
536 2 OS_EXIT_CRITICAL();
537 2 OS_Sched(); /* Find HPT ready to run */
538 2 *perr = OS_ERR_PEND_ABORT;
539 2 return (nbr_tasks);
540 2 }
541 1 OS_EXIT_CRITICAL();
542 1 *perr = OS_ERR_NONE;
543 1 return (0); /* No tasks waiting on queue */
544 1 }
545 #endif
546
547 /*$PAGE*/
548 /*
549 *********************************************************************************************************
C51 COMPILER V7.50 OS_Q 12/14/2007 08:25:37 PAGE 10
550 * POST MESSAGE TO A QUEUE
551 *
552 * Description: This function sends a message to a queue
553 *
554 * Arguments : pevent is a pointer to the event control block associated with the desired queue
555 *
556 * pmsg is a pointer to the message to send.
557 *
558 * Returns : OS_ERR_NONE The call was successful and the message was sent
559 * OS_ERR_Q_FULL If the queue cannot accept any more messages because it is full.
560 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a queue.
561 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
562 *
563 * Note(s) : As of V2.60, this function allows you to send NULL pointer messages.
564 *********************************************************************************************************
565 */
566
567 #if OS_Q_POST_EN > 0
568 INT8U OSQPost (OS_EVENT *pevent, void *pmsg) reentrant
569 {
570 1 OS_Q *pq;
571 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
574 1
575 1
576 1
577 1 #if OS_ARG_CHK_EN > 0
if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
return (OS_ERR_PEVENT_NULL);
}
#endif
582 1 if (pevent->OSEventType != OS_EVENT_TYPE_Q) { /* Validate event block type */
583 2 return (OS_ERR_EVENT_TYPE);
584 2 }
585 1 OS_ENTER_CRITICAL();
586 1 if (pevent->OSEventGrp != 0) { /* See if any task pending on queue */
587 2 /* Ready highest priority task waiting on event */
588 2 (void)OS_EventTaskRdy(pevent, pmsg, OS_STAT_Q, OS_STAT_PEND_OK);
589 2 OS_EXIT_CRITICAL();
590 2 OS_Sched(); /* Find highest priority task ready to run */
591 2 return (OS_ERR_NONE);
592 2 }
593 1 pq = (OS_Q *)pevent->OSEventPtr; /* Point to queue control block */
594 1 if (pq->OSQEntries >= pq->OSQSize) { /* Make sure queue is not full */
595 2 OS_EXIT_CRITICAL();
596 2 return (OS_ERR_Q_FULL);
597 2 }
598 1 *pq->OSQIn++ = pmsg; /* Insert message into queue */
599 1 pq->OSQEntries++; /* Update the nbr of entries in the queue */
600 1 if (pq->OSQIn == pq->OSQEnd) { /* Wrap IN ptr if we are at end of queue */
601 2 pq->OSQIn = pq->OSQStart;
602 2 }
603 1 OS_EXIT_CRITICAL();
604 1 return (OS_ERR_NONE);
605 1 }
606 #endif
607 /*$PAGE*/
608 /*
609 *********************************************************************************************************
610 * POST MESSAGE TO THE FRONT OF A QUEUE
611 *
C51 COMPILER V7.50 OS_Q 12/14/2007 08:25:37 PAGE 11
612 * Description: This function sends a message to a queue but unlike OSQPost(), the message is posted at
613 * the front instead of the end of the queue. Using OSQPostFront() allows you to send
614 * 'priority' messages.
615 *
616 * Arguments : pevent is a pointer to the event control block associated with the desired queue
617 *
618 * pmsg is a pointer to the message to send.
619 *
620 * Returns : OS_ERR_NONE The call was successful and the message was sent
621 * OS_ERR_Q_FULL If the queue cannot accept any more messages because it is full.
622 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a queue.
623 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
624 *
625 * Note(s) : As of V2.60, this function allows you to send NULL pointer messages.
626 *********************************************************************************************************
627 */
628
629 #if OS_Q_POST_FRONT_EN > 0
630 INT8U OSQPostFront (OS_EVENT *pevent, void *pmsg) reentrant
631 {
632 1 OS_Q *pq;
633 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
636 1
637 1
638 1
639 1 #if OS_ARG_CHK_EN > 0
if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
return (OS_ERR_PEVENT_NULL);
}
#endif
644 1 if (pevent->OSEventType != OS_EVENT_TYPE_Q) { /* Validate event block type */
645 2 return (OS_ERR_EVENT_TYPE);
646 2 }
647 1 OS_ENTER_CRITICAL();
648 1 if (pevent->OSEventGrp != 0) { /* See if any task pending on queue */
649 2 /* Ready highest priority task waiting on event */
650 2 (void)OS_EventTaskRdy(pevent, pmsg, OS_STAT_Q, OS_STAT_PEND_OK);
651 2 OS_EXIT_CRITICAL();
652 2 OS_Sched(); /* Find highest priority task ready to run */
653 2 return (OS_ERR_NONE);
654 2 }
655 1 pq = (OS_Q *)pevent->OSEventPtr; /* Point to queue control block */
656 1 if (pq->OSQEntries >= pq->OSQSize) { /* Make sure queue is not full */
657 2 OS_EXIT_CRITICAL();
658 2 return (OS_ERR_Q_FULL);
659 2 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -