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_front_send                               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 send function call.    */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    queue_ptr                         Pointer to queue control block    */
51 /*    source_ptr                        Pointer to message source         */
52 /*    wait_option                       Suspension option                 */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    TX_QUEUE_ERROR                    Invalid queue pointer             */
57 /*    TX_PTR_ERROR                      Invalid source pointer - NULL     */
58 /*    TX_WAIT_ERROR                     Invalid wait option - non thread  */
59 /*    status                            Actual completion status          */
60 /*                                                                        */
61 /*  CALLS                                                                 */
62 /*                                                                        */
63 /*    _tx_queue_front_send              Actual queue send function        */
64 /*                                                                        */
65 /*  CALLED BY                                                             */
66 /*                                                                        */
67 /*    Application Code                                                    */
68 /*                                                                        */
69 /*  RELEASE HISTORY                                                       */
70 /*                                                                        */
71 /*    DATE              NAME                      DESCRIPTION             */
72 /*                                                                        */
73 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
74 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
75 /*                                            resulting in version 6.1    */
76 /*                                                                        */
77 /**************************************************************************/
_txe_queue_front_send(TX_QUEUE * queue_ptr,VOID * source_ptr,ULONG wait_option)78 UINT  _txe_queue_front_send(TX_QUEUE *queue_ptr, VOID *source_ptr, ULONG wait_option)
79 {
80 
81 UINT        status;
82 
83 #ifndef TX_TIMER_PROCESS_IN_ISR
84 TX_THREAD   *current_thread;
85 #endif
86 
87 
88     /* Default status to success.  */
89     status =  TX_SUCCESS;
90 
91     /* Check for an invalid queue pointer.  */
92     if (queue_ptr == TX_NULL)
93     {
94 
95         /* Queue pointer is invalid, return appropriate error code.  */
96         status =  TX_QUEUE_ERROR;
97     }
98 
99     /* Now check for invalid queue ID.  */
100     else if (queue_ptr -> tx_queue_id != TX_QUEUE_ID)
101     {
102 
103         /* Queue pointer is invalid, return appropriate error code.  */
104         status =  TX_QUEUE_ERROR;
105     }
106 
107     /* Check for an invalid source for message.  */
108     else if (source_ptr == TX_NULL)
109     {
110 
111         /* Null source pointer, return appropriate error.  */
112         status =  TX_PTR_ERROR;
113     }
114     else
115     {
116 
117         /* Check for a wait option error.  Only threads are allowed any form of
118            suspension.  */
119         if (wait_option != TX_NO_WAIT)
120         {
121 
122             /* Is the call from an ISR or Initialization?  */
123             if (TX_THREAD_GET_SYSTEM_STATE() != ((ULONG) 0))
124             {
125 
126                 /* A non-thread is trying to suspend, return appropriate error code.  */
127                 status =  TX_WAIT_ERROR;
128             }
129 
130 #ifndef TX_TIMER_PROCESS_IN_ISR
131             else
132             {
133 
134                 /* Pickup thread pointer.  */
135                 TX_THREAD_GET_CURRENT(current_thread)
136 
137                 /* Is the current thread the timer thread?  */
138                 if (current_thread == &_tx_timer_thread)
139                 {
140 
141                     /* A non-thread is trying to suspend, return appropriate error code.  */
142                     status =  TX_WAIT_ERROR;
143                 }
144             }
145 #endif
146         }
147     }
148 
149     /* Determine if everything is okay.  */
150     if (status == TX_SUCCESS)
151     {
152 
153         /* Call actual queue front send function.  */
154         status =  _tx_queue_front_send(queue_ptr, source_ptr, wait_option);
155     }
156 
157     /* Return completion status.  */
158     return(status);
159 }
160 
161