mpu_wrappers.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * FreeRTOS Kernel V10.4.6
  3. * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * SPDX-License-Identifier: MIT
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  8. * this software and associated documentation files (the "Software"), to deal in
  9. * the Software without restriction, including without limitation the rights to
  10. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  11. * the Software, and to permit persons to whom the Software is furnished to do so,
  12. * subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in all
  15. * copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  19. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  20. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  21. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * https://www.FreeRTOS.org
  25. * https://github.com/FreeRTOS
  26. *
  27. */
  28. #ifndef MPU_WRAPPERS_H
  29. #define MPU_WRAPPERS_H
  30. /* This file redefines API functions to be called through a wrapper macro, but
  31. * only for ports that are using the MPU. */
  32. #if ( portUSING_MPU_WRAPPERS == 1 )
  33. /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE will be defined when this file is
  34. * included from queue.c or task.c to prevent it from having an effect within
  35. * those files. */
  36. #ifndef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
  37. /*
  38. * Map standard (non MPU) API functions to equivalents that start
  39. * "MPU_". This will cause the application code to call the MPU_
  40. * version, which wraps the non-MPU version with privilege promoting
  41. * then demoting code, so the kernel code always runs will full
  42. * privileges.
  43. */
  44. /* Map standard tasks.h API functions to the MPU equivalents. */
  45. #define xTaskCreate MPU_xTaskCreate
  46. #define xTaskCreateStatic MPU_xTaskCreateStatic
  47. #define vTaskDelete MPU_vTaskDelete
  48. #define vTaskDelay MPU_vTaskDelay
  49. #define xTaskDelayUntil MPU_xTaskDelayUntil
  50. #define xTaskAbortDelay MPU_xTaskAbortDelay
  51. #define uxTaskPriorityGet MPU_uxTaskPriorityGet
  52. #define eTaskGetState MPU_eTaskGetState
  53. #define vTaskGetInfo MPU_vTaskGetInfo
  54. #define vTaskPrioritySet MPU_vTaskPrioritySet
  55. #define vTaskSuspend MPU_vTaskSuspend
  56. #define vTaskResume MPU_vTaskResume
  57. #define vTaskSuspendAll MPU_vTaskSuspendAll
  58. #define xTaskResumeAll MPU_xTaskResumeAll
  59. #define xTaskGetTickCount MPU_xTaskGetTickCount
  60. #define uxTaskGetNumberOfTasks MPU_uxTaskGetNumberOfTasks
  61. #define pcTaskGetName MPU_pcTaskGetName
  62. #define xTaskGetHandle MPU_xTaskGetHandle
  63. #define uxTaskGetStackHighWaterMark MPU_uxTaskGetStackHighWaterMark
  64. #define uxTaskGetStackHighWaterMark2 MPU_uxTaskGetStackHighWaterMark2
  65. #define vTaskSetApplicationTaskTag MPU_vTaskSetApplicationTaskTag
  66. #define xTaskGetApplicationTaskTag MPU_xTaskGetApplicationTaskTag
  67. #define vTaskSetThreadLocalStoragePointer MPU_vTaskSetThreadLocalStoragePointer
  68. #define pvTaskGetThreadLocalStoragePointer MPU_pvTaskGetThreadLocalStoragePointer
  69. #define xTaskCallApplicationTaskHook MPU_xTaskCallApplicationTaskHook
  70. #define xTaskGetIdleTaskHandle MPU_xTaskGetIdleTaskHandle
  71. #define uxTaskGetSystemState MPU_uxTaskGetSystemState
  72. #define vTaskList MPU_vTaskList
  73. #define vTaskGetRunTimeStats MPU_vTaskGetRunTimeStats
  74. #define ulTaskGetIdleRunTimeCounter MPU_ulTaskGetIdleRunTimeCounter
  75. #define ulTaskGetIdleRunTimePercent MPU_ulTaskGetIdleRunTimePercent
  76. #define xTaskGenericNotify MPU_xTaskGenericNotify
  77. #define xTaskGenericNotifyWait MPU_xTaskGenericNotifyWait
  78. #define ulTaskGenericNotifyTake MPU_ulTaskGenericNotifyTake
  79. #define xTaskGenericNotifyStateClear MPU_xTaskGenericNotifyStateClear
  80. #define ulTaskGenericNotifyValueClear MPU_ulTaskGenericNotifyValueClear
  81. #define xTaskCatchUpTicks MPU_xTaskCatchUpTicks
  82. #define xTaskGetCurrentTaskHandle MPU_xTaskGetCurrentTaskHandle
  83. #define vTaskSetTimeOutState MPU_vTaskSetTimeOutState
  84. #define xTaskCheckForTimeOut MPU_xTaskCheckForTimeOut
  85. #define xTaskGetSchedulerState MPU_xTaskGetSchedulerState
  86. /* Map standard queue.h API functions to the MPU equivalents. */
  87. #define xQueueGenericSend MPU_xQueueGenericSend
  88. #define xQueueReceive MPU_xQueueReceive
  89. #define xQueuePeek MPU_xQueuePeek
  90. #define xQueueSemaphoreTake MPU_xQueueSemaphoreTake
  91. #define uxQueueMessagesWaiting MPU_uxQueueMessagesWaiting
  92. #define uxQueueSpacesAvailable MPU_uxQueueSpacesAvailable
  93. #define vQueueDelete MPU_vQueueDelete
  94. #define xQueueCreateMutex MPU_xQueueCreateMutex
  95. #define xQueueCreateMutexStatic MPU_xQueueCreateMutexStatic
  96. #define xQueueCreateCountingSemaphore MPU_xQueueCreateCountingSemaphore
  97. #define xQueueCreateCountingSemaphoreStatic MPU_xQueueCreateCountingSemaphoreStatic
  98. #define xQueueGetMutexHolder MPU_xQueueGetMutexHolder
  99. #define xQueueTakeMutexRecursive MPU_xQueueTakeMutexRecursive
  100. #define xQueueGiveMutexRecursive MPU_xQueueGiveMutexRecursive
  101. #define xQueueGenericCreate MPU_xQueueGenericCreate
  102. #define xQueueGenericCreateStatic MPU_xQueueGenericCreateStatic
  103. #define xQueueCreateSet MPU_xQueueCreateSet
  104. #define xQueueAddToSet MPU_xQueueAddToSet
  105. #define xQueueRemoveFromSet MPU_xQueueRemoveFromSet
  106. #define xQueueSelectFromSet MPU_xQueueSelectFromSet
  107. #define xQueueGenericReset MPU_xQueueGenericReset
  108. #if ( configQUEUE_REGISTRY_SIZE > 0 )
  109. #define vQueueAddToRegistry MPU_vQueueAddToRegistry
  110. #define vQueueUnregisterQueue MPU_vQueueUnregisterQueue
  111. #define pcQueueGetName MPU_pcQueueGetName
  112. #endif
  113. /* Map standard timer.h API functions to the MPU equivalents. */
  114. #define xTimerCreate MPU_xTimerCreate
  115. #define xTimerCreateStatic MPU_xTimerCreateStatic
  116. #define pvTimerGetTimerID MPU_pvTimerGetTimerID
  117. #define vTimerSetTimerID MPU_vTimerSetTimerID
  118. #define xTimerIsTimerActive MPU_xTimerIsTimerActive
  119. #define xTimerGetTimerDaemonTaskHandle MPU_xTimerGetTimerDaemonTaskHandle
  120. #define xTimerPendFunctionCall MPU_xTimerPendFunctionCall
  121. #define pcTimerGetName MPU_pcTimerGetName
  122. #define vTimerSetReloadMode MPU_vTimerSetReloadMode
  123. #define uxTimerGetReloadMode MPU_uxTimerGetReloadMode
  124. #define xTimerGetPeriod MPU_xTimerGetPeriod
  125. #define xTimerGetExpiryTime MPU_xTimerGetExpiryTime
  126. #define xTimerGenericCommand MPU_xTimerGenericCommand
  127. /* Map standard event_group.h API functions to the MPU equivalents. */
  128. #define xEventGroupCreate MPU_xEventGroupCreate
  129. #define xEventGroupCreateStatic MPU_xEventGroupCreateStatic
  130. #define xEventGroupWaitBits MPU_xEventGroupWaitBits
  131. #define xEventGroupClearBits MPU_xEventGroupClearBits
  132. #define xEventGroupSetBits MPU_xEventGroupSetBits
  133. #define xEventGroupSync MPU_xEventGroupSync
  134. #define vEventGroupDelete MPU_vEventGroupDelete
  135. /* Map standard message/stream_buffer.h API functions to the MPU
  136. * equivalents. */
  137. #define xStreamBufferSend MPU_xStreamBufferSend
  138. #define xStreamBufferReceive MPU_xStreamBufferReceive
  139. #define xStreamBufferNextMessageLengthBytes MPU_xStreamBufferNextMessageLengthBytes
  140. #define vStreamBufferDelete MPU_vStreamBufferDelete
  141. #define xStreamBufferIsFull MPU_xStreamBufferIsFull
  142. #define xStreamBufferIsEmpty MPU_xStreamBufferIsEmpty
  143. #define xStreamBufferReset MPU_xStreamBufferReset
  144. #define xStreamBufferSpacesAvailable MPU_xStreamBufferSpacesAvailable
  145. #define xStreamBufferBytesAvailable MPU_xStreamBufferBytesAvailable
  146. #define xStreamBufferSetTriggerLevel MPU_xStreamBufferSetTriggerLevel
  147. #define xStreamBufferGenericCreate MPU_xStreamBufferGenericCreate
  148. #define xStreamBufferGenericCreateStatic MPU_xStreamBufferGenericCreateStatic
  149. /* Remove the privileged function macro, but keep the PRIVILEGED_DATA
  150. * macro so applications can place data in privileged access sections
  151. * (useful when using statically allocated objects). */
  152. #define PRIVILEGED_FUNCTION
  153. #define PRIVILEGED_DATA __attribute__( ( section( "privileged_data" ) ) )
  154. #define FREERTOS_SYSTEM_CALL
  155. #else /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */
  156. /* Ensure API functions go in the privileged execution section. */
  157. #define PRIVILEGED_FUNCTION __attribute__( ( section( "privileged_functions" ) ) )
  158. #define PRIVILEGED_DATA __attribute__( ( section( "privileged_data" ) ) )
  159. #define FREERTOS_SYSTEM_CALL __attribute__( ( section( "freertos_system_calls" ) ) )
  160. /**
  161. * @brief Calls the port specific code to raise the privilege.
  162. *
  163. * Sets xRunningPrivileged to pdFALSE if privilege was raised, else sets
  164. * it to pdTRUE.
  165. */
  166. #define xPortRaisePrivilege( xRunningPrivileged ) \
  167. { \
  168. /* Check whether the processor is already privileged. */ \
  169. xRunningPrivileged = portIS_PRIVILEGED(); \
  170. \
  171. /* If the processor is not already privileged, raise privilege. */ \
  172. if( xRunningPrivileged == pdFALSE ) \
  173. { \
  174. portRAISE_PRIVILEGE(); \
  175. } \
  176. }
  177. /**
  178. * @brief If xRunningPrivileged is not pdTRUE, calls the port specific
  179. * code to reset the privilege, otherwise does nothing.
  180. */
  181. #define vPortResetPrivilege( xRunningPrivileged ) \
  182. { \
  183. if( xRunningPrivileged == pdFALSE ) \
  184. { \
  185. portRESET_PRIVILEGE(); \
  186. } \
  187. }
  188. #endif /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */
  189. #else /* portUSING_MPU_WRAPPERS */
  190. #define PRIVILEGED_FUNCTION
  191. #define PRIVILEGED_DATA
  192. #define FREERTOS_SYSTEM_CALL
  193. #endif /* portUSING_MPU_WRAPPERS */
  194. #endif /* MPU_WRAPPERS_H */