1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** ThreadX Component */
17 /** */
18 /** Queue */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 #define TX_SOURCE_CODE
24
25
26 /* Include necessary system files. */
27
28 #include "tx_api.h"
29 #include "tx_timer.h"
30 #include "tx_thread.h"
31 #include "tx_queue.h"
32
33
34 /**************************************************************************/
35 /* */
36 /* FUNCTION RELEASE */
37 /* */
38 /* _txe_queue_receive PORTABLE C */
39 /* 6.1 */
40 /* AUTHOR */
41 /* */
42 /* William E. Lamie, Microsoft Corporation */
43 /* */
44 /* DESCRIPTION */
45 /* */
46 /* This function checks for errors in the queue receive function call. */
47 /* */
48 /* INPUT */
49 /* */
50 /* queue_ptr Pointer to queue control block */
51 /* destination_ptr Pointer to message destination */
52 /* **** MUST BE LARGE ENOUGH TO */
53 /* HOLD MESSAGE **** */
54 /* wait_option Suspension option */
55 /* */
56 /* OUTPUT */
57 /* */
58 /* TX_QUEUE_ERROR Invalid queue pointer */
59 /* TX_PTR_ERROR Invalid destination pointer (NULL)*/
60 /* TX_WAIT_ERROR Invalid wait option */
61 /* status Actual completion status */
62 /* */
63 /* CALLS */
64 /* */
65 /* _tx_queue_receive Actual queue receive function */
66 /* */
67 /* CALLED BY */
68 /* */
69 /* Application Code */
70 /* */
71 /* RELEASE HISTORY */
72 /* */
73 /* DATE NAME DESCRIPTION */
74 /* */
75 /* 05-19-2020 William E. Lamie Initial Version 6.0 */
76 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
77 /* resulting in version 6.1 */
78 /* */
79 /**************************************************************************/
_txe_queue_receive(TX_QUEUE * queue_ptr,VOID * destination_ptr,ULONG wait_option)80 UINT _txe_queue_receive(TX_QUEUE *queue_ptr, VOID *destination_ptr, ULONG wait_option)
81 {
82
83 UINT status;
84
85 #ifndef TX_TIMER_PROCESS_IN_ISR
86 TX_THREAD *current_thread;
87 #endif
88
89
90 /* Default status to success. */
91 status = TX_SUCCESS;
92
93 /* Check for an invalid queue pointer. */
94 if (queue_ptr == TX_NULL)
95 {
96
97 /* Queue pointer is invalid, return appropriate error code. */
98 status = TX_QUEUE_ERROR;
99 }
100
101 /* Now check for invalid queue ID. */
102 else if (queue_ptr -> tx_queue_id != TX_QUEUE_ID)
103 {
104
105 /* Queue pointer is invalid, return appropriate error code. */
106 status = TX_QUEUE_ERROR;
107 }
108
109 /* Check for an invalid destination for message. */
110 else if (destination_ptr == TX_NULL)
111 {
112
113 /* Null destination pointer, return appropriate error. */
114 status = TX_PTR_ERROR;
115 }
116 else
117 {
118
119 /* Check for a wait option error. Only threads are allowed any form of
120 suspension. */
121 if (wait_option != TX_NO_WAIT)
122 {
123
124 /* Is the call from an ISR or Initialization? */
125 if (TX_THREAD_GET_SYSTEM_STATE() != ((ULONG) 0))
126 {
127
128 /* A non-thread is trying to suspend, return appropriate error code. */
129 status = TX_WAIT_ERROR;
130 }
131
132 #ifndef TX_TIMER_PROCESS_IN_ISR
133 else
134 {
135
136 /* Pickup thread pointer. */
137 TX_THREAD_GET_CURRENT(current_thread)
138
139 /* Is the current thread the timer thread? */
140 if (current_thread == &_tx_timer_thread)
141 {
142
143 /* A non-thread is trying to suspend, return appropriate error code. */
144 status = TX_WAIT_ERROR;
145 }
146 }
147 #endif
148 }
149 }
150
151 /* Determine if everything is okay. */
152 if (status == TX_SUCCESS)
153 {
154
155 /* Call actual queue receive function. */
156 status = _tx_queue_receive(queue_ptr, destination_ptr, wait_option);
157 }
158
159 /* Return completion status. */
160 return(status);
161 }
162
163