Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "app_threadx.h"
Private includes
Private typedef
Private define
Private macro
Private variables
MsgSenderThreadOne
MsgReceiverThread
MsgSenderThreadTwo
MsgQueueOne
MsgQueueTwo
Private function prototypes
App_ThreadX_Init(void *)
MX_ThreadX_Init()
MsgSenderThreadOne_Entry(ULONG)
MsgSenderThreadTwo_Entry(ULONG)
MsgReceiverThread_Entry(ULONG)
Files
loading (2/5)...
SourceVuSTM32 Libraries and SamplesTx_Thread_MsgQueueSrc/app_threadx.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file app_threadx.c * @author MCD Application Team * @brief ThreadX applicative file ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "app_threadx.h" Includes /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ Private includes /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ Private typedef /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ Private define /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ Private macro /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ TX_THREAD MsgSenderThreadOne; TX_THREAD MsgReceiverThread; TX_THREAD MsgSenderThreadTwo; TX_QUEUE MsgQueueOne; TX_QUEUE MsgQueueTwo; /* USER CODE END PV */ Private variables /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN PFP */ void MsgSenderThreadOne_Entry(ULONG thread_input); void MsgSenderThreadTwo_Entry(ULONG thread_input); void MsgReceiverThread_Entry(ULONG thread_input); /* USER CODE END PFP */ /** * @brief Application ThreadX Initialization. * @param memory_ptr: memory pointer * @retval int *//* ... */ UINT App_ThreadX_Init(VOID *memory_ptr) { UINT ret = TX_SUCCESS; TX_BYTE_POOL *byte_pool = (TX_BYTE_POOL*)memory_ptr; /* USER CODE BEGIN App_ThreadX_Init */ CHAR *pointer; /* Allocate the stack for MsgSenderThreadOne. */ if (tx_byte_allocate(byte_pool, (VOID **) &pointer, APP_STACK_SIZE, TX_NO_WAIT) != TX_SUCCESS) { ret = TX_POOL_ERROR; }if (tx_byte_allocate(byte_pool, (VOID **) &pointer, APP_STACK_SIZE, TX_NO_WAIT) != TX_SUCCESS) { ... } /* Create MsgSenderThreadOne. */ if (tx_thread_create(&MsgSenderThreadOne, "Message Queue Sender Thread One", MsgSenderThreadOne_Entry, 0, pointer, APP_STACK_SIZE, SENDER_THREAD_PRIO, SENDER_THREAD_PREEMPTION_THRESHOLD, TX_NO_TIME_SLICE, TX_AUTO_START) != TX_SUCCESS) { ret = TX_THREAD_ERROR; }if (tx_thread_create(&MsgSenderThreadOne, "Message Queue Sender Thread One", MsgSenderThreadOne_Entry, 0, pointer, APP_STACK_SIZE, SENDER_THREAD_PRIO, SENDER_THREAD_PREEMPTION_THRESHOLD, TX_NO_TIME_SLICE, TX_AUTO_START) != TX_SUCCESS) { ... } /* Allocate the stack for MsgSenderThreadTwo. */ if (tx_byte_allocate(byte_pool, (VOID **) &pointer, APP_STACK_SIZE, TX_NO_WAIT) != TX_SUCCESS) { ret = TX_POOL_ERROR; }if (tx_byte_allocate(byte_pool, (VOID **) &pointer, APP_STACK_SIZE, TX_NO_WAIT) != TX_SUCCESS) { ... } /* Create MsgSenderThreadTwo. */ if (tx_thread_create(&MsgSenderThreadTwo, "Message Queue Sender Thread Two", MsgSenderThreadTwo_Entry, 0, pointer, APP_STACK_SIZE, SENDER_THREAD_PRIO, SENDER_THREAD_PREEMPTION_THRESHOLD, TX_NO_TIME_SLICE, TX_AUTO_START) != TX_SUCCESS) { ret = TX_THREAD_ERROR; }if (tx_thread_create(&MsgSenderThreadTwo, "Message Queue Sender Thread Two", MsgSenderThreadTwo_Entry, 0, pointer, APP_STACK_SIZE, SENDER_THREAD_PRIO, SENDER_THREAD_PREEMPTION_THRESHOLD, TX_NO_TIME_SLICE, TX_AUTO_START) != TX_SUCCESS) { ... } /* Allocate the stack for MsgReceiverThread. */ if (tx_byte_allocate(byte_pool, (VOID **) &pointer, APP_STACK_SIZE, TX_NO_WAIT) != TX_SUCCESS) { ret = TX_POOL_ERROR; }if (tx_byte_allocate(byte_pool, (VOID **) &pointer, APP_STACK_SIZE, TX_NO_WAIT) != TX_SUCCESS) { ... } /* Create MsgReceiverThread. */ if (tx_thread_create(&MsgReceiverThread, "Message Queue Receiver Thread", MsgReceiverThread_Entry, 0, pointer, APP_STACK_SIZE, RECEIVER_THREAD_PRIO, RECEIVER_THREAD_PREEMPTION_THRESHOLD, TX_NO_TIME_SLICE, TX_AUTO_START) != TX_SUCCESS) { ret = TX_THREAD_ERROR; }if (tx_thread_create(&MsgReceiverThread, "Message Queue Receiver Thread", MsgReceiverThread_Entry, 0, pointer, APP_STACK_SIZE, RECEIVER_THREAD_PRIO, RECEIVER_THREAD_PREEMPTION_THRESHOLD, TX_NO_TIME_SLICE, TX_AUTO_START) != TX_SUCCESS) { ... } /* Allocate the MsgQueueOne. */ if (tx_byte_allocate(byte_pool, (VOID **) &pointer, APP_QUEUE_SIZE*sizeof(ULONG), TX_NO_WAIT) != TX_SUCCESS) { ret = TX_POOL_ERROR; }if (tx_byte_allocate(byte_pool, (VOID **) &pointer, APP_QUEUE_SIZE*sizeof(ULONG), TX_NO_WAIT) != TX_SUCCESS) { ... } /* Create the MsgQueueOne shared by MsgSenderThreadOne and MsgReceiverThread */ if (tx_queue_create(&MsgQueueOne, "Message Queue One",TX_1_ULONG, pointer, APP_QUEUE_SIZE*sizeof(ULONG)) != TX_SUCCESS) { ret = TX_QUEUE_ERROR; }if (tx_queue_create(&MsgQueueOne, "Message Queue One",TX_1_ULONG, pointer, APP_QUEUE_SIZE*sizeof(ULONG)) != TX_SUCCESS) { ... } /* Allocate the MsgQueueTwo. */ if (tx_byte_allocate(byte_pool, (VOID **) &pointer, APP_QUEUE_SIZE*sizeof(ULONG), TX_NO_WAIT) != TX_SUCCESS) { ret = TX_POOL_ERROR; }if (tx_byte_allocate(byte_pool, (VOID **) &pointer, APP_QUEUE_SIZE*sizeof(ULONG), TX_NO_WAIT) != TX_SUCCESS) { ... } /* Create the MsgQueueTwo shared by MsgSenderThreadTwo and MsgReceiverThread. */ if (tx_queue_create(&MsgQueueTwo, "Message Queue Two", TX_1_ULONG, pointer, APP_QUEUE_SIZE*sizeof(ULONG)) != TX_SUCCESS) { ret = TX_QUEUE_ERROR; }if (tx_queue_create(&MsgQueueTwo, "Message Queue Two", TX_1_ULONG, pointer, APP_QUEUE_SIZE*sizeof(ULONG)) != TX_SUCCESS) { ... } /* USER CODE END App_ThreadX_Init */ return ret; }{ ... } /** * @brief MX_ThreadX_Init * @param None * @retval None *//* ... */ void MX_ThreadX_Init(void) { /* USER CODE BEGIN Before_Kernel_Start */ /* USER CODE END Before_Kernel_Start */ tx_kernel_enter(); /* USER CODE BEGIN Kernel_Start_Error */ /* USER CODE END Kernel_Start_Error */ }{ ... } /* USER CODE BEGIN 1 */ /** * @brief Function implementing the MsgSenderThreadOne thread. * @param thread_input: Not used * @retval None *//* ... */ void MsgSenderThreadOne_Entry(ULONG thread_input) { ULONG Msg = TOGGLE_LED; (void) thread_input; /* Infinite loop */ while(1) { /* Send message to MsgQueueOne. */ if (tx_queue_send(&MsgQueueOne, &Msg, TX_WAIT_FOREVER) != TX_SUCCESS) { Error_Handler(); }if (tx_queue_send(&MsgQueueOne, &Msg, TX_WAIT_FOREVER) != TX_SUCCESS) { ... } /* Sleep for 200ms */ tx_thread_sleep(20); }while (1) { ... } }{ ... } /** * @brief Function implementing the MsgSenderThreadTwo thread. * @param thread_input: Not used * @retval None *//* ... */ void MsgSenderThreadTwo_Entry(ULONG thread_input) { ULONG Msg = TOGGLE_LED; (void) thread_input; /* Infinite loop */ while(1) { /* Send message to MsgQueueTwo. */ if (tx_queue_send(&MsgQueueTwo, &Msg, TX_WAIT_FOREVER) != TX_SUCCESS) { Error_Handler(); }if (tx_queue_send(&MsgQueueTwo, &Msg, TX_WAIT_FOREVER) != TX_SUCCESS) { ... } /* Sleep for 500s */ tx_thread_sleep(50); }while (1) { ... } }{ ... } /** * @brief Function implementing the MsgReceiverThread thread. * @param thread_input: Not used * @retval None *//* ... */ void MsgReceiverThread_Entry(ULONG thread_input) { ULONG RMsg = 0; UINT status = 0 ; (void) thread_input; /* Infinite loop */ while (1) { /* Determine whether a message MsgQueueOne or MsgQueueTwo is available */ status = tx_queue_receive(&MsgQueueOne, &RMsg, TX_NO_WAIT); if (status == TX_SUCCESS) { /* Check Message value */ if (RMsg != TOGGLE_LED) { Error_Handler(); }if (RMsg != TOGGLE_LED) { ... } else { BSP_LED_Toggle(LED_GREEN); }else { ... } }if (status == TX_SUCCESS) { ... } else { status = tx_queue_receive(&MsgQueueTwo, &RMsg, TX_NO_WAIT); if ( status == TX_SUCCESS) { /* Check Message value */ if (RMsg != TOGGLE_LED) { Error_Handler(); }if (RMsg != TOGGLE_LED) { ... } else { BSP_LED_Toggle(LED_RED); }else { ... } }if (status == TX_SUCCESS) { ... } }else { ... } }while (1) { ... } }{ ... } /* USER CODE END 1 */Private function prototypes
Details