📄 os_q.lst
字号:
695 * OS_ERR_EVENT_TYPE If you didn't pass a pointer to a queue.
696 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
697 *
698 * Warning : Interrupts can be disabled for a long time if you do a 'broadcast'. In fact, the
699 * interrupt disable time is proportional to the number of tasks waiting on the queue.
700 *********************************************************************************************************
701 */
702
703 #if OS_Q_POST_OPT_EN > 0
704 INT8U OSQPostOpt (OS_EVENT *pevent, void *pmsg, INT8U opt)
705 {
706 OS_Q *pq;
707 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
708 OS_CPU_SR cpu_sr = 0;
709 #endif
710
711
712
713 #if OS_ARG_CHK_EN > 0
714 if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
715 return (OS_ERR_PEVENT_NULL);
716 }
717 #endif
718 if (pevent->OSEventType != OS_EVENT_TYPE_Q) { /* Validate event block type */
719 return (OS_ERR_EVENT_TYPE);
720 }
721 OS_ENTER_CRITICAL();
722 if (pevent->OSEventGrp != 0x00) { /* See if any task pending on queue */
723 if ((opt & OS_POST_OPT_BROADCAST) != 0x00) { /* Do we need to post msg to ALL waiting tasks ? */
724 while (pevent->OSEventGrp != 0) { /* Yes, Post to ALL tasks waiting on queue */
725 (void)OS_EventTaskRdy(pevent, pmsg, OS_STAT_Q, OS_STAT_PEND_OK);
726 }
727 } else { /* No, Post to HPT waiting on queue */
728 (void)OS_EventTaskRdy(pevent, pmsg, OS_STAT_Q, OS_STAT_PEND_OK);
729 }
730 OS_EXIT_CRITICAL();
731 if ((opt & OS_POST_OPT_NO_SCHED) == 0) { /* See if scheduler needs to be invoked */
732 OS_Sched(); /* Find highest priority task ready to run */
733 }
734 return (OS_ERR_NONE);
735 }
736 pq = (OS_Q *)pevent->OSEventPtr; /* Point to queue control block */
737 if (pq->OSQEntries >= pq->OSQSize) { /* Make sure queue is not full */
738 OS_EXIT_CRITICAL();
739 return (OS_ERR_Q_FULL);
740 }
741 if ((opt & OS_POST_OPT_FRONT) != 0x00) { /* Do we post to the FRONT of the queue? */
742 if (pq->OSQOut == pq->OSQStart) { /* Yes, Post as LIFO, Wrap OUT pointer if we ... */
743 pq->OSQOut = pq->OSQEnd; /* ... are at the 1st queue entry */
744 }
745 pq->OSQOut--;
746 *pq->OSQOut = pmsg; /* Insert message into queue */
747 } else { /* No, Post as FIFO */
748 *pq->OSQIn++ = pmsg; /* Insert message into queue */
749 if (pq->OSQIn == pq->OSQEnd) { /* Wrap IN ptr if we are at end of queue */
750 pq->OSQIn = pq->OSQStart;
751 }
752 }
753 pq->OSQEntries++; /* Update the nbr of entries in the queue */
754 OS_EXIT_CRITICAL();
755 return (OS_ERR_NONE);
756 }
757 #endif
758 /*$PAGE*/
759 /*
760 *********************************************************************************************************
761 * QUERY A MESSAGE QUEUE
762 *
763 * Description: This function obtains information about a message queue.
764 *
765 * Arguments : pevent is a pointer to the event control block associated with the desired queue
766 *
767 * p_q_data is a pointer to a structure that will contain information about the message
768 * queue.
769 *
770 * Returns : OS_ERR_NONE The call was successful and the message was sent
771 * OS_ERR_EVENT_TYPE If you are attempting to obtain data from a non queue.
772 * OS_ERR_PEVENT_NULL If 'pevent' is a NULL pointer
773 * OS_ERR_PDATA_NULL If 'p_q_data' is a NULL pointer
774 *********************************************************************************************************
775 */
776
777 #if OS_Q_QUERY_EN > 0
778 INT8U OSQQuery (OS_EVENT *pevent, OS_Q_DATA *p_q_data)
779 {
780 OS_Q *pq;
781 INT8U i;
782 #if OS_LOWEST_PRIO <= 63
783 INT8U *psrc;
784 INT8U *pdest;
785 #else
786 INT16U *psrc;
787 INT16U *pdest;
788 #endif
789 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
790 OS_CPU_SR cpu_sr = 0;
791 #endif
792
793
794
795 #if OS_ARG_CHK_EN > 0
796 if (pevent == (OS_EVENT *)0) { /* Validate 'pevent' */
797 return (OS_ERR_PEVENT_NULL);
798 }
799 if (p_q_data == (OS_Q_DATA *)0) { /* Validate 'p_q_data' */
800 return (OS_ERR_PDATA_NULL);
801 }
802 #endif
803 if (pevent->OSEventType != OS_EVENT_TYPE_Q) { /* Validate event block type */
804 return (OS_ERR_EVENT_TYPE);
805 }
806 OS_ENTER_CRITICAL();
807 p_q_data->OSEventGrp = pevent->OSEventGrp; /* Copy message queue wait list */
808 psrc = &pevent->OSEventTbl[0];
809 pdest = &p_q_data->OSEventTbl[0];
810 for (i = 0; i < OS_EVENT_TBL_SIZE; i++) {
811 *pdest++ = *psrc++;
812 }
813 pq = (OS_Q *)pevent->OSEventPtr;
814 if (pq->OSQEntries > 0) {
815 p_q_data->OSMsg = *pq->OSQOut; /* Get next message to return if available */
816 } else {
817 p_q_data->OSMsg = (void *)0;
818 }
819 p_q_data->OSNMsgs = pq->OSQEntries;
820 p_q_data->OSQSize = pq->OSQSize;
821 OS_EXIT_CRITICAL();
822 return (OS_ERR_NONE);
823 }
824 #endif /* OS_Q_QUERY_EN */
825
826 /*$PAGE*/
827 /*
828 *********************************************************************************************************
829 * QUEUE MODULE INITIALIZATION
830 *
831 * Description : This function is called by uC/OS-II to initialize the message queue module. Your
832 * application MUST NOT call this function.
833 *
834 * Arguments : none
835 *
836 * Returns : none
837 *
838 * Note(s) : This function is INTERNAL to uC/OS-II and your application should not call it.
839 *********************************************************************************************************
840 */
841
842 void OS_QInit (void)
843 {
844 #if OS_MAX_QS == 1
845 OSQFreeList = &OSQTbl[0]; /* Only ONE queue! */
846 OSQFreeList->OSQPtr = (OS_Q *)0;
847 #endif
848
849 #if OS_MAX_QS >= 2
850 INT16U i;
851 OS_Q *pq1;
852 OS_Q *pq2;
853
854
855
856 OS_MemClr((INT8U *)&OSQTbl[0], sizeof(OSQTbl)); /* Clear the queue table */
857 pq1 = &OSQTbl[0];
858 pq2 = &OSQTbl[1];
859 for (i = 0; i < (OS_MAX_QS - 1); i++) { /* Init. list of free QUEUE control blocks */
860 pq1->OSQPtr = pq2;
861 pq1++;
862 pq2++;
863 }
864 pq1->OSQPtr = (OS_Q *)0;
865 OSQFreeList = &OSQTbl[0];
866 #endif
867 }
868 #endif /* OS_Q_EN */
Segment part sizes:
Function/Label Bytes
-------------- -----
0 bytes of memory
Errors: none
Warnings: none
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -