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
50
51
52
53
54
55
56
57
61
62
63
70
71
72
73
74
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
144
145
146
147
148
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
183
184
185
186
187
193
194
195
196
197
198
199
204
205
206
207
208
213
214
221
/* ... */
#include "app_tx_cmsisrtos.h"
Includes
#include "stdio.h"
Private includes
Private typedef
Private define
#if defined ( __GNUC__) && !defined(__clang__)
/* ... */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
/* ... */#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif
Private macro
extern UART_HandleTypeDef huart3;
__IO uint32_t OsStatus = 0;
osThreadId_t ThreadOne;
osThreadId_t ThreadTwo;
APP_SYNC_TYPE SyncObject;
static osThreadAttr_t attr = {
.priority = osPriorityNormal,
.stack_size = APP_THREAD_STACK_SIZE,
...};
Private variables
static void ThreadOne_Entry(void *argument);
static void ThreadTwo_Entry(void *argument);
static void Led_Toggle(Led_TypeDef led, uint32_t iter);
Private function prototypes
/* ... */
uint32_t App_TX_CmsisRTOS_Init(void)
{
osStatus_t ret = osOK;
ret = osKernelInitialize();
if (ret == osOK)
{
attr.name = "ThreadOne";
ThreadOne = osThreadNew(ThreadOne_Entry, NULL, (const osThreadAttr_t *)&attr);
attr.name = "ThreadTwo";
ThreadOne = osThreadNew(ThreadTwo_Entry, NULL, (const osThreadAttr_t *)&attr);
SyncObject = APP_SYNC_CREATE();
ret = osKernelStart();
}if (ret == osOK) { ... }
return ((uint32_t)ret);
}{ ... }
Global user code
/* ... */
static void ThreadOne_Entry(void *argument)
{
(void) argument;
uint32_t iteration = 0;
while(1)
{
if (APP_SYNC_GET(SyncObject, DEFAULT_WAIT_TIME) == osOK)
{
printf("** ThreadOne : SyncObject acquired ** \n");
Led_Toggle(LED_GREEN, 10);
APP_SYNC_PUT(SyncObject);
printf("** ThreadOne : SyncObject released ** \n");
osDelay(1);
}if (APP_SYNC_GET(SyncObject, DEFAULT_WAIT_TIME) == osOK) { ... }
else
{
if ((iteration % 20) == 0)
{
printf("** ThreadOne : waiting for SyncObject !! **\n");
}if ((iteration % 20) == 0) { ... }
}else { ... }
iteration++;
}while (1) { ... }
}{ ... }
/* ... */
static void ThreadTwo_Entry(void *argument)
{
(void) argument;
uint32_t iteration = 0;
while(1)
{
if (APP_SYNC_GET(SyncObject, DEFAULT_WAIT_TIME) == osOK)
{
printf("** ThreadTwo : SyncObject acquired ** \n");
Led_Toggle(LED_RED, 10);
APP_SYNC_PUT(SyncObject);
printf("** ThreadTwo : SyncObject released ** \n");
osDelay(1);
}if (APP_SYNC_GET(SyncObject, DEFAULT_WAIT_TIME) == osOK) { ... }
else
{
if ((iteration % 20) == 0)
{
printf("** ThreadTwo : waiting for SyncObject !! **\n");
}if ((iteration % 20) == 0) { ... }
}else { ... }
iteration++;
}while (1) { ... }
}{ ... }
/* ... */
static void Led_Toggle(Led_TypeDef led, uint32_t iter)
{
uint32_t i;
BSP_LED_Off(led);
for (i =0; i < iter; i++)
{
BSP_LED_Toggle(led);
osDelay(50);
}for (i =0; i < iter; i++) { ... }
BSP_LED_Off(led);
}{ ... }
/* ... */
PUTCHAR_PROTOTYPE
{
HAL_UART_Transmit(&huart3, (uint8_t *)&ch, 1, 0xFFFF);
return ch;
...}
Private user code