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