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