2 * FreeRTOS Kernel <DEVELOPMENT BRANCH>
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: MIT
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:
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
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.
24 * https://www.FreeRTOS.org
25 * https://github.com/FreeRTOS
29 #ifndef MPU_WRAPPERS_H
30 #define MPU_WRAPPERS_H
32 /* This file redefines API functions to be called through a wrapper macro, but
33 * only for ports that are using the MPU. */
34 #if ( portUSING_MPU_WRAPPERS == 1 )
36 /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE will be defined when this file is
37 * included from queue.c or task.c to prevent it from having an effect within
39 #ifndef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
42 * Map standard (non MPU) API functions to equivalents that start
43 * "MPU_". This will cause the application code to call the MPU_
44 * version, which wraps the non-MPU version with privilege promoting
45 * then demoting code, so the kernel code always runs will full
49 /* Map standard task.h API functions to the MPU equivalents. */
50 #define vTaskDelay MPU_vTaskDelay
51 #define xTaskDelayUntil MPU_xTaskDelayUntil
52 #define xTaskAbortDelay MPU_xTaskAbortDelay
53 #define uxTaskPriorityGet MPU_uxTaskPriorityGet
54 #define eTaskGetState MPU_eTaskGetState
55 #define vTaskGetInfo MPU_vTaskGetInfo
56 #define vTaskSuspend MPU_vTaskSuspend
57 #define vTaskResume MPU_vTaskResume
58 #define xTaskGetTickCount MPU_xTaskGetTickCount
59 #define uxTaskGetNumberOfTasks MPU_uxTaskGetNumberOfTasks
60 #define uxTaskGetStackHighWaterMark MPU_uxTaskGetStackHighWaterMark
61 #define uxTaskGetStackHighWaterMark2 MPU_uxTaskGetStackHighWaterMark2
62 #define vTaskSetApplicationTaskTag MPU_vTaskSetApplicationTaskTag
63 #define xTaskGetApplicationTaskTag MPU_xTaskGetApplicationTaskTag
64 #define vTaskSetThreadLocalStoragePointer MPU_vTaskSetThreadLocalStoragePointer
65 #define pvTaskGetThreadLocalStoragePointer MPU_pvTaskGetThreadLocalStoragePointer
66 #define xTaskGetIdleTaskHandle MPU_xTaskGetIdleTaskHandle
67 #define uxTaskGetSystemState MPU_uxTaskGetSystemState
68 #define ulTaskGetIdleRunTimeCounter MPU_ulTaskGetIdleRunTimeCounter
69 #define ulTaskGetIdleRunTimePercent MPU_ulTaskGetIdleRunTimePercent
70 #define xTaskGenericNotify MPU_xTaskGenericNotify
71 #define xTaskGenericNotifyWait MPU_xTaskGenericNotifyWait
72 #define ulTaskGenericNotifyTake MPU_ulTaskGenericNotifyTake
73 #define xTaskGenericNotifyStateClear MPU_xTaskGenericNotifyStateClear
74 #define ulTaskGenericNotifyValueClear MPU_ulTaskGenericNotifyValueClear
75 #define vTaskSetTimeOutState MPU_vTaskSetTimeOutState
76 #define xTaskCheckForTimeOut MPU_xTaskCheckForTimeOut
77 #define xTaskGetCurrentTaskHandle MPU_xTaskGetCurrentTaskHandle
78 #define xTaskGetSchedulerState MPU_xTaskGetSchedulerState
80 #if ( configUSE_MPU_WRAPPERS_V1 == 0 )
81 #define ulTaskGetRunTimeCounter MPU_ulTaskGetRunTimeCounter
82 #define ulTaskGetRunTimePercent MPU_ulTaskGetRunTimePercent
83 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
85 /* Privileged only wrappers for Task APIs. These are needed so that
86 * the application can use opaque handles maintained in mpu_wrappers.c
87 * with all the APIs. */
88 #if ( configUSE_MPU_WRAPPERS_V1 == 1 )
90 /* These are not needed in v2 because they do not take a task
91 * handle and therefore, no lookup is needed. Needed in v1 because
92 * these are available as system calls in v1. */
93 #define vTaskGetRunTimeStatistics MPU_vTaskGetRunTimeStatistics
94 #define vTaskListTasks MPU_vTaskListTasks
95 #define vTaskSuspendAll MPU_vTaskSuspendAll
96 #define xTaskCatchUpTicks MPU_xTaskCatchUpTicks
97 #define xTaskResumeAll MPU_xTaskResumeAll
98 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 1 ) */
100 #define xTaskCreate MPU_xTaskCreate
101 #define xTaskCreateStatic MPU_xTaskCreateStatic
102 #define vTaskDelete MPU_vTaskDelete
103 #define vTaskPrioritySet MPU_vTaskPrioritySet
104 #define xTaskGetHandle MPU_xTaskGetHandle
105 #define xTaskCallApplicationTaskHook MPU_xTaskCallApplicationTaskHook
107 #if ( configUSE_MPU_WRAPPERS_V1 == 0 )
108 #define pcTaskGetName MPU_pcTaskGetName
109 #define xTaskCreateRestricted MPU_xTaskCreateRestricted
110 #define xTaskCreateRestrictedStatic MPU_xTaskCreateRestrictedStatic
111 #define vTaskAllocateMPURegions MPU_vTaskAllocateMPURegions
112 #define xTaskGetStaticBuffers MPU_xTaskGetStaticBuffers
113 #define uxTaskPriorityGetFromISR MPU_uxTaskPriorityGetFromISR
114 #define uxTaskBasePriorityGet MPU_uxTaskBasePriorityGet
115 #define uxTaskBasePriorityGetFromISR MPU_uxTaskBasePriorityGetFromISR
116 #define xTaskResumeFromISR MPU_xTaskResumeFromISR
117 #define xTaskGetApplicationTaskTagFromISR MPU_xTaskGetApplicationTaskTagFromISR
118 #define xTaskGenericNotifyFromISR MPU_xTaskGenericNotifyFromISR
119 #define vTaskGenericNotifyGiveFromISR MPU_vTaskGenericNotifyGiveFromISR
120 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
122 /* Map standard queue.h API functions to the MPU equivalents. */
123 #define xQueueGenericSend MPU_xQueueGenericSend
124 #define xQueueReceive MPU_xQueueReceive
125 #define xQueuePeek MPU_xQueuePeek
126 #define xQueueSemaphoreTake MPU_xQueueSemaphoreTake
127 #define uxQueueMessagesWaiting MPU_uxQueueMessagesWaiting
128 #define uxQueueSpacesAvailable MPU_uxQueueSpacesAvailable
129 #define xQueueGetMutexHolder MPU_xQueueGetMutexHolder
130 #define xQueueTakeMutexRecursive MPU_xQueueTakeMutexRecursive
131 #define xQueueGiveMutexRecursive MPU_xQueueGiveMutexRecursive
132 #define xQueueAddToSet MPU_xQueueAddToSet
133 #define xQueueSelectFromSet MPU_xQueueSelectFromSet
135 #if ( configQUEUE_REGISTRY_SIZE > 0 )
136 #define vQueueAddToRegistry MPU_vQueueAddToRegistry
137 #define vQueueUnregisterQueue MPU_vQueueUnregisterQueue
138 #define pcQueueGetName MPU_pcQueueGetName
139 #endif /* #if ( configQUEUE_REGISTRY_SIZE > 0 ) */
141 /* Privileged only wrappers for Queue APIs. These are needed so that
142 * the application can use opaque handles maintained in mpu_wrappers.c
143 * with all the APIs. */
144 #define vQueueDelete MPU_vQueueDelete
145 #define xQueueCreateMutex MPU_xQueueCreateMutex
146 #define xQueueCreateMutexStatic MPU_xQueueCreateMutexStatic
147 #define xQueueCreateCountingSemaphore MPU_xQueueCreateCountingSemaphore
148 #define xQueueCreateCountingSemaphoreStatic MPU_xQueueCreateCountingSemaphoreStatic
149 #define xQueueGenericCreate MPU_xQueueGenericCreate
150 #define xQueueGenericCreateStatic MPU_xQueueGenericCreateStatic
151 #define xQueueGenericReset MPU_xQueueGenericReset
152 #define xQueueCreateSet MPU_xQueueCreateSet
153 #define xQueueRemoveFromSet MPU_xQueueRemoveFromSet
155 #if ( configUSE_MPU_WRAPPERS_V1 == 0 )
156 #define xQueueGenericGetStaticBuffers MPU_xQueueGenericGetStaticBuffers
157 #define xQueueGenericSendFromISR MPU_xQueueGenericSendFromISR
158 #define xQueueGiveFromISR MPU_xQueueGiveFromISR
159 #define xQueuePeekFromISR MPU_xQueuePeekFromISR
160 #define xQueueReceiveFromISR MPU_xQueueReceiveFromISR
161 #define xQueueIsQueueEmptyFromISR MPU_xQueueIsQueueEmptyFromISR
162 #define xQueueIsQueueFullFromISR MPU_xQueueIsQueueFullFromISR
163 #define uxQueueMessagesWaitingFromISR MPU_uxQueueMessagesWaitingFromISR
164 #define xQueueGetMutexHolderFromISR MPU_xQueueGetMutexHolderFromISR
165 #define xQueueSelectFromSetFromISR MPU_xQueueSelectFromSetFromISR
166 #endif /* if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
168 /* Map standard timer.h API functions to the MPU equivalents. */
169 #define pvTimerGetTimerID MPU_pvTimerGetTimerID
170 #define vTimerSetTimerID MPU_vTimerSetTimerID
171 #define xTimerIsTimerActive MPU_xTimerIsTimerActive
172 #define xTimerGetTimerDaemonTaskHandle MPU_xTimerGetTimerDaemonTaskHandle
173 #define xTimerGenericCommandFromTask MPU_xTimerGenericCommandFromTask
174 #define pcTimerGetName MPU_pcTimerGetName
175 #define vTimerSetReloadMode MPU_vTimerSetReloadMode
176 #define uxTimerGetReloadMode MPU_uxTimerGetReloadMode
177 #define xTimerGetPeriod MPU_xTimerGetPeriod
178 #define xTimerGetExpiryTime MPU_xTimerGetExpiryTime
180 #if ( configUSE_MPU_WRAPPERS_V1 == 0 )
181 #define xTimerGetReloadMode MPU_xTimerGetReloadMode
182 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
184 /* Privileged only wrappers for Timer APIs. These are needed so that
185 * the application can use opaque handles maintained in mpu_wrappers.c
186 * with all the APIs. */
187 #if ( configUSE_MPU_WRAPPERS_V1 == 0 )
188 #define xTimerCreate MPU_xTimerCreate
189 #define xTimerCreateStatic MPU_xTimerCreateStatic
190 #define xTimerGetStaticBuffer MPU_xTimerGetStaticBuffer
191 #define xTimerGenericCommandFromISR MPU_xTimerGenericCommandFromISR
192 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
194 /* Map standard event_group.h API functions to the MPU equivalents. */
195 #define xEventGroupWaitBits MPU_xEventGroupWaitBits
196 #define xEventGroupClearBits MPU_xEventGroupClearBits
197 #define xEventGroupSetBits MPU_xEventGroupSetBits
198 #define xEventGroupSync MPU_xEventGroupSync
200 #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) )
201 #define uxEventGroupGetNumber MPU_uxEventGroupGetNumber
202 #define vEventGroupSetNumber MPU_vEventGroupSetNumber
203 #endif /* #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) ) */
205 /* Privileged only wrappers for Event Group APIs. These are needed so that
206 * the application can use opaque handles maintained in mpu_wrappers.c
207 * with all the APIs. */
208 #define xEventGroupCreate MPU_xEventGroupCreate
209 #define xEventGroupCreateStatic MPU_xEventGroupCreateStatic
210 #define vEventGroupDelete MPU_vEventGroupDelete
212 #if ( configUSE_MPU_WRAPPERS_V1 == 0 )
213 #define xEventGroupGetStaticBuffer MPU_xEventGroupGetStaticBuffer
214 #define xEventGroupClearBitsFromISR MPU_xEventGroupClearBitsFromISR
215 #define xEventGroupSetBitsFromISR MPU_xEventGroupSetBitsFromISR
216 #define xEventGroupGetBitsFromISR MPU_xEventGroupGetBitsFromISR
217 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
219 /* Map standard message/stream_buffer.h API functions to the MPU
221 #define xStreamBufferSend MPU_xStreamBufferSend
222 #define xStreamBufferReceive MPU_xStreamBufferReceive
223 #define xStreamBufferIsFull MPU_xStreamBufferIsFull
224 #define xStreamBufferIsEmpty MPU_xStreamBufferIsEmpty
225 #define xStreamBufferSpacesAvailable MPU_xStreamBufferSpacesAvailable
226 #define xStreamBufferBytesAvailable MPU_xStreamBufferBytesAvailable
227 #define xStreamBufferSetTriggerLevel MPU_xStreamBufferSetTriggerLevel
228 #define xStreamBufferNextMessageLengthBytes MPU_xStreamBufferNextMessageLengthBytes
230 /* Privileged only wrappers for Stream Buffer APIs. These are needed so that
231 * the application can use opaque handles maintained in mpu_wrappers.c
232 * with all the APIs. */
234 #define xStreamBufferGenericCreate MPU_xStreamBufferGenericCreate
235 #define xStreamBufferGenericCreateStatic MPU_xStreamBufferGenericCreateStatic
236 #define vStreamBufferDelete MPU_vStreamBufferDelete
237 #define xStreamBufferReset MPU_xStreamBufferReset
239 #if ( configUSE_MPU_WRAPPERS_V1 == 0 )
240 #define xStreamBufferGetStaticBuffers MPU_xStreamBufferGetStaticBuffers
241 #define xStreamBufferSendFromISR MPU_xStreamBufferSendFromISR
242 #define xStreamBufferReceiveFromISR MPU_xStreamBufferReceiveFromISR
243 #define xStreamBufferSendCompletedFromISR MPU_xStreamBufferSendCompletedFromISR
244 #define xStreamBufferReceiveCompletedFromISR MPU_xStreamBufferReceiveCompletedFromISR
245 #define xStreamBufferResetFromISR MPU_xStreamBufferResetFromISR
246 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
248 #if ( ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configENABLE_ACCESS_CONTROL_LIST == 1 ) )
250 #define vGrantAccessToTask( xTask, xTaskToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xTaskToGrantAccess ) )
251 #define vRevokeAccessToTask( xTask, xTaskToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xTaskToRevokeAccess ) )
253 #define vGrantAccessToSemaphore( xTask, xSemaphoreToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xSemaphoreToGrantAccess ) )
254 #define vRevokeAccessToSemaphore( xTask, xSemaphoreToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xSemaphoreToRevokeAccess ) )
256 #define vGrantAccessToQueue( xTask, xQueueToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xQueueToGrantAccess ) )
257 #define vRevokeAccessToQueue( xTask, xQueueToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xQueueToRevokeAccess ) )
259 #define vGrantAccessToQueueSet( xTask, xQueueSetToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xQueueSetToGrantAccess ) )
260 #define vRevokeAccessToQueueSet( xTask, xQueueSetToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xQueueSetToRevokeAccess ) )
262 #define vGrantAccessToEventGroup( xTask, xEventGroupToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xEventGroupToGrantAccess ) )
263 #define vRevokeAccessToEventGroup( xTask, xEventGroupToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xEventGroupToRevokeAccess ) )
265 #define vGrantAccessToStreamBuffer( xTask, xStreamBufferToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xStreamBufferToGrantAccess ) )
266 #define vRevokeAccessToStreamBuffer( xTask, xStreamBufferToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xStreamBufferToRevokeAccess ) )
268 #define vGrantAccessToMessageBuffer( xTask, xMessageBufferToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xMessageBufferToGrantAccess ) )
269 #define vRevokeAccessToMessageBuffer( xTask, xMessageBufferToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xMessageBufferToRevokeAccess ) )
271 #define vGrantAccessToTimer( xTask, xTimerToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xTimerToGrantAccess ) )
272 #define vRevokeAccessToTimer( xTask, xTimerToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xTimerToRevokeAccess ) )
274 #endif /* #if ( ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configENABLE_ACCESS_CONTROL_LIST == 1 ) ) */
276 #endif /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */
278 #define PRIVILEGED_FUNCTION __attribute__( ( section( "privileged_functions" ) ) )
279 #define PRIVILEGED_DATA __attribute__( ( section( "privileged_data" ) ) )
280 #define FREERTOS_SYSTEM_CALL __attribute__( ( section( "freertos_system_calls" ) ) )
282 #else /* portUSING_MPU_WRAPPERS */
284 #define PRIVILEGED_FUNCTION
285 #define PRIVILEGED_DATA
286 #define FREERTOS_SYSTEM_CALL
288 #endif /* portUSING_MPU_WRAPPERS */
291 #endif /* MPU_WRAPPERS_H */