freertos_os2.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /* --------------------------------------------------------------------------
  2. * Copyright (c) 2013-2020 Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * Name: freertos_os2.h
  19. * Purpose: CMSIS RTOS2 wrapper for FreeRTOS
  20. *
  21. *---------------------------------------------------------------------------*/
  22. #ifndef FREERTOS_OS2_H_
  23. #define FREERTOS_OS2_H_
  24. #include <string.h>
  25. #include <stdint.h>
  26. #include "FreeRTOS.h" // ARM.FreeRTOS::RTOS:Core
  27. #include CMSIS_device_header
  28. /*
  29. CMSIS-RTOS2 FreeRTOS image size optimization definitions.
  30. Note: Definitions configUSE_OS2 can be used to optimize FreeRTOS image size when
  31. certain functionality is not required when using CMSIS-RTOS2 API.
  32. In general optimization decisions are left to the tool chain but in cases
  33. when coding style prevents it to optimize the code following optional
  34. definitions can be used.
  35. */
  36. /*
  37. Option to exclude CMSIS-RTOS2 functions osThreadSuspend and osThreadResume from
  38. the application image.
  39. */
  40. #ifndef configUSE_OS2_THREAD_SUSPEND_RESUME
  41. #define configUSE_OS2_THREAD_SUSPEND_RESUME 1
  42. #endif
  43. /*
  44. Option to exclude CMSIS-RTOS2 function osThreadEnumerate from the application image.
  45. */
  46. #ifndef configUSE_OS2_THREAD_ENUMERATE
  47. #define configUSE_OS2_THREAD_ENUMERATE 1
  48. #endif
  49. /*
  50. Option to disable CMSIS-RTOS2 function osEventFlagsSet and osEventFlagsClear
  51. operation from ISR.
  52. */
  53. #ifndef configUSE_OS2_EVENTFLAGS_FROM_ISR
  54. #define configUSE_OS2_EVENTFLAGS_FROM_ISR 1
  55. #endif
  56. /*
  57. Option to exclude CMSIS-RTOS2 Thread Flags API functions from the application image.
  58. */
  59. #ifndef configUSE_OS2_THREAD_FLAGS
  60. #define configUSE_OS2_THREAD_FLAGS configUSE_TASK_NOTIFICATIONS
  61. #endif
  62. /*
  63. Option to exclude CMSIS-RTOS2 Timer API functions from the application image.
  64. */
  65. #ifndef configUSE_OS2_TIMER
  66. #define configUSE_OS2_TIMER configUSE_TIMERS
  67. #endif
  68. /*
  69. Option to exclude CMSIS-RTOS2 Mutex API functions from the application image.
  70. */
  71. #ifndef configUSE_OS2_MUTEX
  72. #define configUSE_OS2_MUTEX configUSE_MUTEXES
  73. #endif
  74. /*
  75. CMSIS-RTOS2 FreeRTOS configuration check (FreeRTOSConfig.h).
  76. Note: CMSIS-RTOS API requires functions included by using following definitions.
  77. In case if certain API function is not used compiler will optimize it away.
  78. */
  79. #if (INCLUDE_xSemaphoreGetMutexHolder == 0)
  80. /*
  81. CMSIS-RTOS2 function osMutexGetOwner uses FreeRTOS function xSemaphoreGetMutexHolder. In case if
  82. osMutexGetOwner is not used in the application image, compiler will optimize it away.
  83. Set #define INCLUDE_xSemaphoreGetMutexHolder 1 to fix this error.
  84. */
  85. #error "Definition INCLUDE_xSemaphoreGetMutexHolder must equal 1 to implement Mutex Management API."
  86. #endif
  87. #if (INCLUDE_vTaskDelay == 0)
  88. /*
  89. CMSIS-RTOS2 function osDelay uses FreeRTOS function vTaskDelay. In case if
  90. osDelay is not used in the application image, compiler will optimize it away.
  91. Set #define INCLUDE_vTaskDelay 1 to fix this error.
  92. */
  93. #error "Definition INCLUDE_vTaskDelay must equal 1 to implement Generic Wait Functions API."
  94. #endif
  95. #if (INCLUDE_vTaskDelayUntil == 0)
  96. /*
  97. CMSIS-RTOS2 function osDelayUntil uses FreeRTOS function vTaskDelayUntil. In case if
  98. osDelayUntil is not used in the application image, compiler will optimize it away.
  99. Set #define INCLUDE_vTaskDelayUntil 1 to fix this error.
  100. */
  101. #error "Definition INCLUDE_vTaskDelayUntil must equal 1 to implement Generic Wait Functions API."
  102. #endif
  103. #if (INCLUDE_vTaskDelete == 0)
  104. /*
  105. CMSIS-RTOS2 function osThreadTerminate and osThreadExit uses FreeRTOS function
  106. vTaskDelete. In case if they are not used in the application image, compiler
  107. will optimize them away.
  108. Set #define INCLUDE_vTaskDelete 1 to fix this error.
  109. */
  110. #error "Definition INCLUDE_vTaskDelete must equal 1 to implement Thread Management API."
  111. #endif
  112. #if (INCLUDE_xTaskGetCurrentTaskHandle == 0)
  113. /*
  114. CMSIS-RTOS2 API uses FreeRTOS function xTaskGetCurrentTaskHandle to implement
  115. functions osThreadGetId, osThreadFlagsClear and osThreadFlagsGet. In case if these
  116. functions are not used in the application image, compiler will optimize them away.
  117. Set #define INCLUDE_xTaskGetCurrentTaskHandle 1 to fix this error.
  118. */
  119. #error "Definition INCLUDE_xTaskGetCurrentTaskHandle must equal 1 to implement Thread Management API."
  120. #endif
  121. #if (INCLUDE_xTaskGetSchedulerState == 0)
  122. /*
  123. CMSIS-RTOS2 API uses FreeRTOS function xTaskGetSchedulerState to implement Kernel
  124. tick handling and therefore it is vital that xTaskGetSchedulerState is included into
  125. the application image.
  126. Set #define INCLUDE_xTaskGetSchedulerState 1 to fix this error.
  127. */
  128. #error "Definition INCLUDE_xTaskGetSchedulerState must equal 1 to implement Kernel Information and Control API."
  129. #endif
  130. #if (INCLUDE_uxTaskGetStackHighWaterMark == 0)
  131. /*
  132. CMSIS-RTOS2 function osThreadGetStackSpace uses FreeRTOS function uxTaskGetStackHighWaterMark.
  133. In case if osThreadGetStackSpace is not used in the application image, compiler will
  134. optimize it away.
  135. Set #define INCLUDE_uxTaskGetStackHighWaterMark 1 to fix this error.
  136. */
  137. #error "Definition INCLUDE_uxTaskGetStackHighWaterMark must equal 1 to implement Thread Management API."
  138. #endif
  139. #if (INCLUDE_uxTaskPriorityGet == 0)
  140. /*
  141. CMSIS-RTOS2 function osThreadGetPriority uses FreeRTOS function uxTaskPriorityGet. In case if
  142. osThreadGetPriority is not used in the application image, compiler will optimize it away.
  143. Set #define INCLUDE_uxTaskPriorityGet 1 to fix this error.
  144. */
  145. #error "Definition INCLUDE_uxTaskPriorityGet must equal 1 to implement Thread Management API."
  146. #endif
  147. #if (INCLUDE_vTaskPrioritySet == 0)
  148. /*
  149. CMSIS-RTOS2 function osThreadSetPriority uses FreeRTOS function vTaskPrioritySet. In case if
  150. osThreadSetPriority is not used in the application image, compiler will optimize it away.
  151. Set #define INCLUDE_vTaskPrioritySet 1 to fix this error.
  152. */
  153. #error "Definition INCLUDE_vTaskPrioritySet must equal 1 to implement Thread Management API."
  154. #endif
  155. #if (INCLUDE_eTaskGetState == 0)
  156. /*
  157. CMSIS-RTOS2 API uses FreeRTOS function vTaskDelayUntil to implement functions osThreadGetState
  158. and osThreadTerminate. In case if these functions are not used in the application image,
  159. compiler will optimize them away.
  160. Set #define INCLUDE_eTaskGetState 1 to fix this error.
  161. */
  162. #error "Definition INCLUDE_eTaskGetState must equal 1 to implement Thread Management API."
  163. #endif
  164. #if (INCLUDE_vTaskSuspend == 0)
  165. /*
  166. CMSIS-RTOS2 API uses FreeRTOS functions vTaskSuspend and vTaskResume to implement
  167. functions osThreadSuspend and osThreadResume. In case if these functions are not
  168. used in the application image, compiler will optimize them away.
  169. Set #define INCLUDE_vTaskSuspend 1 to fix this error.
  170. Alternatively, if the application does not use osThreadSuspend and
  171. osThreadResume they can be excluded from the image code by setting:
  172. #define configUSE_OS2_THREAD_SUSPEND_RESUME 0 (in FreeRTOSConfig.h)
  173. */
  174. #if (configUSE_OS2_THREAD_SUSPEND_RESUME == 1)
  175. #error "Definition INCLUDE_vTaskSuspend must equal 1 to implement Kernel Information and Control API."
  176. #endif
  177. #endif
  178. #if (INCLUDE_xTimerPendFunctionCall == 0)
  179. /*
  180. CMSIS-RTOS2 function osEventFlagsSet and osEventFlagsClear, when called from
  181. the ISR, call FreeRTOS functions xEventGroupSetBitsFromISR and
  182. xEventGroupClearBitsFromISR which are only enabled if timers are operational and
  183. xTimerPendFunctionCall in enabled.
  184. Set #define INCLUDE_xTimerPendFunctionCall 1 and #define configUSE_TIMERS 1
  185. to fix this error.
  186. Alternatively, if the application does not use osEventFlagsSet and osEventFlagsClear
  187. from the ISR their operation from ISR can be restricted by setting:
  188. #define configUSE_OS2_EVENTFLAGS_FROM_ISR 0 (in FreeRTOSConfig.h)
  189. */
  190. #if (configUSE_OS2_EVENTFLAGS_FROM_ISR == 1)
  191. #error "Definition INCLUDE_xTimerPendFunctionCall must equal 1 to implement Event Flags API."
  192. #endif
  193. #endif
  194. #if (configUSE_TIMERS == 0)
  195. /*
  196. CMSIS-RTOS2 Timer Management API functions use FreeRTOS timer functions to implement
  197. timer management. In case if these functions are not used in the application image,
  198. compiler will optimize them away.
  199. Set #define configUSE_TIMERS 1 to fix this error.
  200. Alternatively, if the application does not use timer functions they can be
  201. excluded from the image code by setting:
  202. #define configUSE_OS2_TIMER 0 (in FreeRTOSConfig.h)
  203. */
  204. #if (configUSE_OS2_TIMER == 1)
  205. #error "Definition configUSE_TIMERS must equal 1 to implement Timer Management API."
  206. #endif
  207. #endif
  208. #if (configUSE_MUTEXES == 0)
  209. /*
  210. CMSIS-RTOS2 Mutex Management API functions use FreeRTOS mutex functions to implement
  211. mutex management. In case if these functions are not used in the application image,
  212. compiler will optimize them away.
  213. Set #define configUSE_MUTEXES 1 to fix this error.
  214. Alternatively, if the application does not use mutex functions they can be
  215. excluded from the image code by setting:
  216. #define configUSE_OS2_MUTEX 0 (in FreeRTOSConfig.h)
  217. */
  218. #if (configUSE_OS2_MUTEX == 1)
  219. #error "Definition configUSE_MUTEXES must equal 1 to implement Mutex Management API."
  220. #endif
  221. #endif
  222. #if (configUSE_COUNTING_SEMAPHORES == 0)
  223. /*
  224. CMSIS-RTOS2 Memory Pool functions use FreeRTOS function xSemaphoreCreateCounting
  225. to implement memory pools. In case if these functions are not used in the application image,
  226. compiler will optimize them away.
  227. Set #define configUSE_COUNTING_SEMAPHORES 1 to fix this error.
  228. */
  229. #error "Definition configUSE_COUNTING_SEMAPHORES must equal 1 to implement Memory Pool API."
  230. #endif
  231. #if (configUSE_TASK_NOTIFICATIONS == 0)
  232. /*
  233. CMSIS-RTOS2 Thread Flags API functions use FreeRTOS Task Notification functions to implement
  234. thread flag management. In case if these functions are not used in the application image,
  235. compiler will optimize them away.
  236. Set #define configUSE_TASK_NOTIFICATIONS 1 to fix this error.
  237. Alternatively, if the application does not use thread flags functions they can be
  238. excluded from the image code by setting:
  239. #define configUSE_OS2_THREAD_FLAGS 0 (in FreeRTOSConfig.h)
  240. */
  241. #if (configUSE_OS2_THREAD_FLAGS == 1)
  242. #error "Definition configUSE_TASK_NOTIFICATIONS must equal 1 to implement Thread Flags API."
  243. #endif
  244. #endif
  245. #if (configUSE_TRACE_FACILITY == 0)
  246. /*
  247. CMSIS-RTOS2 function osThreadEnumerate requires FreeRTOS function uxTaskGetSystemState
  248. which is only enabled if configUSE_TRACE_FACILITY == 1.
  249. Set #define configUSE_TRACE_FACILITY 1 to fix this error.
  250. Alternatively, if the application does not use osThreadEnumerate it can be
  251. excluded from the image code by setting:
  252. #define configUSE_OS2_THREAD_ENUMERATE 0 (in FreeRTOSConfig.h)
  253. */
  254. #if (configUSE_OS2_THREAD_ENUMERATE == 1)
  255. #error "Definition configUSE_TRACE_FACILITY must equal 1 to implement osThreadEnumerate."
  256. #endif
  257. #endif
  258. #if (configUSE_16_BIT_TICKS == 1)
  259. /*
  260. CMSIS-RTOS2 wrapper for FreeRTOS relies on 32-bit tick timer which is also optimal on
  261. a 32-bit CPU architectures.
  262. Set #define configUSE_16_BIT_TICKS 0 to fix this error.
  263. */
  264. #error "Definition configUSE_16_BIT_TICKS must be zero to implement CMSIS-RTOS2 API."
  265. #endif
  266. #if (configMAX_PRIORITIES != 56)
  267. /*
  268. CMSIS-RTOS2 defines 56 different priorities (see osPriority_t) and portable CMSIS-RTOS2
  269. implementation should implement the same number of priorities.
  270. Set #define configMAX_PRIORITIES 56 to fix this error.
  271. */
  272. #error "Definition configMAX_PRIORITIES must equal 56 to implement Thread Management API."
  273. #endif
  274. #if (configUSE_PORT_OPTIMISED_TASK_SELECTION != 0)
  275. /*
  276. CMSIS-RTOS2 requires handling of 56 different priorities (see osPriority_t) while FreeRTOS port
  277. optimised selection for Cortex core only handles 32 different priorities.
  278. Set #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 to fix this error.
  279. */
  280. #error "Definition configUSE_PORT_OPTIMISED_TASK_SELECTION must be zero to implement Thread Management API."
  281. #endif
  282. #endif /* FREERTOS_OS2_H_ */