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