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