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