Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "app_threadx.h"
Private includes
#include "stdio.h"
Private typedef
Private define
Private macro
#define PUTCHAR_PROTOTYPE
#define PUTCHAR_PROTOTYPE
Private variables
ThreadOne
ThreadTwo
SyncObject
Private function prototypes
App_ThreadX_Init(void *)
MX_ThreadX_Init()
ThreadOne_Entry(ULONG)
ThreadTwo_Entry(ULONG)
Led_Toggle(Led_TypeDef, UINT)
App_Delay(ULONG)
fputc(int, FILE *)
Files
loading...
SourceVuSTM32 Libraries and SamplesTx_Thread_SyncSrc/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
262
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* 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 */ #include "stdio.h" /* 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 */ #if defined ( __GNUC__) && !defined(__clang__) /* With GCC, small printf (option LD Linker->Libraries->Small printf set to 'Yes') calls __io_putchar() *//* ... */ #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) /* ... */#else #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) #endif /* __GNUC__ */ /* USER CODE END PM */ Private macro /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ TX_THREAD ThreadOne; TX_THREAD ThreadTwo; APP_SYNC_TYPE SyncObject; extern UART_HandleTypeDef huart3; /* USER CODE END PV */ Private variables /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN PFP */ VOID ThreadOne_Entry(ULONG thread_input); VOID ThreadTwo_Entry(ULONG thread_input); static VOID Led_Toggle(Led_TypeDef led, UINT iter); static VOID App_Delay(ULONG Delay); /* 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 ThreadOne. */ 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 ThreadOne. */ if (tx_thread_create(&ThreadOne, "Thread One", ThreadOne_Entry, 0, pointer, APP_STACK_SIZE, THREAD_ONE_PRIO, THREAD_ONE_PREEMPTION_THRESHOLD, DEFAULT_TIME_SLICE, TX_AUTO_START) != TX_SUCCESS) { ret = TX_THREAD_ERROR; }if (tx_thread_create(&ThreadOne, "Thread One", ThreadOne_Entry, 0, pointer, APP_STACK_SIZE, THREAD_ONE_PRIO, THREAD_ONE_PREEMPTION_THRESHOLD, DEFAULT_TIME_SLICE, TX_AUTO_START) != TX_SUCCESS) { ... } /* Allocate the stack for ThreadTwo. */ 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 ThreadTwo. */ if (tx_thread_create(&ThreadTwo, "Thread Two", ThreadTwo_Entry, 0, pointer, APP_STACK_SIZE, THREAD_TWO_PRIO, THREAD_TWO_PREEMPTION_THRESHOLD, DEFAULT_TIME_SLICE, TX_AUTO_START) != TX_SUCCESS) { ret = TX_THREAD_ERROR; }if (tx_thread_create(&ThreadTwo, "Thread Two", ThreadTwo_Entry, 0, pointer, APP_STACK_SIZE, THREAD_TWO_PRIO, THREAD_TWO_PREEMPTION_THRESHOLD, DEFAULT_TIME_SLICE, TX_AUTO_START) != TX_SUCCESS) { ... } /* Create the Synchronization API used by ThreadOne and ThreadTwo.*/ if (APP_SYNC_CREATE(&SyncObject) != TX_SUCCESS) { ret = TX_SYNC_ERROR; }if (APP_SYNC_CREATE(&SyncObject) != 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 ThreadOne thread. * @param thread_input: Not used * @retval None *//* ... */ void ThreadOne_Entry(ULONG thread_input) { UNUSED(thread_input); ULONG iteration = 0; /* Infinite loop */ while(1) { /* try to acquire the sync object without waiting */ if (APP_SYNC_GET(&SyncObject, TX_NO_WAIT) == TX_SUCCESS) { printf("** ThreadOne : SyncObject acquired ** \n"); /*sync object acquired, toggle the LED_GREEN each 500ms for 5s */ Led_Toggle(LED_GREEN, 10); /*release the sync object */ APP_SYNC_PUT(&SyncObject); printf("** ThreadOne : SyncObject released ** \n"); tx_thread_sleep(1); }if (APP_SYNC_GET(&SyncObject, TX_NO_WAIT) == TX_SUCCESS) { ... } else { if ((iteration % 2000000) == 0) { printf("** ThreadOne : waiting for SyncObject !! **\n"); }if ((iteration % 2000000) == 0) { ... } }else { ... } iteration++; }while (1) { ... } }{ ... } /** * @brief Function implementing the ThreadTwo thread. * @param thread_input: Not used * @retval None *//* ... */ void ThreadTwo_Entry(ULONG thread_input) { UNUSED(thread_input); ULONG iteration = 0; /* Infinite loop */ while(1) { /* try to acquire the sync object without waiting */ if (APP_SYNC_GET(&SyncObject, TX_NO_WAIT) == TX_SUCCESS) { printf("** ThreadTwo : SyncObject acquired ** \n"); /*Sync object acquired toggle the LED_RED each 500ms for 5s*/ Led_Toggle(LED_RED, 10); /*release the sync object*/ APP_SYNC_PUT(&SyncObject); printf("** ThreadTwo : SyncObject released ** \n"); tx_thread_sleep(1); }if (APP_SYNC_GET(&SyncObject, TX_NO_WAIT) == TX_SUCCESS) { ... } else { if ((iteration % 2000000) == 0) { printf("** ThreadTwo : waiting for SyncObject !! **\n"); }if ((iteration % 2000000) == 0) { ... } }else { ... } iteration++; }while (1) { ... } }{ ... } /** * @brief Critical section function that needs acquiring SyncObject. * @param led: LED to toggle * @param iter: Number of iterations * @retval None *//* ... */ static VOID Led_Toggle(Led_TypeDef led, UINT iter) { UINT i; BSP_LED_Off(led); for (i =0; i < iter; i++) { BSP_LED_Toggle(led); /* Toggle the Led each 500ms */ App_Delay(50); }for (i =0; i < iter; i++) { ... } BSP_LED_Off(led); }{ ... } /** * @brief Application Delay function. * @param Delay : number of ticks to wait * @retval None *//* ... */ void App_Delay(ULONG Delay) { ULONG initial_time = tx_time_get(); while ((tx_time_get() - initial_time) < Delay); }{ ... } /** * @brief Retargets the C library printf function to the USART. * @param None * @retval None *//* ... */ PUTCHAR_PROTOTYPE { /* Place your implementation of fputc here */ /* e.g. write a character to the USART1 and Loop until the end of transmission */ HAL_UART_Transmit(&huart3, (uint8_t *)&ch, 1, 0xFFFF); return ch; ...} Private function prototypes /* USER CODE END 1 */
Details