1 /*
2  * FreeRTOS Kernel V11.1.0
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 /*
30  * Implementation of the wrapper functions used to raise the processor privilege
31  * before calling a standard FreeRTOS API function.
32  */
33 
34 /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
35  * all the API functions to use the MPU wrappers.  That should only be done when
36  * task.h is included from an application file. */
37 #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
38 
39 /* Scheduler includes. */
40 #include "FreeRTOS.h"
41 #include "task.h"
42 #include "queue.h"
43 #include "timers.h"
44 #include "event_groups.h"
45 #include "stream_buffer.h"
46 #include "mpu_prototypes.h"
47 #include "mpu_syscall_numbers.h"
48 
49 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
50 /*-----------------------------------------------------------*/
51 
52 #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) )
53 
54     #ifndef configPROTECTED_KERNEL_OBJECT_POOL_SIZE
55         #error configPROTECTED_KERNEL_OBJECT_POOL_SIZE must be defined to maximum number of kernel objects in the application.
56     #endif
57 
58 /**
59  * @brief Offset added to the index before returning to the user.
60  *
61  * If the actual handle is stored at index i, ( i + INDEX_OFFSET )
62  * is returned to the user.
63  */
64     #define INDEX_OFFSET    1
65 
66 /**
67  * @brief Opaque type for a kernel object.
68  */
69     struct OpaqueObject;
70     typedef struct OpaqueObject * OpaqueObjectHandle_t;
71 
72 /**
73  * @brief Defines kernel object in the kernel object pool.
74  */
75     typedef struct KernelObject
76     {
77         OpaqueObjectHandle_t xInternalObjectHandle;
78         uint32_t ulKernelObjectType;
79         void * pvKernelObjectData;
80     } KernelObject_t;
81 
82 /**
83  * @brief Kernel object types.
84  */
85     #define KERNEL_OBJECT_TYPE_INVALID          ( 0UL )
86     #define KERNEL_OBJECT_TYPE_QUEUE            ( 1UL )
87     #define KERNEL_OBJECT_TYPE_TASK             ( 2UL )
88     #define KERNEL_OBJECT_TYPE_STREAM_BUFFER    ( 3UL )
89     #define KERNEL_OBJECT_TYPE_EVENT_GROUP      ( 4UL )
90     #define KERNEL_OBJECT_TYPE_TIMER            ( 5UL )
91 
92 /**
93  * @brief Checks whether an external index is valid or not.
94  */
95     #define IS_EXTERNAL_INDEX_VALID( lIndex )   \
96     ( ( ( ( lIndex ) >= INDEX_OFFSET ) &&       \
97         ( ( lIndex ) < ( configPROTECTED_KERNEL_OBJECT_POOL_SIZE + INDEX_OFFSET ) ) ) ? pdTRUE : pdFALSE )
98 
99 /**
100  * @brief Checks whether an internal index is valid or not.
101  */
102     #define IS_INTERNAL_INDEX_VALID( lIndex )   \
103     ( ( ( ( lIndex ) >= 0 ) &&                  \
104         ( ( lIndex ) < ( configPROTECTED_KERNEL_OBJECT_POOL_SIZE ) ) ) ? pdTRUE : pdFALSE )
105 
106 /**
107  * @brief Converts an internal index into external.
108  */
109     #define CONVERT_TO_EXTERNAL_INDEX( lIndex )    ( ( lIndex ) + INDEX_OFFSET )
110 
111 /**
112  * @brief Converts an external index into internal.
113  */
114     #define CONVERT_TO_INTERNAL_INDEX( lIndex )    ( ( lIndex ) - INDEX_OFFSET )
115 
116 /**
117  * @brief Max value that fits in a uint32_t type.
118  */
119     #define mpuUINT32_MAX    ( ~( ( uint32_t ) 0 ) )
120 
121 /**
122  * @brief Check if multiplying a and b will result in overflow.
123  */
124     #define mpuMULTIPLY_UINT32_WILL_OVERFLOW( a, b )    ( ( ( a ) > 0 ) && ( ( b ) > ( mpuUINT32_MAX / ( a ) ) ) )
125 
126 /**
127  * @brief Get the index of a free slot in the kernel object pool.
128  *
129  * If a free slot is found, this function marks the slot as
130  * "not free".
131  *
132  * @return Index of a free slot is returned, if a free slot is
133  *         found. Otherwise -1 is returned.
134  */
135     static int32_t MPU_GetFreeIndexInKernelObjectPool( void ) PRIVILEGED_FUNCTION;
136 
137 /**
138  * @brief Set the given index as free in the kernel object pool.
139  *
140  * @param lIndex The index to set as free.
141  */
142     static void MPU_SetIndexFreeInKernelObjectPool( int32_t lIndex ) PRIVILEGED_FUNCTION;
143 
144 /**
145  * @brief Get the index at which a given kernel object is stored.
146  *
147  * @param xHandle The given kernel object handle.
148  * @param ulKernelObjectType The kernel object type.
149  *
150  * @return Index at which the kernel object is stored if it is a valid
151  *         handle, -1 otherwise.
152  */
153     static int32_t MPU_GetIndexForHandle( OpaqueObjectHandle_t xHandle,
154                                           uint32_t ulKernelObjectType ) PRIVILEGED_FUNCTION;
155 
156 /**
157  * @brief Store the given kernel object handle at the given index in
158  *        the kernel object pool.
159  *
160  * @param lIndex Index to store the given handle at.
161  * @param xHandle Kernel object handle to store.
162  * @param pvKernelObjectData The data associated with the kernel object.
163  *        Currently, only used for timer objects to store timer callback.
164  * @param ulKernelObjectType The kernel object type.
165  */
166     static void MPU_StoreHandleAndDataAtIndex( int32_t lIndex,
167                                                OpaqueObjectHandle_t xHandle,
168                                                void * pvKernelObjectData,
169                                                uint32_t ulKernelObjectType ) PRIVILEGED_FUNCTION;
170 
171 /**
172  * @brief Get the kernel object handle at the given index from
173  *        the kernel object pool.
174  *
175  * @param lIndex Index at which to get the kernel object handle.
176  * @param ulKernelObjectType The kernel object type.
177  *
178  * @return The kernel object handle at the index.
179  */
180     static OpaqueObjectHandle_t MPU_GetHandleAtIndex( int32_t lIndex,
181                                                       uint32_t ulKernelObjectType ) PRIVILEGED_FUNCTION;
182 
183     #if ( configUSE_TIMERS == 1 )
184 
185 /**
186  * @brief The function registered as callback for all the timers.
187  *
188  * We intercept all the timer callbacks so that we can call application
189  * callbacks with opaque handle.
190  *
191  * @param xInternalHandle The internal timer handle.
192  */
193         static void MPU_TimerCallback( TimerHandle_t xInternalHandle ) PRIVILEGED_FUNCTION;
194 
195     #endif /* #if ( configUSE_TIMERS == 1 ) */
196 
197 /*
198  * Wrappers to keep all the casting in one place.
199  */
200     #define MPU_StoreQueueHandleAtIndex( lIndex, xHandle )                 MPU_StoreHandleAndDataAtIndex( ( lIndex ), ( OpaqueObjectHandle_t ) ( xHandle ), NULL, KERNEL_OBJECT_TYPE_QUEUE )
201     #define MPU_GetQueueHandleAtIndex( lIndex )                            ( QueueHandle_t ) MPU_GetHandleAtIndex( ( lIndex ), KERNEL_OBJECT_TYPE_QUEUE )
202 
203     #if ( configUSE_QUEUE_SETS == 1 )
204         #define MPU_StoreQueueSetHandleAtIndex( lIndex, xHandle )          MPU_StoreHandleAndDataAtIndex( ( lIndex ), ( OpaqueObjectHandle_t ) ( xHandle ), NULL, KERNEL_OBJECT_TYPE_QUEUE )
205         #define MPU_GetQueueSetHandleAtIndex( lIndex )                     ( QueueSetHandle_t ) MPU_GetHandleAtIndex( ( lIndex ), KERNEL_OBJECT_TYPE_QUEUE )
206         #define MPU_StoreQueueSetMemberHandleAtIndex( lIndex, xHandle )    MPU_StoreHandleAndDataAtIndex( ( lIndex ), ( OpaqueObjectHandle_t ) ( xHandle ), NULL, KERNEL_OBJECT_TYPE_QUEUE )
207         #define MPU_GetQueueSetMemberHandleAtIndex( lIndex )               ( QueueSetMemberHandle_t ) MPU_GetHandleAtIndex( ( lIndex ), KERNEL_OBJECT_TYPE_QUEUE )
208         #define MPU_GetIndexForQueueSetMemberHandle( xHandle )             MPU_GetIndexForHandle( ( OpaqueObjectHandle_t ) ( xHandle ), KERNEL_OBJECT_TYPE_QUEUE )
209     #endif
210 
211 /*
212  * Wrappers to keep all the casting in one place for Task APIs.
213  */
214     #define MPU_StoreTaskHandleAtIndex( lIndex, xHandle )            MPU_StoreHandleAndDataAtIndex( ( lIndex ), ( OpaqueObjectHandle_t ) ( xHandle ), NULL, KERNEL_OBJECT_TYPE_TASK )
215     #define MPU_GetTaskHandleAtIndex( lIndex )                       ( TaskHandle_t ) MPU_GetHandleAtIndex( ( lIndex ), KERNEL_OBJECT_TYPE_TASK )
216     #define MPU_GetIndexForTaskHandle( xHandle )                     MPU_GetIndexForHandle( ( OpaqueObjectHandle_t ) ( xHandle ), KERNEL_OBJECT_TYPE_TASK )
217 
218     #if ( configUSE_EVENT_GROUPS == 1 )
219 /*
220  * Wrappers to keep all the casting in one place for Event Group APIs.
221  */
222         #define MPU_StoreEventGroupHandleAtIndex( lIndex, xHandle )      MPU_StoreHandleAndDataAtIndex( ( lIndex ), ( OpaqueObjectHandle_t ) ( xHandle ), NULL, KERNEL_OBJECT_TYPE_EVENT_GROUP )
223         #define MPU_GetEventGroupHandleAtIndex( lIndex )                 ( EventGroupHandle_t ) MPU_GetHandleAtIndex( ( lIndex ), KERNEL_OBJECT_TYPE_EVENT_GROUP )
224         #define MPU_GetIndexForEventGroupHandle( xHandle )               MPU_GetIndexForHandle( ( OpaqueObjectHandle_t ) ( xHandle ), KERNEL_OBJECT_TYPE_EVENT_GROUP )
225 
226     #endif /* #if ( configUSE_EVENT_GROUPS == 1 ) */
227 
228     #if ( configUSE_STREAM_BUFFERS == 1 )
229 /*
230  * Wrappers to keep all the casting in one place for Stream Buffer APIs.
231  */
232         #define MPU_StoreStreamBufferHandleAtIndex( lIndex, xHandle )    MPU_StoreHandleAndDataAtIndex( ( lIndex ), ( OpaqueObjectHandle_t ) ( xHandle), NULL, KERNEL_OBJECT_TYPE_STREAM_BUFFER )
233         #define MPU_GetStreamBufferHandleAtIndex( lIndex )               ( StreamBufferHandle_t ) MPU_GetHandleAtIndex( ( lIndex ), KERNEL_OBJECT_TYPE_STREAM_BUFFER )
234         #define MPU_GetIndexForStreamBufferHandle( xHandle )             MPU_GetIndexForHandle( ( OpaqueObjectHandle_t ) ( xHandle ), KERNEL_OBJECT_TYPE_STREAM_BUFFER )
235 
236     #endif /* #if ( configUSE_STREAM_BUFFERS == 1 ) */
237 
238     #if ( configUSE_TIMERS == 1 )
239 /*
240  * Wrappers to keep all the casting in one place for Timer APIs.
241  */
242         #define MPU_StoreTimerHandleAtIndex( lIndex, xHandle, pxApplicationCallback )    MPU_StoreHandleAndDataAtIndex( ( lIndex ), ( OpaqueObjectHandle_t ) ( xHandle ), ( void * ) ( pxApplicationCallback ), KERNEL_OBJECT_TYPE_TIMER )
243         #define MPU_GetTimerHandleAtIndex( lIndex )                                      ( TimerHandle_t ) MPU_GetHandleAtIndex( ( lIndex ), KERNEL_OBJECT_TYPE_TIMER )
244         #define MPU_GetIndexForTimerHandle( xHandle )                                    MPU_GetIndexForHandle( ( OpaqueObjectHandle_t ) ( xHandle ), KERNEL_OBJECT_TYPE_TIMER )
245 
246     #endif /* #if ( configUSE_TIMERS == 1 ) */
247 
248 /*-----------------------------------------------------------*/
249 
250 /**
251  * @brief Kernel object pool.
252  */
253     PRIVILEGED_DATA static KernelObject_t xKernelObjectPool[ configPROTECTED_KERNEL_OBJECT_POOL_SIZE ] = { 0 };
254 /*-----------------------------------------------------------*/
255 
MPU_GetFreeIndexInKernelObjectPool(void)256     static int32_t MPU_GetFreeIndexInKernelObjectPool( void ) /* PRIVILEGED_FUNCTION */
257     {
258         int32_t i, lFreeIndex = -1;
259 
260         /* This function is called only from resource create APIs
261          * which are not supposed to be called from ISRs. Therefore,
262          * we only need to suspend the scheduler and do not require
263          * critical section. */
264         vTaskSuspendAll();
265         {
266             for( i = 0; i < configPROTECTED_KERNEL_OBJECT_POOL_SIZE; i++ )
267             {
268                 if( xKernelObjectPool[ i ].xInternalObjectHandle == NULL )
269                 {
270                     /* Mark this index as not free. */
271                     xKernelObjectPool[ i ].xInternalObjectHandle = ( OpaqueObjectHandle_t ) ( ~0U );
272                     lFreeIndex = i;
273                     break;
274                 }
275             }
276         }
277         ( void ) xTaskResumeAll();
278 
279         return lFreeIndex;
280     }
281 /*-----------------------------------------------------------*/
282 
MPU_SetIndexFreeInKernelObjectPool(int32_t lIndex)283     static void MPU_SetIndexFreeInKernelObjectPool( int32_t lIndex ) /* PRIVILEGED_FUNCTION */
284     {
285         configASSERT( IS_INTERNAL_INDEX_VALID( lIndex ) != pdFALSE );
286 
287         taskENTER_CRITICAL();
288         {
289             xKernelObjectPool[ lIndex ].xInternalObjectHandle = NULL;
290             xKernelObjectPool[ lIndex ].ulKernelObjectType = KERNEL_OBJECT_TYPE_INVALID;
291             xKernelObjectPool[ lIndex ].pvKernelObjectData = NULL;
292         }
293         taskEXIT_CRITICAL();
294     }
295 /*-----------------------------------------------------------*/
296 
MPU_GetIndexForHandle(OpaqueObjectHandle_t xHandle,uint32_t ulKernelObjectType)297     static int32_t MPU_GetIndexForHandle( OpaqueObjectHandle_t xHandle,
298                                           uint32_t ulKernelObjectType ) /* PRIVILEGED_FUNCTION */
299     {
300         int32_t i, lIndex = -1;
301 
302         configASSERT( xHandle != NULL );
303 
304         for( i = 0; i < configPROTECTED_KERNEL_OBJECT_POOL_SIZE; i++ )
305         {
306             if( ( xKernelObjectPool[ i ].xInternalObjectHandle == xHandle ) &&
307                 ( xKernelObjectPool[ i ].ulKernelObjectType == ulKernelObjectType ) )
308             {
309                 lIndex = i;
310                 break;
311             }
312         }
313 
314         return lIndex;
315     }
316 /*-----------------------------------------------------------*/
317 
MPU_StoreHandleAndDataAtIndex(int32_t lIndex,OpaqueObjectHandle_t xHandle,void * pvKernelObjectData,uint32_t ulKernelObjectType)318     static void MPU_StoreHandleAndDataAtIndex( int32_t lIndex,
319                                                OpaqueObjectHandle_t xHandle,
320                                                void * pvKernelObjectData,
321                                                uint32_t ulKernelObjectType ) /* PRIVILEGED_FUNCTION */
322     {
323         configASSERT( IS_INTERNAL_INDEX_VALID( lIndex ) != pdFALSE );
324         xKernelObjectPool[ lIndex ].xInternalObjectHandle = xHandle;
325         xKernelObjectPool[ lIndex ].ulKernelObjectType = ulKernelObjectType;
326         xKernelObjectPool[ lIndex ].pvKernelObjectData = pvKernelObjectData;
327     }
328 /*-----------------------------------------------------------*/
329 
MPU_GetHandleAtIndex(int32_t lIndex,uint32_t ulKernelObjectType)330     static OpaqueObjectHandle_t MPU_GetHandleAtIndex( int32_t lIndex,
331                                                       uint32_t ulKernelObjectType ) /* PRIVILEGED_FUNCTION */
332     {
333         OpaqueObjectHandle_t xObjectHandle = NULL;
334 
335         configASSERT( IS_INTERNAL_INDEX_VALID( lIndex ) != pdFALSE );
336 
337         if( xKernelObjectPool[ lIndex ].ulKernelObjectType == ulKernelObjectType )
338         {
339             xObjectHandle = xKernelObjectPool[ lIndex ].xInternalObjectHandle;
340         }
341 
342         return xObjectHandle;
343     }
344 /*-----------------------------------------------------------*/
345 
346     #if ( configENABLE_ACCESS_CONTROL_LIST == 1 )
347 
vGrantAccessToKernelObject(TaskHandle_t xExternalTaskHandle,int32_t lExternalKernelObjectHandle)348         void vGrantAccessToKernelObject( TaskHandle_t xExternalTaskHandle,
349                                          int32_t lExternalKernelObjectHandle ) /* PRIVILEGED_FUNCTION */
350         {
351             int32_t lExternalTaskIndex;
352             TaskHandle_t xInternalTaskHandle = NULL;
353 
354             if( IS_EXTERNAL_INDEX_VALID( lExternalKernelObjectHandle ) != pdFALSE )
355             {
356                 if( xExternalTaskHandle == NULL )
357                 {
358                     vPortGrantAccessToKernelObject( xExternalTaskHandle, CONVERT_TO_INTERNAL_INDEX( lExternalKernelObjectHandle ) );
359                 }
360                 else
361                 {
362                     lExternalTaskIndex = ( int32_t ) xExternalTaskHandle;
363 
364                     if( IS_EXTERNAL_INDEX_VALID( lExternalTaskIndex ) != pdFALSE )
365                     {
366                         xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lExternalTaskIndex ) );
367 
368                         if( xInternalTaskHandle != NULL )
369                         {
370                             vPortGrantAccessToKernelObject( xInternalTaskHandle,
371                                                             CONVERT_TO_INTERNAL_INDEX( lExternalKernelObjectHandle ) );
372                         }
373                     }
374                 }
375             }
376         }
377 
378     #endif /* #if ( configENABLE_ACCESS_CONTROL_LIST == 1 ) */
379 /*-----------------------------------------------------------*/
380 
381     #if ( configENABLE_ACCESS_CONTROL_LIST == 1 )
382 
vRevokeAccessToKernelObject(TaskHandle_t xExternalTaskHandle,int32_t lExternalKernelObjectHandle)383         void vRevokeAccessToKernelObject( TaskHandle_t xExternalTaskHandle,
384                                           int32_t lExternalKernelObjectHandle ) /* PRIVILEGED_FUNCTION */
385         {
386             int32_t lExternalTaskIndex;
387             TaskHandle_t xInternalTaskHandle = NULL;
388 
389             if( IS_EXTERNAL_INDEX_VALID( lExternalKernelObjectHandle ) != pdFALSE )
390             {
391                 if( xExternalTaskHandle == NULL )
392                 {
393                     vPortRevokeAccessToKernelObject( xExternalTaskHandle, CONVERT_TO_INTERNAL_INDEX( lExternalKernelObjectHandle ) );
394                 }
395                 else
396                 {
397                     lExternalTaskIndex = ( int32_t ) xExternalTaskHandle;
398 
399                     if( IS_EXTERNAL_INDEX_VALID( lExternalTaskIndex ) != pdFALSE )
400                     {
401                         xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lExternalTaskIndex ) );
402 
403                         if( xInternalTaskHandle != NULL )
404                         {
405                             vPortRevokeAccessToKernelObject( xInternalTaskHandle,
406                                                              CONVERT_TO_INTERNAL_INDEX( lExternalKernelObjectHandle ) );
407                         }
408                     }
409                 }
410             }
411         }
412 
413     #endif /* #if ( configENABLE_ACCESS_CONTROL_LIST == 1 ) */
414 /*-----------------------------------------------------------*/
415 
416     #if ( configUSE_TIMERS == 1 )
417 
MPU_TimerCallback(TimerHandle_t xInternalHandle)418         static void MPU_TimerCallback( TimerHandle_t xInternalHandle ) /* PRIVILEGED_FUNCTION */
419         {
420             int32_t i, lIndex = -1;
421             TimerHandle_t xExternalHandle = NULL;
422             TimerCallbackFunction_t pxApplicationCallBack = NULL;
423 
424             /* Coming from the timer task and therefore, should be valid. */
425             configASSERT( xInternalHandle != NULL );
426 
427             for( i = 0; i < configPROTECTED_KERNEL_OBJECT_POOL_SIZE; i++ )
428             {
429                 if( ( ( TimerHandle_t ) xKernelObjectPool[ i ].xInternalObjectHandle == xInternalHandle ) &&
430                     ( xKernelObjectPool[ i ].ulKernelObjectType == KERNEL_OBJECT_TYPE_TIMER ) )
431                 {
432                     lIndex = i;
433                     break;
434                 }
435             }
436 
437             configASSERT( lIndex != -1 );
438             xExternalHandle = ( TimerHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
439 
440             pxApplicationCallBack = ( TimerCallbackFunction_t ) xKernelObjectPool[ lIndex ].pvKernelObjectData;
441             pxApplicationCallBack( xExternalHandle );
442         }
443 
444     #endif /* #if ( configUSE_TIMERS == 1 ) */
445 /*-----------------------------------------------------------*/
446 
447 /*-----------------------------------------------------------*/
448 /*            MPU wrappers for tasks APIs.                   */
449 /*-----------------------------------------------------------*/
450 
451     #if ( INCLUDE_xTaskDelayUntil == 1 )
452 
453         BaseType_t MPU_xTaskDelayUntilImpl( TickType_t * const pxPreviousWakeTime,
454                                             TickType_t xTimeIncrement ) PRIVILEGED_FUNCTION;
455 
MPU_xTaskDelayUntilImpl(TickType_t * const pxPreviousWakeTime,TickType_t xTimeIncrement)456         BaseType_t MPU_xTaskDelayUntilImpl( TickType_t * const pxPreviousWakeTime,
457                                             TickType_t xTimeIncrement ) /* PRIVILEGED_FUNCTION */
458         {
459             BaseType_t xReturn = pdFAIL;
460             BaseType_t xIsPreviousWakeTimeAccessible = pdFALSE;
461 
462             if( ( pxPreviousWakeTime != NULL ) && ( xTimeIncrement > 0U ) )
463             {
464                 xIsPreviousWakeTimeAccessible = xPortIsAuthorizedToAccessBuffer( pxPreviousWakeTime,
465                                                                                  sizeof( TickType_t ),
466                                                                                  ( tskMPU_WRITE_PERMISSION | tskMPU_READ_PERMISSION ) );
467 
468                 if( xIsPreviousWakeTimeAccessible == pdTRUE )
469                 {
470                     xReturn = xTaskDelayUntil( pxPreviousWakeTime, xTimeIncrement );
471                 }
472             }
473 
474             return xReturn;
475         }
476 
477     #endif /* if ( INCLUDE_xTaskDelayUntil == 1 ) */
478 /*-----------------------------------------------------------*/
479 
480     #if ( INCLUDE_xTaskAbortDelay == 1 )
481 
482         BaseType_t MPU_xTaskAbortDelayImpl( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
483 
MPU_xTaskAbortDelayImpl(TaskHandle_t xTask)484         BaseType_t MPU_xTaskAbortDelayImpl( TaskHandle_t xTask ) /* PRIVILEGED_FUNCTION */
485         {
486             BaseType_t xReturn = pdFAIL;
487             BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
488             TaskHandle_t xInternalTaskHandle = NULL;
489             int32_t lIndex;
490 
491             lIndex = ( int32_t ) xTask;
492 
493             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
494             {
495                 xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
496 
497                 if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
498                 {
499                     xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
500 
501                     if( xInternalTaskHandle != NULL )
502                     {
503                         xReturn = xTaskAbortDelay( xInternalTaskHandle );
504                     }
505                 }
506             }
507 
508             return xReturn;
509         }
510 
511     #endif /* if ( INCLUDE_xTaskAbortDelay == 1 ) */
512 /*-----------------------------------------------------------*/
513 
514     #if ( INCLUDE_vTaskDelay == 1 )
515 
516         void MPU_vTaskDelayImpl( TickType_t xTicksToDelay ) PRIVILEGED_FUNCTION;
517 
MPU_vTaskDelayImpl(TickType_t xTicksToDelay)518         void MPU_vTaskDelayImpl( TickType_t xTicksToDelay ) /* PRIVILEGED_FUNCTION */
519         {
520             vTaskDelay( xTicksToDelay );
521         }
522 
523     #endif /* if ( INCLUDE_vTaskDelay == 1 ) */
524 /*-----------------------------------------------------------*/
525 
526     #if ( INCLUDE_uxTaskPriorityGet == 1 )
527 
528         UBaseType_t MPU_uxTaskPriorityGetImpl( const TaskHandle_t pxTask ) PRIVILEGED_FUNCTION;
529 
MPU_uxTaskPriorityGetImpl(const TaskHandle_t pxTask)530         UBaseType_t MPU_uxTaskPriorityGetImpl( const TaskHandle_t pxTask ) /* PRIVILEGED_FUNCTION */
531         {
532             UBaseType_t uxReturn = configMAX_PRIORITIES;
533             BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
534             int32_t lIndex;
535             TaskHandle_t xInternalTaskHandle = NULL;
536 
537             if( pxTask == NULL )
538             {
539                 uxReturn = uxTaskPriorityGet( pxTask );
540             }
541             else
542             {
543                 lIndex = ( int32_t ) pxTask;
544 
545                 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
546                 {
547                     xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
548 
549                     if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
550                     {
551                         xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
552 
553                         if( xInternalTaskHandle != NULL )
554                         {
555                             uxReturn = uxTaskPriorityGet( xInternalTaskHandle );
556                         }
557                     }
558                 }
559             }
560 
561             return uxReturn;
562         }
563 
564     #endif /* if ( INCLUDE_uxTaskPriorityGet == 1 ) */
565 /*-----------------------------------------------------------*/
566 
567     #if ( INCLUDE_eTaskGetState == 1 )
568 
569         eTaskState MPU_eTaskGetStateImpl( TaskHandle_t pxTask ) PRIVILEGED_FUNCTION;
570 
MPU_eTaskGetStateImpl(TaskHandle_t pxTask)571         eTaskState MPU_eTaskGetStateImpl( TaskHandle_t pxTask ) /* PRIVILEGED_FUNCTION */
572         {
573             eTaskState eReturn = eInvalid;
574             TaskHandle_t xInternalTaskHandle = NULL;
575             int32_t lIndex;
576             BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
577 
578             lIndex = ( int32_t ) pxTask;
579 
580             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
581             {
582                 xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
583 
584                 if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
585                 {
586                     xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
587 
588                     if( xInternalTaskHandle != NULL )
589                     {
590                         eReturn = eTaskGetState( xInternalTaskHandle );
591                     }
592                 }
593             }
594 
595             return eReturn;
596         }
597 
598     #endif /* if ( INCLUDE_eTaskGetState == 1 ) */
599 /*-----------------------------------------------------------*/
600 
601     #if ( configUSE_TRACE_FACILITY == 1 )
602 
603         void MPU_vTaskGetInfoImpl( TaskHandle_t xTask,
604                                    TaskStatus_t * pxTaskStatus,
605                                    BaseType_t xGetFreeStackSpace,
606                                    eTaskState eState ) PRIVILEGED_FUNCTION;
607 
MPU_vTaskGetInfoImpl(TaskHandle_t xTask,TaskStatus_t * pxTaskStatus,BaseType_t xGetFreeStackSpace,eTaskState eState)608         void MPU_vTaskGetInfoImpl( TaskHandle_t xTask,
609                                    TaskStatus_t * pxTaskStatus,
610                                    BaseType_t xGetFreeStackSpace,
611                                    eTaskState eState ) /* PRIVILEGED_FUNCTION */
612         {
613             int32_t lIndex;
614             TaskHandle_t xInternalTaskHandle = NULL;
615             BaseType_t xIsTaskStatusWriteable = pdFALSE;
616             BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
617 
618             xIsTaskStatusWriteable = xPortIsAuthorizedToAccessBuffer( pxTaskStatus,
619                                                                       sizeof( TaskStatus_t ),
620                                                                       tskMPU_WRITE_PERMISSION );
621 
622             if( xIsTaskStatusWriteable == pdTRUE )
623             {
624                 if( xTask == NULL )
625                 {
626                     vTaskGetInfo( xTask, pxTaskStatus, xGetFreeStackSpace, eState );
627                 }
628                 else
629                 {
630                     lIndex = ( int32_t ) xTask;
631 
632                     if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
633                     {
634                         xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
635 
636                         if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
637                         {
638                             xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
639 
640                             if( xInternalTaskHandle != NULL )
641                             {
642                                 vTaskGetInfo( xInternalTaskHandle, pxTaskStatus, xGetFreeStackSpace, eState );
643                             }
644                         }
645                     }
646                 }
647             }
648         }
649 
650     #endif /* if ( configUSE_TRACE_FACILITY == 1 ) */
651 /*-----------------------------------------------------------*/
652 
653     #if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )
654 
655         TaskHandle_t MPU_xTaskGetIdleTaskHandleImpl( void ) PRIVILEGED_FUNCTION;
656 
MPU_xTaskGetIdleTaskHandleImpl(void)657         TaskHandle_t MPU_xTaskGetIdleTaskHandleImpl( void ) /* PRIVILEGED_FUNCTION */
658         {
659             TaskHandle_t xIdleTaskHandle = NULL;
660 
661             xIdleTaskHandle = xTaskGetIdleTaskHandle();
662 
663             return xIdleTaskHandle;
664         }
665 
666     #endif /* if ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) */
667 /*-----------------------------------------------------------*/
668 
669     #if ( INCLUDE_vTaskSuspend == 1 )
670 
671         void MPU_vTaskSuspendImpl( TaskHandle_t pxTaskToSuspend ) PRIVILEGED_FUNCTION;
672 
MPU_vTaskSuspendImpl(TaskHandle_t pxTaskToSuspend)673         void MPU_vTaskSuspendImpl( TaskHandle_t pxTaskToSuspend ) /* PRIVILEGED_FUNCTION */
674         {
675             int32_t lIndex;
676             TaskHandle_t xInternalTaskHandle = NULL;
677             BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
678 
679             if( pxTaskToSuspend == NULL )
680             {
681                 vTaskSuspend( pxTaskToSuspend );
682             }
683             else
684             {
685                 /* After the scheduler starts, only privileged tasks are allowed
686                  * to suspend other tasks. */
687                 #if ( INCLUDE_xTaskGetSchedulerState == 1 )
688                     if( ( xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED ) || ( portIS_TASK_PRIVILEGED() == pdTRUE ) )
689                 #else
690                     if( portIS_TASK_PRIVILEGED() == pdTRUE )
691                 #endif
692                 {
693                     lIndex = ( int32_t ) pxTaskToSuspend;
694 
695                     if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
696                     {
697                         xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
698 
699                         if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
700                         {
701                             xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
702 
703                             if( xInternalTaskHandle != NULL )
704                             {
705                                 vTaskSuspend( xInternalTaskHandle );
706                             }
707                         }
708                     }
709                 }
710             }
711         }
712 
713     #endif /* if ( INCLUDE_vTaskSuspend == 1 ) */
714 /*-----------------------------------------------------------*/
715 
716     #if ( INCLUDE_vTaskSuspend == 1 )
717 
718         void MPU_vTaskResumeImpl( TaskHandle_t pxTaskToResume ) PRIVILEGED_FUNCTION;
719 
MPU_vTaskResumeImpl(TaskHandle_t pxTaskToResume)720         void MPU_vTaskResumeImpl( TaskHandle_t pxTaskToResume ) /* PRIVILEGED_FUNCTION */
721         {
722             int32_t lIndex;
723             TaskHandle_t xInternalTaskHandle = NULL;
724             BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
725 
726             lIndex = ( int32_t ) pxTaskToResume;
727 
728             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
729             {
730                 xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
731 
732                 if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
733                 {
734                     xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
735 
736                     if( xInternalTaskHandle != NULL )
737                     {
738                         vTaskResume( xInternalTaskHandle );
739                     }
740                 }
741             }
742         }
743 
744     #endif /* if ( INCLUDE_vTaskSuspend == 1 ) */
745 /*-----------------------------------------------------------*/
746 
747     TickType_t MPU_xTaskGetTickCountImpl( void ) PRIVILEGED_FUNCTION;
748 
MPU_xTaskGetTickCountImpl(void)749     TickType_t MPU_xTaskGetTickCountImpl( void ) /* PRIVILEGED_FUNCTION */
750     {
751         TickType_t xReturn;
752 
753         xReturn = xTaskGetTickCount();
754 
755         return xReturn;
756     }
757 /*-----------------------------------------------------------*/
758 
759     UBaseType_t MPU_uxTaskGetNumberOfTasksImpl( void ) PRIVILEGED_FUNCTION;
760 
MPU_uxTaskGetNumberOfTasksImpl(void)761     UBaseType_t MPU_uxTaskGetNumberOfTasksImpl( void ) /* PRIVILEGED_FUNCTION */
762     {
763         UBaseType_t uxReturn;
764 
765         uxReturn = uxTaskGetNumberOfTasks();
766 
767         return uxReturn;
768     }
769 /*-----------------------------------------------------------*/
770 
771     #if ( configGENERATE_RUN_TIME_STATS == 1 )
772 
773         configRUN_TIME_COUNTER_TYPE MPU_ulTaskGetRunTimeCounterImpl( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
774 
MPU_ulTaskGetRunTimeCounterImpl(const TaskHandle_t xTask)775         configRUN_TIME_COUNTER_TYPE MPU_ulTaskGetRunTimeCounterImpl( const TaskHandle_t xTask ) /* PRIVILEGED_FUNCTION */
776         {
777             configRUN_TIME_COUNTER_TYPE xReturn = 0;
778             int32_t lIndex;
779             TaskHandle_t xInternalTaskHandle = NULL;
780             BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
781 
782             if( xTask == NULL )
783             {
784                 xReturn = ulTaskGetRunTimeCounter( xTask );
785             }
786             else
787             {
788                 lIndex = ( int32_t ) xTask;
789 
790                 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
791                 {
792                     xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
793 
794                     if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
795                     {
796                         xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
797 
798                         if( xInternalTaskHandle != NULL )
799                         {
800                             xReturn = ulTaskGetRunTimeCounter( xInternalTaskHandle );
801                         }
802                     }
803                 }
804             }
805 
806             return xReturn;
807         }
808 
809     #endif /* if ( ( configGENERATE_RUN_TIME_STATS == 1 ) */
810 /*-----------------------------------------------------------*/
811 
812     #if ( configGENERATE_RUN_TIME_STATS == 1 )
813 
814         configRUN_TIME_COUNTER_TYPE MPU_ulTaskGetRunTimePercentImpl( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
815 
MPU_ulTaskGetRunTimePercentImpl(const TaskHandle_t xTask)816         configRUN_TIME_COUNTER_TYPE MPU_ulTaskGetRunTimePercentImpl( const TaskHandle_t xTask ) /* PRIVILEGED_FUNCTION */
817         {
818             configRUN_TIME_COUNTER_TYPE xReturn = 0;
819             int32_t lIndex;
820             TaskHandle_t xInternalTaskHandle = NULL;
821             BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
822 
823             if( xTask == NULL )
824             {
825                 xReturn = ulTaskGetRunTimePercent( xTask );
826             }
827             else
828             {
829                 lIndex = ( int32_t ) xTask;
830 
831                 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
832                 {
833                     xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
834 
835                     if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
836                     {
837                         xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
838 
839                         if( xInternalTaskHandle != NULL )
840                         {
841                             xReturn = ulTaskGetRunTimePercent( xInternalTaskHandle );
842                         }
843                     }
844                 }
845             }
846 
847             return xReturn;
848         }
849 
850     #endif /* if ( ( configGENERATE_RUN_TIME_STATS == 1 ) */
851 /*-----------------------------------------------------------*/
852 
853     #if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) )
854 
855         configRUN_TIME_COUNTER_TYPE MPU_ulTaskGetIdleRunTimePercentImpl( void ) PRIVILEGED_FUNCTION;
856 
MPU_ulTaskGetIdleRunTimePercentImpl(void)857         configRUN_TIME_COUNTER_TYPE MPU_ulTaskGetIdleRunTimePercentImpl( void ) /* PRIVILEGED_FUNCTION */
858         {
859             configRUN_TIME_COUNTER_TYPE xReturn;
860 
861             xReturn = ulTaskGetIdleRunTimePercent();
862 
863             return xReturn;
864         }
865 
866     #endif /* if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) ) */
867 /*-----------------------------------------------------------*/
868 
869     #if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) )
870 
871         configRUN_TIME_COUNTER_TYPE MPU_ulTaskGetIdleRunTimeCounterImpl( void ) PRIVILEGED_FUNCTION;
872 
MPU_ulTaskGetIdleRunTimeCounterImpl(void)873         configRUN_TIME_COUNTER_TYPE MPU_ulTaskGetIdleRunTimeCounterImpl( void ) /* PRIVILEGED_FUNCTION */
874         {
875             configRUN_TIME_COUNTER_TYPE xReturn;
876 
877             xReturn = ulTaskGetIdleRunTimeCounter();
878 
879             return xReturn;
880         }
881 
882     #endif /* if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) ) */
883 /*-----------------------------------------------------------*/
884 
885     #if ( configUSE_APPLICATION_TASK_TAG == 1 )
886 
887         void MPU_vTaskSetApplicationTaskTagImpl( TaskHandle_t xTask,
888                                                  TaskHookFunction_t pxTagValue ) PRIVILEGED_FUNCTION;
889 
MPU_vTaskSetApplicationTaskTagImpl(TaskHandle_t xTask,TaskHookFunction_t pxTagValue)890         void MPU_vTaskSetApplicationTaskTagImpl( TaskHandle_t xTask,
891                                                  TaskHookFunction_t pxTagValue ) /* PRIVILEGED_FUNCTION */
892         {
893             TaskHandle_t xInternalTaskHandle = NULL;
894             int32_t lIndex;
895             BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
896 
897             if( xTask == NULL )
898             {
899                 vTaskSetApplicationTaskTag( xTask, pxTagValue );
900             }
901             else
902             {
903                 lIndex = ( int32_t ) xTask;
904 
905                 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
906                 {
907                     xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
908 
909                     if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
910                     {
911                         xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
912 
913                         if( xInternalTaskHandle != NULL )
914                         {
915                             vTaskSetApplicationTaskTag( xInternalTaskHandle, pxTagValue );
916                         }
917                     }
918                 }
919             }
920         }
921 
922     #endif /* if ( configUSE_APPLICATION_TASK_TAG == 1 ) */
923 /*-----------------------------------------------------------*/
924 
925     #if ( configUSE_APPLICATION_TASK_TAG == 1 )
926 
927         TaskHookFunction_t MPU_xTaskGetApplicationTaskTagImpl( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
928 
MPU_xTaskGetApplicationTaskTagImpl(TaskHandle_t xTask)929         TaskHookFunction_t MPU_xTaskGetApplicationTaskTagImpl( TaskHandle_t xTask ) /* PRIVILEGED_FUNCTION */
930         {
931             TaskHookFunction_t xReturn = NULL;
932             int32_t lIndex;
933             TaskHandle_t xInternalTaskHandle = NULL;
934             BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
935 
936             if( xTask == NULL )
937             {
938                 xReturn = xTaskGetApplicationTaskTag( xTask );
939             }
940             else
941             {
942                 lIndex = ( int32_t ) xTask;
943 
944                 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
945                 {
946                     xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
947 
948                     if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
949                     {
950                         xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
951 
952                         if( xInternalTaskHandle != NULL )
953                         {
954                             xReturn = xTaskGetApplicationTaskTag( xInternalTaskHandle );
955                         }
956                     }
957                 }
958             }
959 
960             return xReturn;
961         }
962 
963     #endif /* if ( configUSE_APPLICATION_TASK_TAG == 1 ) */
964 /*-----------------------------------------------------------*/
965 
966     #if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 )
967 
968         void MPU_vTaskSetThreadLocalStoragePointerImpl( TaskHandle_t xTaskToSet,
969                                                         BaseType_t xIndex,
970                                                         void * pvValue ) PRIVILEGED_FUNCTION;
971 
MPU_vTaskSetThreadLocalStoragePointerImpl(TaskHandle_t xTaskToSet,BaseType_t xIndex,void * pvValue)972         void MPU_vTaskSetThreadLocalStoragePointerImpl( TaskHandle_t xTaskToSet,
973                                                         BaseType_t xIndex,
974                                                         void * pvValue ) /* PRIVILEGED_FUNCTION */
975         {
976             int32_t lIndex;
977             TaskHandle_t xInternalTaskHandle = NULL;
978             BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
979 
980             if( xTaskToSet == NULL )
981             {
982                 vTaskSetThreadLocalStoragePointer( xTaskToSet, xIndex, pvValue );
983             }
984             else
985             {
986                 lIndex = ( int32_t ) xTaskToSet;
987 
988                 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
989                 {
990                     xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
991 
992                     if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
993                     {
994                         xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
995 
996                         if( xInternalTaskHandle != NULL )
997                         {
998                             vTaskSetThreadLocalStoragePointer( xInternalTaskHandle, xIndex, pvValue );
999                         }
1000                     }
1001                 }
1002             }
1003         }
1004 
1005     #endif /* if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 ) */
1006 /*-----------------------------------------------------------*/
1007 
1008     #if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 )
1009 
1010         void * MPU_pvTaskGetThreadLocalStoragePointerImpl( TaskHandle_t xTaskToQuery,
1011                                                            BaseType_t xIndex ) PRIVILEGED_FUNCTION;
1012 
MPU_pvTaskGetThreadLocalStoragePointerImpl(TaskHandle_t xTaskToQuery,BaseType_t xIndex)1013         void * MPU_pvTaskGetThreadLocalStoragePointerImpl( TaskHandle_t xTaskToQuery,
1014                                                            BaseType_t xIndex ) /* PRIVILEGED_FUNCTION */
1015         {
1016             void * pvReturn = NULL;
1017             int32_t lIndex;
1018             TaskHandle_t xInternalTaskHandle = NULL;
1019             BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
1020 
1021             if( xTaskToQuery == NULL )
1022             {
1023                 pvReturn = pvTaskGetThreadLocalStoragePointer( xTaskToQuery, xIndex );
1024             }
1025             else
1026             {
1027                 lIndex = ( int32_t ) xTaskToQuery;
1028 
1029                 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1030                 {
1031                     xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1032 
1033                     if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
1034                     {
1035                         xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1036 
1037                         if( xInternalTaskHandle != NULL )
1038                         {
1039                             pvReturn = pvTaskGetThreadLocalStoragePointer( xInternalTaskHandle, xIndex );
1040                         }
1041                     }
1042                 }
1043             }
1044 
1045             return pvReturn;
1046         }
1047 
1048     #endif /* if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 ) */
1049 /*-----------------------------------------------------------*/
1050 
1051     #if ( configUSE_TRACE_FACILITY == 1 )
1052 
1053         UBaseType_t MPU_uxTaskGetSystemStateImpl( TaskStatus_t * pxTaskStatusArray,
1054                                                   UBaseType_t uxArraySize,
1055                                                   configRUN_TIME_COUNTER_TYPE * pulTotalRunTime ) PRIVILEGED_FUNCTION;
1056 
MPU_uxTaskGetSystemStateImpl(TaskStatus_t * pxTaskStatusArray,UBaseType_t uxArraySize,configRUN_TIME_COUNTER_TYPE * pulTotalRunTime)1057         UBaseType_t MPU_uxTaskGetSystemStateImpl( TaskStatus_t * pxTaskStatusArray,
1058                                                   UBaseType_t uxArraySize,
1059                                                   configRUN_TIME_COUNTER_TYPE * pulTotalRunTime ) /* PRIVILEGED_FUNCTION */
1060         {
1061             UBaseType_t uxReturn = 0;
1062             UBaseType_t xIsTaskStatusArrayWriteable = pdFALSE;
1063             UBaseType_t xIsTotalRunTimeWriteable = pdFALSE;
1064             uint32_t ulArraySize = ( uint32_t ) uxArraySize;
1065             uint32_t ulTaskStatusSize = ( uint32_t ) sizeof( TaskStatus_t );
1066 
1067             if( mpuMULTIPLY_UINT32_WILL_OVERFLOW( ulTaskStatusSize, ulArraySize ) == 0 )
1068             {
1069                 xIsTaskStatusArrayWriteable = xPortIsAuthorizedToAccessBuffer( pxTaskStatusArray,
1070                                                                                ulTaskStatusSize * ulArraySize,
1071                                                                                tskMPU_WRITE_PERMISSION );
1072 
1073                 if( pulTotalRunTime != NULL )
1074                 {
1075                     xIsTotalRunTimeWriteable = xPortIsAuthorizedToAccessBuffer( pulTotalRunTime,
1076                                                                                 sizeof( configRUN_TIME_COUNTER_TYPE ),
1077                                                                                 tskMPU_WRITE_PERMISSION );
1078                 }
1079 
1080                 if( ( xIsTaskStatusArrayWriteable == pdTRUE ) &&
1081                     ( ( pulTotalRunTime == NULL ) || ( xIsTotalRunTimeWriteable == pdTRUE ) ) )
1082                 {
1083                     uxReturn = uxTaskGetSystemState( pxTaskStatusArray, ( UBaseType_t ) ulArraySize, pulTotalRunTime );
1084                 }
1085             }
1086 
1087             return uxReturn;
1088         }
1089 
1090     #endif /* if ( configUSE_TRACE_FACILITY == 1 ) */
1091 /*-----------------------------------------------------------*/
1092 
1093     #if ( INCLUDE_uxTaskGetStackHighWaterMark == 1 )
1094 
1095         UBaseType_t MPU_uxTaskGetStackHighWaterMarkImpl( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1096 
MPU_uxTaskGetStackHighWaterMarkImpl(TaskHandle_t xTask)1097         UBaseType_t MPU_uxTaskGetStackHighWaterMarkImpl( TaskHandle_t xTask ) /* PRIVILEGED_FUNCTION */
1098         {
1099             UBaseType_t uxReturn = 0;
1100             int32_t lIndex;
1101             TaskHandle_t xInternalTaskHandle = NULL;
1102             BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
1103 
1104             if( xTask == NULL )
1105             {
1106                 uxReturn = uxTaskGetStackHighWaterMark( xTask );
1107             }
1108             else
1109             {
1110                 lIndex = ( int32_t ) xTask;
1111 
1112                 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1113                 {
1114                     xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1115 
1116                     if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
1117                     {
1118                         xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1119 
1120                         if( xInternalTaskHandle != NULL )
1121                         {
1122                             uxReturn = uxTaskGetStackHighWaterMark( xInternalTaskHandle );
1123                         }
1124                     }
1125                 }
1126             }
1127 
1128             return uxReturn;
1129         }
1130 
1131     #endif /* if ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) */
1132 /*-----------------------------------------------------------*/
1133 
1134     #if ( INCLUDE_uxTaskGetStackHighWaterMark2 == 1 )
1135 
1136         configSTACK_DEPTH_TYPE MPU_uxTaskGetStackHighWaterMark2Impl( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1137 
MPU_uxTaskGetStackHighWaterMark2Impl(TaskHandle_t xTask)1138         configSTACK_DEPTH_TYPE MPU_uxTaskGetStackHighWaterMark2Impl( TaskHandle_t xTask ) /* PRIVILEGED_FUNCTION */
1139         {
1140             configSTACK_DEPTH_TYPE uxReturn = 0;
1141             int32_t lIndex;
1142             TaskHandle_t xInternalTaskHandle = NULL;
1143             BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
1144 
1145             if( xTask == NULL )
1146             {
1147                 uxReturn = uxTaskGetStackHighWaterMark2( xTask );
1148             }
1149             else
1150             {
1151                 lIndex = ( int32_t ) xTask;
1152 
1153                 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1154                 {
1155                     xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1156 
1157                     if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
1158                     {
1159                         xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1160 
1161                         if( xInternalTaskHandle != NULL )
1162                         {
1163                             uxReturn = uxTaskGetStackHighWaterMark2( xInternalTaskHandle );
1164                         }
1165                     }
1166                 }
1167             }
1168 
1169             return uxReturn;
1170         }
1171 
1172     #endif /* if ( INCLUDE_uxTaskGetStackHighWaterMark2 == 1 ) */
1173 /*-----------------------------------------------------------*/
1174 
1175     #if ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) )
1176 
1177         TaskHandle_t MPU_xTaskGetCurrentTaskHandleImpl( void ) PRIVILEGED_FUNCTION;
1178 
MPU_xTaskGetCurrentTaskHandleImpl(void)1179         TaskHandle_t MPU_xTaskGetCurrentTaskHandleImpl( void ) /* PRIVILEGED_FUNCTION */
1180         {
1181             TaskHandle_t xInternalTaskHandle = NULL;
1182             TaskHandle_t xExternalTaskHandle = NULL;
1183             int32_t lIndex;
1184 
1185             xInternalTaskHandle = xTaskGetCurrentTaskHandle();
1186 
1187             if( xInternalTaskHandle != NULL )
1188             {
1189                 lIndex = MPU_GetIndexForTaskHandle( xInternalTaskHandle );
1190 
1191                 if( lIndex != -1 )
1192                 {
1193                     xExternalTaskHandle = ( TaskHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
1194                 }
1195             }
1196 
1197             return xExternalTaskHandle;
1198         }
1199 
1200     #endif /* if ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) ) */
1201 /*-----------------------------------------------------------*/
1202 
1203     #if ( INCLUDE_xTaskGetSchedulerState == 1 )
1204 
1205         BaseType_t MPU_xTaskGetSchedulerStateImpl( void ) PRIVILEGED_FUNCTION;
1206 
MPU_xTaskGetSchedulerStateImpl(void)1207         BaseType_t MPU_xTaskGetSchedulerStateImpl( void ) /* PRIVILEGED_FUNCTION */
1208         {
1209             BaseType_t xReturn = taskSCHEDULER_NOT_STARTED;
1210 
1211             xReturn = xTaskGetSchedulerState();
1212 
1213             return xReturn;
1214         }
1215 
1216     #endif /* if ( INCLUDE_xTaskGetSchedulerState == 1 ) */
1217 /*-----------------------------------------------------------*/
1218 
1219     void MPU_vTaskSetTimeOutStateImpl( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
1220 
MPU_vTaskSetTimeOutStateImpl(TimeOut_t * const pxTimeOut)1221     void MPU_vTaskSetTimeOutStateImpl( TimeOut_t * const pxTimeOut ) /* PRIVILEGED_FUNCTION */
1222     {
1223         BaseType_t xIsTimeOutWriteable = pdFALSE;
1224 
1225         if( pxTimeOut != NULL )
1226         {
1227             xIsTimeOutWriteable = xPortIsAuthorizedToAccessBuffer( pxTimeOut,
1228                                                                    sizeof( TimeOut_t ),
1229                                                                    tskMPU_WRITE_PERMISSION );
1230 
1231             if( xIsTimeOutWriteable == pdTRUE )
1232             {
1233                 vTaskSetTimeOutState( pxTimeOut );
1234             }
1235         }
1236     }
1237 /*-----------------------------------------------------------*/
1238 
1239     BaseType_t MPU_xTaskCheckForTimeOutImpl( TimeOut_t * const pxTimeOut,
1240                                              TickType_t * const pxTicksToWait ) PRIVILEGED_FUNCTION;
1241 
MPU_xTaskCheckForTimeOutImpl(TimeOut_t * const pxTimeOut,TickType_t * const pxTicksToWait)1242     BaseType_t MPU_xTaskCheckForTimeOutImpl( TimeOut_t * const pxTimeOut,
1243                                              TickType_t * const pxTicksToWait ) /* PRIVILEGED_FUNCTION */
1244     {
1245         BaseType_t xReturn = pdFALSE;
1246         BaseType_t xIsTimeOutWriteable = pdFALSE;
1247         BaseType_t xIsTicksToWaitWriteable = pdFALSE;
1248 
1249         if( ( pxTimeOut != NULL ) && ( pxTicksToWait != NULL ) )
1250         {
1251             xIsTimeOutWriteable = xPortIsAuthorizedToAccessBuffer( pxTimeOut,
1252                                                                    sizeof( TimeOut_t ),
1253                                                                    tskMPU_WRITE_PERMISSION );
1254             xIsTicksToWaitWriteable = xPortIsAuthorizedToAccessBuffer( pxTicksToWait,
1255                                                                        sizeof( TickType_t ),
1256                                                                        tskMPU_WRITE_PERMISSION );
1257 
1258             if( ( xIsTimeOutWriteable == pdTRUE ) && ( xIsTicksToWaitWriteable == pdTRUE ) )
1259             {
1260                 xReturn = xTaskCheckForTimeOut( pxTimeOut, pxTicksToWait );
1261             }
1262         }
1263 
1264         return xReturn;
1265     }
1266 /*-----------------------------------------------------------*/
1267 
1268     #if ( configUSE_TASK_NOTIFICATIONS == 1 )
1269 
MPU_xTaskGenericNotify(TaskHandle_t xTaskToNotify,UBaseType_t uxIndexToNotify,uint32_t ulValue,eNotifyAction eAction,uint32_t * pulPreviousNotificationValue)1270         BaseType_t MPU_xTaskGenericNotify( TaskHandle_t xTaskToNotify,
1271                                            UBaseType_t uxIndexToNotify,
1272                                            uint32_t ulValue,
1273                                            eNotifyAction eAction,
1274                                            uint32_t * pulPreviousNotificationValue ) /* FREERTOS_SYSTEM_CALL */
1275         {
1276             BaseType_t xReturn = pdFAIL;
1277             xTaskGenericNotifyParams_t xParams;
1278 
1279             xParams.xTaskToNotify = xTaskToNotify;
1280             xParams.uxIndexToNotify = uxIndexToNotify;
1281             xParams.ulValue = ulValue;
1282             xParams.eAction = eAction;
1283             xParams.pulPreviousNotificationValue = pulPreviousNotificationValue;
1284 
1285             xReturn = MPU_xTaskGenericNotifyEntry( &( xParams ) );
1286 
1287             return xReturn;
1288         }
1289 
1290         BaseType_t MPU_xTaskGenericNotifyImpl( const xTaskGenericNotifyParams_t * pxParams ) PRIVILEGED_FUNCTION;
1291 
MPU_xTaskGenericNotifyImpl(const xTaskGenericNotifyParams_t * pxParams)1292         BaseType_t MPU_xTaskGenericNotifyImpl( const xTaskGenericNotifyParams_t * pxParams ) /* PRIVILEGED_FUNCTION */
1293         {
1294             BaseType_t xReturn = pdFAIL;
1295             int32_t lIndex;
1296             TaskHandle_t xInternalTaskHandle = NULL;
1297             BaseType_t xIsPreviousNotificationValueWriteable = pdFALSE;
1298             BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
1299             BaseType_t xAreParamsReadable = pdFALSE;
1300 
1301             if( pxParams != NULL )
1302             {
1303                 xAreParamsReadable = xPortIsAuthorizedToAccessBuffer( pxParams,
1304                                                                       sizeof( xTaskGenericNotifyParams_t ),
1305                                                                       tskMPU_READ_PERMISSION );
1306             }
1307 
1308             if( xAreParamsReadable == pdTRUE )
1309             {
1310                 if( ( pxParams->uxIndexToNotify < configTASK_NOTIFICATION_ARRAY_ENTRIES ) &&
1311                     ( ( pxParams->eAction == eNoAction ) ||
1312                       ( pxParams->eAction == eSetBits ) ||
1313                       ( pxParams->eAction == eIncrement ) ||
1314                       ( pxParams->eAction == eSetValueWithOverwrite ) ||
1315                       ( pxParams->eAction == eSetValueWithoutOverwrite ) ) )
1316                 {
1317                     if( pxParams->pulPreviousNotificationValue != NULL )
1318                     {
1319                         xIsPreviousNotificationValueWriteable = xPortIsAuthorizedToAccessBuffer( pxParams->pulPreviousNotificationValue,
1320                                                                                                  sizeof( uint32_t ),
1321                                                                                                  tskMPU_WRITE_PERMISSION );
1322                     }
1323 
1324                     if( ( pxParams->pulPreviousNotificationValue == NULL ) ||
1325                         ( xIsPreviousNotificationValueWriteable == pdTRUE ) )
1326                     {
1327                         lIndex = ( int32_t ) ( pxParams->xTaskToNotify );
1328 
1329                         if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1330                         {
1331                             xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1332 
1333                             if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
1334                             {
1335                                 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1336 
1337                                 if( xInternalTaskHandle != NULL )
1338                                 {
1339                                     xReturn = xTaskGenericNotify( xInternalTaskHandle,
1340                                                                   pxParams->uxIndexToNotify,
1341                                                                   pxParams->ulValue,
1342                                                                   pxParams->eAction,
1343                                                                   pxParams->pulPreviousNotificationValue );
1344                                 }
1345                             }
1346                         }
1347                     }
1348                 }
1349             }
1350 
1351             return xReturn;
1352         }
1353 
1354     #endif /* if ( configUSE_TASK_NOTIFICATIONS == 1 ) */
1355 /*-----------------------------------------------------------*/
1356 
1357     #if ( configUSE_TASK_NOTIFICATIONS == 1 )
1358 
MPU_xTaskGenericNotifyWait(UBaseType_t uxIndexToWaitOn,uint32_t ulBitsToClearOnEntry,uint32_t ulBitsToClearOnExit,uint32_t * pulNotificationValue,TickType_t xTicksToWait)1359         BaseType_t MPU_xTaskGenericNotifyWait( UBaseType_t uxIndexToWaitOn,
1360                                                uint32_t ulBitsToClearOnEntry,
1361                                                uint32_t ulBitsToClearOnExit,
1362                                                uint32_t * pulNotificationValue,
1363                                                TickType_t xTicksToWait )
1364         {
1365             BaseType_t xReturn = pdFAIL;
1366             xTaskGenericNotifyWaitParams_t xParams;
1367 
1368             xParams.uxIndexToWaitOn = uxIndexToWaitOn;
1369             xParams.ulBitsToClearOnEntry = ulBitsToClearOnEntry;
1370             xParams.ulBitsToClearOnExit = ulBitsToClearOnExit;
1371             xParams.pulNotificationValue = pulNotificationValue;
1372             xParams.xTicksToWait = xTicksToWait;
1373 
1374             xReturn = MPU_xTaskGenericNotifyWaitEntry( &( xParams ) );
1375 
1376             return xReturn;
1377         }
1378 
1379         BaseType_t MPU_xTaskGenericNotifyWaitImpl( const xTaskGenericNotifyWaitParams_t * pxParams ) PRIVILEGED_FUNCTION;
1380 
MPU_xTaskGenericNotifyWaitImpl(const xTaskGenericNotifyWaitParams_t * pxParams)1381         BaseType_t MPU_xTaskGenericNotifyWaitImpl( const xTaskGenericNotifyWaitParams_t * pxParams ) /* PRIVILEGED_FUNCTION */
1382         {
1383             BaseType_t xReturn = pdFAIL;
1384             BaseType_t xIsNotificationValueWritable = pdFALSE;
1385             BaseType_t xAreParamsReadable = pdFALSE;
1386 
1387             if( pxParams != NULL )
1388             {
1389                 xAreParamsReadable = xPortIsAuthorizedToAccessBuffer( pxParams,
1390                                                                       sizeof( xTaskGenericNotifyWaitParams_t ),
1391                                                                       tskMPU_READ_PERMISSION );
1392             }
1393 
1394             if( xAreParamsReadable == pdTRUE )
1395             {
1396                 if( pxParams->uxIndexToWaitOn < configTASK_NOTIFICATION_ARRAY_ENTRIES )
1397                 {
1398                     if( pxParams->pulNotificationValue != NULL )
1399                     {
1400                         xIsNotificationValueWritable = xPortIsAuthorizedToAccessBuffer( pxParams->pulNotificationValue,
1401                                                                                         sizeof( uint32_t ),
1402                                                                                         tskMPU_WRITE_PERMISSION );
1403                     }
1404 
1405                     if( ( pxParams->pulNotificationValue == NULL ) ||
1406                         ( xIsNotificationValueWritable == pdTRUE ) )
1407                     {
1408                         xReturn = xTaskGenericNotifyWait( pxParams->uxIndexToWaitOn,
1409                                                           pxParams->ulBitsToClearOnEntry,
1410                                                           pxParams->ulBitsToClearOnExit,
1411                                                           pxParams->pulNotificationValue,
1412                                                           pxParams->xTicksToWait );
1413                     }
1414                 }
1415             }
1416 
1417             return xReturn;
1418         }
1419 
1420     #endif /* if ( configUSE_TASK_NOTIFICATIONS == 1 ) */
1421 /*-----------------------------------------------------------*/
1422 
1423     #if ( configUSE_TASK_NOTIFICATIONS == 1 )
1424 
1425         uint32_t MPU_ulTaskGenericNotifyTakeImpl( UBaseType_t uxIndexToWaitOn,
1426                                                   BaseType_t xClearCountOnExit,
1427                                                   TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1428 
MPU_ulTaskGenericNotifyTakeImpl(UBaseType_t uxIndexToWaitOn,BaseType_t xClearCountOnExit,TickType_t xTicksToWait)1429         uint32_t MPU_ulTaskGenericNotifyTakeImpl( UBaseType_t uxIndexToWaitOn,
1430                                                   BaseType_t xClearCountOnExit,
1431                                                   TickType_t xTicksToWait ) /* PRIVILEGED_FUNCTION */
1432         {
1433             uint32_t ulReturn = 0;
1434 
1435             if( uxIndexToWaitOn < configTASK_NOTIFICATION_ARRAY_ENTRIES )
1436             {
1437                 ulReturn = ulTaskGenericNotifyTake( uxIndexToWaitOn, xClearCountOnExit, xTicksToWait );
1438             }
1439 
1440             return ulReturn;
1441         }
1442 
1443     #endif /* if ( configUSE_TASK_NOTIFICATIONS == 1 ) */
1444 /*-----------------------------------------------------------*/
1445 
1446     #if ( configUSE_TASK_NOTIFICATIONS == 1 )
1447 
1448         BaseType_t MPU_xTaskGenericNotifyStateClearImpl( TaskHandle_t xTask,
1449                                                          UBaseType_t uxIndexToClear ) PRIVILEGED_FUNCTION;
1450 
MPU_xTaskGenericNotifyStateClearImpl(TaskHandle_t xTask,UBaseType_t uxIndexToClear)1451         BaseType_t MPU_xTaskGenericNotifyStateClearImpl( TaskHandle_t xTask,
1452                                                          UBaseType_t uxIndexToClear ) /* PRIVILEGED_FUNCTION */
1453         {
1454             BaseType_t xReturn = pdFAIL;
1455             int32_t lIndex;
1456             TaskHandle_t xInternalTaskHandle = NULL;
1457             BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
1458 
1459             if( uxIndexToClear < configTASK_NOTIFICATION_ARRAY_ENTRIES )
1460             {
1461                 if( xTask == NULL )
1462                 {
1463                     xReturn = xTaskGenericNotifyStateClear( xTask, uxIndexToClear );
1464                 }
1465                 else
1466                 {
1467                     lIndex = ( int32_t ) xTask;
1468 
1469                     if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1470                     {
1471                         xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1472 
1473                         if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
1474                         {
1475                             xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1476 
1477                             if( xInternalTaskHandle != NULL )
1478                             {
1479                                 xReturn = xTaskGenericNotifyStateClear( xInternalTaskHandle, uxIndexToClear );
1480                             }
1481                         }
1482                     }
1483                 }
1484             }
1485 
1486             return xReturn;
1487         }
1488 
1489     #endif /* if ( configUSE_TASK_NOTIFICATIONS == 1 ) */
1490 /*-----------------------------------------------------------*/
1491 
1492     #if ( configUSE_TASK_NOTIFICATIONS == 1 )
1493 
1494         uint32_t MPU_ulTaskGenericNotifyValueClearImpl( TaskHandle_t xTask,
1495                                                         UBaseType_t uxIndexToClear,
1496                                                         uint32_t ulBitsToClear ) PRIVILEGED_FUNCTION;
1497 
MPU_ulTaskGenericNotifyValueClearImpl(TaskHandle_t xTask,UBaseType_t uxIndexToClear,uint32_t ulBitsToClear)1498         uint32_t MPU_ulTaskGenericNotifyValueClearImpl( TaskHandle_t xTask,
1499                                                         UBaseType_t uxIndexToClear,
1500                                                         uint32_t ulBitsToClear ) /* PRIVILEGED_FUNCTION */
1501         {
1502             uint32_t ulReturn = 0;
1503             int32_t lIndex;
1504             TaskHandle_t xInternalTaskHandle = NULL;
1505             BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
1506 
1507             if( uxIndexToClear < configTASK_NOTIFICATION_ARRAY_ENTRIES )
1508             {
1509                 if( xTask == NULL )
1510                 {
1511                     ulReturn = ulTaskGenericNotifyValueClear( xTask, uxIndexToClear, ulBitsToClear );
1512                 }
1513                 else
1514                 {
1515                     lIndex = ( int32_t ) xTask;
1516 
1517                     if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1518                     {
1519                         xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1520 
1521                         if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
1522                         {
1523                             xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1524 
1525                             if( xInternalTaskHandle != NULL )
1526                             {
1527                                 ulReturn = ulTaskGenericNotifyValueClear( xInternalTaskHandle, uxIndexToClear, ulBitsToClear );
1528                             }
1529                         }
1530                     }
1531                 }
1532             }
1533 
1534             return ulReturn;
1535         }
1536 
1537     #endif /* if ( configUSE_TASK_NOTIFICATIONS == 1 ) */
1538 /*-----------------------------------------------------------*/
1539 
1540 /* Privileged only wrappers for Task APIs. These are needed so that
1541  * the application can use opaque handles maintained in mpu_wrappers.c
1542  * with all the APIs. */
1543 /*-----------------------------------------------------------*/
1544 
1545     #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
1546 
MPU_xTaskCreate(TaskFunction_t pvTaskCode,const char * const pcName,const configSTACK_DEPTH_TYPE uxStackDepth,void * pvParameters,UBaseType_t uxPriority,TaskHandle_t * pxCreatedTask)1547         BaseType_t MPU_xTaskCreate( TaskFunction_t pvTaskCode,
1548                                     const char * const pcName,
1549                                     const configSTACK_DEPTH_TYPE uxStackDepth,
1550                                     void * pvParameters,
1551                                     UBaseType_t uxPriority,
1552                                     TaskHandle_t * pxCreatedTask ) /* PRIVILEGED_FUNCTION */
1553         {
1554             BaseType_t xReturn = pdFAIL;
1555             int32_t lIndex;
1556             TaskHandle_t xInternalTaskHandle = NULL;
1557 
1558             lIndex = MPU_GetFreeIndexInKernelObjectPool();
1559 
1560             if( lIndex != -1 )
1561             {
1562                 /* xTaskCreate() can only be used to create privileged tasks in MPU port. */
1563                 if( ( uxPriority & portPRIVILEGE_BIT ) != 0 )
1564                 {
1565                     xReturn = xTaskCreate( pvTaskCode, pcName, uxStackDepth, pvParameters, uxPriority, &( xInternalTaskHandle ) );
1566 
1567                     if( ( xReturn == pdPASS ) && ( xInternalTaskHandle != NULL ) )
1568                     {
1569                         MPU_StoreTaskHandleAtIndex( lIndex, xInternalTaskHandle );
1570 
1571                         if( pxCreatedTask != NULL )
1572                         {
1573                             *pxCreatedTask = ( TaskHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
1574                         }
1575                     }
1576                     else
1577                     {
1578                         MPU_SetIndexFreeInKernelObjectPool( lIndex );
1579                     }
1580                 }
1581             }
1582 
1583             return xReturn;
1584         }
1585 
1586     #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
1587 /*-----------------------------------------------------------*/
1588 
1589     #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1590 
MPU_xTaskCreateStatic(TaskFunction_t pxTaskCode,const char * const pcName,const configSTACK_DEPTH_TYPE uxStackDepth,void * const pvParameters,UBaseType_t uxPriority,StackType_t * const puxStackBuffer,StaticTask_t * const pxTaskBuffer)1591         TaskHandle_t MPU_xTaskCreateStatic( TaskFunction_t pxTaskCode,
1592                                             const char * const pcName,
1593                                             const configSTACK_DEPTH_TYPE uxStackDepth,
1594                                             void * const pvParameters,
1595                                             UBaseType_t uxPriority,
1596                                             StackType_t * const puxStackBuffer,
1597                                             StaticTask_t * const pxTaskBuffer ) /* PRIVILEGED_FUNCTION */
1598         {
1599             TaskHandle_t xExternalTaskHandle = NULL;
1600             TaskHandle_t xInternalTaskHandle = NULL;
1601             int32_t lIndex;
1602 
1603             lIndex = MPU_GetFreeIndexInKernelObjectPool();
1604 
1605             if( lIndex != -1 )
1606             {
1607                 xInternalTaskHandle = xTaskCreateStatic( pxTaskCode, pcName, uxStackDepth, pvParameters, uxPriority, puxStackBuffer, pxTaskBuffer );
1608 
1609                 if( xInternalTaskHandle != NULL )
1610                 {
1611                     MPU_StoreTaskHandleAtIndex( lIndex, xInternalTaskHandle );
1612 
1613                     #if ( configENABLE_ACCESS_CONTROL_LIST == 1 )
1614                     {
1615                         /* By default, an unprivileged task has access to itself. */
1616                         if( ( uxPriority & portPRIVILEGE_BIT ) == 0 )
1617                         {
1618                             vPortGrantAccessToKernelObject( xInternalTaskHandle, lIndex );
1619                         }
1620                     }
1621                     #endif
1622 
1623                     xExternalTaskHandle = ( TaskHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
1624                 }
1625                 else
1626                 {
1627                     MPU_SetIndexFreeInKernelObjectPool( lIndex );
1628                 }
1629             }
1630 
1631             return xExternalTaskHandle;
1632         }
1633 
1634     #endif /* configSUPPORT_STATIC_ALLOCATION */
1635 /*-----------------------------------------------------------*/
1636 
1637     #if ( INCLUDE_vTaskDelete == 1 )
1638 
MPU_vTaskDelete(TaskHandle_t pxTaskToDelete)1639         void MPU_vTaskDelete( TaskHandle_t pxTaskToDelete ) /* PRIVILEGED_FUNCTION */
1640         {
1641             TaskHandle_t xInternalTaskHandle = NULL;
1642             int32_t lIndex;
1643 
1644             if( pxTaskToDelete == NULL )
1645             {
1646                 xInternalTaskHandle = xTaskGetCurrentTaskHandle();
1647                 lIndex = MPU_GetIndexForTaskHandle( xInternalTaskHandle );
1648 
1649                 if( lIndex != -1 )
1650                 {
1651                     MPU_SetIndexFreeInKernelObjectPool( lIndex );
1652                 }
1653 
1654                 vTaskDelete( xInternalTaskHandle );
1655             }
1656             else
1657             {
1658                 lIndex = ( int32_t ) pxTaskToDelete;
1659 
1660                 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1661                 {
1662                     xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1663 
1664                     if( xInternalTaskHandle != NULL )
1665                     {
1666                         MPU_SetIndexFreeInKernelObjectPool( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1667                         vTaskDelete( xInternalTaskHandle );
1668                     }
1669                 }
1670             }
1671         }
1672 
1673     #endif /* #if ( INCLUDE_vTaskDelete == 1 ) */
1674 /*-----------------------------------------------------------*/
1675 
1676 
1677     #if ( INCLUDE_vTaskPrioritySet == 1 )
1678 
MPU_vTaskPrioritySet(TaskHandle_t pxTask,UBaseType_t uxNewPriority)1679         void MPU_vTaskPrioritySet( TaskHandle_t pxTask,
1680                                    UBaseType_t uxNewPriority ) /* PRIVILEGED_FUNCTION */
1681         {
1682             TaskHandle_t xInternalTaskHandle = NULL;
1683             int32_t lIndex;
1684 
1685             if( pxTask == NULL )
1686             {
1687                 vTaskPrioritySet( pxTask, uxNewPriority );
1688             }
1689             else
1690             {
1691                 lIndex = ( int32_t ) pxTask;
1692 
1693                 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1694                 {
1695                     xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1696 
1697                     if( xInternalTaskHandle != NULL )
1698                     {
1699                         vTaskPrioritySet( xInternalTaskHandle, uxNewPriority );
1700                     }
1701                 }
1702             }
1703         }
1704 
1705     #endif /* if ( INCLUDE_vTaskPrioritySet == 1 ) */
1706 /*-----------------------------------------------------------*/
1707 
1708     #if ( INCLUDE_xTaskGetHandle == 1 )
1709 
MPU_xTaskGetHandle(const char * pcNameToQuery)1710         TaskHandle_t MPU_xTaskGetHandle( const char * pcNameToQuery ) /* PRIVILEGED_FUNCTION */
1711         {
1712             TaskHandle_t xInternalTaskHandle = NULL;
1713             TaskHandle_t xExternalTaskHandle = NULL;
1714             int32_t lIndex;
1715 
1716             xInternalTaskHandle = xTaskGetHandle( pcNameToQuery );
1717 
1718             if( xInternalTaskHandle != NULL )
1719             {
1720                 lIndex = MPU_GetIndexForTaskHandle( xInternalTaskHandle );
1721 
1722                 if( lIndex != -1 )
1723                 {
1724                     xExternalTaskHandle = ( TaskHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
1725                 }
1726             }
1727 
1728             return xExternalTaskHandle;
1729         }
1730 
1731     #endif /* if ( INCLUDE_xTaskGetHandle == 1 ) */
1732 /*-----------------------------------------------------------*/
1733 
1734 
1735     #if ( configUSE_APPLICATION_TASK_TAG == 1 )
1736 
MPU_xTaskCallApplicationTaskHook(TaskHandle_t xTask,void * pvParameter)1737         BaseType_t MPU_xTaskCallApplicationTaskHook( TaskHandle_t xTask,
1738                                                      void * pvParameter ) /* PRIVILEGED_FUNCTION */
1739         {
1740             BaseType_t xReturn = pdFAIL;
1741             int32_t lIndex;
1742             TaskHandle_t xInternalTaskHandle = NULL;
1743 
1744             if( xTask == NULL )
1745             {
1746                 xReturn = xTaskCallApplicationTaskHook( xTask, pvParameter );
1747             }
1748             else
1749             {
1750                 lIndex = ( int32_t ) xTask;
1751 
1752                 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1753                 {
1754                     xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1755 
1756                     if( xInternalTaskHandle != NULL )
1757                     {
1758                         xReturn = xTaskCallApplicationTaskHook( xInternalTaskHandle, pvParameter );
1759                     }
1760                 }
1761             }
1762 
1763             return xReturn;
1764         }
1765 
1766     #endif /* if ( configUSE_APPLICATION_TASK_TAG == 1 ) */
1767 /*-----------------------------------------------------------*/
1768 
1769     #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
1770 
MPU_xTaskCreateRestricted(const TaskParameters_t * const pxTaskDefinition,TaskHandle_t * pxCreatedTask)1771         BaseType_t MPU_xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition,
1772                                               TaskHandle_t * pxCreatedTask ) /* PRIVILEGED_FUNCTION */
1773         {
1774             BaseType_t xReturn = pdFAIL;
1775             int32_t lIndex;
1776             TaskHandle_t xInternalTaskHandle = NULL;
1777 
1778             lIndex = MPU_GetFreeIndexInKernelObjectPool();
1779 
1780             if( lIndex != -1 )
1781             {
1782                 xReturn = xTaskCreateRestricted( pxTaskDefinition, &( xInternalTaskHandle ) );
1783 
1784                 if( ( xReturn == pdPASS ) && ( xInternalTaskHandle != NULL ) )
1785                 {
1786                     MPU_StoreTaskHandleAtIndex( lIndex, xInternalTaskHandle );
1787 
1788                     #if ( configENABLE_ACCESS_CONTROL_LIST == 1 )
1789                     {
1790                         /* By default, an unprivileged task has access to itself. */
1791                         if( ( pxTaskDefinition->uxPriority & portPRIVILEGE_BIT ) == 0 )
1792                         {
1793                             vPortGrantAccessToKernelObject( xInternalTaskHandle, lIndex );
1794                         }
1795                     }
1796                     #endif
1797 
1798                     if( pxCreatedTask != NULL )
1799                     {
1800                         *pxCreatedTask = ( TaskHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
1801                     }
1802                 }
1803                 else
1804                 {
1805                     MPU_SetIndexFreeInKernelObjectPool( lIndex );
1806                 }
1807             }
1808 
1809             return xReturn;
1810         }
1811 
1812     #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
1813 /*-----------------------------------------------------------*/
1814 
1815     #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1816 
MPU_xTaskCreateRestrictedStatic(const TaskParameters_t * const pxTaskDefinition,TaskHandle_t * pxCreatedTask)1817         BaseType_t MPU_xTaskCreateRestrictedStatic( const TaskParameters_t * const pxTaskDefinition,
1818                                                     TaskHandle_t * pxCreatedTask ) /* PRIVILEGED_FUNCTION */
1819         {
1820             BaseType_t xReturn = pdFAIL;
1821             int32_t lIndex;
1822             TaskHandle_t xInternalTaskHandle = NULL;
1823 
1824             lIndex = MPU_GetFreeIndexInKernelObjectPool();
1825 
1826             if( lIndex != -1 )
1827             {
1828                 xReturn = xTaskCreateRestrictedStatic( pxTaskDefinition, &( xInternalTaskHandle ) );
1829 
1830                 if( ( xReturn == pdPASS ) && ( xInternalTaskHandle != NULL ) )
1831                 {
1832                     MPU_StoreTaskHandleAtIndex( lIndex, xInternalTaskHandle );
1833 
1834                     #if ( configENABLE_ACCESS_CONTROL_LIST == 1 )
1835                     {
1836                         /* By default, an unprivileged task has access to itself. */
1837                         if( ( pxTaskDefinition->uxPriority & portPRIVILEGE_BIT ) == 0 )
1838                         {
1839                             vPortGrantAccessToKernelObject( xInternalTaskHandle, lIndex );
1840                         }
1841                     }
1842                     #endif
1843 
1844                     if( pxCreatedTask != NULL )
1845                     {
1846                         *pxCreatedTask = ( TaskHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
1847                     }
1848                 }
1849                 else
1850                 {
1851                     MPU_SetIndexFreeInKernelObjectPool( lIndex );
1852                 }
1853             }
1854 
1855             return xReturn;
1856         }
1857 
1858     #endif /* configSUPPORT_STATIC_ALLOCATION */
1859 /*-----------------------------------------------------------*/
1860 
MPU_vTaskAllocateMPURegions(TaskHandle_t xTaskToModify,const MemoryRegion_t * const xRegions)1861     void MPU_vTaskAllocateMPURegions( TaskHandle_t xTaskToModify,
1862                                       const MemoryRegion_t * const xRegions ) /* PRIVILEGED_FUNCTION */
1863     {
1864         TaskHandle_t xInternalTaskHandle = NULL;
1865         int32_t lIndex;
1866 
1867         if( xTaskToModify == NULL )
1868         {
1869             vTaskAllocateMPURegions( xTaskToModify, xRegions );
1870         }
1871         else
1872         {
1873             lIndex = ( int32_t ) xTaskToModify;
1874 
1875             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1876             {
1877                 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1878 
1879                 if( xInternalTaskHandle != NULL )
1880                 {
1881                     vTaskAllocateMPURegions( xInternalTaskHandle, xRegions );
1882                 }
1883             }
1884         }
1885     }
1886 /*-----------------------------------------------------------*/
1887 
1888     #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1889 
MPU_xTaskGetStaticBuffers(TaskHandle_t xTask,StackType_t ** ppuxStackBuffer,StaticTask_t ** ppxTaskBuffer)1890         BaseType_t MPU_xTaskGetStaticBuffers( TaskHandle_t xTask,
1891                                               StackType_t ** ppuxStackBuffer,
1892                                               StaticTask_t ** ppxTaskBuffer ) /* PRIVILEGED_FUNCTION */
1893         {
1894             TaskHandle_t xInternalTaskHandle = NULL;
1895             int32_t lIndex;
1896             BaseType_t xReturn = pdFALSE;
1897 
1898             if( xTask == NULL )
1899             {
1900                 xInternalTaskHandle = xTaskGetCurrentTaskHandle();
1901                 xReturn = xTaskGetStaticBuffers( xInternalTaskHandle, ppuxStackBuffer, ppxTaskBuffer );
1902             }
1903             else
1904             {
1905                 lIndex = ( int32_t ) xTask;
1906 
1907                 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1908                 {
1909                     xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1910 
1911                     if( xInternalTaskHandle != NULL )
1912                     {
1913                         xReturn = xTaskGetStaticBuffers( xInternalTaskHandle, ppuxStackBuffer, ppxTaskBuffer );
1914                     }
1915                 }
1916             }
1917 
1918             return xReturn;
1919         }
1920 
1921     #endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
1922 /*-----------------------------------------------------------*/
1923 
MPU_pcTaskGetName(TaskHandle_t xTaskToQuery)1924     char * MPU_pcTaskGetName( TaskHandle_t xTaskToQuery ) /* PRIVILEGED_FUNCTION */
1925     {
1926         char * pcReturn = NULL;
1927         int32_t lIndex;
1928         TaskHandle_t xInternalTaskHandle = NULL;
1929 
1930         if( xTaskToQuery == NULL )
1931         {
1932             pcReturn = pcTaskGetName( xTaskToQuery );
1933         }
1934         else
1935         {
1936             lIndex = ( int32_t ) xTaskToQuery;
1937 
1938             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1939             {
1940                 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1941 
1942                 if( xInternalTaskHandle != NULL )
1943                 {
1944                     pcReturn = pcTaskGetName( xInternalTaskHandle );
1945                 }
1946             }
1947         }
1948 
1949         return pcReturn;
1950     }
1951 /*-----------------------------------------------------------*/
1952 
1953     #if ( INCLUDE_uxTaskPriorityGet == 1 )
1954 
MPU_uxTaskPriorityGetFromISR(const TaskHandle_t xTask)1955         UBaseType_t MPU_uxTaskPriorityGetFromISR( const TaskHandle_t xTask ) /* PRIVILEGED_FUNCTION */
1956         {
1957             UBaseType_t uxReturn = configMAX_PRIORITIES;
1958             int32_t lIndex;
1959             TaskHandle_t xInternalTaskHandle = NULL;
1960 
1961             if( xTask == NULL )
1962             {
1963                 uxReturn = uxTaskPriorityGetFromISR( xTask );
1964             }
1965             else
1966             {
1967                 lIndex = ( int32_t ) xTask;
1968 
1969                 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1970                 {
1971                     xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1972 
1973                     if( xInternalTaskHandle != NULL )
1974                     {
1975                         uxReturn = uxTaskPriorityGetFromISR( xInternalTaskHandle );
1976                     }
1977                 }
1978             }
1979 
1980             return uxReturn;
1981         }
1982 
1983     #endif /* #if ( INCLUDE_uxTaskPriorityGet == 1 ) */
1984 /*-----------------------------------------------------------*/
1985 
1986     #if ( ( INCLUDE_uxTaskPriorityGet == 1 ) && ( configUSE_MUTEXES == 1 ) )
1987 
MPU_uxTaskBasePriorityGet(const TaskHandle_t xTask)1988         UBaseType_t MPU_uxTaskBasePriorityGet( const TaskHandle_t xTask ) /* PRIVILEGED_FUNCTION */
1989         {
1990             UBaseType_t uxReturn = configMAX_PRIORITIES;
1991             int32_t lIndex;
1992             TaskHandle_t xInternalTaskHandle = NULL;
1993 
1994             if( xTask == NULL )
1995             {
1996                 uxReturn = uxTaskBasePriorityGet( xTask );
1997             }
1998             else
1999             {
2000                 lIndex = ( int32_t ) xTask;
2001 
2002                 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2003                 {
2004                     xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2005 
2006                     if( xInternalTaskHandle != NULL )
2007                     {
2008                         uxReturn = uxTaskBasePriorityGet( xInternalTaskHandle );
2009                     }
2010                 }
2011             }
2012 
2013             return uxReturn;
2014         }
2015 
2016     #endif /* #if ( ( INCLUDE_uxTaskPriorityGet == 1 ) && ( configUSE_MUTEXES == 1 ) ) */
2017 /*-----------------------------------------------------------*/
2018 
2019     #if ( ( INCLUDE_uxTaskPriorityGet == 1 ) && ( configUSE_MUTEXES == 1 ) )
2020 
MPU_uxTaskBasePriorityGetFromISR(const TaskHandle_t xTask)2021         UBaseType_t MPU_uxTaskBasePriorityGetFromISR( const TaskHandle_t xTask ) /* PRIVILEGED_FUNCTION */
2022         {
2023             UBaseType_t uxReturn = configMAX_PRIORITIES;
2024             int32_t lIndex;
2025             TaskHandle_t xInternalTaskHandle = NULL;
2026 
2027             if( xTask == NULL )
2028             {
2029                 uxReturn = uxTaskBasePriorityGetFromISR( xTask );
2030             }
2031             else
2032             {
2033                 lIndex = ( int32_t ) xTask;
2034 
2035                 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2036                 {
2037                     xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2038 
2039                     if( xInternalTaskHandle != NULL )
2040                     {
2041                         uxReturn = uxTaskBasePriorityGetFromISR( xInternalTaskHandle );
2042                     }
2043                 }
2044             }
2045 
2046             return uxReturn;
2047         }
2048 
2049     #endif /* #if ( ( INCLUDE_uxTaskPriorityGet == 1 ) && ( configUSE_MUTEXES == 1 ) ) */
2050 /*-----------------------------------------------------------*/
2051 
2052     #if ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) )
2053 
MPU_xTaskResumeFromISR(TaskHandle_t xTaskToResume)2054         BaseType_t MPU_xTaskResumeFromISR( TaskHandle_t xTaskToResume ) /* PRIVILEGED_FUNCTION */
2055         {
2056             BaseType_t xReturn = pdFAIL;
2057             int32_t lIndex;
2058             TaskHandle_t xInternalTaskHandle = NULL;
2059 
2060             lIndex = ( int32_t ) xTaskToResume;
2061 
2062             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2063             {
2064                 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2065 
2066                 if( xInternalTaskHandle != NULL )
2067                 {
2068                     xReturn = xTaskResumeFromISR( xInternalTaskHandle );
2069                 }
2070             }
2071 
2072             return xReturn;
2073         }
2074 
2075     #endif /* #if ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) )*/
2076 /*---------------------------------------------------------------------------------------*/
2077 
2078     #if ( configUSE_APPLICATION_TASK_TAG == 1 )
2079 
MPU_xTaskGetApplicationTaskTagFromISR(TaskHandle_t xTask)2080         TaskHookFunction_t MPU_xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask ) /* PRIVILEGED_FUNCTION */
2081         {
2082             TaskHookFunction_t xReturn = NULL;
2083             int32_t lIndex;
2084             TaskHandle_t xInternalTaskHandle = NULL;
2085 
2086             if( xTask == NULL )
2087             {
2088                 xReturn = xTaskGetApplicationTaskTagFromISR( xTask );
2089             }
2090             else
2091             {
2092                 lIndex = ( int32_t ) xTask;
2093 
2094                 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2095                 {
2096                     xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2097 
2098                     if( xInternalTaskHandle != NULL )
2099                     {
2100                         xReturn = xTaskGetApplicationTaskTagFromISR( xInternalTaskHandle );
2101                     }
2102                 }
2103             }
2104 
2105             return xReturn;
2106         }
2107 
2108     #endif /* #if ( configUSE_APPLICATION_TASK_TAG == 1 ) */
2109 /*---------------------------------------------------------------------------------------*/
2110 
2111     #if ( configUSE_TASK_NOTIFICATIONS == 1 )
2112 
MPU_xTaskGenericNotifyFromISR(TaskHandle_t xTaskToNotify,UBaseType_t uxIndexToNotify,uint32_t ulValue,eNotifyAction eAction,uint32_t * pulPreviousNotificationValue,BaseType_t * pxHigherPriorityTaskWoken)2113         BaseType_t MPU_xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify,
2114                                                   UBaseType_t uxIndexToNotify,
2115                                                   uint32_t ulValue,
2116                                                   eNotifyAction eAction,
2117                                                   uint32_t * pulPreviousNotificationValue,
2118                                                   BaseType_t * pxHigherPriorityTaskWoken ) /* PRIVILEGED_FUNCTION */
2119         {
2120             BaseType_t xReturn = pdFAIL;
2121             int32_t lIndex;
2122             TaskHandle_t xInternalTaskHandle = NULL;
2123 
2124             lIndex = ( int32_t ) xTaskToNotify;
2125 
2126             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2127             {
2128                 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2129 
2130                 if( xInternalTaskHandle != NULL )
2131                 {
2132                     xReturn = xTaskGenericNotifyFromISR( xInternalTaskHandle, uxIndexToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken );
2133                 }
2134             }
2135 
2136             return xReturn;
2137         }
2138 
2139     #endif /* #if ( configUSE_TASK_NOTIFICATIONS == 1 ) */
2140 /*---------------------------------------------------------------------------------------*/
2141 
2142     #if ( configUSE_TASK_NOTIFICATIONS == 1 )
2143 
MPU_vTaskGenericNotifyGiveFromISR(TaskHandle_t xTaskToNotify,UBaseType_t uxIndexToNotify,BaseType_t * pxHigherPriorityTaskWoken)2144         void MPU_vTaskGenericNotifyGiveFromISR( TaskHandle_t xTaskToNotify,
2145                                                 UBaseType_t uxIndexToNotify,
2146                                                 BaseType_t * pxHigherPriorityTaskWoken ) /* PRIVILEGED_FUNCTION */
2147         {
2148             int32_t lIndex;
2149             TaskHandle_t xInternalTaskHandle = NULL;
2150 
2151             lIndex = ( int32_t ) xTaskToNotify;
2152 
2153             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2154             {
2155                 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2156 
2157                 if( xInternalTaskHandle != NULL )
2158                 {
2159                     vTaskGenericNotifyGiveFromISR( xInternalTaskHandle, uxIndexToNotify, pxHigherPriorityTaskWoken );
2160                 }
2161             }
2162         }
2163     #endif /*#if ( configUSE_TASK_NOTIFICATIONS == 1 )*/
2164 /*-----------------------------------------------------------*/
2165 
2166 /*-----------------------------------------------------------*/
2167 /*            MPU wrappers for queue APIs.                   */
2168 /*-----------------------------------------------------------*/
2169 
2170     BaseType_t MPU_xQueueGenericSendImpl( QueueHandle_t xQueue,
2171                                           const void * const pvItemToQueue,
2172                                           TickType_t xTicksToWait,
2173                                           BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
2174 
MPU_xQueueGenericSendImpl(QueueHandle_t xQueue,const void * const pvItemToQueue,TickType_t xTicksToWait,BaseType_t xCopyPosition)2175     BaseType_t MPU_xQueueGenericSendImpl( QueueHandle_t xQueue,
2176                                           const void * const pvItemToQueue,
2177                                           TickType_t xTicksToWait,
2178                                           BaseType_t xCopyPosition ) /* PRIVILEGED_FUNCTION */
2179     {
2180         int32_t lIndex;
2181         QueueHandle_t xInternalQueueHandle = NULL;
2182         BaseType_t xReturn = pdFAIL;
2183         BaseType_t xIsItemToQueueReadable = pdFALSE;
2184         BaseType_t xCallingTaskIsAuthorizedToAccessQueue = pdFALSE;
2185         UBaseType_t uxQueueItemSize, uxQueueLength;
2186 
2187         lIndex = ( int32_t ) xQueue;
2188 
2189         if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2190         {
2191             xCallingTaskIsAuthorizedToAccessQueue = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2192 
2193             if( xCallingTaskIsAuthorizedToAccessQueue == pdTRUE )
2194             {
2195                 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2196 
2197                 if( xInternalQueueHandle != NULL )
2198                 {
2199                     uxQueueItemSize = uxQueueGetQueueItemSize( xInternalQueueHandle );
2200                     uxQueueLength = uxQueueGetQueueLength( xInternalQueueHandle );
2201 
2202                     if( ( !( ( pvItemToQueue == NULL ) && ( uxQueueItemSize != ( UBaseType_t ) 0U ) ) ) &&
2203                         ( !( ( xCopyPosition == queueOVERWRITE ) && ( uxQueueLength != ( UBaseType_t ) 1U ) ) )
2204                         #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
2205                             && ( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0U ) ) )
2206                         #endif
2207                         )
2208                     {
2209                         if( pvItemToQueue != NULL )
2210                         {
2211                             xIsItemToQueueReadable = xPortIsAuthorizedToAccessBuffer( pvItemToQueue,
2212                                                                                       uxQueueItemSize,
2213                                                                                       tskMPU_READ_PERMISSION );
2214                         }
2215 
2216                         if( ( pvItemToQueue == NULL ) || ( xIsItemToQueueReadable == pdTRUE ) )
2217                         {
2218                             xReturn = xQueueGenericSend( xInternalQueueHandle, pvItemToQueue, xTicksToWait, xCopyPosition );
2219                         }
2220                     }
2221                 }
2222             }
2223         }
2224 
2225         return xReturn;
2226     }
2227 /*-----------------------------------------------------------*/
2228 
2229     UBaseType_t MPU_uxQueueMessagesWaitingImpl( const QueueHandle_t pxQueue ) PRIVILEGED_FUNCTION;
2230 
MPU_uxQueueMessagesWaitingImpl(const QueueHandle_t pxQueue)2231     UBaseType_t MPU_uxQueueMessagesWaitingImpl( const QueueHandle_t pxQueue ) /* PRIVILEGED_FUNCTION */
2232     {
2233         int32_t lIndex;
2234         QueueHandle_t xInternalQueueHandle = NULL;
2235         UBaseType_t uxReturn = 0;
2236         BaseType_t xCallingTaskIsAuthorizedToAccessQueue = pdFALSE;
2237 
2238         lIndex = ( int32_t ) pxQueue;
2239 
2240         if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2241         {
2242             xCallingTaskIsAuthorizedToAccessQueue = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2243 
2244             if( xCallingTaskIsAuthorizedToAccessQueue == pdTRUE )
2245             {
2246                 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2247 
2248                 if( xInternalQueueHandle != NULL )
2249                 {
2250                     uxReturn = uxQueueMessagesWaiting( xInternalQueueHandle );
2251                 }
2252             }
2253         }
2254 
2255         return uxReturn;
2256     }
2257 /*-----------------------------------------------------------*/
2258 
2259     UBaseType_t MPU_uxQueueSpacesAvailableImpl( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
2260 
MPU_uxQueueSpacesAvailableImpl(const QueueHandle_t xQueue)2261     UBaseType_t MPU_uxQueueSpacesAvailableImpl( const QueueHandle_t xQueue ) /* PRIVILEGED_FUNCTION */
2262     {
2263         int32_t lIndex;
2264         QueueHandle_t xInternalQueueHandle = NULL;
2265         UBaseType_t uxReturn = 0;
2266         BaseType_t xCallingTaskIsAuthorizedToAccessQueue = pdFALSE;
2267 
2268         lIndex = ( int32_t ) xQueue;
2269 
2270         if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2271         {
2272             xCallingTaskIsAuthorizedToAccessQueue = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2273 
2274             if( xCallingTaskIsAuthorizedToAccessQueue == pdTRUE )
2275             {
2276                 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2277 
2278                 if( xInternalQueueHandle != NULL )
2279                 {
2280                     uxReturn = uxQueueSpacesAvailable( xInternalQueueHandle );
2281                 }
2282             }
2283         }
2284 
2285         return uxReturn;
2286     }
2287 /*-----------------------------------------------------------*/
2288 
2289     BaseType_t MPU_xQueueReceiveImpl( QueueHandle_t pxQueue,
2290                                       void * const pvBuffer,
2291                                       TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2292 
MPU_xQueueReceiveImpl(QueueHandle_t pxQueue,void * const pvBuffer,TickType_t xTicksToWait)2293     BaseType_t MPU_xQueueReceiveImpl( QueueHandle_t pxQueue,
2294                                       void * const pvBuffer,
2295                                       TickType_t xTicksToWait ) /* PRIVILEGED_FUNCTION */
2296     {
2297         int32_t lIndex;
2298         QueueHandle_t xInternalQueueHandle = NULL;
2299         BaseType_t xReturn = pdFAIL;
2300         BaseType_t xIsReceiveBufferWritable = pdFALSE;
2301         BaseType_t xCallingTaskIsAuthorizedToAccessQueue = pdFALSE;
2302         UBaseType_t uxQueueItemSize;
2303 
2304         lIndex = ( int32_t ) pxQueue;
2305 
2306         if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2307         {
2308             xCallingTaskIsAuthorizedToAccessQueue = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2309 
2310             if( xCallingTaskIsAuthorizedToAccessQueue == pdTRUE )
2311             {
2312                 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2313 
2314                 if( xInternalQueueHandle != NULL )
2315                 {
2316                     uxQueueItemSize = uxQueueGetQueueItemSize( xInternalQueueHandle );
2317 
2318                     if( ( !( ( ( pvBuffer ) == NULL ) && ( uxQueueItemSize != ( UBaseType_t ) 0U ) ) )
2319                         #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
2320                             && ( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0U ) ) )
2321                         #endif
2322                         )
2323                     {
2324                         xIsReceiveBufferWritable = xPortIsAuthorizedToAccessBuffer( pvBuffer,
2325                                                                                     uxQueueItemSize,
2326                                                                                     tskMPU_WRITE_PERMISSION );
2327 
2328                         if( xIsReceiveBufferWritable == pdTRUE )
2329                         {
2330                             xReturn = xQueueReceive( xInternalQueueHandle, pvBuffer, xTicksToWait );
2331                         }
2332                     }
2333                 }
2334             }
2335         }
2336 
2337         return xReturn;
2338     }
2339 /*-----------------------------------------------------------*/
2340 
2341     BaseType_t MPU_xQueuePeekImpl( QueueHandle_t xQueue,
2342                                    void * const pvBuffer,
2343                                    TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2344 
MPU_xQueuePeekImpl(QueueHandle_t xQueue,void * const pvBuffer,TickType_t xTicksToWait)2345     BaseType_t MPU_xQueuePeekImpl( QueueHandle_t xQueue,
2346                                    void * const pvBuffer,
2347                                    TickType_t xTicksToWait ) /* PRIVILEGED_FUNCTION */
2348     {
2349         int32_t lIndex;
2350         QueueHandle_t xInternalQueueHandle = NULL;
2351         BaseType_t xReturn = pdFAIL;
2352         BaseType_t xIsReceiveBufferWritable = pdFALSE;
2353         UBaseType_t uxQueueItemSize;
2354         BaseType_t xCallingTaskIsAuthorizedToAccessQueue = pdFALSE;
2355 
2356         lIndex = ( int32_t ) xQueue;
2357 
2358         if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2359         {
2360             xCallingTaskIsAuthorizedToAccessQueue = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2361 
2362             if( xCallingTaskIsAuthorizedToAccessQueue == pdTRUE )
2363             {
2364                 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2365 
2366                 if( xInternalQueueHandle != NULL )
2367                 {
2368                     uxQueueItemSize = uxQueueGetQueueItemSize( xInternalQueueHandle );
2369 
2370                     if( ( !( ( ( pvBuffer ) == NULL ) && ( uxQueueItemSize != ( UBaseType_t ) 0U ) ) )
2371                         #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
2372                             && ( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0U ) ) )
2373                         #endif
2374                         )
2375                     {
2376                         xIsReceiveBufferWritable = xPortIsAuthorizedToAccessBuffer( pvBuffer,
2377                                                                                     uxQueueItemSize,
2378                                                                                     tskMPU_WRITE_PERMISSION );
2379 
2380                         if( xIsReceiveBufferWritable == pdTRUE )
2381                         {
2382                             xReturn = xQueuePeek( xInternalQueueHandle, pvBuffer, xTicksToWait );
2383                         }
2384                     }
2385                 }
2386             }
2387         }
2388 
2389         return xReturn;
2390     }
2391 /*-----------------------------------------------------------*/
2392 
2393     BaseType_t MPU_xQueueSemaphoreTakeImpl( QueueHandle_t xQueue,
2394                                             TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2395 
MPU_xQueueSemaphoreTakeImpl(QueueHandle_t xQueue,TickType_t xTicksToWait)2396     BaseType_t MPU_xQueueSemaphoreTakeImpl( QueueHandle_t xQueue,
2397                                             TickType_t xTicksToWait ) /* PRIVILEGED_FUNCTION */
2398     {
2399         int32_t lIndex;
2400         QueueHandle_t xInternalQueueHandle = NULL;
2401         BaseType_t xReturn = pdFAIL;
2402         UBaseType_t uxQueueItemSize;
2403         BaseType_t xCallingTaskIsAuthorizedToAccessQueue = pdFALSE;
2404 
2405         lIndex = ( int32_t ) xQueue;
2406 
2407         if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2408         {
2409             xCallingTaskIsAuthorizedToAccessQueue = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2410 
2411             if( xCallingTaskIsAuthorizedToAccessQueue == pdTRUE )
2412             {
2413                 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2414 
2415                 if( xInternalQueueHandle != NULL )
2416                 {
2417                     uxQueueItemSize = uxQueueGetQueueItemSize( xInternalQueueHandle );
2418 
2419                     if( ( uxQueueItemSize == 0U )
2420                         #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
2421                             && ( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0U ) ) )
2422                         #endif
2423                         )
2424                     {
2425                         xReturn = xQueueSemaphoreTake( xInternalQueueHandle, xTicksToWait );
2426                     }
2427                 }
2428             }
2429         }
2430 
2431         return xReturn;
2432     }
2433 /*-----------------------------------------------------------*/
2434 
2435     #if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )
2436 
2437         TaskHandle_t MPU_xQueueGetMutexHolderImpl( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
2438 
MPU_xQueueGetMutexHolderImpl(QueueHandle_t xSemaphore)2439         TaskHandle_t MPU_xQueueGetMutexHolderImpl( QueueHandle_t xSemaphore ) /* PRIVILEGED_FUNCTION */
2440         {
2441             TaskHandle_t xMutexHolderTaskInternalHandle = NULL;
2442             TaskHandle_t xMutexHolderTaskExternalHandle = NULL;
2443             int32_t lIndex, lMutexHolderTaskIndex;
2444             QueueHandle_t xInternalQueueHandle = NULL;
2445             BaseType_t xCallingTaskIsAuthorizedToAccessQueue = pdFALSE;
2446 
2447 
2448             lIndex = ( int32_t ) xSemaphore;
2449 
2450             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2451             {
2452                 xCallingTaskIsAuthorizedToAccessQueue = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2453 
2454                 if( xCallingTaskIsAuthorizedToAccessQueue == pdTRUE )
2455                 {
2456                     xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2457 
2458                     if( xInternalQueueHandle != NULL )
2459                     {
2460                         xMutexHolderTaskInternalHandle = xQueueGetMutexHolder( xInternalQueueHandle );
2461 
2462                         if( xMutexHolderTaskInternalHandle != NULL )
2463                         {
2464                             lMutexHolderTaskIndex = MPU_GetIndexForTaskHandle( xMutexHolderTaskInternalHandle );
2465 
2466                             if( lMutexHolderTaskIndex != -1 )
2467                             {
2468                                 xMutexHolderTaskExternalHandle = ( TaskHandle_t ) ( CONVERT_TO_EXTERNAL_INDEX( lMutexHolderTaskIndex ) );
2469                             }
2470                         }
2471                     }
2472                 }
2473             }
2474 
2475             return xMutexHolderTaskExternalHandle;
2476         }
2477 
2478     #endif /* if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) ) */
2479 /*-----------------------------------------------------------*/
2480 
2481     #if ( configUSE_RECURSIVE_MUTEXES == 1 )
2482 
2483         BaseType_t MPU_xQueueTakeMutexRecursiveImpl( QueueHandle_t xMutex,
2484                                                      TickType_t xBlockTime ) PRIVILEGED_FUNCTION;
2485 
MPU_xQueueTakeMutexRecursiveImpl(QueueHandle_t xMutex,TickType_t xBlockTime)2486         BaseType_t MPU_xQueueTakeMutexRecursiveImpl( QueueHandle_t xMutex,
2487                                                      TickType_t xBlockTime ) /* PRIVILEGED_FUNCTION */
2488         {
2489             BaseType_t xReturn = pdFAIL;
2490             BaseType_t xCallingTaskIsAuthorizedToAccessQueue = pdFALSE;
2491             int32_t lIndex;
2492             QueueHandle_t xInternalQueueHandle = NULL;
2493             UBaseType_t uxQueueItemSize;
2494 
2495             lIndex = ( int32_t ) xMutex;
2496 
2497             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2498             {
2499                 xCallingTaskIsAuthorizedToAccessQueue = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2500 
2501                 if( xCallingTaskIsAuthorizedToAccessQueue == pdTRUE )
2502                 {
2503                     xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2504 
2505                     if( xInternalQueueHandle != NULL )
2506                     {
2507                         uxQueueItemSize = uxQueueGetQueueItemSize( xInternalQueueHandle );
2508 
2509                         if( uxQueueItemSize == 0 )
2510                         {
2511                             xReturn = xQueueTakeMutexRecursive( xInternalQueueHandle, xBlockTime );
2512                         }
2513                     }
2514                 }
2515             }
2516 
2517             return xReturn;
2518         }
2519 
2520     #endif /* if ( configUSE_RECURSIVE_MUTEXES == 1 ) */
2521 /*-----------------------------------------------------------*/
2522 
2523     #if ( configUSE_RECURSIVE_MUTEXES == 1 )
2524 
2525         BaseType_t MPU_xQueueGiveMutexRecursiveImpl( QueueHandle_t xMutex ) PRIVILEGED_FUNCTION;
2526 
MPU_xQueueGiveMutexRecursiveImpl(QueueHandle_t xMutex)2527         BaseType_t MPU_xQueueGiveMutexRecursiveImpl( QueueHandle_t xMutex ) /* PRIVILEGED_FUNCTION */
2528         {
2529             BaseType_t xReturn = pdFAIL;
2530             BaseType_t xCallingTaskIsAuthorizedToAccessQueue = pdFALSE;
2531             int32_t lIndex;
2532             QueueHandle_t xInternalQueueHandle = NULL;
2533 
2534             lIndex = ( int32_t ) xMutex;
2535 
2536             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2537             {
2538                 xCallingTaskIsAuthorizedToAccessQueue = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2539 
2540                 if( xCallingTaskIsAuthorizedToAccessQueue == pdTRUE )
2541                 {
2542                     xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2543 
2544                     if( xInternalQueueHandle != NULL )
2545                     {
2546                         xReturn = xQueueGiveMutexRecursive( xInternalQueueHandle );
2547                     }
2548                 }
2549             }
2550 
2551             return xReturn;
2552         }
2553 
2554     #endif /* if ( configUSE_RECURSIVE_MUTEXES == 1 ) */
2555 /*-----------------------------------------------------------*/
2556 
2557     #if ( configUSE_QUEUE_SETS == 1 )
2558 
2559         QueueSetMemberHandle_t MPU_xQueueSelectFromSetImpl( QueueSetHandle_t xQueueSet,
2560                                                             TickType_t xBlockTimeTicks ) PRIVILEGED_FUNCTION;
2561 
MPU_xQueueSelectFromSetImpl(QueueSetHandle_t xQueueSet,TickType_t xBlockTimeTicks)2562         QueueSetMemberHandle_t MPU_xQueueSelectFromSetImpl( QueueSetHandle_t xQueueSet,
2563                                                             TickType_t xBlockTimeTicks ) /* PRIVILEGED_FUNCTION */
2564         {
2565             QueueSetHandle_t xInternalQueueSetHandle = NULL;
2566             QueueSetMemberHandle_t xSelectedMemberInternal = NULL;
2567             QueueSetMemberHandle_t xSelectedMemberExternal = NULL;
2568             int32_t lIndexQueueSet, lIndexSelectedMember;
2569             BaseType_t xCallingTaskIsAuthorizedToAccessQueueSet = pdFALSE;
2570 
2571             lIndexQueueSet = ( int32_t ) xQueueSet;
2572 
2573             if( IS_EXTERNAL_INDEX_VALID( lIndexQueueSet ) != pdFALSE )
2574             {
2575                 xCallingTaskIsAuthorizedToAccessQueueSet = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndexQueueSet ) );
2576 
2577                 if( xCallingTaskIsAuthorizedToAccessQueueSet == pdTRUE )
2578                 {
2579                     xInternalQueueSetHandle = MPU_GetQueueSetHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndexQueueSet ) );
2580 
2581                     if( xInternalQueueSetHandle != NULL )
2582                     {
2583                         xSelectedMemberInternal = xQueueSelectFromSet( xInternalQueueSetHandle, xBlockTimeTicks );
2584 
2585                         if( xSelectedMemberInternal != NULL )
2586                         {
2587                             lIndexSelectedMember = MPU_GetIndexForQueueSetMemberHandle( xSelectedMemberInternal );
2588 
2589                             if( lIndexSelectedMember != -1 )
2590                             {
2591                                 xSelectedMemberExternal = ( QueueSetMemberHandle_t ) ( CONVERT_TO_EXTERNAL_INDEX( lIndexSelectedMember ) );
2592                             }
2593                         }
2594                     }
2595                 }
2596             }
2597 
2598             return xSelectedMemberExternal;
2599         }
2600 
2601     #endif /* if ( configUSE_QUEUE_SETS == 1 ) */
2602 /*-----------------------------------------------------------*/
2603 
2604     #if ( configUSE_QUEUE_SETS == 1 )
2605 
2606         BaseType_t MPU_xQueueAddToSetImpl( QueueSetMemberHandle_t xQueueOrSemaphore,
2607                                            QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
2608 
MPU_xQueueAddToSetImpl(QueueSetMemberHandle_t xQueueOrSemaphore,QueueSetHandle_t xQueueSet)2609         BaseType_t MPU_xQueueAddToSetImpl( QueueSetMemberHandle_t xQueueOrSemaphore,
2610                                            QueueSetHandle_t xQueueSet ) /* PRIVILEGED_FUNCTION */
2611         {
2612             BaseType_t xReturn = pdFAIL;
2613             QueueSetMemberHandle_t xInternalQueueSetMemberHandle = NULL;
2614             QueueSetHandle_t xInternalQueueSetHandle = NULL;
2615             int32_t lIndexQueueSet, lIndexQueueSetMember;
2616             BaseType_t xCallingTaskIsAuthorizedToAccessQueueSet = pdFALSE;
2617             BaseType_t xCallingTaskIsAuthorizedToAccessQueueSetMember = pdFALSE;
2618 
2619             lIndexQueueSet = ( int32_t ) xQueueSet;
2620             lIndexQueueSetMember = ( int32_t ) xQueueOrSemaphore;
2621 
2622             if( ( IS_EXTERNAL_INDEX_VALID( lIndexQueueSet ) != pdFALSE ) &&
2623                 ( IS_EXTERNAL_INDEX_VALID( lIndexQueueSetMember ) != pdFALSE ) )
2624             {
2625                 xCallingTaskIsAuthorizedToAccessQueueSet = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndexQueueSet ) );
2626                 xCallingTaskIsAuthorizedToAccessQueueSetMember = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndexQueueSetMember ) );
2627 
2628                 if( ( xCallingTaskIsAuthorizedToAccessQueueSet == pdTRUE ) && ( xCallingTaskIsAuthorizedToAccessQueueSetMember == pdTRUE ) )
2629                 {
2630                     xInternalQueueSetHandle = MPU_GetQueueSetHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndexQueueSet ) );
2631                     xInternalQueueSetMemberHandle = MPU_GetQueueSetMemberHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndexQueueSetMember ) );
2632 
2633                     if( ( xInternalQueueSetHandle != NULL ) && ( xInternalQueueSetMemberHandle != NULL ) )
2634                     {
2635                         xReturn = xQueueAddToSet( xInternalQueueSetMemberHandle, xInternalQueueSetHandle );
2636                     }
2637                 }
2638             }
2639 
2640             return xReturn;
2641         }
2642 
2643     #endif /* if ( configUSE_QUEUE_SETS == 1 ) */
2644 /*-----------------------------------------------------------*/
2645 
2646     #if configQUEUE_REGISTRY_SIZE > 0
2647 
2648         void MPU_vQueueAddToRegistryImpl( QueueHandle_t xQueue,
2649                                           const char * pcName ) PRIVILEGED_FUNCTION;
2650 
MPU_vQueueAddToRegistryImpl(QueueHandle_t xQueue,const char * pcName)2651         void MPU_vQueueAddToRegistryImpl( QueueHandle_t xQueue,
2652                                           const char * pcName ) /* PRIVILEGED_FUNCTION */
2653         {
2654             int32_t lIndex;
2655             QueueHandle_t xInternalQueueHandle = NULL;
2656             BaseType_t xCallingTaskIsAuthorizedToAccessQueue = pdFALSE;
2657 
2658             lIndex = ( int32_t ) xQueue;
2659 
2660             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2661             {
2662                 xCallingTaskIsAuthorizedToAccessQueue = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2663 
2664                 if( xCallingTaskIsAuthorizedToAccessQueue == pdTRUE )
2665                 {
2666                     xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2667 
2668                     if( xInternalQueueHandle != NULL )
2669                     {
2670                         vQueueAddToRegistry( xInternalQueueHandle, pcName );
2671                     }
2672                 }
2673             }
2674         }
2675 
2676     #endif /* if configQUEUE_REGISTRY_SIZE > 0 */
2677 /*-----------------------------------------------------------*/
2678 
2679     #if configQUEUE_REGISTRY_SIZE > 0
2680 
2681         void MPU_vQueueUnregisterQueueImpl( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
2682 
MPU_vQueueUnregisterQueueImpl(QueueHandle_t xQueue)2683         void MPU_vQueueUnregisterQueueImpl( QueueHandle_t xQueue ) /* PRIVILEGED_FUNCTION */
2684         {
2685             int32_t lIndex;
2686             QueueHandle_t xInternalQueueHandle = NULL;
2687             BaseType_t xCallingTaskIsAuthorizedToAccessQueue = pdFALSE;
2688 
2689             lIndex = ( int32_t ) xQueue;
2690 
2691             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2692             {
2693                 xCallingTaskIsAuthorizedToAccessQueue = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2694 
2695                 if( xCallingTaskIsAuthorizedToAccessQueue == pdTRUE )
2696                 {
2697                     xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2698 
2699                     if( xInternalQueueHandle != NULL )
2700                     {
2701                         vQueueUnregisterQueue( xInternalQueueHandle );
2702                     }
2703                 }
2704             }
2705         }
2706 
2707     #endif /* if configQUEUE_REGISTRY_SIZE > 0 */
2708 /*-----------------------------------------------------------*/
2709 
2710     #if configQUEUE_REGISTRY_SIZE > 0
2711 
2712         const char * MPU_pcQueueGetNameImpl( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
2713 
MPU_pcQueueGetNameImpl(QueueHandle_t xQueue)2714         const char * MPU_pcQueueGetNameImpl( QueueHandle_t xQueue ) /* PRIVILEGED_FUNCTION */
2715         {
2716             const char * pcReturn = NULL;
2717             QueueHandle_t xInternalQueueHandle = NULL;
2718             int32_t lIndex;
2719             BaseType_t xCallingTaskIsAuthorizedToAccessQueue = pdFALSE;
2720 
2721             lIndex = ( int32_t ) xQueue;
2722 
2723             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2724             {
2725                 xCallingTaskIsAuthorizedToAccessQueue = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2726 
2727                 if( xCallingTaskIsAuthorizedToAccessQueue == pdTRUE )
2728                 {
2729                     xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2730 
2731                     if( xInternalQueueHandle != NULL )
2732                     {
2733                         pcReturn = pcQueueGetName( xInternalQueueHandle );
2734                     }
2735                 }
2736             }
2737 
2738             return pcReturn;
2739         }
2740 
2741     #endif /* if configQUEUE_REGISTRY_SIZE > 0 */
2742 /*-----------------------------------------------------------*/
2743 
2744 /* Privileged only wrappers for Queue APIs. These are needed so that
2745  * the application can use opaque handles maintained in mpu_wrappers.c
2746  * with all the APIs. */
2747 /*-----------------------------------------------------------*/
2748 
MPU_vQueueDelete(QueueHandle_t xQueue)2749     void MPU_vQueueDelete( QueueHandle_t xQueue ) /* PRIVILEGED_FUNCTION */
2750     {
2751         QueueHandle_t xInternalQueueHandle = NULL;
2752         int32_t lIndex;
2753 
2754         lIndex = ( int32_t ) xQueue;
2755 
2756         if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2757         {
2758             xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2759 
2760             if( xInternalQueueHandle != NULL )
2761             {
2762                 vQueueDelete( xInternalQueueHandle );
2763                 MPU_SetIndexFreeInKernelObjectPool( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2764             }
2765         }
2766     }
2767 /*-----------------------------------------------------------*/
2768 
2769     #if ( ( configUSE_MUTEXES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
2770 
MPU_xQueueCreateMutex(const uint8_t ucQueueType)2771         QueueHandle_t MPU_xQueueCreateMutex( const uint8_t ucQueueType ) /* PRIVILEGED_FUNCTION */
2772         {
2773             QueueHandle_t xInternalQueueHandle = NULL;
2774             QueueHandle_t xExternalQueueHandle = NULL;
2775             int32_t lIndex;
2776 
2777             lIndex = MPU_GetFreeIndexInKernelObjectPool();
2778 
2779             if( lIndex != -1 )
2780             {
2781                 xInternalQueueHandle = xQueueCreateMutex( ucQueueType );
2782 
2783                 if( xInternalQueueHandle != NULL )
2784                 {
2785                     MPU_StoreQueueHandleAtIndex( lIndex, xInternalQueueHandle );
2786                     xExternalQueueHandle = ( QueueHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
2787                 }
2788                 else
2789                 {
2790                     MPU_SetIndexFreeInKernelObjectPool( lIndex );
2791                 }
2792             }
2793 
2794             return xExternalQueueHandle;
2795         }
2796 
2797     #endif /* if ( ( configUSE_MUTEXES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */
2798 /*-----------------------------------------------------------*/
2799 
2800     #if ( ( configUSE_MUTEXES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
2801 
MPU_xQueueCreateMutexStatic(const uint8_t ucQueueType,StaticQueue_t * pxStaticQueue)2802         QueueHandle_t MPU_xQueueCreateMutexStatic( const uint8_t ucQueueType,
2803                                                    StaticQueue_t * pxStaticQueue ) /* PRIVILEGED_FUNCTION */
2804         {
2805             QueueHandle_t xInternalQueueHandle = NULL;
2806             QueueHandle_t xExternalQueueHandle = NULL;
2807             int32_t lIndex;
2808 
2809             lIndex = MPU_GetFreeIndexInKernelObjectPool();
2810 
2811             if( lIndex != -1 )
2812             {
2813                 xInternalQueueHandle = xQueueCreateMutexStatic( ucQueueType, pxStaticQueue );
2814 
2815                 if( xInternalQueueHandle != NULL )
2816                 {
2817                     MPU_StoreQueueHandleAtIndex( lIndex, xInternalQueueHandle );
2818                     xExternalQueueHandle = ( QueueHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
2819                 }
2820                 else
2821                 {
2822                     MPU_SetIndexFreeInKernelObjectPool( lIndex );
2823                 }
2824             }
2825 
2826             return xExternalQueueHandle;
2827         }
2828 
2829     #endif /* if ( ( configUSE_MUTEXES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) */
2830 /*-----------------------------------------------------------*/
2831 
2832     #if ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
2833 
MPU_xQueueCreateCountingSemaphore(UBaseType_t uxCountValue,UBaseType_t uxInitialCount)2834         QueueHandle_t MPU_xQueueCreateCountingSemaphore( UBaseType_t uxCountValue,
2835                                                          UBaseType_t uxInitialCount ) /* PRIVILEGED_FUNCTION */
2836         {
2837             QueueHandle_t xInternalQueueHandle = NULL;
2838             QueueHandle_t xExternalQueueHandle = NULL;
2839             int32_t lIndex;
2840 
2841             lIndex = MPU_GetFreeIndexInKernelObjectPool();
2842 
2843             if( lIndex != -1 )
2844             {
2845                 xInternalQueueHandle = xQueueCreateCountingSemaphore( uxCountValue, uxInitialCount );
2846 
2847                 if( xInternalQueueHandle != NULL )
2848                 {
2849                     MPU_StoreQueueHandleAtIndex( lIndex, xInternalQueueHandle );
2850                     xExternalQueueHandle = ( QueueHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
2851                 }
2852                 else
2853                 {
2854                     MPU_SetIndexFreeInKernelObjectPool( lIndex );
2855                 }
2856             }
2857 
2858             return xExternalQueueHandle;
2859         }
2860 
2861     #endif /* if ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */
2862 /*-----------------------------------------------------------*/
2863 
2864     #if ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
2865 
MPU_xQueueCreateCountingSemaphoreStatic(const UBaseType_t uxMaxCount,const UBaseType_t uxInitialCount,StaticQueue_t * pxStaticQueue)2866         QueueHandle_t MPU_xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount,
2867                                                                const UBaseType_t uxInitialCount,
2868                                                                StaticQueue_t * pxStaticQueue ) /* PRIVILEGED_FUNCTION */
2869         {
2870             QueueHandle_t xInternalQueueHandle = NULL;
2871             QueueHandle_t xExternalQueueHandle = NULL;
2872             int32_t lIndex;
2873 
2874             lIndex = MPU_GetFreeIndexInKernelObjectPool();
2875 
2876             if( lIndex != -1 )
2877             {
2878                 xInternalQueueHandle = xQueueCreateCountingSemaphoreStatic( uxMaxCount, uxInitialCount, pxStaticQueue );
2879 
2880                 if( xInternalQueueHandle != NULL )
2881                 {
2882                     MPU_StoreQueueHandleAtIndex( lIndex, xInternalQueueHandle );
2883                     xExternalQueueHandle = ( QueueHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
2884                 }
2885                 else
2886                 {
2887                     MPU_SetIndexFreeInKernelObjectPool( lIndex );
2888                 }
2889             }
2890 
2891             return xExternalQueueHandle;
2892         }
2893 
2894     #endif /* if ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) */
2895 /*-----------------------------------------------------------*/
2896 
2897     #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
2898 
MPU_xQueueGenericCreate(UBaseType_t uxQueueLength,UBaseType_t uxItemSize,uint8_t ucQueueType)2899         QueueHandle_t MPU_xQueueGenericCreate( UBaseType_t uxQueueLength,
2900                                                UBaseType_t uxItemSize,
2901                                                uint8_t ucQueueType ) /* PRIVILEGED_FUNCTION */
2902         {
2903             QueueHandle_t xInternalQueueHandle = NULL;
2904             QueueHandle_t xExternalQueueHandle = NULL;
2905             int32_t lIndex;
2906 
2907             lIndex = MPU_GetFreeIndexInKernelObjectPool();
2908 
2909             if( lIndex != -1 )
2910             {
2911                 xInternalQueueHandle = xQueueGenericCreate( uxQueueLength, uxItemSize, ucQueueType );
2912 
2913                 if( xInternalQueueHandle != NULL )
2914                 {
2915                     MPU_StoreQueueHandleAtIndex( lIndex, xInternalQueueHandle );
2916                     xExternalQueueHandle = ( QueueHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
2917                 }
2918                 else
2919                 {
2920                     MPU_SetIndexFreeInKernelObjectPool( lIndex );
2921                 }
2922             }
2923 
2924             return xExternalQueueHandle;
2925         }
2926 
2927     #endif /* if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) */
2928 /*-----------------------------------------------------------*/
2929 
2930     #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
2931 
MPU_xQueueGenericCreateStatic(const UBaseType_t uxQueueLength,const UBaseType_t uxItemSize,uint8_t * pucQueueStorage,StaticQueue_t * pxStaticQueue,const uint8_t ucQueueType)2932         QueueHandle_t MPU_xQueueGenericCreateStatic( const UBaseType_t uxQueueLength,
2933                                                      const UBaseType_t uxItemSize,
2934                                                      uint8_t * pucQueueStorage,
2935                                                      StaticQueue_t * pxStaticQueue,
2936                                                      const uint8_t ucQueueType ) /* PRIVILEGED_FUNCTION */
2937         {
2938             QueueHandle_t xInternalQueueHandle = NULL;
2939             QueueHandle_t xExternalQueueHandle = NULL;
2940             int32_t lIndex;
2941 
2942             lIndex = MPU_GetFreeIndexInKernelObjectPool();
2943 
2944             if( lIndex != -1 )
2945             {
2946                 xInternalQueueHandle = xQueueGenericCreateStatic( uxQueueLength, uxItemSize, pucQueueStorage, pxStaticQueue, ucQueueType );
2947 
2948                 if( xInternalQueueHandle != NULL )
2949                 {
2950                     MPU_StoreQueueHandleAtIndex( lIndex, xInternalQueueHandle );
2951                     xExternalQueueHandle = ( QueueHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
2952                 }
2953                 else
2954                 {
2955                     MPU_SetIndexFreeInKernelObjectPool( lIndex );
2956                 }
2957             }
2958 
2959             return xExternalQueueHandle;
2960         }
2961 
2962     #endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
2963 /*-----------------------------------------------------------*/
2964 
MPU_xQueueGenericReset(QueueHandle_t xQueue,BaseType_t xNewQueue)2965     BaseType_t MPU_xQueueGenericReset( QueueHandle_t xQueue,
2966                                        BaseType_t xNewQueue ) /* PRIVILEGED_FUNCTION */
2967     {
2968         int32_t lIndex;
2969         QueueHandle_t xInternalQueueHandle = NULL;
2970         BaseType_t xReturn = pdFAIL;
2971 
2972         lIndex = ( int32_t ) xQueue;
2973 
2974         if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2975         {
2976             xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2977 
2978             if( xInternalQueueHandle != NULL )
2979             {
2980                 xReturn = xQueueGenericReset( xInternalQueueHandle, xNewQueue );
2981             }
2982         }
2983 
2984         return xReturn;
2985     }
2986 /*-----------------------------------------------------------*/
2987 
2988     #if ( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
2989 
MPU_xQueueCreateSet(UBaseType_t uxEventQueueLength)2990         QueueSetHandle_t MPU_xQueueCreateSet( UBaseType_t uxEventQueueLength ) /* PRIVILEGED_FUNCTION */
2991         {
2992             QueueSetHandle_t xInternalQueueSetHandle = NULL;
2993             QueueSetHandle_t xExternalQueueSetHandle = NULL;
2994             int32_t lIndex;
2995 
2996             lIndex = MPU_GetFreeIndexInKernelObjectPool();
2997 
2998             if( lIndex != -1 )
2999             {
3000                 xInternalQueueSetHandle = xQueueCreateSet( uxEventQueueLength );
3001 
3002                 if( xInternalQueueSetHandle != NULL )
3003                 {
3004                     MPU_StoreQueueSetHandleAtIndex( lIndex, xInternalQueueSetHandle );
3005                     xExternalQueueSetHandle = ( QueueSetHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
3006                 }
3007                 else
3008                 {
3009                     MPU_SetIndexFreeInKernelObjectPool( lIndex );
3010                 }
3011             }
3012 
3013             return xExternalQueueSetHandle;
3014         }
3015 
3016     #endif /* if ( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */
3017 /*-----------------------------------------------------------*/
3018 
3019     #if ( configUSE_QUEUE_SETS == 1 )
3020 
MPU_xQueueRemoveFromSet(QueueSetMemberHandle_t xQueueOrSemaphore,QueueSetHandle_t xQueueSet)3021         BaseType_t MPU_xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore,
3022                                             QueueSetHandle_t xQueueSet ) /* PRIVILEGED_FUNCTION */
3023         {
3024             BaseType_t xReturn = pdFAIL;
3025             QueueSetMemberHandle_t xInternalQueueSetMemberHandle = NULL;
3026             QueueSetHandle_t xInternalQueueSetHandle = NULL;
3027             int32_t lIndexQueueSet, lIndexQueueSetMember;
3028 
3029             lIndexQueueSet = ( int32_t ) xQueueSet;
3030             lIndexQueueSetMember = ( int32_t ) xQueueOrSemaphore;
3031 
3032             if( ( IS_EXTERNAL_INDEX_VALID( lIndexQueueSet ) != pdFALSE ) &&
3033                 ( IS_EXTERNAL_INDEX_VALID( lIndexQueueSetMember ) != pdFALSE ) )
3034             {
3035                 xInternalQueueSetHandle = MPU_GetQueueSetHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndexQueueSet ) );
3036                 xInternalQueueSetMemberHandle = MPU_GetQueueSetMemberHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndexQueueSetMember ) );
3037 
3038                 if( ( xInternalQueueSetHandle != NULL ) && ( xInternalQueueSetMemberHandle != NULL ) )
3039                 {
3040                     xReturn = xQueueRemoveFromSet( xInternalQueueSetMemberHandle, xInternalQueueSetHandle );
3041                 }
3042             }
3043 
3044             return xReturn;
3045         }
3046 
3047     #endif /* if ( configUSE_QUEUE_SETS == 1 ) */
3048 /*-----------------------------------------------------------*/
3049 
3050     #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
3051 
MPU_xQueueGenericGetStaticBuffers(QueueHandle_t xQueue,uint8_t ** ppucQueueStorage,StaticQueue_t ** ppxStaticQueue)3052         BaseType_t MPU_xQueueGenericGetStaticBuffers( QueueHandle_t xQueue,
3053                                                       uint8_t ** ppucQueueStorage,
3054                                                       StaticQueue_t ** ppxStaticQueue ) /* PRIVILEGED_FUNCTION */
3055         {
3056             int32_t lIndex;
3057             QueueHandle_t xInternalQueueHandle = NULL;
3058             BaseType_t xReturn = pdFALSE;
3059 
3060             lIndex = ( int32_t ) xQueue;
3061 
3062             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3063             {
3064                 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3065 
3066                 if( xInternalQueueHandle != NULL )
3067                 {
3068                     xReturn = xQueueGenericGetStaticBuffers( xInternalQueueHandle, ppucQueueStorage, ppxStaticQueue );
3069                 }
3070             }
3071 
3072             return xReturn;
3073         }
3074 
3075     #endif /*if ( configSUPPORT_STATIC_ALLOCATION == 1 )*/
3076 /*-----------------------------------------------------------*/
3077 
MPU_xQueueGenericSendFromISR(QueueHandle_t xQueue,const void * const pvItemToQueue,BaseType_t * const pxHigherPriorityTaskWoken,const BaseType_t xCopyPosition)3078     BaseType_t MPU_xQueueGenericSendFromISR( QueueHandle_t xQueue,
3079                                              const void * const pvItemToQueue,
3080                                              BaseType_t * const pxHigherPriorityTaskWoken,
3081                                              const BaseType_t xCopyPosition ) /* PRIVILEGED_FUNCTION */
3082     {
3083         BaseType_t xReturn = pdFAIL;
3084         int32_t lIndex;
3085         QueueHandle_t xInternalQueueHandle = NULL;
3086 
3087         lIndex = ( int32_t ) xQueue;
3088 
3089         if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3090         {
3091             xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3092 
3093             if( xInternalQueueHandle != NULL )
3094             {
3095                 xReturn = xQueueGenericSendFromISR( xInternalQueueHandle, pvItemToQueue, pxHigherPriorityTaskWoken, xCopyPosition );
3096             }
3097         }
3098 
3099         return xReturn;
3100     }
3101 
3102 /*-----------------------------------------------------------*/
3103 
MPU_xQueueGiveFromISR(QueueHandle_t xQueue,BaseType_t * const pxHigherPriorityTaskWoken)3104     BaseType_t MPU_xQueueGiveFromISR( QueueHandle_t xQueue,
3105                                       BaseType_t * const pxHigherPriorityTaskWoken ) /* PRIVILEGED_FUNCTION */
3106     {
3107         BaseType_t xReturn = pdFAIL;
3108         int32_t lIndex;
3109         QueueHandle_t xInternalQueueHandle = NULL;
3110 
3111         lIndex = ( int32_t ) xQueue;
3112 
3113         if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3114         {
3115             xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3116 
3117             if( xInternalQueueHandle != NULL )
3118             {
3119                 xReturn = xQueueGiveFromISR( xInternalQueueHandle, pxHigherPriorityTaskWoken );
3120             }
3121         }
3122 
3123         return xReturn;
3124     }
3125 
3126 /*-----------------------------------------------------------*/
3127 
MPU_xQueuePeekFromISR(QueueHandle_t xQueue,void * const pvBuffer)3128     BaseType_t MPU_xQueuePeekFromISR( QueueHandle_t xQueue,
3129                                       void * const pvBuffer ) /* PRIVILEGED_FUNCTION */
3130     {
3131         BaseType_t xReturn = pdFAIL;
3132         int32_t lIndex;
3133         QueueHandle_t xInternalQueueHandle = NULL;
3134 
3135         lIndex = ( int32_t ) xQueue;
3136 
3137         if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3138         {
3139             xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3140 
3141             if( xInternalQueueHandle != NULL )
3142             {
3143                 xReturn = xQueuePeekFromISR( xInternalQueueHandle, pvBuffer );
3144             }
3145         }
3146 
3147         return xReturn;
3148     }
3149 
3150 /*-----------------------------------------------------------*/
3151 
MPU_xQueueReceiveFromISR(QueueHandle_t xQueue,void * const pvBuffer,BaseType_t * const pxHigherPriorityTaskWoken)3152     BaseType_t MPU_xQueueReceiveFromISR( QueueHandle_t xQueue,
3153                                          void * const pvBuffer,
3154                                          BaseType_t * const pxHigherPriorityTaskWoken ) /* PRIVILEGED_FUNCTION */
3155     {
3156         BaseType_t xReturn = pdFAIL;
3157         int32_t lIndex;
3158         QueueHandle_t xInternalQueueHandle = NULL;
3159 
3160         lIndex = ( int32_t ) xQueue;
3161 
3162         if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3163         {
3164             xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3165 
3166             if( xInternalQueueHandle != NULL )
3167             {
3168                 xReturn = xQueueReceiveFromISR( xInternalQueueHandle, pvBuffer, pxHigherPriorityTaskWoken );
3169             }
3170         }
3171 
3172         return xReturn;
3173     }
3174 
3175 /*-----------------------------------------------------------*/
3176 
MPU_xQueueIsQueueEmptyFromISR(const QueueHandle_t xQueue)3177     BaseType_t MPU_xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue ) /* PRIVILEGED_FUNCTION */
3178     {
3179         BaseType_t xReturn = pdFAIL;
3180         int32_t lIndex;
3181         QueueHandle_t xInternalQueueHandle = NULL;
3182 
3183         lIndex = ( int32_t ) xQueue;
3184 
3185         if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3186         {
3187             xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3188 
3189             if( xInternalQueueHandle != NULL )
3190             {
3191                 xReturn = xQueueIsQueueEmptyFromISR( xInternalQueueHandle );
3192             }
3193         }
3194 
3195         return xReturn;
3196     }
3197 /*-----------------------------------------------------------*/
3198 
MPU_xQueueIsQueueFullFromISR(const QueueHandle_t xQueue)3199     BaseType_t MPU_xQueueIsQueueFullFromISR( const QueueHandle_t xQueue ) /* PRIVILEGED_FUNCTION */
3200     {
3201         BaseType_t xReturn = pdFAIL;
3202         int32_t lIndex;
3203         QueueHandle_t xInternalQueueHandle = NULL;
3204 
3205         lIndex = ( int32_t ) xQueue;
3206 
3207         if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3208         {
3209             xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3210 
3211             if( xInternalQueueHandle != NULL )
3212             {
3213                 xReturn = xQueueIsQueueFullFromISR( xInternalQueueHandle );
3214             }
3215         }
3216 
3217         return xReturn;
3218     }
3219 
3220 /*-----------------------------------------------------------*/
3221 
MPU_uxQueueMessagesWaitingFromISR(const QueueHandle_t xQueue)3222     UBaseType_t MPU_uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue ) /* PRIVILEGED_FUNCTION */
3223     {
3224         UBaseType_t uxReturn = 0;
3225         int32_t lIndex;
3226         QueueHandle_t xInternalQueueHandle = NULL;
3227 
3228         lIndex = ( int32_t ) xQueue;
3229 
3230         if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3231         {
3232             xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3233 
3234             if( xInternalQueueHandle != NULL )
3235             {
3236                 uxReturn = uxQueueMessagesWaitingFromISR( xInternalQueueHandle );
3237             }
3238         }
3239 
3240         return uxReturn;
3241     }
3242 
3243 /*-----------------------------------------------------------*/
3244 
3245     #if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )
3246 
MPU_xQueueGetMutexHolderFromISR(QueueHandle_t xSemaphore)3247         TaskHandle_t MPU_xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore ) /* PRIVILEGED_FUNCTION */
3248         {
3249             TaskHandle_t xMutexHolderTaskInternalHandle = NULL;
3250             TaskHandle_t xMutexHolderTaskExternalHandle = NULL;
3251             int32_t lIndex, lMutexHolderTaskIndex;
3252             QueueHandle_t xInternalSemaphoreHandle = NULL;
3253 
3254             lIndex = ( int32_t ) xSemaphore;
3255 
3256             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3257             {
3258                 xInternalSemaphoreHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3259 
3260                 if( xInternalSemaphoreHandle != NULL )
3261                 {
3262                     xMutexHolderTaskInternalHandle = xQueueGetMutexHolder( xInternalSemaphoreHandle );
3263 
3264                     if( xMutexHolderTaskInternalHandle != NULL )
3265                     {
3266                         lMutexHolderTaskIndex = MPU_GetIndexForTaskHandle( xMutexHolderTaskInternalHandle );
3267 
3268                         if( lMutexHolderTaskIndex != -1 )
3269                         {
3270                             xMutexHolderTaskExternalHandle = ( TaskHandle_t ) ( CONVERT_TO_EXTERNAL_INDEX( lMutexHolderTaskIndex ) );
3271                         }
3272                     }
3273                 }
3274             }
3275 
3276             return xMutexHolderTaskExternalHandle;
3277         }
3278 
3279     #endif /* #if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) ) */
3280 /*-----------------------------------------------------------*/
3281 
3282     #if ( configUSE_QUEUE_SETS == 1 )
3283 
MPU_xQueueSelectFromSetFromISR(QueueSetHandle_t xQueueSet)3284         QueueSetMemberHandle_t MPU_xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet ) /* PRIVILEGED_FUNCTION */
3285         {
3286             QueueSetHandle_t xInternalQueueSetHandle = NULL;
3287             QueueSetMemberHandle_t xSelectedMemberInternal = NULL;
3288             QueueSetMemberHandle_t xSelectedMemberExternal = NULL;
3289             int32_t lIndexQueueSet, lIndexSelectedMember;
3290 
3291             lIndexQueueSet = ( int32_t ) xQueueSet;
3292 
3293             if( IS_EXTERNAL_INDEX_VALID( lIndexQueueSet ) != pdFALSE )
3294             {
3295                 xInternalQueueSetHandle = MPU_GetQueueSetHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndexQueueSet ) );
3296 
3297                 if( xInternalQueueSetHandle != NULL )
3298                 {
3299                     xSelectedMemberInternal = xQueueSelectFromSetFromISR( xInternalQueueSetHandle );
3300 
3301                     if( xSelectedMemberInternal != NULL )
3302                     {
3303                         lIndexSelectedMember = MPU_GetIndexForQueueSetMemberHandle( xSelectedMemberInternal );
3304 
3305                         if( lIndexSelectedMember != -1 )
3306                         {
3307                             xSelectedMemberExternal = ( QueueSetMemberHandle_t ) ( CONVERT_TO_EXTERNAL_INDEX( lIndexSelectedMember ) );
3308                         }
3309                     }
3310                 }
3311             }
3312 
3313             return xSelectedMemberExternal;
3314         }
3315 
3316     #endif /* if ( configUSE_QUEUE_SETS == 1 ) */
3317 /*-----------------------------------------------------------*/
3318 
3319 /*-----------------------------------------------------------*/
3320 /*            MPU wrappers for timers APIs.                  */
3321 /*-----------------------------------------------------------*/
3322 
3323     #if ( configUSE_TIMERS == 1 )
3324 
3325         void * MPU_pvTimerGetTimerIDImpl( const TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
3326 
MPU_pvTimerGetTimerIDImpl(const TimerHandle_t xTimer)3327         void * MPU_pvTimerGetTimerIDImpl( const TimerHandle_t xTimer ) /* PRIVILEGED_FUNCTION */
3328         {
3329             void * pvReturn = NULL;
3330             TimerHandle_t xInternalTimerHandle = NULL;
3331             int32_t lIndex;
3332             BaseType_t xCallingTaskIsAuthorizedToAccessTimer = pdFALSE;
3333 
3334             lIndex = ( int32_t ) xTimer;
3335 
3336             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3337             {
3338                 xCallingTaskIsAuthorizedToAccessTimer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3339 
3340                 if( xCallingTaskIsAuthorizedToAccessTimer == pdTRUE )
3341                 {
3342                     xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3343 
3344                     if( xInternalTimerHandle != NULL )
3345                     {
3346                         pvReturn = pvTimerGetTimerID( xInternalTimerHandle );
3347                     }
3348                 }
3349             }
3350 
3351             return pvReturn;
3352         }
3353 
3354     #endif /* if ( configUSE_TIMERS == 1 ) */
3355 /*-----------------------------------------------------------*/
3356 
3357     #if ( configUSE_TIMERS == 1 )
3358 
3359         void MPU_vTimerSetTimerIDImpl( TimerHandle_t xTimer,
3360                                        void * pvNewID ) PRIVILEGED_FUNCTION;
3361 
MPU_vTimerSetTimerIDImpl(TimerHandle_t xTimer,void * pvNewID)3362         void MPU_vTimerSetTimerIDImpl( TimerHandle_t xTimer,
3363                                        void * pvNewID ) /* PRIVILEGED_FUNCTION */
3364         {
3365             TimerHandle_t xInternalTimerHandle = NULL;
3366             int32_t lIndex;
3367             BaseType_t xCallingTaskIsAuthorizedToAccessTimer = pdFALSE;
3368 
3369             lIndex = ( int32_t ) xTimer;
3370 
3371             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3372             {
3373                 xCallingTaskIsAuthorizedToAccessTimer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3374 
3375                 if( xCallingTaskIsAuthorizedToAccessTimer == pdTRUE )
3376                 {
3377                     xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3378 
3379                     if( xInternalTimerHandle != NULL )
3380                     {
3381                         vTimerSetTimerID( xInternalTimerHandle, pvNewID );
3382                     }
3383                 }
3384             }
3385         }
3386 
3387     #endif /* if ( configUSE_TIMERS == 1 ) */
3388 /*-----------------------------------------------------------*/
3389 
3390     #if ( configUSE_TIMERS == 1 )
3391 
3392         BaseType_t MPU_xTimerIsTimerActiveImpl( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
3393 
MPU_xTimerIsTimerActiveImpl(TimerHandle_t xTimer)3394         BaseType_t MPU_xTimerIsTimerActiveImpl( TimerHandle_t xTimer ) /* PRIVILEGED_FUNCTION */
3395         {
3396             BaseType_t xReturn = pdFALSE;
3397             TimerHandle_t xInternalTimerHandle = NULL;
3398             int32_t lIndex;
3399             BaseType_t xCallingTaskIsAuthorizedToAccessTimer = pdFALSE;
3400 
3401             lIndex = ( int32_t ) xTimer;
3402 
3403             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3404             {
3405                 xCallingTaskIsAuthorizedToAccessTimer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3406 
3407                 if( xCallingTaskIsAuthorizedToAccessTimer == pdTRUE )
3408                 {
3409                     xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3410 
3411                     if( xInternalTimerHandle != NULL )
3412                     {
3413                         xReturn = xTimerIsTimerActive( xInternalTimerHandle );
3414                     }
3415                 }
3416             }
3417 
3418             return xReturn;
3419         }
3420 
3421     #endif /* if ( configUSE_TIMERS == 1 ) */
3422 /*-----------------------------------------------------------*/
3423 
3424     #if ( configUSE_TIMERS == 1 )
3425 
3426         TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandleImpl( void ) PRIVILEGED_FUNCTION;
3427 
MPU_xTimerGetTimerDaemonTaskHandleImpl(void)3428         TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandleImpl( void ) /* PRIVILEGED_FUNCTION */
3429         {
3430             TaskHandle_t xReturn;
3431 
3432             xReturn = xTimerGetTimerDaemonTaskHandle();
3433 
3434             return xReturn;
3435         }
3436 
3437     #endif /* if ( configUSE_TIMERS == 1 ) */
3438 /*-----------------------------------------------------------*/
3439 
3440     #if ( configUSE_TIMERS == 1 )
3441 
MPU_xTimerGenericCommandFromTask(TimerHandle_t xTimer,const BaseType_t xCommandID,const TickType_t xOptionalValue,BaseType_t * const pxHigherPriorityTaskWoken,const TickType_t xTicksToWait)3442         BaseType_t MPU_xTimerGenericCommandFromTask( TimerHandle_t xTimer,
3443                                                      const BaseType_t xCommandID,
3444                                                      const TickType_t xOptionalValue,
3445                                                      BaseType_t * const pxHigherPriorityTaskWoken,
3446                                                      const TickType_t xTicksToWait ) /* FREERTOS_SYSTEM_CALL */
3447         {
3448             BaseType_t xReturn = pdFALSE;
3449             xTimerGenericCommandFromTaskParams_t xParams;
3450 
3451             xParams.xTimer = xTimer;
3452             xParams.xCommandID = xCommandID;
3453             xParams.xOptionalValue = xOptionalValue;
3454             xParams.pxHigherPriorityTaskWoken = pxHigherPriorityTaskWoken;
3455             xParams.xTicksToWait = xTicksToWait;
3456 
3457             xReturn = MPU_xTimerGenericCommandFromTaskEntry( &( xParams ) );
3458 
3459             return xReturn;
3460         }
3461 
3462         BaseType_t MPU_xTimerGenericCommandFromTaskImpl( const xTimerGenericCommandFromTaskParams_t * pxParams ) PRIVILEGED_FUNCTION;
3463 
MPU_xTimerGenericCommandFromTaskImpl(const xTimerGenericCommandFromTaskParams_t * pxParams)3464         BaseType_t MPU_xTimerGenericCommandFromTaskImpl( const xTimerGenericCommandFromTaskParams_t * pxParams ) /* PRIVILEGED_FUNCTION */
3465         {
3466             BaseType_t xReturn = pdFALSE;
3467             TimerHandle_t xInternalTimerHandle = NULL;
3468             int32_t lIndex;
3469             BaseType_t xIsHigherPriorityTaskWokenWriteable = pdFALSE;
3470             BaseType_t xCallingTaskIsAuthorizedToAccessTimer = pdFALSE;
3471             BaseType_t xAreParamsReadable = pdFALSE;
3472 
3473             if( pxParams != NULL )
3474             {
3475                 xAreParamsReadable = xPortIsAuthorizedToAccessBuffer( pxParams,
3476                                                                       sizeof( xTimerGenericCommandFromTaskParams_t ),
3477                                                                       tskMPU_READ_PERMISSION );
3478             }
3479 
3480             if( xAreParamsReadable == pdTRUE )
3481             {
3482                 if( pxParams->xCommandID < tmrFIRST_FROM_ISR_COMMAND )
3483                 {
3484                     if( pxParams->pxHigherPriorityTaskWoken != NULL )
3485                     {
3486                         xIsHigherPriorityTaskWokenWriteable = xPortIsAuthorizedToAccessBuffer( pxParams->pxHigherPriorityTaskWoken,
3487                                                                                                sizeof( BaseType_t ),
3488                                                                                                tskMPU_WRITE_PERMISSION );
3489                     }
3490 
3491                     if( ( pxParams->pxHigherPriorityTaskWoken == NULL ) ||
3492                         ( xIsHigherPriorityTaskWokenWriteable == pdTRUE ) )
3493                     {
3494                         lIndex = ( int32_t ) ( pxParams->xTimer );
3495 
3496                         if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3497                         {
3498                             xCallingTaskIsAuthorizedToAccessTimer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3499 
3500                             if( xCallingTaskIsAuthorizedToAccessTimer == pdTRUE )
3501                             {
3502                                 xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3503 
3504                                 if( xInternalTimerHandle != NULL )
3505                                 {
3506                                     xReturn = xTimerGenericCommandFromTask( xInternalTimerHandle,
3507                                                                             pxParams->xCommandID,
3508                                                                             pxParams->xOptionalValue,
3509                                                                             pxParams->pxHigherPriorityTaskWoken,
3510                                                                             pxParams->xTicksToWait );
3511                                 }
3512                             }
3513                         }
3514                     }
3515                 }
3516             }
3517 
3518             return xReturn;
3519         }
3520 
3521     #endif /* if ( configUSE_TIMERS == 1 ) */
3522 /*-----------------------------------------------------------*/
3523 
3524     #if ( configUSE_TIMERS == 1 )
3525 
3526         const char * MPU_pcTimerGetNameImpl( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
3527 
MPU_pcTimerGetNameImpl(TimerHandle_t xTimer)3528         const char * MPU_pcTimerGetNameImpl( TimerHandle_t xTimer ) /* PRIVILEGED_FUNCTION */
3529         {
3530             const char * pcReturn = NULL;
3531             TimerHandle_t xInternalTimerHandle = NULL;
3532             int32_t lIndex;
3533             BaseType_t xCallingTaskIsAuthorizedToAccessTimer = pdFALSE;
3534 
3535             lIndex = ( int32_t ) xTimer;
3536 
3537             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3538             {
3539                 xCallingTaskIsAuthorizedToAccessTimer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3540 
3541                 if( xCallingTaskIsAuthorizedToAccessTimer == pdTRUE )
3542                 {
3543                     xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3544 
3545                     if( xInternalTimerHandle != NULL )
3546                     {
3547                         pcReturn = pcTimerGetName( xInternalTimerHandle );
3548                     }
3549                 }
3550             }
3551 
3552             return pcReturn;
3553         }
3554 
3555     #endif /* if ( configUSE_TIMERS == 1 ) */
3556 /*-----------------------------------------------------------*/
3557 
3558     #if ( configUSE_TIMERS == 1 )
3559 
3560         void MPU_vTimerSetReloadModeImpl( TimerHandle_t xTimer,
3561                                           const UBaseType_t uxAutoReload ) PRIVILEGED_FUNCTION;
3562 
MPU_vTimerSetReloadModeImpl(TimerHandle_t xTimer,const UBaseType_t uxAutoReload)3563         void MPU_vTimerSetReloadModeImpl( TimerHandle_t xTimer,
3564                                           const UBaseType_t uxAutoReload ) /* PRIVILEGED_FUNCTION */
3565         {
3566             TimerHandle_t xInternalTimerHandle = NULL;
3567             int32_t lIndex;
3568             BaseType_t xCallingTaskIsAuthorizedToAccessTimer = pdFALSE;
3569 
3570             lIndex = ( int32_t ) xTimer;
3571 
3572             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3573             {
3574                 xCallingTaskIsAuthorizedToAccessTimer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3575 
3576                 if( xCallingTaskIsAuthorizedToAccessTimer == pdTRUE )
3577                 {
3578                     xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3579 
3580                     if( xInternalTimerHandle != NULL )
3581                     {
3582                         vTimerSetReloadMode( xInternalTimerHandle, uxAutoReload );
3583                     }
3584                 }
3585             }
3586         }
3587 
3588     #endif /* if ( configUSE_TIMERS == 1 ) */
3589 /*-----------------------------------------------------------*/
3590 
3591     #if ( configUSE_TIMERS == 1 )
3592 
3593         BaseType_t MPU_xTimerGetReloadModeImpl( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
3594 
MPU_xTimerGetReloadModeImpl(TimerHandle_t xTimer)3595         BaseType_t MPU_xTimerGetReloadModeImpl( TimerHandle_t xTimer ) /* PRIVILEGED_FUNCTION */
3596         {
3597             BaseType_t xReturn = pdFALSE;
3598             TimerHandle_t xInternalTimerHandle = NULL;
3599             int32_t lIndex;
3600             BaseType_t xCallingTaskIsAuthorizedToAccessTimer = pdFALSE;
3601 
3602             lIndex = ( int32_t ) xTimer;
3603 
3604             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3605             {
3606                 xCallingTaskIsAuthorizedToAccessTimer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3607 
3608                 if( xCallingTaskIsAuthorizedToAccessTimer == pdTRUE )
3609                 {
3610                     xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3611 
3612                     if( xInternalTimerHandle != NULL )
3613                     {
3614                         xReturn = xTimerGetReloadMode( xInternalTimerHandle );
3615                     }
3616                 }
3617             }
3618 
3619             return xReturn;
3620         }
3621 
3622     #endif /* if ( configUSE_TIMERS == 1 ) */
3623 /*-----------------------------------------------------------*/
3624 
3625     #if ( configUSE_TIMERS == 1 )
3626 
3627         UBaseType_t MPU_uxTimerGetReloadModeImpl( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
3628 
MPU_uxTimerGetReloadModeImpl(TimerHandle_t xTimer)3629         UBaseType_t MPU_uxTimerGetReloadModeImpl( TimerHandle_t xTimer ) /* PRIVILEGED_FUNCTION */
3630         {
3631             UBaseType_t uxReturn = 0;
3632             TimerHandle_t xInternalTimerHandle = NULL;
3633             int32_t lIndex;
3634             BaseType_t xCallingTaskIsAuthorizedToAccessTimer = pdFALSE;
3635 
3636             lIndex = ( int32_t ) xTimer;
3637 
3638             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3639             {
3640                 xCallingTaskIsAuthorizedToAccessTimer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3641 
3642                 if( xCallingTaskIsAuthorizedToAccessTimer == pdTRUE )
3643                 {
3644                     xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3645 
3646                     if( xInternalTimerHandle != NULL )
3647                     {
3648                         uxReturn = uxTimerGetReloadMode( xInternalTimerHandle );
3649                     }
3650                 }
3651             }
3652 
3653             return uxReturn;
3654         }
3655 
3656     #endif /* if ( configUSE_TIMERS == 1 ) */
3657 /*-----------------------------------------------------------*/
3658 
3659     #if ( configUSE_TIMERS == 1 )
3660 
3661         TickType_t MPU_xTimerGetPeriodImpl( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
3662 
MPU_xTimerGetPeriodImpl(TimerHandle_t xTimer)3663         TickType_t MPU_xTimerGetPeriodImpl( TimerHandle_t xTimer ) /* PRIVILEGED_FUNCTION */
3664         {
3665             TickType_t xReturn = 0;
3666             TimerHandle_t xInternalTimerHandle = NULL;
3667             int32_t lIndex;
3668             BaseType_t xCallingTaskIsAuthorizedToAccessTimer = pdFALSE;
3669 
3670             lIndex = ( int32_t ) xTimer;
3671 
3672             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3673             {
3674                 xCallingTaskIsAuthorizedToAccessTimer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3675 
3676                 if( xCallingTaskIsAuthorizedToAccessTimer == pdTRUE )
3677                 {
3678                     xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3679 
3680                     if( xInternalTimerHandle != NULL )
3681                     {
3682                         xReturn = xTimerGetPeriod( xInternalTimerHandle );
3683                     }
3684                 }
3685             }
3686 
3687             return xReturn;
3688         }
3689 
3690     #endif /* if ( configUSE_TIMERS == 1 ) */
3691 /*-----------------------------------------------------------*/
3692 
3693     #if ( configUSE_TIMERS == 1 )
3694 
3695         TickType_t MPU_xTimerGetExpiryTimeImpl( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
3696 
MPU_xTimerGetExpiryTimeImpl(TimerHandle_t xTimer)3697         TickType_t MPU_xTimerGetExpiryTimeImpl( TimerHandle_t xTimer ) /* PRIVILEGED_FUNCTION */
3698         {
3699             TickType_t xReturn = 0;
3700             TimerHandle_t xInternalTimerHandle = NULL;
3701             int32_t lIndex;
3702             BaseType_t xCallingTaskIsAuthorizedToAccessTimer = pdFALSE;
3703 
3704             lIndex = ( int32_t ) xTimer;
3705 
3706             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3707             {
3708                 xCallingTaskIsAuthorizedToAccessTimer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3709 
3710                 if( xCallingTaskIsAuthorizedToAccessTimer == pdTRUE )
3711                 {
3712                     xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3713 
3714                     if( xInternalTimerHandle != NULL )
3715                     {
3716                         xReturn = xTimerGetExpiryTime( xInternalTimerHandle );
3717                     }
3718                 }
3719             }
3720 
3721             return xReturn;
3722         }
3723 
3724     #endif /* if ( configUSE_TIMERS == 1 ) */
3725 /*-----------------------------------------------------------*/
3726 
3727 /* Privileged only wrappers for Timer APIs. These are needed so that
3728  * the application can use opaque handles maintained in mpu_wrappers.c
3729  * with all the APIs. */
3730 /*-----------------------------------------------------------*/
3731 
3732     #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configUSE_TIMERS == 1 )
3733 
MPU_xTimerCreate(const char * const pcTimerName,const TickType_t xTimerPeriodInTicks,const UBaseType_t uxAutoReload,void * const pvTimerID,TimerCallbackFunction_t pxCallbackFunction)3734         TimerHandle_t MPU_xTimerCreate( const char * const pcTimerName,
3735                                         const TickType_t xTimerPeriodInTicks,
3736                                         const UBaseType_t uxAutoReload,
3737                                         void * const pvTimerID,
3738                                         TimerCallbackFunction_t pxCallbackFunction ) /* PRIVILEGED_FUNCTION */
3739         {
3740             TimerHandle_t xInternalTimerHandle = NULL;
3741             TimerHandle_t xExternalTimerHandle = NULL;
3742             int32_t lIndex;
3743 
3744             lIndex = MPU_GetFreeIndexInKernelObjectPool();
3745 
3746             if( lIndex != -1 )
3747             {
3748                 xInternalTimerHandle = xTimerCreate( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, MPU_TimerCallback );
3749 
3750                 if( xInternalTimerHandle != NULL )
3751                 {
3752                     MPU_StoreTimerHandleAtIndex( lIndex, xInternalTimerHandle, pxCallbackFunction );
3753                     xExternalTimerHandle = ( TimerHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
3754                 }
3755                 else
3756                 {
3757                     MPU_SetIndexFreeInKernelObjectPool( lIndex );
3758                 }
3759             }
3760 
3761             return xExternalTimerHandle;
3762         }
3763 
3764     #endif /* if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configUSE_TIMERS == 1 ) */
3765 /*-----------------------------------------------------------*/
3766 
3767     #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_TIMERS == 1 )
3768 
MPU_xTimerCreateStatic(const char * const pcTimerName,const TickType_t xTimerPeriodInTicks,const UBaseType_t uxAutoReload,void * const pvTimerID,TimerCallbackFunction_t pxCallbackFunction,StaticTimer_t * pxTimerBuffer)3769         TimerHandle_t MPU_xTimerCreateStatic( const char * const pcTimerName,
3770                                               const TickType_t xTimerPeriodInTicks,
3771                                               const UBaseType_t uxAutoReload,
3772                                               void * const pvTimerID,
3773                                               TimerCallbackFunction_t pxCallbackFunction,
3774                                               StaticTimer_t * pxTimerBuffer ) /* PRIVILEGED_FUNCTION */
3775         {
3776             TimerHandle_t xInternalTimerHandle = NULL;
3777             TimerHandle_t xExternalTimerHandle = NULL;
3778             int32_t lIndex;
3779 
3780             lIndex = MPU_GetFreeIndexInKernelObjectPool();
3781 
3782             if( lIndex != -1 )
3783             {
3784                 xInternalTimerHandle = xTimerCreateStatic( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, MPU_TimerCallback, pxTimerBuffer );
3785 
3786                 if( xInternalTimerHandle != NULL )
3787                 {
3788                     MPU_StoreTimerHandleAtIndex( lIndex, xInternalTimerHandle, pxCallbackFunction );
3789                     xExternalTimerHandle = ( TimerHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
3790                 }
3791                 else
3792                 {
3793                     MPU_SetIndexFreeInKernelObjectPool( lIndex );
3794                 }
3795             }
3796 
3797             return xExternalTimerHandle;
3798         }
3799 
3800     #endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_TIMERS == 1 ) */
3801 /*-----------------------------------------------------------*/
3802 
3803     #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_TIMERS == 1 )
3804 
MPU_xTimerGetStaticBuffer(TimerHandle_t xTimer,StaticTimer_t ** ppxTimerBuffer)3805         BaseType_t MPU_xTimerGetStaticBuffer( TimerHandle_t xTimer,
3806                                               StaticTimer_t ** ppxTimerBuffer ) /* PRIVILEGED_FUNCTION */
3807         {
3808             TimerHandle_t xInternalTimerHandle = NULL;
3809             int32_t lIndex;
3810             BaseType_t xReturn = pdFALSE;
3811 
3812             lIndex = ( int32_t ) xTimer;
3813 
3814             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3815             {
3816                 xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3817 
3818                 if( xInternalTimerHandle != NULL )
3819                 {
3820                     xReturn = xTimerGetStaticBuffer( xInternalTimerHandle, ppxTimerBuffer );
3821                 }
3822             }
3823 
3824             return xReturn;
3825         }
3826 
3827     #endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_TIMERS == 1 ) */
3828 /*-----------------------------------------------------------*/
3829 
3830     #if ( configUSE_TIMERS == 1 )
3831 
MPU_xTimerGenericCommandFromISR(TimerHandle_t xTimer,const BaseType_t xCommandID,const TickType_t xOptionalValue,BaseType_t * const pxHigherPriorityTaskWoken,const TickType_t xTicksToWait)3832         BaseType_t MPU_xTimerGenericCommandFromISR( TimerHandle_t xTimer,
3833                                                     const BaseType_t xCommandID,
3834                                                     const TickType_t xOptionalValue,
3835                                                     BaseType_t * const pxHigherPriorityTaskWoken,
3836                                                     const TickType_t xTicksToWait ) /* PRIVILEGED_FUNCTION */
3837         {
3838             BaseType_t xReturn = pdFALSE;
3839             TimerHandle_t xInternalTimerHandle = NULL;
3840             int32_t lIndex;
3841             BaseType_t xIsHigherPriorityTaskWokenWriteable = pdFALSE;
3842 
3843             if( pxHigherPriorityTaskWoken != NULL )
3844             {
3845                 xIsHigherPriorityTaskWokenWriteable = xPortIsAuthorizedToAccessBuffer( pxHigherPriorityTaskWoken,
3846                                                                                        sizeof( BaseType_t ),
3847                                                                                        tskMPU_WRITE_PERMISSION );
3848             }
3849 
3850             if( ( pxHigherPriorityTaskWoken == NULL ) || ( xIsHigherPriorityTaskWokenWriteable == pdTRUE ) )
3851             {
3852                 lIndex = ( int32_t ) xTimer;
3853 
3854                 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3855                 {
3856                     xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3857 
3858                     if( xInternalTimerHandle != NULL )
3859                     {
3860                         xReturn = xTimerGenericCommandFromISR( xInternalTimerHandle, xCommandID, xOptionalValue, pxHigherPriorityTaskWoken, xTicksToWait );
3861                     }
3862                 }
3863             }
3864 
3865             return xReturn;
3866         }
3867 
3868     #endif /* if ( configUSE_TIMERS == 1 ) */
3869 /*-----------------------------------------------------------*/
3870 
3871 /*-----------------------------------------------------------*/
3872 /*           MPU wrappers for event group APIs.              */
3873 /*-----------------------------------------------------------*/
3874 
3875     #if ( configUSE_EVENT_GROUPS == 1 )
3876 
MPU_xEventGroupWaitBits(EventGroupHandle_t xEventGroup,const EventBits_t uxBitsToWaitFor,const BaseType_t xClearOnExit,const BaseType_t xWaitForAllBits,TickType_t xTicksToWait)3877         EventBits_t MPU_xEventGroupWaitBits( EventGroupHandle_t xEventGroup,
3878                                              const EventBits_t uxBitsToWaitFor,
3879                                              const BaseType_t xClearOnExit,
3880                                              const BaseType_t xWaitForAllBits,
3881                                              TickType_t xTicksToWait ) /* FREERTOS_SYSTEM_CALL */
3882         {
3883             EventBits_t xReturn = 0;
3884             xEventGroupWaitBitsParams_t xParams;
3885 
3886             xParams.xEventGroup = xEventGroup;
3887             xParams.uxBitsToWaitFor = uxBitsToWaitFor;
3888             xParams.xClearOnExit = xClearOnExit;
3889             xParams.xWaitForAllBits = xWaitForAllBits;
3890             xParams.xTicksToWait = xTicksToWait;
3891 
3892             xReturn = MPU_xEventGroupWaitBitsEntry( &( xParams ) );
3893 
3894             return xReturn;
3895         }
3896 
3897         EventBits_t MPU_xEventGroupWaitBitsImpl( const xEventGroupWaitBitsParams_t * pxParams ) PRIVILEGED_FUNCTION;
3898 
MPU_xEventGroupWaitBitsImpl(const xEventGroupWaitBitsParams_t * pxParams)3899         EventBits_t MPU_xEventGroupWaitBitsImpl( const xEventGroupWaitBitsParams_t * pxParams ) /* PRIVILEGED_FUNCTION */
3900         {
3901             EventBits_t xReturn = 0;
3902             EventGroupHandle_t xInternalEventGroupHandle = NULL;
3903             int32_t lIndex;
3904             BaseType_t xCallingTaskIsAuthorizedToAccessEventGroup = pdFALSE;
3905             BaseType_t xAreParamsReadable = pdFALSE;
3906 
3907             if( pxParams != NULL )
3908             {
3909                 xAreParamsReadable = xPortIsAuthorizedToAccessBuffer( pxParams,
3910                                                                       sizeof( xEventGroupWaitBitsParams_t ),
3911                                                                       tskMPU_READ_PERMISSION );
3912             }
3913 
3914             if( xAreParamsReadable == pdTRUE )
3915             {
3916                 if( ( ( pxParams->uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0U ) &&
3917                     ( pxParams->uxBitsToWaitFor != 0U )
3918                     #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
3919                         && ( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( pxParams->xTicksToWait != 0U ) ) )
3920                     #endif
3921                     )
3922                 {
3923                     lIndex = ( int32_t ) ( pxParams->xEventGroup );
3924 
3925                     if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3926                     {
3927                         xCallingTaskIsAuthorizedToAccessEventGroup = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3928 
3929                         if( xCallingTaskIsAuthorizedToAccessEventGroup == pdTRUE )
3930                         {
3931                             xInternalEventGroupHandle = MPU_GetEventGroupHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3932 
3933                             if( xInternalEventGroupHandle != NULL )
3934                             {
3935                                 xReturn = xEventGroupWaitBits( xInternalEventGroupHandle,
3936                                                                pxParams->uxBitsToWaitFor,
3937                                                                pxParams->xClearOnExit,
3938                                                                pxParams->xWaitForAllBits,
3939                                                                pxParams->xTicksToWait );
3940                             }
3941                         }
3942                     }
3943                 }
3944             }
3945 
3946             return xReturn;
3947         }
3948 
3949     #endif /* #if ( configUSE_EVENT_GROUPS == 1 ) */
3950 /*-----------------------------------------------------------*/
3951 
3952     #if ( configUSE_EVENT_GROUPS == 1 )
3953 
3954         EventBits_t MPU_xEventGroupClearBitsImpl( EventGroupHandle_t xEventGroup,
3955                                                   const EventBits_t uxBitsToClear ) PRIVILEGED_FUNCTION;
3956 
MPU_xEventGroupClearBitsImpl(EventGroupHandle_t xEventGroup,const EventBits_t uxBitsToClear)3957         EventBits_t MPU_xEventGroupClearBitsImpl( EventGroupHandle_t xEventGroup,
3958                                                   const EventBits_t uxBitsToClear ) /* PRIVILEGED_FUNCTION */
3959         {
3960             EventBits_t xReturn = 0;
3961             EventGroupHandle_t xInternalEventGroupHandle = NULL;
3962             int32_t lIndex;
3963             BaseType_t xCallingTaskIsAuthorizedToAccessEventGroup = pdFALSE;
3964 
3965             if( ( uxBitsToClear & eventEVENT_BITS_CONTROL_BYTES ) == 0U )
3966             {
3967                 lIndex = ( int32_t ) xEventGroup;
3968 
3969                 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3970                 {
3971                     xCallingTaskIsAuthorizedToAccessEventGroup = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3972 
3973                     if( xCallingTaskIsAuthorizedToAccessEventGroup == pdTRUE )
3974                     {
3975                         xInternalEventGroupHandle = MPU_GetEventGroupHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3976 
3977                         if( xInternalEventGroupHandle != NULL )
3978                         {
3979                             xReturn = xEventGroupClearBits( xInternalEventGroupHandle, uxBitsToClear );
3980                         }
3981                     }
3982                 }
3983             }
3984 
3985             return xReturn;
3986         }
3987 
3988     #endif /* #if ( configUSE_EVENT_GROUPS == 1 ) */
3989 /*-----------------------------------------------------------*/
3990 
3991     #if ( configUSE_EVENT_GROUPS == 1 )
3992 
3993         EventBits_t MPU_xEventGroupSetBitsImpl( EventGroupHandle_t xEventGroup,
3994                                                 const EventBits_t uxBitsToSet ) PRIVILEGED_FUNCTION;
3995 
MPU_xEventGroupSetBitsImpl(EventGroupHandle_t xEventGroup,const EventBits_t uxBitsToSet)3996         EventBits_t MPU_xEventGroupSetBitsImpl( EventGroupHandle_t xEventGroup,
3997                                                 const EventBits_t uxBitsToSet ) /* PRIVILEGED_FUNCTION */
3998         {
3999             EventBits_t xReturn = 0;
4000             EventGroupHandle_t xInternalEventGroupHandle = NULL;
4001             int32_t lIndex;
4002             BaseType_t xCallingTaskIsAuthorizedToAccessEventGroup = pdFALSE;
4003 
4004             if( ( uxBitsToSet & eventEVENT_BITS_CONTROL_BYTES ) == 0U )
4005             {
4006                 lIndex = ( int32_t ) xEventGroup;
4007 
4008                 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4009                 {
4010                     xCallingTaskIsAuthorizedToAccessEventGroup = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4011 
4012                     if( xCallingTaskIsAuthorizedToAccessEventGroup == pdTRUE )
4013                     {
4014                         xInternalEventGroupHandle = MPU_GetEventGroupHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4015 
4016                         if( xInternalEventGroupHandle != NULL )
4017                         {
4018                             xReturn = xEventGroupSetBits( xInternalEventGroupHandle, uxBitsToSet );
4019                         }
4020                     }
4021                 }
4022             }
4023 
4024             return xReturn;
4025         }
4026 
4027     #endif /* #if ( configUSE_EVENT_GROUPS == 1 ) */
4028 /*-----------------------------------------------------------*/
4029 
4030     #if ( configUSE_EVENT_GROUPS == 1 )
4031 
4032         EventBits_t MPU_xEventGroupSyncImpl( EventGroupHandle_t xEventGroup,
4033                                              const EventBits_t uxBitsToSet,
4034                                              const EventBits_t uxBitsToWaitFor,
4035                                              TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
4036 
MPU_xEventGroupSyncImpl(EventGroupHandle_t xEventGroup,const EventBits_t uxBitsToSet,const EventBits_t uxBitsToWaitFor,TickType_t xTicksToWait)4037         EventBits_t MPU_xEventGroupSyncImpl( EventGroupHandle_t xEventGroup,
4038                                              const EventBits_t uxBitsToSet,
4039                                              const EventBits_t uxBitsToWaitFor,
4040                                              TickType_t xTicksToWait ) /* PRIVILEGED_FUNCTION */
4041         {
4042             EventBits_t xReturn = 0;
4043             EventGroupHandle_t xInternalEventGroupHandle = NULL;
4044             int32_t lIndex;
4045             BaseType_t xCallingTaskIsAuthorizedToAccessEventGroup = pdFALSE;
4046 
4047             if( ( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0U ) &&
4048                 ( uxBitsToWaitFor != 0U )
4049                 #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
4050                     && ( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0U ) ) )
4051                 #endif
4052                 )
4053             {
4054                 lIndex = ( int32_t ) xEventGroup;
4055 
4056                 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4057                 {
4058                     xCallingTaskIsAuthorizedToAccessEventGroup = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4059 
4060                     if( xCallingTaskIsAuthorizedToAccessEventGroup == pdTRUE )
4061                     {
4062                         xInternalEventGroupHandle = MPU_GetEventGroupHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4063 
4064                         if( xInternalEventGroupHandle != NULL )
4065                         {
4066                             xReturn = xEventGroupSync( xInternalEventGroupHandle, uxBitsToSet, uxBitsToWaitFor, xTicksToWait );
4067                         }
4068                     }
4069                 }
4070             }
4071 
4072             return xReturn;
4073         }
4074 
4075     #endif /* #if ( configUSE_EVENT_GROUPS == 1 ) */
4076 /*-----------------------------------------------------------*/
4077 
4078     #if ( ( configUSE_EVENT_GROUPS == 1 ) && ( configUSE_TRACE_FACILITY == 1 ) )
4079 
4080         UBaseType_t MPU_uxEventGroupGetNumberImpl( void * xEventGroup ) PRIVILEGED_FUNCTION;
4081 
MPU_uxEventGroupGetNumberImpl(void * xEventGroup)4082         UBaseType_t MPU_uxEventGroupGetNumberImpl( void * xEventGroup ) /* PRIVILEGED_FUNCTION */
4083         {
4084             UBaseType_t xReturn = 0;
4085             EventGroupHandle_t xInternalEventGroupHandle = NULL;
4086             int32_t lIndex;
4087             BaseType_t xCallingTaskIsAuthorizedToAccessEventGroup = pdFALSE;
4088 
4089             lIndex = ( int32_t ) xEventGroup;
4090 
4091             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4092             {
4093                 xCallingTaskIsAuthorizedToAccessEventGroup = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4094 
4095                 if( xCallingTaskIsAuthorizedToAccessEventGroup == pdTRUE )
4096                 {
4097                     xInternalEventGroupHandle = MPU_GetEventGroupHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4098 
4099                     if( xInternalEventGroupHandle != NULL )
4100                     {
4101                         xReturn = uxEventGroupGetNumber( xInternalEventGroupHandle );
4102                     }
4103                 }
4104             }
4105 
4106             return xReturn;
4107         }
4108 
4109     #endif /* #if ( ( configUSE_EVENT_GROUPS == 1 ) && ( configUSE_TRACE_FACILITY == 1 ) ) */
4110 /*-----------------------------------------------------------*/
4111 
4112     #if ( ( configUSE_EVENT_GROUPS == 1 ) && ( configUSE_TRACE_FACILITY == 1 ) )
4113 
4114         void MPU_vEventGroupSetNumberImpl( void * xEventGroup,
4115                                            UBaseType_t uxEventGroupNumber ) PRIVILEGED_FUNCTION;
4116 
MPU_vEventGroupSetNumberImpl(void * xEventGroup,UBaseType_t uxEventGroupNumber)4117         void MPU_vEventGroupSetNumberImpl( void * xEventGroup,
4118                                            UBaseType_t uxEventGroupNumber ) /* PRIVILEGED_FUNCTION */
4119         {
4120             EventGroupHandle_t xInternalEventGroupHandle = NULL;
4121             int32_t lIndex;
4122             BaseType_t xCallingTaskIsAuthorizedToAccessEventGroup = pdFALSE;
4123 
4124             lIndex = ( int32_t ) xEventGroup;
4125 
4126             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4127             {
4128                 xCallingTaskIsAuthorizedToAccessEventGroup = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4129 
4130                 if( xCallingTaskIsAuthorizedToAccessEventGroup == pdTRUE )
4131                 {
4132                     xInternalEventGroupHandle = MPU_GetEventGroupHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4133 
4134                     if( xInternalEventGroupHandle != NULL )
4135                     {
4136                         vEventGroupSetNumber( xInternalEventGroupHandle, uxEventGroupNumber );
4137                     }
4138                 }
4139             }
4140         }
4141 
4142     #endif /* #if ( ( configUSE_EVENT_GROUPS == 1 ) && ( configUSE_TRACE_FACILITY == 1 ) ) */
4143 /*-----------------------------------------------------------*/
4144 
4145 /* Privileged only wrappers for Event Group APIs. These are needed so that
4146  * the application can use opaque handles maintained in mpu_wrappers.c
4147  * with all the APIs. */
4148 /*-----------------------------------------------------------*/
4149 
4150     #if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configUSE_EVENT_GROUPS == 1 ) )
4151 
MPU_xEventGroupCreate(void)4152         EventGroupHandle_t MPU_xEventGroupCreate( void ) /* PRIVILEGED_FUNCTION */
4153         {
4154             EventGroupHandle_t xInternalEventGroupHandle = NULL;
4155             EventGroupHandle_t xExternalEventGroupHandle = NULL;
4156             int32_t lIndex;
4157 
4158             lIndex = MPU_GetFreeIndexInKernelObjectPool();
4159 
4160             if( lIndex != -1 )
4161             {
4162                 xInternalEventGroupHandle = xEventGroupCreate();
4163 
4164                 if( xInternalEventGroupHandle != NULL )
4165                 {
4166                     MPU_StoreEventGroupHandleAtIndex( lIndex, xInternalEventGroupHandle );
4167                     xExternalEventGroupHandle = ( EventGroupHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
4168                 }
4169                 else
4170                 {
4171                     MPU_SetIndexFreeInKernelObjectPool( lIndex );
4172                 }
4173             }
4174 
4175             return xExternalEventGroupHandle;
4176         }
4177 
4178     #endif /* #if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configUSE_EVENT_GROUPS == 1 ) ) */
4179 /*-----------------------------------------------------------*/
4180 
4181     #if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_EVENT_GROUPS == 1 ) )
4182 
MPU_xEventGroupCreateStatic(StaticEventGroup_t * pxEventGroupBuffer)4183         EventGroupHandle_t MPU_xEventGroupCreateStatic( StaticEventGroup_t * pxEventGroupBuffer ) /* PRIVILEGED_FUNCTION */
4184         {
4185             EventGroupHandle_t xInternalEventGroupHandle = NULL;
4186             EventGroupHandle_t xExternalEventGroupHandle = NULL;
4187             int32_t lIndex;
4188 
4189             lIndex = MPU_GetFreeIndexInKernelObjectPool();
4190 
4191             if( lIndex != -1 )
4192             {
4193                 xInternalEventGroupHandle = xEventGroupCreateStatic( pxEventGroupBuffer );
4194 
4195                 if( xInternalEventGroupHandle != NULL )
4196                 {
4197                     MPU_StoreEventGroupHandleAtIndex( lIndex, xInternalEventGroupHandle );
4198                     xExternalEventGroupHandle = ( EventGroupHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
4199                 }
4200                 else
4201                 {
4202                     MPU_SetIndexFreeInKernelObjectPool( lIndex );
4203                 }
4204             }
4205 
4206             return xExternalEventGroupHandle;
4207         }
4208 
4209     #endif /* #if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_EVENT_GROUPS == 1 ) ) */
4210 /*-----------------------------------------------------------*/
4211 
4212     #if ( configUSE_EVENT_GROUPS == 1 )
4213 
MPU_vEventGroupDelete(EventGroupHandle_t xEventGroup)4214         void MPU_vEventGroupDelete( EventGroupHandle_t xEventGroup ) /* PRIVILEGED_FUNCTION */
4215         {
4216             EventGroupHandle_t xInternalEventGroupHandle = NULL;
4217             int32_t lIndex;
4218 
4219             lIndex = ( int32_t ) xEventGroup;
4220 
4221             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4222             {
4223                 xInternalEventGroupHandle = MPU_GetEventGroupHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4224 
4225                 if( xInternalEventGroupHandle != NULL )
4226                 {
4227                     vEventGroupDelete( xInternalEventGroupHandle );
4228                     MPU_SetIndexFreeInKernelObjectPool( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4229                 }
4230             }
4231         }
4232 
4233     #endif /* #if ( configUSE_EVENT_GROUPS == 1 ) */
4234 /*-----------------------------------------------------------*/
4235 
4236     #if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_EVENT_GROUPS == 1 ) )
4237 
MPU_xEventGroupGetStaticBuffer(EventGroupHandle_t xEventGroup,StaticEventGroup_t ** ppxEventGroupBuffer)4238         BaseType_t MPU_xEventGroupGetStaticBuffer( EventGroupHandle_t xEventGroup,
4239                                                    StaticEventGroup_t ** ppxEventGroupBuffer ) /* PRIVILEGED_FUNCTION */
4240         {
4241             BaseType_t xReturn = pdFALSE;
4242             EventGroupHandle_t xInternalEventGroupHandle = NULL;
4243             int32_t lIndex;
4244 
4245             lIndex = ( int32_t ) xEventGroup;
4246 
4247             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4248             {
4249                 xInternalEventGroupHandle = MPU_GetEventGroupHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4250 
4251                 if( xInternalEventGroupHandle != NULL )
4252                 {
4253                     xReturn = xEventGroupGetStaticBuffer( xInternalEventGroupHandle, ppxEventGroupBuffer );
4254                 }
4255             }
4256 
4257             return xReturn;
4258         }
4259 
4260     #endif /* #if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_EVENT_GROUPS == 1 ) ) */
4261 /*-----------------------------------------------------------*/
4262 
4263     #if ( ( configUSE_EVENT_GROUPS == 1 ) && ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) )
4264 
MPU_xEventGroupClearBitsFromISR(EventGroupHandle_t xEventGroup,const EventBits_t uxBitsToClear)4265         BaseType_t MPU_xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup,
4266                                                     const EventBits_t uxBitsToClear ) /* PRIVILEGED_FUNCTION */
4267         {
4268             BaseType_t xReturn = pdFALSE;
4269             EventGroupHandle_t xInternalEventGroupHandle = NULL;
4270             int32_t lIndex;
4271 
4272             lIndex = ( int32_t ) xEventGroup;
4273 
4274             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4275             {
4276                 xInternalEventGroupHandle = MPU_GetEventGroupHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4277 
4278                 if( xInternalEventGroupHandle != NULL )
4279                 {
4280                     xReturn = xEventGroupClearBitsFromISR( xInternalEventGroupHandle, uxBitsToClear );
4281                 }
4282             }
4283 
4284             return xReturn;
4285         }
4286 
4287     #endif /* #if ( ( configUSE_EVENT_GROUPS == 1 ) && ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) ) */
4288 /*-----------------------------------------------------------*/
4289 
4290     #if ( ( configUSE_EVENT_GROUPS == 1 ) && ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) )
4291 
MPU_xEventGroupSetBitsFromISR(EventGroupHandle_t xEventGroup,const EventBits_t uxBitsToSet,BaseType_t * pxHigherPriorityTaskWoken)4292         BaseType_t MPU_xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup,
4293                                                   const EventBits_t uxBitsToSet,
4294                                                   BaseType_t * pxHigherPriorityTaskWoken ) /* PRIVILEGED_FUNCTION */
4295         {
4296             BaseType_t xReturn = pdFALSE;
4297             EventGroupHandle_t xInternalEventGroupHandle = NULL;
4298             int32_t lIndex;
4299 
4300             lIndex = ( int32_t ) xEventGroup;
4301 
4302             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4303             {
4304                 xInternalEventGroupHandle = MPU_GetEventGroupHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4305 
4306                 if( xInternalEventGroupHandle != NULL )
4307                 {
4308                     xReturn = xEventGroupSetBitsFromISR( xInternalEventGroupHandle, uxBitsToSet, pxHigherPriorityTaskWoken );
4309                 }
4310             }
4311 
4312             return xReturn;
4313         }
4314 
4315     #endif /* #if ( ( configUSE_EVENT_GROUPS == 1 ) && ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) ) */
4316 /*-----------------------------------------------------------*/
4317 
4318     #if ( configUSE_EVENT_GROUPS == 1 )
4319 
MPU_xEventGroupGetBitsFromISR(EventGroupHandle_t xEventGroup)4320         EventBits_t MPU_xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup ) /* PRIVILEGED_FUNCTION */
4321         {
4322             EventBits_t xReturn = 0;
4323             EventGroupHandle_t xInternalEventGroupHandle = NULL;
4324             int32_t lIndex;
4325 
4326             lIndex = ( int32_t ) xEventGroup;
4327 
4328             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4329             {
4330                 xInternalEventGroupHandle = MPU_GetEventGroupHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4331 
4332                 if( xInternalEventGroupHandle != NULL )
4333                 {
4334                     xReturn = xEventGroupGetBitsFromISR( xInternalEventGroupHandle );
4335                 }
4336             }
4337 
4338             return xReturn;
4339         }
4340 
4341     #endif /* #if ( configUSE_EVENT_GROUPS == 1 ) */
4342 /*-----------------------------------------------------------*/
4343 
4344 /*-----------------------------------------------------------*/
4345 /*           MPU wrappers for stream buffer APIs.            */
4346 /*-----------------------------------------------------------*/
4347 
4348     #if ( configUSE_STREAM_BUFFERS == 1 )
4349 
4350         size_t MPU_xStreamBufferSendImpl( StreamBufferHandle_t xStreamBuffer,
4351                                           const void * pvTxData,
4352                                           size_t xDataLengthBytes,
4353                                           TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
4354 
MPU_xStreamBufferSendImpl(StreamBufferHandle_t xStreamBuffer,const void * pvTxData,size_t xDataLengthBytes,TickType_t xTicksToWait)4355         size_t MPU_xStreamBufferSendImpl( StreamBufferHandle_t xStreamBuffer,
4356                                           const void * pvTxData,
4357                                           size_t xDataLengthBytes,
4358                                           TickType_t xTicksToWait ) /* PRIVILEGED_FUNCTION */
4359         {
4360             size_t xReturn = 0;
4361             StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4362             int32_t lIndex;
4363             BaseType_t xIsTxDataBufferReadable = pdFALSE;
4364             BaseType_t xCallingTaskIsAuthorizedToAccessStreamBuffer = pdFALSE;
4365 
4366             if( pvTxData != NULL )
4367             {
4368                 xIsTxDataBufferReadable = xPortIsAuthorizedToAccessBuffer( pvTxData,
4369                                                                            xDataLengthBytes,
4370                                                                            tskMPU_READ_PERMISSION );
4371 
4372                 if( xIsTxDataBufferReadable == pdTRUE )
4373                 {
4374                     lIndex = ( int32_t ) xStreamBuffer;
4375 
4376                     if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4377                     {
4378                         xCallingTaskIsAuthorizedToAccessStreamBuffer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4379 
4380                         if( xCallingTaskIsAuthorizedToAccessStreamBuffer == pdTRUE )
4381                         {
4382                             xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4383 
4384                             if( xInternalStreamBufferHandle != NULL )
4385                             {
4386                                 xReturn = xStreamBufferSend( xInternalStreamBufferHandle, pvTxData, xDataLengthBytes, xTicksToWait );
4387                             }
4388                         }
4389                     }
4390                 }
4391             }
4392 
4393             return xReturn;
4394         }
4395 
4396     #endif /* #if ( configUSE_STREAM_BUFFERS == 1 ) */
4397 /*-----------------------------------------------------------*/
4398 
4399     #if ( configUSE_STREAM_BUFFERS == 1 )
4400 
4401         size_t MPU_xStreamBufferReceiveImpl( StreamBufferHandle_t xStreamBuffer,
4402                                              void * pvRxData,
4403                                              size_t xBufferLengthBytes,
4404                                              TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
4405 
MPU_xStreamBufferReceiveImpl(StreamBufferHandle_t xStreamBuffer,void * pvRxData,size_t xBufferLengthBytes,TickType_t xTicksToWait)4406         size_t MPU_xStreamBufferReceiveImpl( StreamBufferHandle_t xStreamBuffer,
4407                                              void * pvRxData,
4408                                              size_t xBufferLengthBytes,
4409                                              TickType_t xTicksToWait ) /* PRIVILEGED_FUNCTION */
4410         {
4411             size_t xReturn = 0;
4412             StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4413             int32_t lIndex;
4414             BaseType_t xIsRxDataBufferWriteable = pdFALSE;
4415             BaseType_t xCallingTaskIsAuthorizedToAccessStreamBuffer = pdFALSE;
4416 
4417             if( pvRxData != NULL )
4418             {
4419                 xIsRxDataBufferWriteable = xPortIsAuthorizedToAccessBuffer( pvRxData,
4420                                                                             xBufferLengthBytes,
4421                                                                             tskMPU_WRITE_PERMISSION );
4422 
4423                 if( xIsRxDataBufferWriteable == pdTRUE )
4424                 {
4425                     lIndex = ( int32_t ) xStreamBuffer;
4426 
4427                     if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4428                     {
4429                         xCallingTaskIsAuthorizedToAccessStreamBuffer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4430 
4431                         if( xCallingTaskIsAuthorizedToAccessStreamBuffer == pdTRUE )
4432                         {
4433                             xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4434 
4435                             if( xInternalStreamBufferHandle != NULL )
4436                             {
4437                                 xReturn = xStreamBufferReceive( xInternalStreamBufferHandle, pvRxData, xBufferLengthBytes, xTicksToWait );
4438                             }
4439                         }
4440                     }
4441                 }
4442             }
4443 
4444             return xReturn;
4445         }
4446 
4447     #endif /* #if ( configUSE_STREAM_BUFFERS == 1 ) */
4448 /*-----------------------------------------------------------*/
4449 
4450     #if ( configUSE_STREAM_BUFFERS == 1 )
4451 
4452         BaseType_t MPU_xStreamBufferIsFullImpl( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
4453 
MPU_xStreamBufferIsFullImpl(StreamBufferHandle_t xStreamBuffer)4454         BaseType_t MPU_xStreamBufferIsFullImpl( StreamBufferHandle_t xStreamBuffer ) /* PRIVILEGED_FUNCTION */
4455         {
4456             BaseType_t xReturn = pdFALSE;
4457             StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4458             int32_t lIndex;
4459             BaseType_t xCallingTaskIsAuthorizedToAccessStreamBuffer = pdFALSE;
4460 
4461             lIndex = ( int32_t ) xStreamBuffer;
4462 
4463             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4464             {
4465                 xCallingTaskIsAuthorizedToAccessStreamBuffer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4466 
4467                 if( xCallingTaskIsAuthorizedToAccessStreamBuffer == pdTRUE )
4468                 {
4469                     xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4470 
4471                     if( xInternalStreamBufferHandle != NULL )
4472                     {
4473                         xReturn = xStreamBufferIsFull( xInternalStreamBufferHandle );
4474                     }
4475                 }
4476             }
4477 
4478             return xReturn;
4479         }
4480 
4481     #endif /* #if ( configUSE_STREAM_BUFFERS == 1 ) */
4482 /*-----------------------------------------------------------*/
4483 
4484     #if ( configUSE_STREAM_BUFFERS == 1 )
4485 
4486         BaseType_t MPU_xStreamBufferIsEmptyImpl( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
4487 
MPU_xStreamBufferIsEmptyImpl(StreamBufferHandle_t xStreamBuffer)4488         BaseType_t MPU_xStreamBufferIsEmptyImpl( StreamBufferHandle_t xStreamBuffer ) /* PRIVILEGED_FUNCTION */
4489         {
4490             BaseType_t xReturn = pdFALSE;
4491             StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4492             int32_t lIndex;
4493             BaseType_t xCallingTaskIsAuthorizedToAccessStreamBuffer = pdFALSE;
4494 
4495             lIndex = ( int32_t ) xStreamBuffer;
4496 
4497             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4498             {
4499                 xCallingTaskIsAuthorizedToAccessStreamBuffer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4500 
4501                 if( xCallingTaskIsAuthorizedToAccessStreamBuffer == pdTRUE )
4502                 {
4503                     xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4504 
4505                     if( xInternalStreamBufferHandle != NULL )
4506                     {
4507                         xReturn = xStreamBufferIsEmpty( xInternalStreamBufferHandle );
4508                     }
4509                 }
4510             }
4511 
4512             return xReturn;
4513         }
4514 
4515     #endif /* #if ( configUSE_STREAM_BUFFERS == 1 ) */
4516 /*-----------------------------------------------------------*/
4517 
4518     #if ( configUSE_STREAM_BUFFERS == 1 )
4519 
4520         size_t MPU_xStreamBufferSpacesAvailableImpl( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
4521 
MPU_xStreamBufferSpacesAvailableImpl(StreamBufferHandle_t xStreamBuffer)4522         size_t MPU_xStreamBufferSpacesAvailableImpl( StreamBufferHandle_t xStreamBuffer ) /* PRIVILEGED_FUNCTION */
4523         {
4524             size_t xReturn = 0;
4525             StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4526             int32_t lIndex;
4527             BaseType_t xCallingTaskIsAuthorizedToAccessStreamBuffer = pdFALSE;
4528 
4529             lIndex = ( int32_t ) xStreamBuffer;
4530 
4531             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4532             {
4533                 xCallingTaskIsAuthorizedToAccessStreamBuffer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4534 
4535                 if( xCallingTaskIsAuthorizedToAccessStreamBuffer == pdTRUE )
4536                 {
4537                     xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4538 
4539                     if( xInternalStreamBufferHandle != NULL )
4540                     {
4541                         xReturn = xStreamBufferSpacesAvailable( xInternalStreamBufferHandle );
4542                     }
4543                 }
4544             }
4545 
4546             return xReturn;
4547         }
4548 
4549     #endif /* #if ( configUSE_STREAM_BUFFERS == 1 ) */
4550 /*-----------------------------------------------------------*/
4551 
4552     #if ( configUSE_STREAM_BUFFERS == 1 )
4553 
4554         size_t MPU_xStreamBufferBytesAvailableImpl( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
4555 
MPU_xStreamBufferBytesAvailableImpl(StreamBufferHandle_t xStreamBuffer)4556         size_t MPU_xStreamBufferBytesAvailableImpl( StreamBufferHandle_t xStreamBuffer ) /* PRIVILEGED_FUNCTION */
4557         {
4558             size_t xReturn = 0;
4559             StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4560             int32_t lIndex;
4561             BaseType_t xCallingTaskIsAuthorizedToAccessStreamBuffer = pdFALSE;
4562 
4563             lIndex = ( int32_t ) xStreamBuffer;
4564 
4565             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4566             {
4567                 xCallingTaskIsAuthorizedToAccessStreamBuffer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4568 
4569                 if( xCallingTaskIsAuthorizedToAccessStreamBuffer == pdTRUE )
4570                 {
4571                     xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4572 
4573                     if( xInternalStreamBufferHandle != NULL )
4574                     {
4575                         xReturn = xStreamBufferBytesAvailable( xInternalStreamBufferHandle );
4576                     }
4577                 }
4578             }
4579 
4580             return xReturn;
4581         }
4582 
4583     #endif /* #if ( configUSE_STREAM_BUFFERS == 1 ) */
4584 /*-----------------------------------------------------------*/
4585 
4586     #if ( configUSE_STREAM_BUFFERS == 1 )
4587 
4588         BaseType_t MPU_xStreamBufferSetTriggerLevelImpl( StreamBufferHandle_t xStreamBuffer,
4589                                                          size_t xTriggerLevel ) PRIVILEGED_FUNCTION;
4590 
MPU_xStreamBufferSetTriggerLevelImpl(StreamBufferHandle_t xStreamBuffer,size_t xTriggerLevel)4591         BaseType_t MPU_xStreamBufferSetTriggerLevelImpl( StreamBufferHandle_t xStreamBuffer,
4592                                                          size_t xTriggerLevel ) /* PRIVILEGED_FUNCTION */
4593         {
4594             BaseType_t xReturn = pdFALSE;
4595             StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4596             int32_t lIndex;
4597             BaseType_t xCallingTaskIsAuthorizedToAccessStreamBuffer = pdFALSE;
4598 
4599             lIndex = ( int32_t ) xStreamBuffer;
4600 
4601             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4602             {
4603                 xCallingTaskIsAuthorizedToAccessStreamBuffer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4604 
4605                 if( xCallingTaskIsAuthorizedToAccessStreamBuffer == pdTRUE )
4606                 {
4607                     xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4608 
4609                     if( xInternalStreamBufferHandle != NULL )
4610                     {
4611                         xReturn = xStreamBufferSetTriggerLevel( xInternalStreamBufferHandle, xTriggerLevel );
4612                     }
4613                 }
4614             }
4615 
4616             return xReturn;
4617         }
4618 
4619     #endif /* #if ( configUSE_STREAM_BUFFERS == 1 ) */
4620 /*-----------------------------------------------------------*/
4621 
4622     #if ( configUSE_STREAM_BUFFERS == 1 )
4623 
4624         size_t MPU_xStreamBufferNextMessageLengthBytesImpl( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
4625 
MPU_xStreamBufferNextMessageLengthBytesImpl(StreamBufferHandle_t xStreamBuffer)4626         size_t MPU_xStreamBufferNextMessageLengthBytesImpl( StreamBufferHandle_t xStreamBuffer ) /* PRIVILEGED_FUNCTION */
4627         {
4628             size_t xReturn = 0;
4629             StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4630             int32_t lIndex;
4631             BaseType_t xCallingTaskIsAuthorizedToAccessStreamBuffer = pdFALSE;
4632 
4633             lIndex = ( int32_t ) xStreamBuffer;
4634 
4635             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4636             {
4637                 xCallingTaskIsAuthorizedToAccessStreamBuffer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4638 
4639                 if( xCallingTaskIsAuthorizedToAccessStreamBuffer == pdTRUE )
4640                 {
4641                     xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4642 
4643                     if( xInternalStreamBufferHandle != NULL )
4644                     {
4645                         xReturn = xStreamBufferNextMessageLengthBytes( xInternalStreamBufferHandle );
4646                     }
4647                 }
4648             }
4649 
4650             return xReturn;
4651         }
4652 
4653     #endif /* #if ( configUSE_STREAM_BUFFERS == 1 ) */
4654 /*-----------------------------------------------------------*/
4655 
4656 /* Privileged only wrappers for Stream Buffer APIs. These are needed so that
4657  * the application can use opaque handles maintained in mpu_wrappers.c
4658  * with all the APIs. */
4659 /*-----------------------------------------------------------*/
4660 
4661     #if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configUSE_STREAM_BUFFERS == 1 ) )
4662 
MPU_xStreamBufferGenericCreate(size_t xBufferSizeBytes,size_t xTriggerLevelBytes,BaseType_t xStreamBufferType,StreamBufferCallbackFunction_t pxSendCompletedCallback,StreamBufferCallbackFunction_t pxReceiveCompletedCallback)4663         StreamBufferHandle_t MPU_xStreamBufferGenericCreate( size_t xBufferSizeBytes,
4664                                                              size_t xTriggerLevelBytes,
4665                                                              BaseType_t xStreamBufferType,
4666                                                              StreamBufferCallbackFunction_t pxSendCompletedCallback,
4667                                                              StreamBufferCallbackFunction_t pxReceiveCompletedCallback ) /* PRIVILEGED_FUNCTION */
4668         {
4669             StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4670             StreamBufferHandle_t xExternalStreamBufferHandle = NULL;
4671             int32_t lIndex;
4672 
4673             /**
4674              * Stream buffer application level callback functionality is disabled for MPU
4675              * enabled ports.
4676              */
4677             configASSERT( ( pxSendCompletedCallback == NULL ) &&
4678                           ( pxReceiveCompletedCallback == NULL ) );
4679 
4680             if( ( pxSendCompletedCallback == NULL ) &&
4681                 ( pxReceiveCompletedCallback == NULL ) )
4682             {
4683                 lIndex = MPU_GetFreeIndexInKernelObjectPool();
4684 
4685                 if( lIndex != -1 )
4686                 {
4687                     xInternalStreamBufferHandle = xStreamBufferGenericCreate( xBufferSizeBytes,
4688                                                                               xTriggerLevelBytes,
4689                                                                               xStreamBufferType,
4690                                                                               NULL,
4691                                                                               NULL );
4692 
4693                     if( xInternalStreamBufferHandle != NULL )
4694                     {
4695                         MPU_StoreStreamBufferHandleAtIndex( lIndex, xInternalStreamBufferHandle );
4696                         xExternalStreamBufferHandle = ( StreamBufferHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
4697                     }
4698                     else
4699                     {
4700                         MPU_SetIndexFreeInKernelObjectPool( lIndex );
4701                     }
4702                 }
4703             }
4704             else
4705             {
4706                 traceSTREAM_BUFFER_CREATE_FAILED( xStreamBufferType );
4707                 xExternalStreamBufferHandle = NULL;
4708             }
4709 
4710             return xExternalStreamBufferHandle;
4711         }
4712 
4713     #endif /* #if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configUSE_STREAM_BUFFERS == 1 ) ) */
4714 /*-----------------------------------------------------------*/
4715 
4716     #if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_STREAM_BUFFERS == 1 ) )
4717 
MPU_xStreamBufferGenericCreateStatic(size_t xBufferSizeBytes,size_t xTriggerLevelBytes,BaseType_t xStreamBufferType,uint8_t * const pucStreamBufferStorageArea,StaticStreamBuffer_t * const pxStaticStreamBuffer,StreamBufferCallbackFunction_t pxSendCompletedCallback,StreamBufferCallbackFunction_t pxReceiveCompletedCallback)4718         StreamBufferHandle_t MPU_xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes,
4719                                                                    size_t xTriggerLevelBytes,
4720                                                                    BaseType_t xStreamBufferType,
4721                                                                    uint8_t * const pucStreamBufferStorageArea,
4722                                                                    StaticStreamBuffer_t * const pxStaticStreamBuffer,
4723                                                                    StreamBufferCallbackFunction_t pxSendCompletedCallback,
4724                                                                    StreamBufferCallbackFunction_t pxReceiveCompletedCallback ) /* PRIVILEGED_FUNCTION */
4725         {
4726             StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4727             StreamBufferHandle_t xExternalStreamBufferHandle = NULL;
4728             int32_t lIndex;
4729 
4730             /**
4731              * Stream buffer application level callback functionality is disabled for MPU
4732              * enabled ports.
4733              */
4734             configASSERT( ( pxSendCompletedCallback == NULL ) &&
4735                           ( pxReceiveCompletedCallback == NULL ) );
4736 
4737             if( ( pxSendCompletedCallback == NULL ) &&
4738                 ( pxReceiveCompletedCallback == NULL ) )
4739             {
4740                 lIndex = MPU_GetFreeIndexInKernelObjectPool();
4741 
4742                 if( lIndex != -1 )
4743                 {
4744                     xInternalStreamBufferHandle = xStreamBufferGenericCreateStatic( xBufferSizeBytes,
4745                                                                                     xTriggerLevelBytes,
4746                                                                                     xStreamBufferType,
4747                                                                                     pucStreamBufferStorageArea,
4748                                                                                     pxStaticStreamBuffer,
4749                                                                                     NULL,
4750                                                                                     NULL );
4751 
4752                     if( xInternalStreamBufferHandle != NULL )
4753                     {
4754                         MPU_StoreStreamBufferHandleAtIndex( lIndex, xInternalStreamBufferHandle );
4755                         xExternalStreamBufferHandle = ( StreamBufferHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
4756                     }
4757                     else
4758                     {
4759                         MPU_SetIndexFreeInKernelObjectPool( lIndex );
4760                     }
4761                 }
4762             }
4763             else
4764             {
4765                 traceSTREAM_BUFFER_CREATE_STATIC_FAILED( xReturn, xStreamBufferType );
4766                 xExternalStreamBufferHandle = NULL;
4767             }
4768 
4769             return xExternalStreamBufferHandle;
4770         }
4771 
4772     #endif /* #if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_STREAM_BUFFERS == 1 ) ) */
4773 /*-----------------------------------------------------------*/
4774 
4775     #if ( configUSE_STREAM_BUFFERS == 1 )
4776 
MPU_vStreamBufferDelete(StreamBufferHandle_t xStreamBuffer)4777         void MPU_vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer ) /* PRIVILEGED_FUNCTION */
4778         {
4779             StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4780             int32_t lIndex;
4781 
4782             lIndex = ( int32_t ) xStreamBuffer;
4783 
4784             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4785             {
4786                 xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4787 
4788                 if( xInternalStreamBufferHandle != NULL )
4789                 {
4790                     vStreamBufferDelete( xInternalStreamBufferHandle );
4791                 }
4792 
4793                 MPU_SetIndexFreeInKernelObjectPool( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4794             }
4795         }
4796 
4797     #endif /* #if ( configUSE_STREAM_BUFFERS == 1 ) */
4798 /*-----------------------------------------------------------*/
4799 
4800     #if ( configUSE_STREAM_BUFFERS == 1 )
4801 
MPU_xStreamBufferReset(StreamBufferHandle_t xStreamBuffer)4802         BaseType_t MPU_xStreamBufferReset( StreamBufferHandle_t xStreamBuffer ) /* PRIVILEGED_FUNCTION */
4803         {
4804             BaseType_t xReturn = pdFALSE;
4805             StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4806             int32_t lIndex;
4807 
4808             lIndex = ( int32_t ) xStreamBuffer;
4809 
4810             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4811             {
4812                 xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4813 
4814                 if( xInternalStreamBufferHandle != NULL )
4815                 {
4816                     xReturn = xStreamBufferReset( xInternalStreamBufferHandle );
4817                 }
4818             }
4819 
4820             return xReturn;
4821         }
4822 
4823     #endif /* #if ( configUSE_STREAM_BUFFERS == 1 ) */
4824 /*-----------------------------------------------------------*/
4825 
4826     #if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_STREAM_BUFFERS == 1 ) )
4827 
MPU_xStreamBufferGetStaticBuffers(StreamBufferHandle_t xStreamBuffers,uint8_t * ppucStreamBufferStorageArea,StaticStreamBuffer_t * ppxStaticStreamBuffer)4828         BaseType_t MPU_xStreamBufferGetStaticBuffers( StreamBufferHandle_t xStreamBuffers,
4829                                                       uint8_t * ppucStreamBufferStorageArea,
4830                                                       StaticStreamBuffer_t * ppxStaticStreamBuffer ) /* PRIVILEGED_FUNCTION */
4831         {
4832             BaseType_t xReturn = pdFALSE;
4833             StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4834             int32_t lIndex;
4835 
4836             lIndex = ( int32_t ) xStreamBuffers;
4837 
4838             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4839             {
4840                 xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4841 
4842                 if( xInternalStreamBufferHandle != NULL )
4843                 {
4844                     xReturn = MPU_xStreamBufferGetStaticBuffers( xInternalStreamBufferHandle, ppucStreamBufferStorageArea, ppxStaticStreamBuffer );
4845                 }
4846             }
4847 
4848             return xReturn;
4849         }
4850 
4851     #endif /* #if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_STREAM_BUFFERS == 1 ) ) */
4852 /*-----------------------------------------------------------*/
4853 
4854     #if ( configUSE_STREAM_BUFFERS == 1 )
4855 
MPU_xStreamBufferSendFromISR(StreamBufferHandle_t xStreamBuffer,const void * pvTxData,size_t xDataLengthBytes,BaseType_t * const pxHigherPriorityTaskWoken)4856     size_t MPU_xStreamBufferSendFromISR( StreamBufferHandle_t xStreamBuffer,
4857                                          const void * pvTxData,
4858                                          size_t xDataLengthBytes,
4859                                          BaseType_t * const pxHigherPriorityTaskWoken ) /* PRIVILEGED_FUNCTION */
4860     {
4861         size_t xReturn = 0;
4862         StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4863         int32_t lIndex;
4864 
4865         lIndex = ( int32_t ) xStreamBuffer;
4866 
4867         if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4868         {
4869             xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4870 
4871             if( xInternalStreamBufferHandle != NULL )
4872             {
4873                 xReturn = xStreamBufferSendFromISR( xInternalStreamBufferHandle, pvTxData, xDataLengthBytes, pxHigherPriorityTaskWoken );
4874             }
4875         }
4876 
4877         return xReturn;
4878     }
4879 
4880     #endif /* #if ( configUSE_STREAM_BUFFERS == 1 ) */
4881 /*-----------------------------------------------------------*/
4882 
4883     #if ( configUSE_STREAM_BUFFERS == 1 )
4884 
MPU_xStreamBufferReceiveFromISR(StreamBufferHandle_t xStreamBuffer,void * pvRxData,size_t xBufferLengthBytes,BaseType_t * const pxHigherPriorityTaskWoken)4885     size_t MPU_xStreamBufferReceiveFromISR( StreamBufferHandle_t xStreamBuffer,
4886                                             void * pvRxData,
4887                                             size_t xBufferLengthBytes,
4888                                             BaseType_t * const pxHigherPriorityTaskWoken ) /* PRIVILEGED_FUNCTION */
4889     {
4890         size_t xReturn = 0;
4891         StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4892         int32_t lIndex;
4893 
4894         lIndex = ( int32_t ) xStreamBuffer;
4895 
4896         if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4897         {
4898             xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4899 
4900             if( xInternalStreamBufferHandle != NULL )
4901             {
4902                 xReturn = xStreamBufferReceiveFromISR( xInternalStreamBufferHandle, pvRxData, xBufferLengthBytes, pxHigherPriorityTaskWoken );
4903             }
4904         }
4905 
4906         return xReturn;
4907     }
4908 
4909     #endif /* #if ( configUSE_STREAM_BUFFERS == 1 ) */
4910 /*-----------------------------------------------------------*/
4911 
4912     #if ( configUSE_STREAM_BUFFERS == 1 )
4913 
MPU_xStreamBufferSendCompletedFromISR(StreamBufferHandle_t xStreamBuffer,BaseType_t * pxHigherPriorityTaskWoken)4914         BaseType_t MPU_xStreamBufferSendCompletedFromISR( StreamBufferHandle_t xStreamBuffer,
4915                                                           BaseType_t * pxHigherPriorityTaskWoken ) /* PRIVILEGED_FUNCTION */
4916         {
4917             BaseType_t xReturn = pdFALSE;
4918             StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4919             int32_t lIndex;
4920 
4921             lIndex = ( int32_t ) xStreamBuffer;
4922 
4923             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4924             {
4925                 xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4926 
4927                 if( xInternalStreamBufferHandle != NULL )
4928                 {
4929                     xReturn = xStreamBufferSendCompletedFromISR( xInternalStreamBufferHandle, pxHigherPriorityTaskWoken );
4930                 }
4931             }
4932 
4933             return xReturn;
4934         }
4935 
4936     #endif /* #if ( configUSE_STREAM_BUFFERS == 1 ) */
4937 /*-----------------------------------------------------------*/
4938 
4939     #if ( configUSE_STREAM_BUFFERS == 1 )
4940 
MPU_xStreamBufferReceiveCompletedFromISR(StreamBufferHandle_t xStreamBuffer,BaseType_t * pxHigherPriorityTaskWoken)4941         BaseType_t MPU_xStreamBufferReceiveCompletedFromISR( StreamBufferHandle_t xStreamBuffer,
4942                                                              BaseType_t * pxHigherPriorityTaskWoken ) /*PRIVILEGED_FUNCTION */
4943         {
4944             BaseType_t xReturn = pdFALSE;
4945             StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4946             int32_t lIndex;
4947 
4948             lIndex = ( int32_t ) xStreamBuffer;
4949 
4950             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4951             {
4952                 xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4953 
4954                 if( xInternalStreamBufferHandle != NULL )
4955                 {
4956                     xReturn = xStreamBufferReceiveCompletedFromISR( xInternalStreamBufferHandle, pxHigherPriorityTaskWoken );
4957                 }
4958             }
4959 
4960             return xReturn;
4961         }
4962 
4963     #endif /* #if ( configUSE_STREAM_BUFFERS == 1 ) */
4964 
4965 /*-----------------------------------------------------------*/
4966 
4967     #if ( configUSE_STREAM_BUFFERS == 1 )
4968 
MPU_xStreamBufferResetFromISR(StreamBufferHandle_t xStreamBuffer)4969         BaseType_t MPU_xStreamBufferResetFromISR( StreamBufferHandle_t xStreamBuffer ) /*PRIVILEGED_FUNCTION */
4970         {
4971             BaseType_t xReturn = pdFAIL;
4972             StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4973             int32_t lIndex;
4974 
4975             lIndex = ( int32_t ) xStreamBuffer;
4976 
4977             if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4978             {
4979                 xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4980 
4981                 if( xInternalStreamBufferHandle != NULL )
4982                 {
4983                     xReturn = xStreamBufferResetFromISR( xInternalStreamBufferHandle );
4984                 }
4985             }
4986 
4987             return xReturn;
4988         }
4989 
4990     #endif /* #if ( configUSE_STREAM_BUFFERS == 1 ) */
4991 
4992 /*-----------------------------------------------------------*/
4993 
4994 /* Functions that the application writer wants to execute in privileged mode
4995  * can be defined in application_defined_privileged_functions.h. */
4996 
4997     #if configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS == 1
4998         #include "application_defined_privileged_functions.h"
4999     #endif
5000 /*-----------------------------------------------------------*/
5001 
5002 /**
5003  * @brief Array of system call implementation functions.
5004  *
5005  * The index in the array MUST match the corresponding system call number
5006  * defined in mpu_wrappers.h.
5007  */
5008     PRIVILEGED_DATA UBaseType_t uxSystemCallImplementations[ NUM_SYSTEM_CALLS ] =
5009     {
5010         #if ( configUSE_TASK_NOTIFICATIONS == 1 )
5011             ( UBaseType_t ) MPU_xTaskGenericNotifyImpl,                     /* SYSTEM_CALL_xTaskGenericNotify. */
5012             ( UBaseType_t ) MPU_xTaskGenericNotifyWaitImpl,                 /* SYSTEM_CALL_xTaskGenericNotifyWait. */
5013         #else
5014             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xTaskGenericNotify. */
5015             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xTaskGenericNotifyWait. */
5016         #endif
5017 
5018         #if ( configUSE_TIMERS == 1 )
5019             ( UBaseType_t ) MPU_xTimerGenericCommandFromTaskImpl,           /* SYSTEM_CALL_xTimerGenericCommandFromTask. */
5020         #else
5021             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xTimerGenericCommandFromTask. */
5022         #endif
5023 
5024         #if ( configUSE_EVENT_GROUPS == 1 )
5025             ( UBaseType_t ) MPU_xEventGroupWaitBitsImpl,                    /* SYSTEM_CALL_xEventGroupWaitBits. */
5026         #else
5027             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xEventGroupWaitBits. */
5028         #endif
5029 
5030         /* The system calls above this line take 5 parameters. */
5031 
5032         #if ( INCLUDE_xTaskDelayUntil == 1 )
5033             ( UBaseType_t ) MPU_xTaskDelayUntilImpl,                        /* SYSTEM_CALL_xTaskDelayUntil. */
5034         #else
5035             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xTaskDelayUntil. */
5036         #endif
5037 
5038         #if ( INCLUDE_xTaskAbortDelay == 1 )
5039             ( UBaseType_t ) MPU_xTaskAbortDelayImpl,                        /* SYSTEM_CALL_xTaskAbortDelay. */
5040         #else
5041             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xTaskAbortDelay. */
5042         #endif
5043 
5044         #if ( INCLUDE_vTaskDelay == 1 )
5045             ( UBaseType_t ) MPU_vTaskDelayImpl,                             /* SYSTEM_CALL_vTaskDelay. */
5046         #else
5047             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_vTaskDelay. */
5048         #endif
5049 
5050         #if ( INCLUDE_uxTaskPriorityGet == 1 )
5051             ( UBaseType_t ) MPU_uxTaskPriorityGetImpl,                      /* SYSTEM_CALL_uxTaskPriorityGet. */
5052         #else
5053             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_uxTaskPriorityGet. */
5054         #endif
5055 
5056         #if ( INCLUDE_eTaskGetState == 1 )
5057             ( UBaseType_t ) MPU_eTaskGetStateImpl,                          /* SYSTEM_CALL_eTaskGetState. */
5058         #else
5059             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_eTaskGetState. */
5060         #endif
5061 
5062         #if ( configUSE_TRACE_FACILITY == 1 )
5063             ( UBaseType_t ) MPU_vTaskGetInfoImpl,                           /* SYSTEM_CALL_vTaskGetInfo. */
5064         #else
5065             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_vTaskGetInfo. */
5066         #endif
5067 
5068         #if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )
5069             ( UBaseType_t ) MPU_xTaskGetIdleTaskHandleImpl,                 /* SYSTEM_CALL_xTaskGetIdleTaskHandle. */
5070         #else
5071             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xTaskGetIdleTaskHandle. */
5072         #endif
5073 
5074         #if ( INCLUDE_vTaskSuspend == 1 )
5075             ( UBaseType_t ) MPU_vTaskSuspendImpl,                           /* SYSTEM_CALL_vTaskSuspend. */
5076             ( UBaseType_t ) MPU_vTaskResumeImpl,                            /* SYSTEM_CALL_vTaskResume. */
5077         #else
5078             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_vTaskSuspend. */
5079             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_vTaskResume. */
5080         #endif
5081 
5082         ( UBaseType_t ) MPU_xTaskGetTickCountImpl,                          /* SYSTEM_CALL_xTaskGetTickCount. */
5083         ( UBaseType_t ) MPU_uxTaskGetNumberOfTasksImpl,                     /* SYSTEM_CALL_uxTaskGetNumberOfTasks. */
5084 
5085         #if ( configGENERATE_RUN_TIME_STATS == 1 )
5086             ( UBaseType_t ) MPU_ulTaskGetRunTimeCounterImpl,                /* SYSTEM_CALL_ulTaskGetRunTimeCounter. */
5087             ( UBaseType_t ) MPU_ulTaskGetRunTimePercentImpl,                /* SYSTEM_CALL_ulTaskGetRunTimePercent. */
5088         #else
5089             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_ulTaskGetRunTimeCounter. */
5090             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_ulTaskGetRunTimePercent. */
5091         #endif
5092 
5093         #if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) )
5094             ( UBaseType_t ) MPU_ulTaskGetIdleRunTimePercentImpl,            /* SYSTEM_CALL_ulTaskGetIdleRunTimePercent. */
5095             ( UBaseType_t ) MPU_ulTaskGetIdleRunTimeCounterImpl,            /* SYSTEM_CALL_ulTaskGetIdleRunTimeCounter. */
5096         #else
5097             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_ulTaskGetIdleRunTimePercent. */
5098             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_ulTaskGetIdleRunTimeCounter. */
5099         #endif
5100 
5101         #if ( configUSE_APPLICATION_TASK_TAG == 1 )
5102             ( UBaseType_t ) MPU_vTaskSetApplicationTaskTagImpl,             /* SYSTEM_CALL_vTaskSetApplicationTaskTag. */
5103             ( UBaseType_t ) MPU_xTaskGetApplicationTaskTagImpl,             /* SYSTEM_CALL_xTaskGetApplicationTaskTag. */
5104         #else
5105             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_vTaskSetApplicationTaskTag. */
5106             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xTaskGetApplicationTaskTag. */
5107         #endif
5108 
5109         #if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 )
5110             ( UBaseType_t ) MPU_vTaskSetThreadLocalStoragePointerImpl,      /* SYSTEM_CALL_vTaskSetThreadLocalStoragePointer. */
5111             ( UBaseType_t ) MPU_pvTaskGetThreadLocalStoragePointerImpl,     /* SYSTEM_CALL_pvTaskGetThreadLocalStoragePointer. */
5112         #else
5113             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_vTaskSetThreadLocalStoragePointer. */
5114             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_pvTaskGetThreadLocalStoragePointer. */
5115         #endif
5116 
5117         #if ( configUSE_TRACE_FACILITY == 1 )
5118             ( UBaseType_t ) MPU_uxTaskGetSystemStateImpl,                   /* SYSTEM_CALL_uxTaskGetSystemState. */
5119         #else
5120             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_uxTaskGetSystemState. */
5121         #endif
5122 
5123         #if ( INCLUDE_uxTaskGetStackHighWaterMark == 1 )
5124             ( UBaseType_t ) MPU_uxTaskGetStackHighWaterMarkImpl,            /* SYSTEM_CALL_uxTaskGetStackHighWaterMark. */
5125         #else
5126             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_uxTaskGetStackHighWaterMark. */
5127         #endif
5128 
5129         #if ( INCLUDE_uxTaskGetStackHighWaterMark2 == 1 )
5130             ( UBaseType_t ) MPU_uxTaskGetStackHighWaterMark2Impl,           /* SYSTEM_CALL_uxTaskGetStackHighWaterMark2. */
5131         #else
5132             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_uxTaskGetStackHighWaterMark2. */
5133         #endif
5134 
5135         #if ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) )
5136             ( UBaseType_t ) MPU_xTaskGetCurrentTaskHandleImpl,              /* SYSTEM_CALL_xTaskGetCurrentTaskHandle. */
5137         #else
5138             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xTaskGetCurrentTaskHandle. */
5139         #endif
5140 
5141         #if ( INCLUDE_xTaskGetSchedulerState == 1 )
5142             ( UBaseType_t ) MPU_xTaskGetSchedulerStateImpl,                 /* SYSTEM_CALL_xTaskGetSchedulerState. */
5143         #else
5144             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xTaskGetSchedulerState. */
5145         #endif
5146 
5147         ( UBaseType_t ) MPU_vTaskSetTimeOutStateImpl,                       /* SYSTEM_CALL_vTaskSetTimeOutState. */
5148         ( UBaseType_t ) MPU_xTaskCheckForTimeOutImpl,                       /* SYSTEM_CALL_xTaskCheckForTimeOut. */
5149 
5150         #if ( configUSE_TASK_NOTIFICATIONS == 1 )
5151             ( UBaseType_t ) MPU_ulTaskGenericNotifyTakeImpl,                /* SYSTEM_CALL_ulTaskGenericNotifyTake. */
5152             ( UBaseType_t ) MPU_xTaskGenericNotifyStateClearImpl,           /* SYSTEM_CALL_xTaskGenericNotifyStateClear. */
5153             ( UBaseType_t ) MPU_ulTaskGenericNotifyValueClearImpl,          /* SYSTEM_CALL_ulTaskGenericNotifyValueClear. */
5154         #else
5155             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_ulTaskGenericNotifyTake. */
5156             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xTaskGenericNotifyStateClear. */
5157             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_ulTaskGenericNotifyValueClear. */
5158         #endif
5159 
5160         ( UBaseType_t ) MPU_xQueueGenericSendImpl,                          /* SYSTEM_CALL_xQueueGenericSend. */
5161         ( UBaseType_t ) MPU_uxQueueMessagesWaitingImpl,                     /* SYSTEM_CALL_uxQueueMessagesWaiting. */
5162         ( UBaseType_t ) MPU_uxQueueSpacesAvailableImpl,                     /* SYSTEM_CALL_uxQueueSpacesAvailable. */
5163         ( UBaseType_t ) MPU_xQueueReceiveImpl,                              /* SYSTEM_CALL_xQueueReceive. */
5164         ( UBaseType_t ) MPU_xQueuePeekImpl,                                 /* SYSTEM_CALL_xQueuePeek. */
5165         ( UBaseType_t ) MPU_xQueueSemaphoreTakeImpl,                        /* SYSTEM_CALL_xQueueSemaphoreTake. */
5166 
5167         #if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )
5168             ( UBaseType_t ) MPU_xQueueGetMutexHolderImpl,                   /* SYSTEM_CALL_xQueueGetMutexHolder. */
5169         #else
5170             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xQueueGetMutexHolder. */
5171         #endif
5172 
5173         #if ( configUSE_RECURSIVE_MUTEXES == 1 )
5174             ( UBaseType_t ) MPU_xQueueTakeMutexRecursiveImpl,               /* SYSTEM_CALL_xQueueTakeMutexRecursive. */
5175             ( UBaseType_t ) MPU_xQueueGiveMutexRecursiveImpl,               /* SYSTEM_CALL_xQueueGiveMutexRecursive. */
5176         #else
5177             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xQueueTakeMutexRecursive. */
5178             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xQueueGiveMutexRecursive. */
5179         #endif
5180 
5181         #if ( configUSE_QUEUE_SETS == 1 )
5182             ( UBaseType_t ) MPU_xQueueSelectFromSetImpl,                    /* SYSTEM_CALL_xQueueSelectFromSet. */
5183             ( UBaseType_t ) MPU_xQueueAddToSetImpl,                         /* SYSTEM_CALL_xQueueAddToSet. */
5184         #else
5185             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xQueueSelectFromSet. */
5186             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xQueueAddToSet. */
5187         #endif
5188 
5189         #if configQUEUE_REGISTRY_SIZE > 0
5190             ( UBaseType_t ) MPU_vQueueAddToRegistryImpl,                    /* SYSTEM_CALL_vQueueAddToRegistry. */
5191             ( UBaseType_t ) MPU_vQueueUnregisterQueueImpl,                  /* SYSTEM_CALL_vQueueUnregisterQueue. */
5192             ( UBaseType_t ) MPU_pcQueueGetNameImpl,                         /* SYSTEM_CALL_pcQueueGetName. */
5193         #else
5194             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_vQueueAddToRegistry. */
5195             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_vQueueUnregisterQueue. */
5196             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_pcQueueGetName. */
5197         #endif
5198 
5199         #if ( configUSE_TIMERS == 1 )
5200             ( UBaseType_t ) MPU_pvTimerGetTimerIDImpl,                      /* SYSTEM_CALL_pvTimerGetTimerID. */
5201             ( UBaseType_t ) MPU_vTimerSetTimerIDImpl,                       /* SYSTEM_CALL_vTimerSetTimerID. */
5202             ( UBaseType_t ) MPU_xTimerIsTimerActiveImpl,                    /* SYSTEM_CALL_xTimerIsTimerActive. */
5203             ( UBaseType_t ) MPU_xTimerGetTimerDaemonTaskHandleImpl,         /* SYSTEM_CALL_xTimerGetTimerDaemonTaskHandle. */
5204             ( UBaseType_t ) MPU_pcTimerGetNameImpl,                         /* SYSTEM_CALL_pcTimerGetName. */
5205             ( UBaseType_t ) MPU_vTimerSetReloadModeImpl,                    /* SYSTEM_CALL_vTimerSetReloadMode. */
5206             ( UBaseType_t ) MPU_xTimerGetReloadModeImpl,                    /* SYSTEM_CALL_xTimerGetReloadMode. */
5207             ( UBaseType_t ) MPU_uxTimerGetReloadModeImpl,                   /* SYSTEM_CALL_uxTimerGetReloadMode. */
5208             ( UBaseType_t ) MPU_xTimerGetPeriodImpl,                        /* SYSTEM_CALL_xTimerGetPeriod. */
5209             ( UBaseType_t ) MPU_xTimerGetExpiryTimeImpl,                    /* SYSTEM_CALL_xTimerGetExpiryTime. */
5210         #else
5211             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_pvTimerGetTimerID. */
5212             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_vTimerSetTimerID. */
5213             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xTimerIsTimerActive. */
5214             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xTimerGetTimerDaemonTaskHandle. */
5215             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_pcTimerGetName. */
5216             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_vTimerSetReloadMode. */
5217             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xTimerGetReloadMode. */
5218             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_uxTimerGetReloadMode. */
5219             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xTimerGetPeriod. */
5220             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xTimerGetExpiryTime. */
5221         #endif
5222 
5223         #if ( configUSE_EVENT_GROUPS == 1 )
5224             ( UBaseType_t ) MPU_xEventGroupClearBitsImpl,                   /* SYSTEM_CALL_xEventGroupClearBits. */
5225             ( UBaseType_t ) MPU_xEventGroupSetBitsImpl,                     /* SYSTEM_CALL_xEventGroupSetBits. */
5226             ( UBaseType_t ) MPU_xEventGroupSyncImpl,                        /* SYSTEM_CALL_xEventGroupSync. */
5227 
5228             #if ( configUSE_TRACE_FACILITY == 1 )
5229                 ( UBaseType_t ) MPU_uxEventGroupGetNumberImpl,              /* SYSTEM_CALL_uxEventGroupGetNumber. */
5230                 ( UBaseType_t ) MPU_vEventGroupSetNumberImpl,               /* SYSTEM_CALL_vEventGroupSetNumber. */
5231             #else
5232                 ( UBaseType_t ) 0,                                          /* SYSTEM_CALL_uxEventGroupGetNumber. */
5233                 ( UBaseType_t ) 0,                                          /* SYSTEM_CALL_vEventGroupSetNumber. */
5234             #endif
5235         #else
5236             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xEventGroupClearBits. */
5237             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xEventGroupSetBits. */
5238             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xEventGroupSync. */
5239             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_uxEventGroupGetNumber. */
5240             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_vEventGroupSetNumber. */
5241         #endif
5242 
5243         #if ( configUSE_STREAM_BUFFERS == 1 )
5244             ( UBaseType_t ) MPU_xStreamBufferSendImpl,                      /* SYSTEM_CALL_xStreamBufferSend. */
5245             ( UBaseType_t ) MPU_xStreamBufferReceiveImpl,                   /* SYSTEM_CALL_xStreamBufferReceive. */
5246             ( UBaseType_t ) MPU_xStreamBufferIsFullImpl,                    /* SYSTEM_CALL_xStreamBufferIsFull. */
5247             ( UBaseType_t ) MPU_xStreamBufferIsEmptyImpl,                   /* SYSTEM_CALL_xStreamBufferIsEmpty. */
5248             ( UBaseType_t ) MPU_xStreamBufferSpacesAvailableImpl,           /* SYSTEM_CALL_xStreamBufferSpacesAvailable. */
5249             ( UBaseType_t ) MPU_xStreamBufferBytesAvailableImpl,            /* SYSTEM_CALL_xStreamBufferBytesAvailable. */
5250             ( UBaseType_t ) MPU_xStreamBufferSetTriggerLevelImpl,           /* SYSTEM_CALL_xStreamBufferSetTriggerLevel. */
5251             ( UBaseType_t ) MPU_xStreamBufferNextMessageLengthBytesImpl     /* SYSTEM_CALL_xStreamBufferNextMessageLengthBytes. */
5252         #else
5253             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xStreamBufferSend. */
5254             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xStreamBufferReceive. */
5255             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xStreamBufferIsFull. */
5256             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xStreamBufferIsEmpty. */
5257             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xStreamBufferSpacesAvailable. */
5258             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xStreamBufferBytesAvailable. */
5259             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xStreamBufferSetTriggerLevel. */
5260             ( UBaseType_t ) 0,                                              /* SYSTEM_CALL_xStreamBufferNextMessageLengthBytes. */
5261         #endif
5262 
5263     };
5264 /*-----------------------------------------------------------*/
5265 
5266 #endif /* #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) ) */
5267 /*-----------------------------------------------------------*/
5268