📄 os_q.lst
字号:
660 1 if (pq->OSQOut == pq->OSQStart) { /* Wrap OUT ptr if we are at the 1st queue entry */
661 2 pq->OSQOut = pq->OSQEnd;
662 2 }
663 1 pq->OSQOut--;
664 1 *pq->OSQOut = pmsg; /* Insert message into queue */
665 1 pq->OSQEntries++; /* Update the nbr of entries in the queue */
666 1 OS_EXIT_CRITICAL();
667 1 return (OS_ERR_NONE);
668 1 }
669 #endif
670 /*$PAGE*/
671 /*
672 *********************************************************************************************************
673 * POST MESSAGE TO A QUEUE
C51 COMPILER V7.50 OS_Q 12/14/2007 08:25:37 PAGE 12
674 *
675 * Description: This function sends a message to a queue. This call has been added to reduce code size
676 * since it can replace both OSQPost() and OSQPostFront(). Also, this function adds the
677 * capability to broadcast a message to ALL tasks waiting on the message queue.
678 *
679 * Arguments : pevent is a pointer to the event control block associated with the desired queue
680 *
681 * pmsg is a pointer to the message to send.
682 *
683 * opt determines the type of POST performed:
684 * OS_POST_OPT_NONE POST to a single waiting task
685 * (Identical to OSQPost())
686 * OS_POST_OPT_BROADCAST POST to ALL tasks that are waiting on the queue
687 * OS_POST_OPT_FRONT POST as LIFO (Simulates OSQPostFront())
688 * OS_POST_OPT_NO_SCHED Indicates that the scheduler will NOT be invoked
689 *
690 * Returns : OS_ERR_NONE The call was successful and the message was sent
691 * OS_ERR_Q_FULL If the queue cannot accept any more messages because it is full.
692 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a queue.
693 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
694 *
695 * Warning : Interrupts can be disabled for a long time if you do a 'broadcast'. In fact, the
696 * interrupt disable time is proportional to the number of tasks waiting on the queue.
697 *********************************************************************************************************
698 */
699
700 #if OS_Q_POST_OPT_EN > 0
701 INT8U OSQPostOpt (OS_EVENT *pevent, void *pmsg, INT8U opt) reentrant
702 {
703 1 OS_Q *pq;
704 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
707 1
708 1
709 1
710 1 #if OS_ARG_CHK_EN > 0
if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
return (OS_ERR_PEVENT_NULL);
}
#endif
715 1 if (pevent->OSEventType != OS_EVENT_TYPE_Q) { /* Validate event block type */
716 2 return (OS_ERR_EVENT_TYPE);
717 2 }
718 1 OS_ENTER_CRITICAL();
719 1 if (pevent->OSEventGrp != 0x00) { /* See if any task pending on queue */
720 2 if ((opt & OS_POST_OPT_BROADCAST) != 0x00) { /* Do we need to post msg to ALL waiting tasks ? */
721 3 while (pevent->OSEventGrp != 0) { /* Yes, Post to ALL tasks waiting on queue */
722 4 (void)OS_EventTaskRdy(pevent, pmsg, OS_STAT_Q, OS_STAT_PEND_OK);
723 4 }
724 3 } else { /* No, Post to HPT waiting on queue */
725 3 (void)OS_EventTaskRdy(pevent, pmsg, OS_STAT_Q, OS_STAT_PEND_OK);
726 3 }
727 2 OS_EXIT_CRITICAL();
728 2 if ((opt & OS_POST_OPT_NO_SCHED) == 0) { /* See if scheduler needs to be invoked */
729 3 OS_Sched(); /* Find highest priority task ready to run */
730 3 }
731 2 return (OS_ERR_NONE);
732 2 }
733 1 pq = (OS_Q *)pevent->OSEventPtr; /* Point to queue control block */
734 1 if (pq->OSQEntries >= pq->OSQSize) { /* Make sure queue is not full */
735 2 OS_EXIT_CRITICAL();
C51 COMPILER V7.50 OS_Q 12/14/2007 08:25:37 PAGE 13
736 2 return (OS_ERR_Q_FULL);
737 2 }
738 1 if ((opt & OS_POST_OPT_FRONT) != 0x00) { /* Do we post to the FRONT of the queue? */
739 2 if (pq->OSQOut == pq->OSQStart) { /* Yes, Post as LIFO, Wrap OUT pointer if we ... */
740 3 pq->OSQOut = pq->OSQEnd; /* ... are at the 1st queue entry */
741 3 }
742 2 pq->OSQOut--;
743 2 *pq->OSQOut = pmsg; /* Insert message into queue */
744 2 } else { /* No, Post as FIFO */
745 2 *pq->OSQIn++ = pmsg; /* Insert message into queue */
746 2 if (pq->OSQIn == pq->OSQEnd) { /* Wrap IN ptr if we are at end of queue */
747 3 pq->OSQIn = pq->OSQStart;
748 3 }
749 2 }
750 1 pq->OSQEntries++; /* Update the nbr of entries in the queue */
751 1 OS_EXIT_CRITICAL();
752 1 return (OS_ERR_NONE);
753 1 }
754 #endif
755 /*$PAGE*/
756 /*
757 *********************************************************************************************************
758 * QUERY A MESSAGE QUEUE
759 *
760 * Description: This function obtains information about a message queue.
761 *
762 * Arguments : pevent is a pointer to the event control block associated with the desired queue
763 *
764 * p_q_data is a pointer to a structure that will contain information about the message
765 * queue.
766 *
767 * Returns : OS_ERR_NONE The call was successful and the message was sent
768 * OS_ERR_EVENT_TYPE If you are attempting to obtain data from a non queue.
769 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
770 * OS_ERR_PDATA_NULL If 'p_q_data' is a NULL pointer
771 *********************************************************************************************************
772 */
773
774 #if OS_Q_QUERY_EN > 0
775 INT8U OSQQuery (OS_EVENT *pevent, OS_Q_DATA *p_q_data) reentrant
776 {
777 1 OS_Q *pq;
778 1 INT8U i;
779 1 #if OS_LOWEST_PRIO <= 63
780 1 INT8U *psrc;
781 1 INT8U *pdest;
782 1 #else
INT16U *psrc;
INT16U *pdest;
#endif
786 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
789 1
790 1
791 1
792 1 #if OS_ARG_CHK_EN > 0
if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
return (OS_ERR_PEVENT_NULL);
}
if (p_q_data == (OS_Q_DATA *)0) { /* Validate 'p_q_data' */
return (OS_ERR_PDATA_NULL);
C51 COMPILER V7.50 OS_Q 12/14/2007 08:25:37 PAGE 14
}
#endif
800 1 if (pevent->OSEventType != OS_EVENT_TYPE_Q) { /* Validate event block type */
801 2 return (OS_ERR_EVENT_TYPE);
802 2 }
803 1 OS_ENTER_CRITICAL();
804 1 p_q_data->OSEventGrp = pevent->OSEventGrp; /* Copy message queue wait list */
805 1 psrc = &pevent->OSEventTbl[0];
806 1 pdest = &p_q_data->OSEventTbl[0];
807 1 for (i = 0; i < OS_EVENT_TBL_SIZE; i++) {
808 2 *pdest++ = *psrc++;
809 2 }
810 1 pq = (OS_Q *)pevent->OSEventPtr;
811 1 if (pq->OSQEntries > 0) {
812 2 p_q_data->OSMsg = *pq->OSQOut; /* Get next message to return if available */
813 2 } else {
814 2 p_q_data->OSMsg = (void *)0;
815 2 }
816 1 p_q_data->OSNMsgs = pq->OSQEntries;
817 1 p_q_data->OSQSize = pq->OSQSize;
818 1 OS_EXIT_CRITICAL();
819 1 return (OS_ERR_NONE);
820 1 }
821 #endif /* OS_Q_QUERY_EN */
822
823 /*$PAGE*/
824 /*
825 *********************************************************************************************************
826 * QUEUE MODULE INITIALIZATION
827 *
828 * Description : This function is called by uC/OS-II to initialize the message queue module. Your
829 * application MUST NOT call this function.
830 *
831 * Arguments : none
832 *
833 * Returns : none
834 *
835 * Note(s) : This function is INTERNAL to uC/OS-II and your application should not call it.
836 *********************************************************************************************************
837 */
838
839 void OS_QInit (void) reentrant
840 {
841 1 #if OS_MAX_QS == 1
OSQFreeList = &OSQTbl[0]; /* Only ONE queue! */
OSQFreeList->OSQPtr = (OS_Q *)0;
#endif
845 1
846 1 #if OS_MAX_QS >= 2
847 1 INT16U i;
848 1 OS_Q *pq1;
849 1 OS_Q *pq2;
850 1
851 1
852 1
853 1 OS_MemClr((INT8U *)&OSQTbl[0], sizeof(OSQTbl)); /* Clear the queue table */
854 1 pq1 = &OSQTbl[0];
855 1 pq2 = &OSQTbl[1];
856 1 for (i = 0; i < (OS_MAX_QS - 1); i++) { /* Init. list of free QUEUE control blocks */
857 2 pq1->OSQPtr = pq2;
858 2 pq1++;
859 2 pq2++;
C51 COMPILER V7.50 OS_Q 12/14/2007 08:25:37 PAGE 15
860 2 }
861 1 pq1->OSQPtr = (OS_Q *)0;
862 1 OSQFreeList = &OSQTbl[0];
863 1 #endif
864 1 }
865 #endif /* OS_Q_EN */
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 5189 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -