1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
24
29
34
39
44
53
54
55
56
57
58
59
60
65
66
67
68
69
70
71
72
73
74
79
80
81
88
89
90
95
96
97
104
105
106
111
112
113
120
121
122
127
128
129
134
135
136
141
142
143
148
149
150
151
152
153
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
177
193
194
199
215
216
221
222
223
224
225
226
227
260
261
/* ... */
#include "app_threadx.h"
Includes
Private includes
Private typedef
Private define
Private macro
TX_THREAD MsgSenderThreadOne;
TX_THREAD MsgReceiverThread;
TX_THREAD MsgSenderThreadTwo;
TX_QUEUE MsgQueueOne;
TX_QUEUE MsgQueueTwo;
Private variables
void MsgSenderThreadOne_Entry(ULONG thread_input);
void MsgSenderThreadTwo_Entry(ULONG thread_input);
void MsgReceiverThread_Entry(ULONG thread_input);
/* ... */
UINT App_ThreadX_Init(VOID *memory_ptr)
{
UINT ret = TX_SUCCESS;
TX_BYTE_POOL *byte_pool = (TX_BYTE_POOL*)memory_ptr;
CHAR *pointer;
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) { ... }
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) { ... }
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) { ... }
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) { ... }
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) { ... }
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) { ... }
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) { ... }
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) { ... }
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) { ... }
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) { ... }
return ret;
}{ ... }
/* ... */
void MX_ThreadX_Init(void)
{
tx_kernel_enter();
}{ ... }
/* ... */
void MsgSenderThreadOne_Entry(ULONG thread_input)
{
ULONG Msg = TOGGLE_LED;
(void) thread_input;
while(1)
{
if (tx_queue_send(&MsgQueueOne, &Msg, TX_WAIT_FOREVER) != TX_SUCCESS)
{
Error_Handler();
}if (tx_queue_send(&MsgQueueOne, &Msg, TX_WAIT_FOREVER) != TX_SUCCESS) { ... }
tx_thread_sleep(20);
}while (1) { ... }
}{ ... }
/* ... */
void MsgSenderThreadTwo_Entry(ULONG thread_input)
{
ULONG Msg = TOGGLE_LED;
(void) thread_input;
while(1)
{
if (tx_queue_send(&MsgQueueTwo, &Msg, TX_WAIT_FOREVER) != TX_SUCCESS)
{
Error_Handler();
}if (tx_queue_send(&MsgQueueTwo, &Msg, TX_WAIT_FOREVER) != TX_SUCCESS) { ... }
tx_thread_sleep(50);
}while (1) { ... }
}{ ... }
/* ... */
void MsgReceiverThread_Entry(ULONG thread_input)
{
ULONG RMsg = 0;
UINT status = 0 ;
(void) thread_input;
while (1)
{
status = tx_queue_receive(&MsgQueueOne, &RMsg, TX_NO_WAIT);
if (status == TX_SUCCESS)
{
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)
{
if (RMsg != TOGGLE_LED)
{
Error_Handler();
}if (RMsg != TOGGLE_LED) { ... }
else
{
BSP_LED_Toggle(LED_RED);
}else { ... }
}if (status == TX_SUCCESS) { ... }
}else { ... }
}while (1) { ... }
}{ ... }
Private function prototypes