Skip to content

Commit 04cd0ea

Browse files
committed
Enhanced configuration handling and checking (#33)
1 parent 0fc2f4d commit 04cd0ea

2 files changed

Lines changed: 376 additions & 61 deletions

File tree

CMSIS/RTOS2/FreeRTOS/Include/freertos_os2.h

Lines changed: 265 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* --------------------------------------------------------------------------
2-
* Copyright (c) 2013-2019 Arm Limited. All rights reserved.
2+
* Copyright (c) 2013-2020 Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -28,12 +28,23 @@
2828

2929
#include "FreeRTOS.h" // ARM.FreeRTOS::RTOS:Core
3030

31+
#if defined(_RTE_)
3132
#include "RTE_Components.h" // Component selection
3233
#include CMSIS_device_header
3334

3435
/* Configuration and component setup check */
3536
#if defined(RTE_Compiler_EventRecorder)
36-
#define USE_TRACE_EVENT_RECORDER
37+
#if !defined(EVR_FREERTOS_DISABLE)
38+
#define USE_TRACE_EVENT_RECORDER
39+
/*
40+
FreeRTOS provides functions and hooks to support execution tracing. This
41+
functionality is only enabled if configUSE_TRACE_FACILITY == 1.
42+
Set #define configUSE_TRACE_FACILITY 1 in FreeRTOSConfig.h to enable trace events.
43+
*/
44+
#if (configUSE_TRACE_FACILITY == 0)
45+
#error "Definition configUSE_TRACE_FACILITY must equal 1 to enable FreeRTOS trace events."
46+
#endif
47+
#endif
3748
#endif
3849

3950
#if defined(RTE_RTOS_FreeRTOS_HEAP_1)
@@ -43,46 +54,283 @@
4354
#if defined(RTE_RTOS_FreeRTOS_HEAP_5)
4455
#define USE_FreeRTOS_HEAP_5
4556
#endif
57+
#endif /* _RTE_ */
4658

47-
/* Check FreeRTOSConfig.h include definitions.
48-
Note: CMSIS-RTOS API requires functions included by using following definitions.
49-
In case if certain API function is not used compiler will optimize it away.
59+
/*
60+
CMSIS-RTOS2 FreeRTOS image size optimization definitions.
61+
62+
Note: Definitions configUSE_OS2 can be used to optimize FreeRTOS image size when
63+
certain functionality is not required when using CMSIS-RTOS2 API.
64+
In general optimization decisions are left to the tool chain but in cases
65+
when coding style prevents it to optimize the code following optional
66+
definitions can be used.
67+
*/
68+
69+
/*
70+
Option to exclude CMSIS-RTOS2 functions osThreadSuspend and osThreadResume from
71+
the application image.
72+
*/
73+
#ifndef configUSE_OS2_THREAD_SUSPEND_RESUME
74+
#define configUSE_OS2_THREAD_SUSPEND_RESUME 1
75+
#endif
76+
77+
/*
78+
Option to exclude CMSIS-RTOS2 function osThreadEnumerate from the application image.
79+
*/
80+
#ifndef configUSE_OS2_THREAD_ENUMERATE
81+
#define configUSE_OS2_THREAD_ENUMERATE 1
82+
#endif
83+
84+
/*
85+
Option to disable CMSIS-RTOS2 function osEventFlagsSet and osEventFlagsClear
86+
operation from ISR.
87+
*/
88+
#ifndef configUSE_OS2_EVENTFLAGS_FROM_ISR
89+
#define configUSE_OS2_EVENTFLAGS_FROM_ISR 1
90+
#endif
91+
92+
/*
93+
Option to exclude CMSIS-RTOS2 Thread Flags API functions from the application image.
94+
*/
95+
#ifndef configUSE_OS2_THREAD_FLAGS
96+
#define configUSE_OS2_THREAD_FLAGS configUSE_TASK_NOTIFICATIONS
97+
#endif
98+
99+
/*
100+
Option to exclude CMSIS-RTOS2 Timer API functions from the application image.
101+
*/
102+
#ifndef configUSE_OS2_TIMER
103+
#define configUSE_OS2_TIMER configUSE_TIMERS
104+
#endif
105+
106+
/*
107+
Option to exclude CMSIS-RTOS2 Mutex API functions from the application image.
108+
*/
109+
#ifndef configUSE_OS2_MUTEX
110+
#define configUSE_OS2_MUTEX configUSE_MUTEXES
111+
#endif
112+
113+
114+
/*
115+
CMSIS-RTOS2 FreeRTOS configuration check (FreeRTOSConfig.h).
116+
117+
Note: CMSIS-RTOS API requires functions included by using following definitions.
118+
In case if certain API function is not used compiler will optimize it away.
50119
*/
51120
#if (INCLUDE_xSemaphoreGetMutexHolder == 0)
52-
#error "Definition INCLUDE_xSemaphoreGetMutexHolder must be non-zero to implement Mutex Management API."
121+
/*
122+
CMSIS-RTOS2 function osMutexGetOwner uses FreeRTOS function xSemaphoreGetMutexHolder. In case if
123+
osMutexGetOwner is not used in the application image, compiler will optimize it away.
124+
Set #define INCLUDE_xSemaphoreGetMutexHolder 1 to fix this error.
125+
*/
126+
#error "Definition INCLUDE_xSemaphoreGetMutexHolder must equal 1 to implement Mutex Management API."
53127
#endif
54128
#if (INCLUDE_vTaskDelay == 0)
55-
#error "Definition INCLUDE_vTaskDelay must be non-zero to implement Generic Wait Functions API."
129+
/*
130+
CMSIS-RTOS2 function osDelay uses FreeRTOS function vTaskDelay. In case if
131+
osDelay is not used in the application image, compiler will optimize it away.
132+
Set #define INCLUDE_vTaskDelay 1 to fix this error.
133+
*/
134+
#error "Definition INCLUDE_vTaskDelay must equal 1 to implement Generic Wait Functions API."
56135
#endif
57136
#if (INCLUDE_vTaskDelayUntil == 0)
58-
#error "Definition INCLUDE_vTaskDelayUntil must be non-zero to implement Generic Wait Functions API."
137+
/*
138+
CMSIS-RTOS2 function osDelayUntil uses FreeRTOS function vTaskDelayUntil. In case if
139+
osDelayUntil is not used in the application image, compiler will optimize it away.
140+
Set #define INCLUDE_vTaskDelayUntil 1 to fix this error.
141+
*/
142+
#error "Definition INCLUDE_vTaskDelayUntil must equal 1 to implement Generic Wait Functions API."
59143
#endif
60144
#if (INCLUDE_vTaskDelete == 0)
61-
#error "Definition INCLUDE_vTaskDelete must be non-zero to implement Thread Management API."
145+
/*
146+
CMSIS-RTOS2 function osThreadTerminate and osThreadExit uses FreeRTOS function
147+
vTaskDelete. In case if they are not used in the application image, compiler
148+
will optimize them away.
149+
Set #define INCLUDE_vTaskDelete 1 to fix this error.
150+
*/
151+
#error "Definition INCLUDE_vTaskDelete must equal 1 to implement Thread Management API."
62152
#endif
63153
#if (INCLUDE_xTaskGetCurrentTaskHandle == 0)
64-
#error "Definition INCLUDE_xTaskGetCurrentTaskHandle must be non-zero to implement Thread Management API."
154+
/*
155+
CMSIS-RTOS2 API uses FreeRTOS function xTaskGetCurrentTaskHandle to implement
156+
functions osThreadGetId, osThreadFlagsClear and osThreadFlagsGet. In case if these
157+
functions are not used in the application image, compiler will optimize them away.
158+
Set #define INCLUDE_xTaskGetCurrentTaskHandle 1 to fix this error.
159+
*/
160+
#error "Definition INCLUDE_xTaskGetCurrentTaskHandle must equal 1 to implement Thread Management API."
65161
#endif
66162
#if (INCLUDE_xTaskGetSchedulerState == 0)
67-
#error "Definition INCLUDE_xTaskGetSchedulerState must be non-zero to implement Kernel Information and Control API."
163+
/*
164+
CMSIS-RTOS2 API uses FreeRTOS function xTaskGetSchedulerState to implement Kernel
165+
tick handling and therefore it is vital that xTaskGetSchedulerState is included into
166+
the application image.
167+
Set #define INCLUDE_xTaskGetSchedulerState 1 to fix this error.
168+
*/
169+
#error "Definition INCLUDE_xTaskGetSchedulerState must equal 1 to implement Kernel Information and Control API."
68170
#endif
69171
#if (INCLUDE_uxTaskGetStackHighWaterMark == 0)
70-
#error "Definition INCLUDE_uxTaskGetStackHighWaterMark must be non-zero to implement Thread Management API."
172+
/*
173+
CMSIS-RTOS2 function osThreadGetStackSpace uses FreeRTOS function uxTaskGetStackHighWaterMark.
174+
In case if osThreadGetStackSpace is not used in the application image, compiler will
175+
optimize it away.
176+
Set #define INCLUDE_uxTaskGetStackHighWaterMark 1 to fix this error.
177+
*/
178+
#error "Definition INCLUDE_uxTaskGetStackHighWaterMark must equal 1 to implement Thread Management API."
71179
#endif
72180
#if (INCLUDE_uxTaskPriorityGet == 0)
73-
#error "Definition INCLUDE_uxTaskPriorityGet must be non-zero to implement Thread Management API."
181+
/*
182+
CMSIS-RTOS2 function osThreadGetPriority uses FreeRTOS function uxTaskPriorityGet. In case if
183+
osThreadGetPriority is not used in the application image, compiler will optimize it away.
184+
Set #define INCLUDE_uxTaskPriorityGet 1 to fix this error.
185+
*/
186+
#error "Definition INCLUDE_uxTaskPriorityGet must equal 1 to implement Thread Management API."
74187
#endif
75188
#if (INCLUDE_vTaskPrioritySet == 0)
76-
#error "Definition INCLUDE_vTaskPrioritySet must be non-zero to implement Thread Management API."
189+
/*
190+
CMSIS-RTOS2 function osThreadSetPriority uses FreeRTOS function vTaskPrioritySet. In case if
191+
osThreadSetPriority is not used in the application image, compiler will optimize it away.
192+
Set #define INCLUDE_vTaskPrioritySet 1 to fix this error.
193+
*/
194+
#error "Definition INCLUDE_vTaskPrioritySet must equal 1 to implement Thread Management API."
77195
#endif
78196
#if (INCLUDE_eTaskGetState == 0)
79-
#error "Definition INCLUDE_eTaskGetState must be non-zero to implement Thread Management API."
197+
/*
198+
CMSIS-RTOS2 API uses FreeRTOS function vTaskDelayUntil to implement functions osThreadGetState
199+
and osThreadTerminate. In case if these functions are not used in the application image,
200+
compiler will optimize them away.
201+
Set #define INCLUDE_eTaskGetState 1 to fix this error.
202+
*/
203+
#error "Definition INCLUDE_eTaskGetState must equal 1 to implement Thread Management API."
80204
#endif
81205
#if (INCLUDE_vTaskSuspend == 0)
82-
#error "Definition INCLUDE_vTaskSuspend must be non-zero to implement Kernel Information and Control API."
206+
/*
207+
CMSIS-RTOS2 API uses FreeRTOS functions vTaskSuspend and vTaskResume to implement
208+
functions osThreadSuspend and osThreadResume. In case if these functions are not
209+
used in the application image, compiler will optimize them away.
210+
Set #define INCLUDE_vTaskSuspend 1 to fix this error.
211+
212+
Alternatively, if the application does not use osThreadSuspend and
213+
osThreadResume they can be excluded from the image code by setting:
214+
#define configUSE_OS2_THREAD_SUSPEND_RESUME 0 (in FreeRTOSConfig.h)
215+
*/
216+
#if (configUSE_OS2_THREAD_SUSPEND_RESUME == 1)
217+
#error "Definition INCLUDE_vTaskSuspend must equal 1 to implement Kernel Information and Control API."
218+
#endif
83219
#endif
84220
#if (INCLUDE_xTimerPendFunctionCall == 0)
85-
#error "Definition INCLUDE_xTimerPendFunctionCall must be non-zero to implement Event Flags API."
221+
/*
222+
CMSIS-RTOS2 function osEventFlagsSet and osEventFlagsClear, when called from
223+
the ISR, call FreeRTOS functions xEventGroupSetBitsFromISR and
224+
xEventGroupClearBitsFromISR which are only enabled if timers are operational and
225+
xTimerPendFunctionCall in enabled.
226+
Set #define INCLUDE_xTimerPendFunctionCall 1 and #define configUSE_TIMERS 1
227+
to fix this error.
228+
229+
Alternatively, if the application does not use osEventFlagsSet and osEventFlagsClear
230+
from the ISR their operation from ISR can be restricted by setting:
231+
#define configUSE_OS2_EVENTFLAGS_FROM_ISR 0 (in FreeRTOSConfig.h)
232+
*/
233+
#if (configUSE_OS2_EVENTFLAGS_FROM_ISR == 1)
234+
#error "Definition INCLUDE_xTimerPendFunctionCall must equal 1 to implement Event Flags API."
235+
#endif
236+
#endif
237+
238+
#if (configUSE_TIMERS == 0)
239+
/*
240+
CMSIS-RTOS2 Timer Management API functions use FreeRTOS timer functions to implement
241+
timer management. In case if these functions are not used in the application image,
242+
compiler will optimize them away.
243+
Set #define configUSE_TIMERS 1 to fix this error.
244+
245+
Alternatively, if the application does not use timer functions they can be
246+
excluded from the image code by setting:
247+
#define configUSE_OS2_TIMER 0 (in FreeRTOSConfig.h)
248+
*/
249+
#if (configUSE_OS2_TIMER == 1)
250+
#error "Definition configUSE_TIMERS must equal 1 to implement Timer Management API."
251+
#endif
252+
#endif
253+
254+
#if (configUSE_MUTEXES == 0)
255+
/*
256+
CMSIS-RTOS2 Mutex Management API functions use FreeRTOS mutex functions to implement
257+
mutex management. In case if these functions are not used in the application image,
258+
compiler will optimize them away.
259+
Set #define configUSE_MUTEXES 1 to fix this error.
260+
261+
Alternatively, if the application does not use mutex functions they can be
262+
excluded from the image code by setting:
263+
#define configUSE_OS2_MUTEX 0 (in FreeRTOSConfig.h)
264+
*/
265+
#if (configUSE_OS2_MUTEX == 1)
266+
#error "Definition configUSE_MUTEXES must equal 1 to implement Mutex Management API."
267+
#endif
268+
#endif
269+
270+
#if (configUSE_COUNTING_SEMAPHORES == 0)
271+
/*
272+
CMSIS-RTOS2 Memory Pool functions use FreeRTOS function xSemaphoreCreateCounting
273+
to implement memory pools. In case if these functions are not used in the application image,
274+
compiler will optimize them away.
275+
Set #define configUSE_COUNTING_SEMAPHORES 1 to fix this error.
276+
*/
277+
#error "Definition configUSE_COUNTING_SEMAPHORES must equal 1 to implement Memory Pool API."
278+
#endif
279+
#if (configUSE_TASK_NOTIFICATIONS == 0)
280+
/*
281+
CMSIS-RTOS2 Thread Flags API functions use FreeRTOS Task Notification functions to implement
282+
thread flag management. In case if these functions are not used in the application image,
283+
compiler will optimize them away.
284+
Set #define configUSE_TASK_NOTIFICATIONS 1 to fix this error.
285+
286+
Alternatively, if the application does not use thread flags functions they can be
287+
excluded from the image code by setting:
288+
#define configUSE_OS2_THREAD_FLAGS 0 (in FreeRTOSConfig.h)
289+
*/
290+
#if (configUSE_OS2_THREAD_FLAGS == 1)
291+
#error "Definition configUSE_TASK_NOTIFICATIONS must equal 1 to implement Thread Flags API."
292+
#endif
293+
#endif
294+
295+
#if (configUSE_TRACE_FACILITY == 0)
296+
/*
297+
CMSIS-RTOS2 function osThreadEnumerate requires FreeRTOS function uxTaskGetSystemState
298+
which is only enabled if configUSE_TRACE_FACILITY == 1.
299+
Set #define configUSE_TRACE_FACILITY 1 to fix this error.
300+
301+
Alternatively, if the application does not use osThreadEnumerate it can be
302+
excluded from the image code by setting:
303+
#define configUSE_OS2_THREAD_ENUMERATE 0 (in FreeRTOSConfig.h)
304+
*/
305+
#if (configUSE_OS2_THREAD_ENUMERATE == 1)
306+
#error "Definition configUSE_TRACE_FACILITY must equal 1 to implement osThreadEnumerate."
307+
#endif
308+
#endif
309+
310+
#if (configUSE_16_BIT_TICKS == 1)
311+
/*
312+
CMSIS-RTOS2 wrapper for FreeRTOS relies on 32-bit tick timer which is also optimal on
313+
a 32-bit CPU architectures.
314+
Set #define configUSE_16_BIT_TICKS 0 to fix this error.
315+
*/
316+
#error "Definition configUSE_16_BIT_TICKS must be zero to implement CMSIS-RTOS2 API."
317+
#endif
318+
319+
#if (configMAX_PRIORITIES != 56)
320+
/*
321+
CMSIS-RTOS2 defines 56 different priorities (see osPriority_t) and portable CMSIS-RTOS2
322+
implementation should implement the same number of priorities.
323+
Set #define configMAX_PRIORITIES 56 to fix this error.
324+
*/
325+
#error "Definition configMAX_PRIORITIES must equal 56 to implement Thread Management API."
326+
#endif
327+
#if (configUSE_PORT_OPTIMISED_TASK_SELECTION != 0)
328+
/*
329+
CMSIS-RTOS2 requires handling of 56 different priorities (see osPriority_t) while FreeRTOS port
330+
optimised selection for Cortex core only handles 32 different priorities.
331+
Set #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 to fix this error.
332+
*/
333+
#error "Definition configUSE_PORT_OPTIMISED_TASK_SELECTION must be zero to implement Thread Management API."
86334
#endif
87335

88336
#endif /* FREERTOS_OS2_H_ */

0 commit comments

Comments
 (0)