STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
mpu_wrappers.h
Go to the documentation of this file.
1/*
2 * FreeRTOS Kernel V10.6.2
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
29#ifndef MPU_WRAPPERS_H
30#define MPU_WRAPPERS_H
31
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 )
35
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
38 * those files. */
39 #ifndef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
40
41/*
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
46 * privileges.
47 */
48
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 pcTaskGetName MPU_pcTaskGetName
61 #define uxTaskGetStackHighWaterMark MPU_uxTaskGetStackHighWaterMark
62 #define uxTaskGetStackHighWaterMark2 MPU_uxTaskGetStackHighWaterMark2
63 #define vTaskSetApplicationTaskTag MPU_vTaskSetApplicationTaskTag
64 #define xTaskGetApplicationTaskTag MPU_xTaskGetApplicationTaskTag
65 #define vTaskSetThreadLocalStoragePointer MPU_vTaskSetThreadLocalStoragePointer
66 #define pvTaskGetThreadLocalStoragePointer MPU_pvTaskGetThreadLocalStoragePointer
67 #define xTaskGetIdleTaskHandle MPU_xTaskGetIdleTaskHandle
68 #define uxTaskGetSystemState MPU_uxTaskGetSystemState
69 #define ulTaskGetIdleRunTimeCounter MPU_ulTaskGetIdleRunTimeCounter
70 #define ulTaskGetIdleRunTimePercent MPU_ulTaskGetIdleRunTimePercent
71 #define xTaskGenericNotify MPU_xTaskGenericNotify
72 #define xTaskGenericNotifyWait MPU_xTaskGenericNotifyWait
73 #define ulTaskGenericNotifyTake MPU_ulTaskGenericNotifyTake
74 #define xTaskGenericNotifyStateClear MPU_xTaskGenericNotifyStateClear
75 #define ulTaskGenericNotifyValueClear MPU_ulTaskGenericNotifyValueClear
76 #define vTaskSetTimeOutState MPU_vTaskSetTimeOutState
77 #define xTaskCheckForTimeOut MPU_xTaskCheckForTimeOut
78 #define xTaskGetCurrentTaskHandle MPU_xTaskGetCurrentTaskHandle
79 #define xTaskGetSchedulerState MPU_xTaskGetSchedulerState
80
81 #if ( configUSE_MPU_WRAPPERS_V1 == 0 )
82 #define ulTaskGetRunTimeCounter MPU_ulTaskGetRunTimeCounter
83 #define ulTaskGetRunTimePercent MPU_ulTaskGetRunTimePercent
84 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
85
86/* Privileged only wrappers for Task APIs. These are needed so that
87 * the application can use opaque handles maintained in mpu_wrappers.c
88 * with all the APIs. */
89 #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 vTaskGetRunTimeStats MPU_vTaskGetRunTimeStats
94 #define vTaskList MPU_vTaskList
95 #define vTaskSuspendAll MPU_vTaskSuspendAll
96 #define xTaskCatchUpTicks MPU_xTaskCatchUpTicks
97 #define xTaskResumeAll MPU_xTaskResumeAll
98 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 1 ) */
99
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
106
107 #if ( configUSE_MPU_WRAPPERS_V1 == 0 )
108 #define xTaskCreateRestricted MPU_xTaskCreateRestricted
109 #define xTaskCreateRestrictedStatic MPU_xTaskCreateRestrictedStatic
110 #define vTaskAllocateMPURegions MPU_vTaskAllocateMPURegions
111 #define xTaskGetStaticBuffers MPU_xTaskGetStaticBuffers
112 #define uxTaskPriorityGetFromISR MPU_uxTaskPriorityGetFromISR
113 #define xTaskResumeFromISR MPU_xTaskResumeFromISR
114 #define xTaskGetApplicationTaskTagFromISR MPU_xTaskGetApplicationTaskTagFromISR
115 #define xTaskGenericNotifyFromISR MPU_xTaskGenericNotifyFromISR
116 #define vTaskGenericNotifyGiveFromISR MPU_vTaskGenericNotifyGiveFromISR
117 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
118
119/* Map standard queue.h API functions to the MPU equivalents. */
120 #define xQueueGenericSend MPU_xQueueGenericSend
121 #define xQueueReceive MPU_xQueueReceive
122 #define xQueuePeek MPU_xQueuePeek
123 #define xQueueSemaphoreTake MPU_xQueueSemaphoreTake
124 #define uxQueueMessagesWaiting MPU_uxQueueMessagesWaiting
125 #define uxQueueSpacesAvailable MPU_uxQueueSpacesAvailable
126 #define xQueueGetMutexHolder MPU_xQueueGetMutexHolder
127 #define xQueueTakeMutexRecursive MPU_xQueueTakeMutexRecursive
128 #define xQueueGiveMutexRecursive MPU_xQueueGiveMutexRecursive
129 #define xQueueAddToSet MPU_xQueueAddToSet
130 #define xQueueSelectFromSet MPU_xQueueSelectFromSet
131
132 #if ( configQUEUE_REGISTRY_SIZE > 0 )
133 #define vQueueAddToRegistry MPU_vQueueAddToRegistry
134 #define vQueueUnregisterQueue MPU_vQueueUnregisterQueue
135 #define pcQueueGetName MPU_pcQueueGetName
136 #endif /* #if ( configQUEUE_REGISTRY_SIZE > 0 ) */
137
138/* Privileged only wrappers for Queue APIs. These are needed so that
139 * the application can use opaque handles maintained in mpu_wrappers.c
140 * with all the APIs. */
141 #define vQueueDelete MPU_vQueueDelete
142 #define xQueueCreateMutex MPU_xQueueCreateMutex
143 #define xQueueCreateMutexStatic MPU_xQueueCreateMutexStatic
144 #define xQueueCreateCountingSemaphore MPU_xQueueCreateCountingSemaphore
145 #define xQueueCreateCountingSemaphoreStatic MPU_xQueueCreateCountingSemaphoreStatic
146 #define xQueueGenericCreate MPU_xQueueGenericCreate
147 #define xQueueGenericCreateStatic MPU_xQueueGenericCreateStatic
148 #define xQueueGenericReset MPU_xQueueGenericReset
149 #define xQueueCreateSet MPU_xQueueCreateSet
150 #define xQueueRemoveFromSet MPU_xQueueRemoveFromSet
151
152 #if ( configUSE_MPU_WRAPPERS_V1 == 0 )
153 #define xQueueGenericGetStaticBuffers MPU_xQueueGenericGetStaticBuffers
154 #define xQueueGenericSendFromISR MPU_xQueueGenericSendFromISR
155 #define xQueueGiveFromISR MPU_xQueueGiveFromISR
156 #define xQueuePeekFromISR MPU_xQueuePeekFromISR
157 #define xQueueReceiveFromISR MPU_xQueueReceiveFromISR
158 #define xQueueIsQueueEmptyFromISR MPU_xQueueIsQueueEmptyFromISR
159 #define xQueueIsQueueFullFromISR MPU_xQueueIsQueueFullFromISR
160 #define uxQueueMessagesWaitingFromISR MPU_uxQueueMessagesWaitingFromISR
161 #define xQueueGetMutexHolderFromISR MPU_xQueueGetMutexHolderFromISR
162 #define xQueueSelectFromSetFromISR MPU_xQueueSelectFromSetFromISR
163 #endif /* if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
164
165/* Map standard timer.h API functions to the MPU equivalents. */
166 #define pvTimerGetTimerID MPU_pvTimerGetTimerID
167 #define vTimerSetTimerID MPU_vTimerSetTimerID
168 #define xTimerIsTimerActive MPU_xTimerIsTimerActive
169 #define xTimerGetTimerDaemonTaskHandle MPU_xTimerGetTimerDaemonTaskHandle
170 #define xTimerGenericCommand MPU_xTimerGenericCommand
171 #define pcTimerGetName MPU_pcTimerGetName
172 #define vTimerSetReloadMode MPU_vTimerSetReloadMode
173 #define uxTimerGetReloadMode MPU_uxTimerGetReloadMode
174 #define xTimerGetPeriod MPU_xTimerGetPeriod
175 #define xTimerGetExpiryTime MPU_xTimerGetExpiryTime
176
177 #if ( configUSE_MPU_WRAPPERS_V1 == 0 )
178 #define xTimerGetReloadMode MPU_xTimerGetReloadMode
179 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
180
181/* Privileged only wrappers for Timer APIs. These are needed so that
182 * the application can use opaque handles maintained in mpu_wrappers.c
183 * with all the APIs. */
184 #if ( configUSE_MPU_WRAPPERS_V1 == 0 )
185 #define xTimerCreate MPU_xTimerCreate
186 #define xTimerCreateStatic MPU_xTimerCreateStatic
187 #define xTimerGetStaticBuffer MPU_xTimerGetStaticBuffer
188 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
189
190/* Map standard event_group.h API functions to the MPU equivalents. */
191 #define xEventGroupWaitBits MPU_xEventGroupWaitBits
192 #define xEventGroupClearBits MPU_xEventGroupClearBits
193 #define xEventGroupSetBits MPU_xEventGroupSetBits
194 #define xEventGroupSync MPU_xEventGroupSync
195
196 #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) )
197 #define uxEventGroupGetNumber MPU_uxEventGroupGetNumber
198 #define vEventGroupSetNumber MPU_vEventGroupSetNumber
199 #endif /* #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) ) */
200
201/* Privileged only wrappers for Event Group APIs. These are needed so that
202 * the application can use opaque handles maintained in mpu_wrappers.c
203 * with all the APIs. */
204 #define xEventGroupCreate MPU_xEventGroupCreate
205 #define xEventGroupCreateStatic MPU_xEventGroupCreateStatic
206 #define vEventGroupDelete MPU_vEventGroupDelete
207
208 #if ( configUSE_MPU_WRAPPERS_V1 == 0 )
209 #define xEventGroupGetStaticBuffer MPU_xEventGroupGetStaticBuffer
210 #define xEventGroupClearBitsFromISR MPU_xEventGroupClearBitsFromISR
211 #define xEventGroupSetBitsFromISR MPU_xEventGroupSetBitsFromISR
212 #define xEventGroupGetBitsFromISR MPU_xEventGroupGetBitsFromISR
213 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
214
215/* Map standard message/stream_buffer.h API functions to the MPU
216 * equivalents. */
217 #define xStreamBufferSend MPU_xStreamBufferSend
218 #define xStreamBufferReceive MPU_xStreamBufferReceive
219 #define xStreamBufferIsFull MPU_xStreamBufferIsFull
220 #define xStreamBufferIsEmpty MPU_xStreamBufferIsEmpty
221 #define xStreamBufferSpacesAvailable MPU_xStreamBufferSpacesAvailable
222 #define xStreamBufferBytesAvailable MPU_xStreamBufferBytesAvailable
223 #define xStreamBufferSetTriggerLevel MPU_xStreamBufferSetTriggerLevel
224 #define xStreamBufferNextMessageLengthBytes MPU_xStreamBufferNextMessageLengthBytes
225
226/* Privileged only wrappers for Stream Buffer APIs. These are needed so that
227 * the application can use opaque handles maintained in mpu_wrappers.c
228 * with all the APIs. */
229
230 #define xStreamBufferGenericCreate MPU_xStreamBufferGenericCreate
231 #define xStreamBufferGenericCreateStatic MPU_xStreamBufferGenericCreateStatic
232 #define vStreamBufferDelete MPU_vStreamBufferDelete
233 #define xStreamBufferReset MPU_xStreamBufferReset
234
235 #if ( configUSE_MPU_WRAPPERS_V1 == 0 )
236 #define xStreamBufferGetStaticBuffers MPU_xStreamBufferGetStaticBuffers
237 #define xStreamBufferSendFromISR MPU_xStreamBufferSendFromISR
238 #define xStreamBufferReceiveFromISR MPU_xStreamBufferReceiveFromISR
239 #define xStreamBufferSendCompletedFromISR MPU_xStreamBufferSendCompletedFromISR
240 #define xStreamBufferReceiveCompletedFromISR MPU_xStreamBufferReceiveCompletedFromISR
241 #endif /* #if ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
242
243/* Remove the privileged function macro, but keep the PRIVILEGED_DATA
244 * macro so applications can place data in privileged access sections
245 * (useful when using statically allocated objects). */
246 #define PRIVILEGED_FUNCTION
247 #define PRIVILEGED_DATA __attribute__( ( section( "privileged_data" ) ) )
248 #define FREERTOS_SYSTEM_CALL
249
250
251 #if ( ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configENABLE_ACCESS_CONTROL_LIST == 1 ) )
252
253 #define vGrantAccessToTask( xTask, xTaskToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xTaskToGrantAccess ) )
254 #define vRevokeAccessToTask( xTask, xTaskToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xTaskToRevokeAccess ) )
255
256 #define vGrantAccessToSemaphore( xTask, xSemaphoreToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xSemaphoreToGrantAccess ) )
257 #define vRevokeAccessToSemaphore( xTask, xSemaphoreToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xSemaphoreToRevokeAccess ) )
258
259 #define vGrantAccessToQueue( xTask, xQueueToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xQueueToGrantAccess ) )
260 #define vRevokeAccessToQueue( xTask, xQueueToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xQueueToRevokeAccess ) )
261
262 #define vGrantAccessToQueueSet( xTask, xQueueSetToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xQueueSetToGrantAccess ) )
263 #define vRevokeAccessToQueueSet( xTask, xQueueSetToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xQueueSetToRevokeAccess ) )
264
265 #define vGrantAccessToEventGroup( xTask, xEventGroupToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xEventGroupToGrantAccess ) )
266 #define vRevokeAccessToEventGroup( xTask, xEventGroupToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xEventGroupToRevokeAccess ) )
267
268 #define vGrantAccessToStreamBuffer( xTask, xStreamBufferToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xStreamBufferToGrantAccess ) )
269 #define vRevokeAccessToStreamBuffer( xTask, xStreamBufferToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xStreamBufferToRevokeAccess ) )
270
271 #define vGrantAccessToMessageBuffer( xTask, xMessageBufferToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xMessageBufferToGrantAccess ) )
272 #define vRevokeAccessToMessageBuffer( xTask, xMessageBufferToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xMessageBufferToRevokeAccess ) )
273
274 #define vGrantAccessToTimer( xTask, xTimerToGrantAccess ) vGrantAccessToKernelObject( ( xTask ), ( int32_t ) ( xTimerToGrantAccess ) )
275 #define vRevokeAccessToTimer( xTask, xTimerToRevokeAccess ) vRevokeAccessToKernelObject( ( xTask ), ( int32_t ) ( xTimerToRevokeAccess ) )
276
277 #endif /* #if ( ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configENABLE_ACCESS_CONTROL_LIST == 1 ) ) */
278
279 #else /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */
280
281/* Ensure API functions go in the privileged execution section. */
282 #define PRIVILEGED_FUNCTION __attribute__( ( section( "privileged_functions" ) ) )
283 #define PRIVILEGED_DATA __attribute__( ( section( "privileged_data" ) ) )
284 #define FREERTOS_SYSTEM_CALL __attribute__( ( section( "freertos_system_calls" ) ) )
285
286 #endif /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */
287
288#else /* portUSING_MPU_WRAPPERS */
289
290 #define PRIVILEGED_FUNCTION
291 #define PRIVILEGED_DATA
292 #define FREERTOS_SYSTEM_CALL
293
294#endif /* portUSING_MPU_WRAPPERS */
295
296
297#endif /* MPU_WRAPPERS_H */