2 * FreeRTOS Kernel <DEVELOPMENT BRANCH>
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: MIT
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:
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
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.
24 * https://www.FreeRTOS.org
25 * https://github.com/FreeRTOS
30 * Implementation of the wrapper functions used to raise the processor privilege
31 * before calling a standard FreeRTOS API function.
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
39 /* Scheduler includes. */
44 #include "event_groups.h"
45 #include "stream_buffer.h"
46 #include "mpu_prototypes.h"
48 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
49 /*-----------------------------------------------------------*/
51 #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) )
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.
58 * @brief Offset added to the index before returning to the user.
60 * If the actual handle is stored at index i, ( i + INDEX_OFFSET )
61 * is returned to the user.
63 #define INDEX_OFFSET 1
66 * @brief Opaque type for a kernel object.
69 typedef struct OpaqueObject * OpaqueObjectHandle_t;
72 * @brief Defines kernel object in the kernel object pool.
74 typedef struct KernelObject
76 OpaqueObjectHandle_t xInternalObjectHandle;
77 uint32_t ulKernelObjectType;
78 void * pvKernelObjectData;
82 * @brief Kernel object types.
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 )
92 * @brief Checks whether an external index is valid or not.
94 #define IS_EXTERNAL_INDEX_VALID( lIndex ) \
95 ( ( ( lIndex ) >= INDEX_OFFSET ) && \
96 ( ( lIndex ) < ( configPROTECTED_KERNEL_OBJECT_POOL_SIZE + INDEX_OFFSET ) ) )
99 * @brief Checks whether an internal index is valid or not.
101 #define IS_INTERNAL_INDEX_VALID( lIndex ) \
102 ( ( ( lIndex ) >= 0 ) && \
103 ( ( lIndex ) < ( configPROTECTED_KERNEL_OBJECT_POOL_SIZE ) ) )
106 * @brief Converts an internal index into external.
108 #define CONVERT_TO_EXTERNAL_INDEX( lIndex ) ( ( lIndex ) + INDEX_OFFSET )
111 * @brief Converts an external index into internal.
113 #define CONVERT_TO_INTERNAL_INDEX( lIndex ) ( ( lIndex ) - INDEX_OFFSET )
116 * @brief Get the index of a free slot in the kernel object pool.
118 * If a free slot is found, this function marks the slot as
121 * @return Index of a free slot is returned, if a free slot is
122 * found. Otherwise -1 is returned.
124 static int32_t MPU_GetFreeIndexInKernelObjectPool( void ) PRIVILEGED_FUNCTION;
127 * @brief Set the given index as free in the kernel object pool.
129 * @param lIndex The index to set as free.
131 static void MPU_SetIndexFreeInKernelObjectPool( int32_t lIndex ) PRIVILEGED_FUNCTION;
134 * @brief Get the index at which a given kernel object is stored.
136 * @param xHandle The given kernel object handle.
137 * @param ulKernelObjectType The kernel object type.
139 * @return Index at which the kernel object is stored if it is a valid
140 * handle, -1 otherwise.
142 static int32_t MPU_GetIndexForHandle( OpaqueObjectHandle_t xHandle,
143 uint32_t ulKernelObjectType ) PRIVILEGED_FUNCTION;
146 * @brief Store the given kernel object handle at the given index in
147 * the kernel object pool.
149 * @param lIndex Index to store the given handle at.
150 * @param xHandle Kernel object handle to store.
151 * @param pvKernelObjectData The data associated with the kernel object.
152 * Currently, only used for timer objects to store timer callback.
153 * @param ulKernelObjectType The kernel object type.
155 static void MPU_StoreHandleAndDataAtIndex( int32_t lIndex,
156 OpaqueObjectHandle_t xHandle,
157 void * pvKernelObjectData,
158 uint32_t ulKernelObjectType ) PRIVILEGED_FUNCTION;
161 * @brief Get the kernel object handle at the given index from
162 * the kernel object pool.
164 * @param lIndex Index at which to get the kernel object handle.
165 * @param ulKernelObjectType The kernel object type.
167 * @return The kernel object handle at the index.
169 static OpaqueObjectHandle_t MPU_GetHandleAtIndex( int32_t lIndex,
170 uint32_t ulKernelObjectType ) PRIVILEGED_FUNCTION;
172 #if ( configUSE_TIMERS == 1 )
175 * @brief The function registered as callback for all the timers.
177 * We intercept all the timer callbacks so that we can call application
178 * callbacks with opaque handle.
180 * @param xInternalHandle The internal timer handle.
182 static void MPU_TimerCallback( TimerHandle_t xInternalHandle ) PRIVILEGED_FUNCTION;
184 #endif /* #if ( configUSE_TIMERS == 1 ) */
187 * Wrappers to keep all the casting in one place.
189 #define MPU_StoreQueueHandleAtIndex( lIndex, xHandle ) MPU_StoreHandleAndDataAtIndex( lIndex, ( OpaqueObjectHandle_t ) xHandle, NULL, KERNEL_OBJECT_TYPE_QUEUE )
190 #define MPU_GetQueueHandleAtIndex( lIndex ) ( QueueHandle_t ) MPU_GetHandleAtIndex( lIndex, KERNEL_OBJECT_TYPE_QUEUE )
192 #if ( configUSE_QUEUE_SETS == 1 )
193 #define MPU_StoreQueueSetHandleAtIndex( lIndex, xHandle ) MPU_StoreHandleAndDataAtIndex( lIndex, ( OpaqueObjectHandle_t ) xHandle, NULL, KERNEL_OBJECT_TYPE_QUEUE )
194 #define MPU_GetQueueSetHandleAtIndex( lIndex ) ( QueueSetHandle_t ) MPU_GetHandleAtIndex( lIndex, KERNEL_OBJECT_TYPE_QUEUE )
195 #define MPU_StoreQueueSetMemberHandleAtIndex( lIndex, xHandle ) MPU_StoreHandleAndDataAtIndex( lIndex, ( OpaqueObjectHandle_t ) xHandle, NULL, KERNEL_OBJECT_TYPE_QUEUE )
196 #define MPU_GetQueueSetMemberHandleAtIndex( lIndex ) ( QueueSetMemberHandle_t ) MPU_GetHandleAtIndex( lIndex, KERNEL_OBJECT_TYPE_QUEUE )
197 #define MPU_GetIndexForQueueSetMemberHandle( xHandle ) MPU_GetIndexForHandle( ( OpaqueObjectHandle_t ) xHandle, KERNEL_OBJECT_TYPE_QUEUE )
201 * Wrappers to keep all the casting in one place for Task APIs.
203 #define MPU_StoreTaskHandleAtIndex( lIndex, xHandle ) MPU_StoreHandleAndDataAtIndex( lIndex, ( OpaqueObjectHandle_t ) xHandle, NULL, KERNEL_OBJECT_TYPE_TASK )
204 #define MPU_GetTaskHandleAtIndex( lIndex ) ( TaskHandle_t ) MPU_GetHandleAtIndex( lIndex, KERNEL_OBJECT_TYPE_TASK )
205 #define MPU_GetIndexForTaskHandle( xHandle ) MPU_GetIndexForHandle( ( OpaqueObjectHandle_t ) xHandle, KERNEL_OBJECT_TYPE_TASK )
208 * Wrappers to keep all the casting in one place for Event Group APIs.
210 #define MPU_StoreEventGroupHandleAtIndex( lIndex, xHandle ) MPU_StoreHandleAndDataAtIndex( lIndex, ( OpaqueObjectHandle_t ) xHandle, NULL, KERNEL_OBJECT_TYPE_EVENT_GROUP )
211 #define MPU_GetEventGroupHandleAtIndex( lIndex ) ( EventGroupHandle_t ) MPU_GetHandleAtIndex( lIndex, KERNEL_OBJECT_TYPE_EVENT_GROUP )
212 #define MPU_GetIndexForEventGroupHandle( xHandle ) MPU_GetIndexForHandle( ( OpaqueObjectHandle_t ) xHandle, KERNEL_OBJECT_TYPE_EVENT_GROUP )
215 * Wrappers to keep all the casting in one place for Stream Buffer APIs.
217 #define MPU_StoreStreamBufferHandleAtIndex( lIndex, xHandle ) MPU_StoreHandleAndDataAtIndex( lIndex, ( OpaqueObjectHandle_t ) xHandle, NULL, KERNEL_OBJECT_TYPE_STREAM_BUFFER )
218 #define MPU_GetStreamBufferHandleAtIndex( lIndex ) ( StreamBufferHandle_t ) MPU_GetHandleAtIndex( lIndex, KERNEL_OBJECT_TYPE_STREAM_BUFFER )
219 #define MPU_GetIndexForStreamBufferHandle( xHandle ) MPU_GetIndexForHandle( ( OpaqueObjectHandle_t ) xHandle, KERNEL_OBJECT_TYPE_STREAM_BUFFER )
221 #if ( configUSE_TIMERS == 1 )
224 * Wrappers to keep all the casting in one place for Timer APIs.
226 #define MPU_StoreTimerHandleAtIndex( lIndex, xHandle, pxApplicationCallback ) MPU_StoreHandleAndDataAtIndex( lIndex, ( OpaqueObjectHandle_t ) xHandle, ( void * ) pxApplicationCallback, KERNEL_OBJECT_TYPE_TIMER )
227 #define MPU_GetTimerHandleAtIndex( lIndex ) ( TimerHandle_t ) MPU_GetHandleAtIndex( lIndex, KERNEL_OBJECT_TYPE_TIMER )
228 #define MPU_GetIndexForTimerHandle( xHandle ) MPU_GetIndexForHandle( ( OpaqueObjectHandle_t ) xHandle, KERNEL_OBJECT_TYPE_TIMER )
230 #endif /* #if ( configUSE_TIMERS == 1 ) */
232 /*-----------------------------------------------------------*/
235 * @brief Kernel object pool.
237 PRIVILEGED_DATA static KernelObject_t xKernelObjectPool[ configPROTECTED_KERNEL_OBJECT_POOL_SIZE ] = { NULL };
238 /*-----------------------------------------------------------*/
240 static int32_t MPU_GetFreeIndexInKernelObjectPool( void ) /* PRIVILEGED_FUNCTION */
242 int32_t i, lFreeIndex = -1;
244 /* This function is called only from resource create APIs
245 * which are not supposed to be called from ISRs. Therefore,
246 * we only need to suspend the scheduler and do not require
247 * critical section. */
250 for( i = 0; i < configPROTECTED_KERNEL_OBJECT_POOL_SIZE; i++ )
252 if( xKernelObjectPool[ i ].xInternalObjectHandle == NULL )
254 /* Mark this index as not free. */
255 xKernelObjectPool[ i ].xInternalObjectHandle = ( OpaqueObjectHandle_t ) ( ~0 );
265 /*-----------------------------------------------------------*/
267 static void MPU_SetIndexFreeInKernelObjectPool( int32_t lIndex ) /* PRIVILEGED_FUNCTION */
269 configASSERT( IS_INTERNAL_INDEX_VALID( lIndex ) != pdFALSE );
271 taskENTER_CRITICAL();
273 xKernelObjectPool[ lIndex ].xInternalObjectHandle = NULL;
274 xKernelObjectPool[ lIndex ].ulKernelObjectType = KERNEL_OBJECT_TYPE_INVALID;
275 xKernelObjectPool[ lIndex ].pvKernelObjectData = NULL;
279 /*-----------------------------------------------------------*/
281 static int32_t MPU_GetIndexForHandle( OpaqueObjectHandle_t xHandle,
282 uint32_t ulKernelObjectType ) /* PRIVILEGED_FUNCTION */
284 int32_t i, lIndex = -1;
286 configASSERT( xHandle != NULL );
288 for( i = 0; i < configPROTECTED_KERNEL_OBJECT_POOL_SIZE; i++ )
290 if( ( xKernelObjectPool[ i ].xInternalObjectHandle == xHandle ) &&
291 ( xKernelObjectPool[ i ].ulKernelObjectType == ulKernelObjectType ) )
300 /*-----------------------------------------------------------*/
302 static void MPU_StoreHandleAndDataAtIndex( int32_t lIndex,
303 OpaqueObjectHandle_t xHandle,
304 void * pvKernelObjectData,
305 uint32_t ulKernelObjectType ) /* PRIVILEGED_FUNCTION */
307 configASSERT( IS_INTERNAL_INDEX_VALID( lIndex ) != pdFALSE );
308 xKernelObjectPool[ lIndex ].xInternalObjectHandle = xHandle;
309 xKernelObjectPool[ lIndex ].ulKernelObjectType = ulKernelObjectType;
310 xKernelObjectPool[ lIndex ].pvKernelObjectData = pvKernelObjectData;
312 /*-----------------------------------------------------------*/
314 static OpaqueObjectHandle_t MPU_GetHandleAtIndex( int32_t lIndex,
315 uint32_t ulKernelObjectType ) /* PRIVILEGED_FUNCTION */
317 configASSERT( IS_INTERNAL_INDEX_VALID( lIndex ) != pdFALSE );
318 configASSERT( xKernelObjectPool[ lIndex ].ulKernelObjectType == ulKernelObjectType );
319 return xKernelObjectPool[ lIndex ].xInternalObjectHandle;
321 /*-----------------------------------------------------------*/
323 #if ( configENABLE_ACCESS_CONTROL_LIST == 1 )
325 void vGrantAccessToKernelObject( TaskHandle_t xExternalTaskHandle,
326 int32_t lExternalKernelObjectHandle ) /* PRIVILEGED_FUNCTION */
328 int32_t lExternalTaskIndex;
329 TaskHandle_t xInternalTaskHandle = NULL;
331 if( IS_EXTERNAL_INDEX_VALID( lExternalKernelObjectHandle ) != pdFALSE )
333 if( xExternalTaskHandle == NULL )
335 vPortGrantAccessToKernelObject( xExternalTaskHandle, CONVERT_TO_INTERNAL_INDEX( lExternalKernelObjectHandle ) );
339 lExternalTaskIndex = ( int32_t ) xExternalTaskHandle;
341 if( IS_EXTERNAL_INDEX_VALID( lExternalTaskIndex ) != pdFALSE )
343 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lExternalTaskIndex ) );
345 if( xInternalTaskHandle != NULL )
347 vPortGrantAccessToKernelObject( xInternalTaskHandle,
348 CONVERT_TO_INTERNAL_INDEX( lExternalKernelObjectHandle ) );
355 #endif /* #if ( configENABLE_ACCESS_CONTROL_LIST == 1 ) */
356 /*-----------------------------------------------------------*/
358 #if ( configENABLE_ACCESS_CONTROL_LIST == 1 )
360 void vRevokeAccessToKernelObject( TaskHandle_t xExternalTaskHandle,
361 int32_t lExternalKernelObjectHandle ) /* PRIVILEGED_FUNCTION */
363 int32_t lExternalTaskIndex;
364 TaskHandle_t xInternalTaskHandle = NULL;
366 if( IS_EXTERNAL_INDEX_VALID( lExternalKernelObjectHandle ) != pdFALSE )
368 if( xExternalTaskHandle == NULL )
370 vPortRevokeAccessToKernelObject( xExternalTaskHandle, CONVERT_TO_INTERNAL_INDEX( lExternalKernelObjectHandle ) );
374 lExternalTaskIndex = ( int32_t ) xExternalTaskHandle;
376 if( IS_EXTERNAL_INDEX_VALID( lExternalTaskIndex ) != pdFALSE )
378 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lExternalTaskIndex ) );
380 if( xInternalTaskHandle != NULL )
382 vPortRevokeAccessToKernelObject( xInternalTaskHandle,
383 CONVERT_TO_INTERNAL_INDEX( lExternalKernelObjectHandle ) );
390 #endif /* #if ( configENABLE_ACCESS_CONTROL_LIST == 1 ) */
391 /*-----------------------------------------------------------*/
393 #if ( configUSE_TIMERS == 1 )
395 static void MPU_TimerCallback( TimerHandle_t xInternalHandle ) /* PRIVILEGED_FUNCTION */
397 int32_t i, lIndex = -1;
398 TimerHandle_t xExternalHandle = NULL;
399 TimerCallbackFunction_t pxApplicationCallBack = NULL;
401 /* Coming from the timer task and therefore, should be valid. */
402 configASSERT( xInternalHandle != NULL );
404 for( i = 0; i < configPROTECTED_KERNEL_OBJECT_POOL_SIZE; i++ )
406 if( ( ( TimerHandle_t ) xKernelObjectPool[ i ].xInternalObjectHandle == xInternalHandle ) &&
407 ( xKernelObjectPool[ i ].ulKernelObjectType == KERNEL_OBJECT_TYPE_TIMER ) )
414 configASSERT( lIndex != -1 );
415 xExternalHandle = ( TimerHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
417 pxApplicationCallBack = ( TimerCallbackFunction_t ) xKernelObjectPool[ lIndex ].pvKernelObjectData;
418 pxApplicationCallBack( xExternalHandle );
421 #endif /* #if ( configUSE_TIMERS == 1 ) */
422 /*-----------------------------------------------------------*/
424 /*-----------------------------------------------------------*/
425 /* MPU wrappers for tasks APIs. */
426 /*-----------------------------------------------------------*/
428 #if ( INCLUDE_xTaskDelayUntil == 1 )
430 BaseType_t MPU_xTaskDelayUntilImpl( TickType_t * const pxPreviousWakeTime,
431 TickType_t xTimeIncrement ) PRIVILEGED_FUNCTION;
433 BaseType_t MPU_xTaskDelayUntilImpl( TickType_t * const pxPreviousWakeTime,
434 TickType_t xTimeIncrement ) /* PRIVILEGED_FUNCTION */
436 BaseType_t xReturn = pdFAIL;
437 BaseType_t xIsPreviousWakeTimeAccessible = pdFALSE;
439 if( ( pxPreviousWakeTime != NULL ) && ( xTimeIncrement > 0U ) )
441 xIsPreviousWakeTimeAccessible = xPortIsAuthorizedToAccessBuffer( pxPreviousWakeTime,
442 sizeof( TickType_t ),
443 ( tskMPU_WRITE_PERMISSION | tskMPU_READ_PERMISSION ) );
445 if( xIsPreviousWakeTimeAccessible == pdTRUE )
447 xReturn = xTaskDelayUntil( pxPreviousWakeTime, xTimeIncrement );
454 #endif /* if ( INCLUDE_xTaskDelayUntil == 1 ) */
455 /*-----------------------------------------------------------*/
457 #if ( INCLUDE_xTaskAbortDelay == 1 )
459 BaseType_t MPU_xTaskAbortDelayImpl( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
461 BaseType_t MPU_xTaskAbortDelayImpl( TaskHandle_t xTask ) /* PRIVILEGED_FUNCTION */
463 BaseType_t xReturn = pdFAIL;
464 BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
465 TaskHandle_t xInternalTaskHandle = NULL;
468 lIndex = ( int32_t ) xTask;
470 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
472 xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
474 if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
476 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
478 if( xInternalTaskHandle != NULL )
480 xReturn = xTaskAbortDelay( xInternalTaskHandle );
488 #endif /* if ( INCLUDE_xTaskAbortDelay == 1 ) */
489 /*-----------------------------------------------------------*/
491 #if ( INCLUDE_vTaskDelay == 1 )
493 void MPU_vTaskDelayImpl( TickType_t xTicksToDelay ) PRIVILEGED_FUNCTION;
495 void MPU_vTaskDelayImpl( TickType_t xTicksToDelay ) /* PRIVILEGED_FUNCTION */
497 vTaskDelay( xTicksToDelay );
500 #endif /* if ( INCLUDE_vTaskDelay == 1 ) */
501 /*-----------------------------------------------------------*/
503 #if ( INCLUDE_uxTaskPriorityGet == 1 )
505 UBaseType_t MPU_uxTaskPriorityGetImpl( const TaskHandle_t pxTask ) PRIVILEGED_FUNCTION;
507 UBaseType_t MPU_uxTaskPriorityGetImpl( const TaskHandle_t pxTask ) /* PRIVILEGED_FUNCTION */
509 UBaseType_t uxReturn = configMAX_PRIORITIES;
510 BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
512 TaskHandle_t xInternalTaskHandle = NULL;
516 uxReturn = uxTaskPriorityGet( pxTask );
520 lIndex = ( int32_t ) pxTask;
522 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
524 xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
526 if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
528 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
530 if( xInternalTaskHandle != NULL )
532 uxReturn = uxTaskPriorityGet( xInternalTaskHandle );
541 #endif /* if ( INCLUDE_uxTaskPriorityGet == 1 ) */
542 /*-----------------------------------------------------------*/
544 #if ( INCLUDE_eTaskGetState == 1 )
546 eTaskState MPU_eTaskGetStateImpl( TaskHandle_t pxTask ) PRIVILEGED_FUNCTION;
548 eTaskState MPU_eTaskGetStateImpl( TaskHandle_t pxTask ) /* PRIVILEGED_FUNCTION */
550 eTaskState eReturn = eInvalid;
551 TaskHandle_t xInternalTaskHandle = NULL;
553 BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
555 lIndex = ( int32_t ) pxTask;
557 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
559 xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
561 if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
563 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
565 if( xInternalTaskHandle != NULL )
567 eReturn = eTaskGetState( xInternalTaskHandle );
575 #endif /* if ( INCLUDE_eTaskGetState == 1 ) */
576 /*-----------------------------------------------------------*/
578 #if ( configUSE_TRACE_FACILITY == 1 )
580 void MPU_vTaskGetInfoImpl( TaskHandle_t xTask,
581 TaskStatus_t * pxTaskStatus,
582 BaseType_t xGetFreeStackSpace,
583 eTaskState eState ) PRIVILEGED_FUNCTION;
585 void MPU_vTaskGetInfoImpl( TaskHandle_t xTask,
586 TaskStatus_t * pxTaskStatus,
587 BaseType_t xGetFreeStackSpace,
588 eTaskState eState ) /* PRIVILEGED_FUNCTION */
591 TaskHandle_t xInternalTaskHandle = NULL;
592 BaseType_t xIsTaskStatusWriteable = pdFALSE;
593 BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
595 xIsTaskStatusWriteable = xPortIsAuthorizedToAccessBuffer( pxTaskStatus,
596 sizeof( TaskStatus_t ),
597 tskMPU_WRITE_PERMISSION );
599 if( xIsTaskStatusWriteable == pdTRUE )
603 vTaskGetInfo( xTask, pxTaskStatus, xGetFreeStackSpace, eState );
607 lIndex = ( int32_t ) xTask;
609 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
611 xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
613 if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
615 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
617 if( xInternalTaskHandle != NULL )
619 vTaskGetInfo( xInternalTaskHandle, pxTaskStatus, xGetFreeStackSpace, eState );
627 #endif /* if ( configUSE_TRACE_FACILITY == 1 ) */
628 /*-----------------------------------------------------------*/
630 #if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )
632 TaskHandle_t MPU_xTaskGetIdleTaskHandleImpl( void ) PRIVILEGED_FUNCTION;
634 TaskHandle_t MPU_xTaskGetIdleTaskHandleImpl( void ) /* PRIVILEGED_FUNCTION */
636 TaskHandle_t xIdleTaskHandle = NULL;
638 xIdleTaskHandle = xTaskGetIdleTaskHandle();
640 return xIdleTaskHandle;
643 #endif /* if ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) */
644 /*-----------------------------------------------------------*/
646 #if ( INCLUDE_vTaskSuspend == 1 )
648 void MPU_vTaskSuspendImpl( TaskHandle_t pxTaskToSuspend ) PRIVILEGED_FUNCTION;
650 void MPU_vTaskSuspendImpl( TaskHandle_t pxTaskToSuspend ) /* PRIVILEGED_FUNCTION */
653 TaskHandle_t xInternalTaskHandle = NULL;
654 BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
656 if( pxTaskToSuspend == NULL )
658 vTaskSuspend( pxTaskToSuspend );
662 /* After the scheduler starts, only privileged tasks are allowed
663 * to suspend other tasks. */
664 #if ( INCLUDE_xTaskGetSchedulerState == 1 )
665 if( ( xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED ) || ( portIS_TASK_PRIVILEGED() == pdTRUE ) )
667 if( portIS_TASK_PRIVILEGED() == pdTRUE )
670 lIndex = ( int32_t ) pxTaskToSuspend;
672 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
674 xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
676 if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
678 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
680 if( xInternalTaskHandle != NULL )
682 vTaskSuspend( xInternalTaskHandle );
690 #endif /* if ( INCLUDE_vTaskSuspend == 1 ) */
691 /*-----------------------------------------------------------*/
693 #if ( INCLUDE_vTaskSuspend == 1 )
695 void MPU_vTaskResumeImpl( TaskHandle_t pxTaskToResume ) PRIVILEGED_FUNCTION;
697 void MPU_vTaskResumeImpl( TaskHandle_t pxTaskToResume ) /* PRIVILEGED_FUNCTION */
700 TaskHandle_t xInternalTaskHandle = NULL;
701 BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
703 lIndex = ( int32_t ) pxTaskToResume;
705 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
707 xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
709 if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
711 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
713 if( xInternalTaskHandle != NULL )
715 vTaskResume( xInternalTaskHandle );
721 #endif /* if ( INCLUDE_vTaskSuspend == 1 ) */
722 /*-----------------------------------------------------------*/
724 TickType_t MPU_xTaskGetTickCountImpl( void ) PRIVILEGED_FUNCTION;
726 TickType_t MPU_xTaskGetTickCountImpl( void ) /* PRIVILEGED_FUNCTION */
730 xReturn = xTaskGetTickCount();
734 /*-----------------------------------------------------------*/
736 UBaseType_t MPU_uxTaskGetNumberOfTasksImpl( void ) PRIVILEGED_FUNCTION;
738 UBaseType_t MPU_uxTaskGetNumberOfTasksImpl( void ) /* PRIVILEGED_FUNCTION */
740 UBaseType_t uxReturn;
742 uxReturn = uxTaskGetNumberOfTasks();
746 /*-----------------------------------------------------------*/
748 #if ( configGENERATE_RUN_TIME_STATS == 1 )
750 configRUN_TIME_COUNTER_TYPE MPU_ulTaskGetRunTimeCounterImpl( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
752 configRUN_TIME_COUNTER_TYPE MPU_ulTaskGetRunTimeCounterImpl( const TaskHandle_t xTask ) /* PRIVILEGED_FUNCTION */
754 configRUN_TIME_COUNTER_TYPE xReturn = 0;
756 TaskHandle_t xInternalTaskHandle = NULL;
757 BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
761 xReturn = ulTaskGetRunTimeCounter( xTask );
765 lIndex = ( int32_t ) xTask;
767 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
769 xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
771 if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
773 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
775 if( xInternalTaskHandle != NULL )
777 xReturn = ulTaskGetRunTimeCounter( xInternalTaskHandle );
786 #endif /* if ( ( configGENERATE_RUN_TIME_STATS == 1 ) */
787 /*-----------------------------------------------------------*/
789 #if ( configGENERATE_RUN_TIME_STATS == 1 )
791 configRUN_TIME_COUNTER_TYPE MPU_ulTaskGetRunTimePercentImpl( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
793 configRUN_TIME_COUNTER_TYPE MPU_ulTaskGetRunTimePercentImpl( const TaskHandle_t xTask ) /* PRIVILEGED_FUNCTION */
795 configRUN_TIME_COUNTER_TYPE xReturn = 0;
797 TaskHandle_t xInternalTaskHandle = NULL;
798 BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
802 xReturn = ulTaskGetRunTimePercent( xTask );
806 lIndex = ( int32_t ) xTask;
808 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
810 xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
812 if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
814 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
816 if( xInternalTaskHandle != NULL )
818 xReturn = ulTaskGetRunTimePercent( xInternalTaskHandle );
827 #endif /* if ( ( configGENERATE_RUN_TIME_STATS == 1 ) */
828 /*-----------------------------------------------------------*/
830 #if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) )
832 configRUN_TIME_COUNTER_TYPE MPU_ulTaskGetIdleRunTimePercentImpl( void ) PRIVILEGED_FUNCTION;
834 configRUN_TIME_COUNTER_TYPE MPU_ulTaskGetIdleRunTimePercentImpl( void ) /* PRIVILEGED_FUNCTION */
836 configRUN_TIME_COUNTER_TYPE xReturn;
838 xReturn = ulTaskGetIdleRunTimePercent();
843 #endif /* if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) ) */
844 /*-----------------------------------------------------------*/
846 #if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) )
848 configRUN_TIME_COUNTER_TYPE MPU_ulTaskGetIdleRunTimeCounterImpl( void ) PRIVILEGED_FUNCTION;
850 configRUN_TIME_COUNTER_TYPE MPU_ulTaskGetIdleRunTimeCounterImpl( void ) /* PRIVILEGED_FUNCTION */
852 configRUN_TIME_COUNTER_TYPE xReturn;
854 xReturn = ulTaskGetIdleRunTimeCounter();
859 #endif /* if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) ) */
860 /*-----------------------------------------------------------*/
862 #if ( configUSE_APPLICATION_TASK_TAG == 1 )
864 void MPU_vTaskSetApplicationTaskTagImpl( TaskHandle_t xTask,
865 TaskHookFunction_t pxTagValue ) PRIVILEGED_FUNCTION;
867 void MPU_vTaskSetApplicationTaskTagImpl( TaskHandle_t xTask,
868 TaskHookFunction_t pxTagValue ) /* PRIVILEGED_FUNCTION */
870 TaskHandle_t xInternalTaskHandle = NULL;
872 BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
876 vTaskSetApplicationTaskTag( xTask, pxTagValue );
880 lIndex = ( int32_t ) xTask;
882 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
884 xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
886 if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
888 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
890 if( xInternalTaskHandle != NULL )
892 vTaskSetApplicationTaskTag( xInternalTaskHandle, pxTagValue );
899 #endif /* if ( configUSE_APPLICATION_TASK_TAG == 1 ) */
900 /*-----------------------------------------------------------*/
902 #if ( configUSE_APPLICATION_TASK_TAG == 1 )
904 TaskHookFunction_t MPU_xTaskGetApplicationTaskTagImpl( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
906 TaskHookFunction_t MPU_xTaskGetApplicationTaskTagImpl( TaskHandle_t xTask ) /* PRIVILEGED_FUNCTION */
908 TaskHookFunction_t xReturn = NULL;
910 TaskHandle_t xInternalTaskHandle = NULL;
911 BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
915 xReturn = xTaskGetApplicationTaskTag( xTask );
919 lIndex = ( int32_t ) xTask;
921 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
923 xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
925 if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
927 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
929 if( xInternalTaskHandle != NULL )
931 xReturn = xTaskGetApplicationTaskTag( xInternalTaskHandle );
940 #endif /* if ( configUSE_APPLICATION_TASK_TAG == 1 ) */
941 /*-----------------------------------------------------------*/
943 #if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 )
945 void MPU_vTaskSetThreadLocalStoragePointerImpl( TaskHandle_t xTaskToSet,
947 void * pvValue ) PRIVILEGED_FUNCTION;
949 void MPU_vTaskSetThreadLocalStoragePointerImpl( TaskHandle_t xTaskToSet,
951 void * pvValue ) /* PRIVILEGED_FUNCTION */
954 TaskHandle_t xInternalTaskHandle = NULL;
955 BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
957 if( xTaskToSet == NULL )
959 vTaskSetThreadLocalStoragePointer( xTaskToSet, xIndex, pvValue );
963 lIndex = ( int32_t ) xTaskToSet;
965 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
967 xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
969 if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
971 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
973 if( xInternalTaskHandle != NULL )
975 vTaskSetThreadLocalStoragePointer( xInternalTaskHandle, xIndex, pvValue );
982 #endif /* if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 ) */
983 /*-----------------------------------------------------------*/
985 #if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 )
987 void * MPU_pvTaskGetThreadLocalStoragePointerImpl( TaskHandle_t xTaskToQuery,
988 BaseType_t xIndex ) PRIVILEGED_FUNCTION;
990 void * MPU_pvTaskGetThreadLocalStoragePointerImpl( TaskHandle_t xTaskToQuery,
991 BaseType_t xIndex ) /* PRIVILEGED_FUNCTION */
993 void * pvReturn = NULL;
995 TaskHandle_t xInternalTaskHandle = NULL;
996 BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
998 if( xTaskToQuery == NULL )
1000 pvReturn = pvTaskGetThreadLocalStoragePointer( xTaskToQuery, xIndex );
1004 lIndex = ( int32_t ) xTaskToQuery;
1006 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1008 xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1010 if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
1012 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1014 if( xInternalTaskHandle != NULL )
1016 pvReturn = pvTaskGetThreadLocalStoragePointer( xInternalTaskHandle, xIndex );
1025 #endif /* if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 ) */
1026 /*-----------------------------------------------------------*/
1028 #if ( configUSE_TRACE_FACILITY == 1 )
1030 UBaseType_t MPU_uxTaskGetSystemStateImpl( TaskStatus_t * pxTaskStatusArray,
1031 UBaseType_t uxArraySize,
1032 configRUN_TIME_COUNTER_TYPE * pulTotalRunTime ) PRIVILEGED_FUNCTION;
1034 UBaseType_t MPU_uxTaskGetSystemStateImpl( TaskStatus_t * pxTaskStatusArray,
1035 UBaseType_t uxArraySize,
1036 configRUN_TIME_COUNTER_TYPE * pulTotalRunTime ) /* PRIVILEGED_FUNCTION */
1038 UBaseType_t uxReturn = pdFALSE;
1039 UBaseType_t xIsTaskStatusArrayWriteable = pdFALSE;
1040 UBaseType_t xIsTotalRunTimeWriteable = pdFALSE;
1042 xIsTaskStatusArrayWriteable = xPortIsAuthorizedToAccessBuffer( pxTaskStatusArray,
1043 sizeof( TaskStatus_t ) * uxArraySize,
1044 tskMPU_WRITE_PERMISSION );
1046 if( pulTotalRunTime != NULL )
1048 xIsTotalRunTimeWriteable = xPortIsAuthorizedToAccessBuffer( pulTotalRunTime,
1049 sizeof( configRUN_TIME_COUNTER_TYPE ),
1050 tskMPU_WRITE_PERMISSION );
1053 if( ( xIsTaskStatusArrayWriteable == pdTRUE ) &&
1054 ( ( pulTotalRunTime == NULL ) || ( xIsTotalRunTimeWriteable == pdTRUE ) ) )
1056 uxReturn = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, pulTotalRunTime );
1062 #endif /* if ( configUSE_TRACE_FACILITY == 1 ) */
1063 /*-----------------------------------------------------------*/
1065 #if ( INCLUDE_uxTaskGetStackHighWaterMark == 1 )
1067 UBaseType_t MPU_uxTaskGetStackHighWaterMarkImpl( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1069 UBaseType_t MPU_uxTaskGetStackHighWaterMarkImpl( TaskHandle_t xTask ) /* PRIVILEGED_FUNCTION */
1071 UBaseType_t uxReturn = 0;
1073 TaskHandle_t xInternalTaskHandle = NULL;
1074 BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
1078 uxReturn = uxTaskGetStackHighWaterMark( xTask );
1082 lIndex = ( int32_t ) xTask;
1084 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1086 xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1088 if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
1090 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1092 if( xInternalTaskHandle != NULL )
1094 uxReturn = uxTaskGetStackHighWaterMark( xInternalTaskHandle );
1103 #endif /* if ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) */
1104 /*-----------------------------------------------------------*/
1106 #if ( INCLUDE_uxTaskGetStackHighWaterMark2 == 1 )
1108 configSTACK_DEPTH_TYPE MPU_uxTaskGetStackHighWaterMark2Impl( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1110 configSTACK_DEPTH_TYPE MPU_uxTaskGetStackHighWaterMark2Impl( TaskHandle_t xTask ) /* PRIVILEGED_FUNCTION */
1112 configSTACK_DEPTH_TYPE uxReturn = 0;
1114 TaskHandle_t xInternalTaskHandle = NULL;
1115 BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
1119 uxReturn = uxTaskGetStackHighWaterMark2( xTask );
1123 lIndex = ( int32_t ) xTask;
1125 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1127 xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1129 if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
1131 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1133 if( xInternalTaskHandle != NULL )
1135 uxReturn = uxTaskGetStackHighWaterMark2( xInternalTaskHandle );
1144 #endif /* if ( INCLUDE_uxTaskGetStackHighWaterMark2 == 1 ) */
1145 /*-----------------------------------------------------------*/
1147 #if ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) )
1149 TaskHandle_t MPU_xTaskGetCurrentTaskHandleImpl( void ) PRIVILEGED_FUNCTION;
1151 TaskHandle_t MPU_xTaskGetCurrentTaskHandleImpl( void ) /* PRIVILEGED_FUNCTION */
1153 TaskHandle_t xInternalTaskHandle = NULL;
1154 TaskHandle_t xExternalTaskHandle = NULL;
1157 xInternalTaskHandle = xTaskGetCurrentTaskHandle();
1159 if( xInternalTaskHandle != NULL )
1161 lIndex = MPU_GetIndexForTaskHandle( xInternalTaskHandle );
1165 xExternalTaskHandle = ( TaskHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
1169 return xExternalTaskHandle;
1172 #endif /* if ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) ) */
1173 /*-----------------------------------------------------------*/
1175 #if ( INCLUDE_xTaskGetSchedulerState == 1 )
1177 BaseType_t MPU_xTaskGetSchedulerStateImpl( void ) PRIVILEGED_FUNCTION;
1179 BaseType_t MPU_xTaskGetSchedulerStateImpl( void ) /* PRIVILEGED_FUNCTION */
1181 BaseType_t xReturn = taskSCHEDULER_NOT_STARTED;
1183 xReturn = xTaskGetSchedulerState();
1188 #endif /* if ( INCLUDE_xTaskGetSchedulerState == 1 ) */
1189 /*-----------------------------------------------------------*/
1191 void MPU_vTaskSetTimeOutStateImpl( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
1193 void MPU_vTaskSetTimeOutStateImpl( TimeOut_t * const pxTimeOut ) /* PRIVILEGED_FUNCTION */
1195 BaseType_t xIsTimeOutWriteable = pdFALSE;
1197 if( pxTimeOut != NULL )
1199 xIsTimeOutWriteable = xPortIsAuthorizedToAccessBuffer( pxTimeOut,
1200 sizeof( TimeOut_t ),
1201 tskMPU_WRITE_PERMISSION );
1203 if( xIsTimeOutWriteable == pdTRUE )
1205 vTaskSetTimeOutState( pxTimeOut );
1209 /*-----------------------------------------------------------*/
1211 BaseType_t MPU_xTaskCheckForTimeOutImpl( TimeOut_t * const pxTimeOut,
1212 TickType_t * const pxTicksToWait ) PRIVILEGED_FUNCTION;
1214 BaseType_t MPU_xTaskCheckForTimeOutImpl( TimeOut_t * const pxTimeOut,
1215 TickType_t * const pxTicksToWait ) /* PRIVILEGED_FUNCTION */
1217 BaseType_t xReturn = pdFALSE;
1218 BaseType_t xIsTimeOutWriteable = pdFALSE;
1219 BaseType_t xIsTicksToWaitWriteable = pdFALSE;
1221 if( ( pxTimeOut != NULL ) && ( pxTicksToWait != NULL ) )
1223 xIsTimeOutWriteable = xPortIsAuthorizedToAccessBuffer( pxTimeOut,
1224 sizeof( TimeOut_t ),
1225 tskMPU_WRITE_PERMISSION );
1226 xIsTicksToWaitWriteable = xPortIsAuthorizedToAccessBuffer( pxTicksToWait,
1227 sizeof( TickType_t ),
1228 tskMPU_WRITE_PERMISSION );
1230 if( ( xIsTimeOutWriteable == pdTRUE ) && ( xIsTicksToWaitWriteable == pdTRUE ) )
1232 xReturn = xTaskCheckForTimeOut( pxTimeOut, pxTicksToWait );
1238 /*-----------------------------------------------------------*/
1240 #if ( configUSE_TASK_NOTIFICATIONS == 1 )
1242 BaseType_t MPU_xTaskGenericNotifyImpl( TaskHandle_t xTaskToNotify,
1243 UBaseType_t uxIndexToNotify,
1245 eNotifyAction eAction,
1246 uint32_t * pulPreviousNotificationValue ) PRIVILEGED_FUNCTION;
1248 BaseType_t MPU_xTaskGenericNotifyImpl( TaskHandle_t xTaskToNotify,
1249 UBaseType_t uxIndexToNotify,
1251 eNotifyAction eAction,
1252 uint32_t * pulPreviousNotificationValue ) /* PRIVILEGED_FUNCTION */
1254 BaseType_t xReturn = pdFAIL;
1256 TaskHandle_t xInternalTaskHandle = NULL;
1257 BaseType_t xIsPreviousNotificationValueWriteable = pdFALSE;
1258 BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
1260 if( uxIndexToNotify < configTASK_NOTIFICATION_ARRAY_ENTRIES )
1262 if( pulPreviousNotificationValue != NULL )
1264 xIsPreviousNotificationValueWriteable = xPortIsAuthorizedToAccessBuffer( pulPreviousNotificationValue,
1266 tskMPU_WRITE_PERMISSION );
1269 if( ( pulPreviousNotificationValue == NULL ) || ( xIsPreviousNotificationValueWriteable == pdTRUE ) )
1271 lIndex = ( int32_t ) xTaskToNotify;
1273 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1275 xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1277 if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
1279 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1281 if( xInternalTaskHandle != NULL )
1283 xReturn = xTaskGenericNotify( xInternalTaskHandle, uxIndexToNotify, ulValue, eAction, pulPreviousNotificationValue );
1293 #endif /* if ( configUSE_TASK_NOTIFICATIONS == 1 ) */
1294 /*-----------------------------------------------------------*/
1296 #if ( configUSE_TASK_NOTIFICATIONS == 1 )
1298 BaseType_t MPU_xTaskGenericNotifyWaitImpl( UBaseType_t uxIndexToWaitOn,
1299 uint32_t ulBitsToClearOnEntry,
1300 uint32_t ulBitsToClearOnExit,
1301 uint32_t * pulNotificationValue,
1302 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1304 BaseType_t MPU_xTaskGenericNotifyWaitImpl( UBaseType_t uxIndexToWaitOn,
1305 uint32_t ulBitsToClearOnEntry,
1306 uint32_t ulBitsToClearOnExit,
1307 uint32_t * pulNotificationValue,
1308 TickType_t xTicksToWait ) /* PRIVILEGED_FUNCTION */
1310 BaseType_t xReturn = pdFAIL;
1311 BaseType_t xIsNotificationValueWritable = pdFALSE;
1313 if( uxIndexToWaitOn < configTASK_NOTIFICATION_ARRAY_ENTRIES )
1315 if( pulNotificationValue != NULL )
1317 xIsNotificationValueWritable = xPortIsAuthorizedToAccessBuffer( pulNotificationValue,
1319 tskMPU_WRITE_PERMISSION );
1322 if( ( pulNotificationValue == NULL ) || ( xIsNotificationValueWritable == pdTRUE ) )
1324 xReturn = xTaskGenericNotifyWait( uxIndexToWaitOn, ulBitsToClearOnEntry, ulBitsToClearOnExit, pulNotificationValue, xTicksToWait );
1331 #endif /* if ( configUSE_TASK_NOTIFICATIONS == 1 ) */
1332 /*-----------------------------------------------------------*/
1334 #if ( configUSE_TASK_NOTIFICATIONS == 1 )
1336 uint32_t MPU_ulTaskGenericNotifyTakeImpl( UBaseType_t uxIndexToWaitOn,
1337 BaseType_t xClearCountOnExit,
1338 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1340 uint32_t MPU_ulTaskGenericNotifyTakeImpl( UBaseType_t uxIndexToWaitOn,
1341 BaseType_t xClearCountOnExit,
1342 TickType_t xTicksToWait ) /* PRIVILEGED_FUNCTION */
1344 uint32_t ulReturn = 0;
1346 if( uxIndexToWaitOn < configTASK_NOTIFICATION_ARRAY_ENTRIES )
1348 ulReturn = ulTaskGenericNotifyTake( uxIndexToWaitOn, xClearCountOnExit, xTicksToWait );
1354 #endif /* if ( configUSE_TASK_NOTIFICATIONS == 1 ) */
1355 /*-----------------------------------------------------------*/
1357 #if ( configUSE_TASK_NOTIFICATIONS == 1 )
1359 BaseType_t MPU_xTaskGenericNotifyStateClearImpl( TaskHandle_t xTask,
1360 UBaseType_t uxIndexToClear ) PRIVILEGED_FUNCTION;
1362 BaseType_t MPU_xTaskGenericNotifyStateClearImpl( TaskHandle_t xTask,
1363 UBaseType_t uxIndexToClear ) /* PRIVILEGED_FUNCTION */
1365 BaseType_t xReturn = pdFAIL;
1367 TaskHandle_t xInternalTaskHandle = NULL;
1368 BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
1370 if( uxIndexToClear < configTASK_NOTIFICATION_ARRAY_ENTRIES )
1374 xReturn = xTaskGenericNotifyStateClear( xTask, uxIndexToClear );
1378 lIndex = ( int32_t ) xTask;
1380 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1382 xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1384 if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
1386 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1388 if( xInternalTaskHandle != NULL )
1390 xReturn = xTaskGenericNotifyStateClear( xInternalTaskHandle, uxIndexToClear );
1400 #endif /* if ( configUSE_TASK_NOTIFICATIONS == 1 ) */
1401 /*-----------------------------------------------------------*/
1403 #if ( configUSE_TASK_NOTIFICATIONS == 1 )
1405 uint32_t MPU_ulTaskGenericNotifyValueClearImpl( TaskHandle_t xTask,
1406 UBaseType_t uxIndexToClear,
1407 uint32_t ulBitsToClear ) PRIVILEGED_FUNCTION;
1409 uint32_t MPU_ulTaskGenericNotifyValueClearImpl( TaskHandle_t xTask,
1410 UBaseType_t uxIndexToClear,
1411 uint32_t ulBitsToClear ) /* PRIVILEGED_FUNCTION */
1413 uint32_t ulReturn = 0;
1415 TaskHandle_t xInternalTaskHandle = NULL;
1416 BaseType_t xCallingTaskIsAuthorizedToAccessTask = pdFALSE;
1418 if( uxIndexToClear < configTASK_NOTIFICATION_ARRAY_ENTRIES )
1422 ulReturn = ulTaskGenericNotifyValueClear( xTask, uxIndexToClear, ulBitsToClear );
1426 lIndex = ( int32_t ) xTask;
1428 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1430 xCallingTaskIsAuthorizedToAccessTask = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1432 if( xCallingTaskIsAuthorizedToAccessTask == pdTRUE )
1434 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1436 if( xInternalTaskHandle != NULL )
1438 ulReturn = ulTaskGenericNotifyValueClear( xInternalTaskHandle, uxIndexToClear, ulBitsToClear );
1448 #endif /* if ( configUSE_TASK_NOTIFICATIONS == 1 ) */
1449 /*-----------------------------------------------------------*/
1451 /* Privileged only wrappers for Task APIs. These are needed so that
1452 * the application can use opaque handles maintained in mpu_wrappers.c
1453 * with all the APIs. */
1454 /*-----------------------------------------------------------*/
1456 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
1458 BaseType_t MPU_xTaskCreate( TaskFunction_t pvTaskCode,
1459 const char * const pcName,
1460 uint16_t usStackDepth,
1461 void * pvParameters,
1462 UBaseType_t uxPriority,
1463 TaskHandle_t * pxCreatedTask ) /* PRIVILEGED_FUNCTION */
1465 BaseType_t xReturn = pdFAIL;
1467 TaskHandle_t xInternalTaskHandle = NULL;
1469 lIndex = MPU_GetFreeIndexInKernelObjectPool();
1473 /* xTaskCreate() can only be used to create privileged tasks in MPU port. */
1474 if( ( uxPriority & portPRIVILEGE_BIT ) != 0 )
1476 xReturn = xTaskCreate( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, &( xInternalTaskHandle ) );
1478 if( ( xReturn == pdPASS ) && ( xInternalTaskHandle != NULL ) )
1480 MPU_StoreTaskHandleAtIndex( lIndex, xInternalTaskHandle );
1482 if( pxCreatedTask != NULL )
1484 *pxCreatedTask = ( TaskHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
1489 MPU_SetIndexFreeInKernelObjectPool( lIndex );
1497 #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
1498 /*-----------------------------------------------------------*/
1500 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1502 TaskHandle_t MPU_xTaskCreateStatic( TaskFunction_t pxTaskCode,
1503 const char * const pcName,
1504 const uint32_t ulStackDepth,
1505 void * const pvParameters,
1506 UBaseType_t uxPriority,
1507 StackType_t * const puxStackBuffer,
1508 StaticTask_t * const pxTaskBuffer ) /* PRIVILEGED_FUNCTION */
1510 TaskHandle_t xExternalTaskHandle = NULL;
1511 TaskHandle_t xInternalTaskHandle = NULL;
1514 lIndex = MPU_GetFreeIndexInKernelObjectPool();
1518 xInternalTaskHandle = xTaskCreateStatic( pxTaskCode, pcName, ulStackDepth, pvParameters, uxPriority, puxStackBuffer, pxTaskBuffer );
1520 if( xInternalTaskHandle != NULL )
1522 MPU_StoreTaskHandleAtIndex( lIndex, xInternalTaskHandle );
1524 #if ( configENABLE_ACCESS_CONTROL_LIST == 1 )
1526 /* By default, an unprivileged task has access to itself. */
1527 if( ( uxPriority & portPRIVILEGE_BIT ) == 0 )
1529 vPortGrantAccessToKernelObject( xInternalTaskHandle, lIndex );
1534 xExternalTaskHandle = ( TaskHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
1538 MPU_SetIndexFreeInKernelObjectPool( lIndex );
1542 return xExternalTaskHandle;
1545 #endif /* configSUPPORT_STATIC_ALLOCATION */
1546 /*-----------------------------------------------------------*/
1548 #if ( INCLUDE_vTaskDelete == 1 )
1550 void MPU_vTaskDelete( TaskHandle_t pxTaskToDelete ) /* PRIVILEGED_FUNCTION */
1552 TaskHandle_t xInternalTaskHandle = NULL;
1555 if( pxTaskToDelete == NULL )
1557 xInternalTaskHandle = xTaskGetCurrentTaskHandle();
1558 lIndex = MPU_GetIndexForTaskHandle( xInternalTaskHandle );
1562 MPU_SetIndexFreeInKernelObjectPool( lIndex );
1565 vTaskDelete( xInternalTaskHandle );
1569 lIndex = ( int32_t ) pxTaskToDelete;
1571 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1573 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1575 if( xInternalTaskHandle != NULL )
1577 MPU_SetIndexFreeInKernelObjectPool( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1578 vTaskDelete( xInternalTaskHandle );
1584 #endif /* #if ( INCLUDE_vTaskDelete == 1 ) */
1585 /*-----------------------------------------------------------*/
1588 #if ( INCLUDE_vTaskPrioritySet == 1 )
1590 void MPU_vTaskPrioritySet( TaskHandle_t pxTask,
1591 UBaseType_t uxNewPriority ) /* PRIVILEGED_FUNCTION */
1593 TaskHandle_t xInternalTaskHandle = NULL;
1596 if( pxTask == NULL )
1598 vTaskPrioritySet( pxTask, uxNewPriority );
1602 lIndex = ( int32_t ) pxTask;
1604 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1606 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1608 if( xInternalTaskHandle != NULL )
1610 vTaskPrioritySet( xInternalTaskHandle, uxNewPriority );
1616 #endif /* if ( INCLUDE_vTaskPrioritySet == 1 ) */
1617 /*-----------------------------------------------------------*/
1619 #if ( INCLUDE_xTaskGetHandle == 1 )
1621 TaskHandle_t MPU_xTaskGetHandle( const char * pcNameToQuery ) /* PRIVILEGED_FUNCTION */
1623 TaskHandle_t xInternalTaskHandle = NULL;
1624 TaskHandle_t xExternalTaskHandle = NULL;
1627 xInternalTaskHandle = xTaskGetHandle( pcNameToQuery );
1629 if( xInternalTaskHandle != NULL )
1631 lIndex = MPU_GetIndexForTaskHandle( xInternalTaskHandle );
1635 xExternalTaskHandle = ( TaskHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
1639 return xExternalTaskHandle;
1642 #endif /* if ( INCLUDE_xTaskGetHandle == 1 ) */
1643 /*-----------------------------------------------------------*/
1646 #if ( configUSE_APPLICATION_TASK_TAG == 1 )
1648 BaseType_t MPU_xTaskCallApplicationTaskHook( TaskHandle_t xTask,
1649 void * pvParameter ) /* PRIVILEGED_FUNCTION */
1651 BaseType_t xReturn = pdFAIL;
1653 TaskHandle_t xInternalTaskHandle = NULL;
1657 xReturn = xTaskCallApplicationTaskHook( xTask, pvParameter );
1661 lIndex = ( int32_t ) xTask;
1663 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1665 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1667 if( xInternalTaskHandle != NULL )
1669 xReturn = xTaskCallApplicationTaskHook( xInternalTaskHandle, pvParameter );
1677 #endif /* if ( configUSE_APPLICATION_TASK_TAG == 1 ) */
1678 /*-----------------------------------------------------------*/
1680 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
1682 BaseType_t MPU_xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition,
1683 TaskHandle_t * pxCreatedTask ) /* PRIVILEGED_FUNCTION */
1685 BaseType_t xReturn = pdFAIL;
1687 TaskHandle_t xInternalTaskHandle = NULL;
1689 lIndex = MPU_GetFreeIndexInKernelObjectPool();
1693 xReturn = xTaskCreateRestricted( pxTaskDefinition, &( xInternalTaskHandle ) );
1695 if( ( xReturn == pdPASS ) && ( xInternalTaskHandle != NULL ) )
1697 MPU_StoreTaskHandleAtIndex( lIndex, xInternalTaskHandle );
1699 #if ( configENABLE_ACCESS_CONTROL_LIST == 1 )
1701 /* By default, an unprivileged task has access to itself. */
1702 if( ( pxTaskDefinition->uxPriority & portPRIVILEGE_BIT ) == 0 )
1704 vPortGrantAccessToKernelObject( xInternalTaskHandle, lIndex );
1709 if( pxCreatedTask != NULL )
1711 *pxCreatedTask = ( TaskHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
1716 MPU_SetIndexFreeInKernelObjectPool( lIndex );
1723 #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
1724 /*-----------------------------------------------------------*/
1726 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1728 BaseType_t MPU_xTaskCreateRestrictedStatic( const TaskParameters_t * const pxTaskDefinition,
1729 TaskHandle_t * pxCreatedTask ) /* PRIVILEGED_FUNCTION */
1731 BaseType_t xReturn = pdFAIL;
1733 TaskHandle_t xInternalTaskHandle = NULL;
1735 lIndex = MPU_GetFreeIndexInKernelObjectPool();
1739 xReturn = xTaskCreateRestrictedStatic( pxTaskDefinition, &( xInternalTaskHandle ) );
1741 if( ( xReturn == pdPASS ) && ( xInternalTaskHandle != NULL ) )
1743 MPU_StoreTaskHandleAtIndex( lIndex, xInternalTaskHandle );
1745 #if ( configENABLE_ACCESS_CONTROL_LIST == 1 )
1747 /* By default, an unprivileged task has access to itself. */
1748 if( ( pxTaskDefinition->uxPriority & portPRIVILEGE_BIT ) == 0 )
1750 vPortGrantAccessToKernelObject( xInternalTaskHandle, lIndex );
1755 if( pxCreatedTask != NULL )
1757 *pxCreatedTask = ( TaskHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
1762 MPU_SetIndexFreeInKernelObjectPool( lIndex );
1769 #endif /* configSUPPORT_STATIC_ALLOCATION */
1770 /*-----------------------------------------------------------*/
1772 void MPU_vTaskAllocateMPURegions( TaskHandle_t xTaskToModify,
1773 const MemoryRegion_t * const xRegions ) /* PRIVILEGED_FUNCTION */
1775 TaskHandle_t xInternalTaskHandle = NULL;
1778 if( xTaskToModify == NULL )
1780 vTaskAllocateMPURegions( xTaskToModify, xRegions );
1784 lIndex = ( int32_t ) xTaskToModify;
1786 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1788 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1790 if( xInternalTaskHandle != NULL )
1792 vTaskAllocateMPURegions( xInternalTaskHandle, xRegions );
1797 /*-----------------------------------------------------------*/
1799 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1801 BaseType_t MPU_xTaskGetStaticBuffers( TaskHandle_t xTask,
1802 StackType_t ** ppuxStackBuffer,
1803 StaticTask_t ** ppxTaskBuffer ) /* PRIVILEGED_FUNCTION */
1805 TaskHandle_t xInternalTaskHandle = NULL;
1807 BaseType_t xReturn = pdFALSE;
1811 xInternalTaskHandle = xTaskGetCurrentTaskHandle();
1812 xReturn = xTaskGetStaticBuffers( xInternalTaskHandle, ppuxStackBuffer, ppxTaskBuffer );
1816 lIndex = ( int32_t ) xTask;
1818 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1820 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1822 if( xInternalTaskHandle != NULL )
1824 xReturn = xTaskGetStaticBuffers( xInternalTaskHandle, ppuxStackBuffer, ppxTaskBuffer );
1832 #endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
1833 /*-----------------------------------------------------------*/
1835 char * MPU_pcTaskGetName( TaskHandle_t xTaskToQuery ) /* PRIVILEGED_FUNCTION */
1837 char * pcReturn = NULL;
1839 TaskHandle_t xInternalTaskHandle = NULL;
1841 if( xTaskToQuery == NULL )
1843 pcReturn = pcTaskGetName( xTaskToQuery );
1847 lIndex = ( int32_t ) xTaskToQuery;
1849 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1851 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1853 if( xInternalTaskHandle != NULL )
1855 pcReturn = pcTaskGetName( xInternalTaskHandle );
1862 /*-----------------------------------------------------------*/
1864 #if ( INCLUDE_uxTaskPriorityGet == 1 )
1866 UBaseType_t MPU_uxTaskPriorityGetFromISR( const TaskHandle_t xTask ) /* PRIVILEGED_FUNCTION */
1868 UBaseType_t uxReturn = configMAX_PRIORITIES;
1870 TaskHandle_t xInternalTaskHandle = NULL;
1874 uxReturn = uxTaskPriorityGetFromISR( xTask );
1878 lIndex = ( int32_t ) xTask;
1880 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1882 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1884 if( xInternalTaskHandle != NULL )
1886 uxReturn = uxTaskPriorityGetFromISR( xInternalTaskHandle );
1894 #endif /* #if ( INCLUDE_uxTaskPriorityGet == 1 ) */
1895 /*-----------------------------------------------------------*/
1897 #if ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) )
1899 BaseType_t MPU_xTaskResumeFromISR( TaskHandle_t xTaskToResume ) /* PRIVILEGED_FUNCTION */
1901 BaseType_t xReturn = pdFAIL;
1903 TaskHandle_t xInternalTaskHandle = NULL;
1905 lIndex = ( int32_t ) xTaskToResume;
1907 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1909 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1911 if( xInternalTaskHandle != NULL )
1913 xReturn = xTaskResumeFromISR( xInternalTaskHandle );
1920 #endif /* #if ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) )*/
1921 /*---------------------------------------------------------------------------------------*/
1923 #if ( configUSE_APPLICATION_TASK_TAG == 1 )
1925 TaskHookFunction_t MPU_xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask ) /* PRIVILEGED_FUNCTION */
1927 TaskHookFunction_t xReturn = NULL;
1929 TaskHandle_t xInternalTaskHandle = NULL;
1933 xReturn = xTaskGetApplicationTaskTagFromISR( xTask );
1937 lIndex = ( int32_t ) xTask;
1939 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1941 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1943 if( xInternalTaskHandle != NULL )
1945 xReturn = xTaskGetApplicationTaskTagFromISR( xInternalTaskHandle );
1953 #endif /* #if ( configUSE_APPLICATION_TASK_TAG == 1 ) */
1954 /*---------------------------------------------------------------------------------------*/
1956 #if ( configUSE_TASK_NOTIFICATIONS == 1 )
1958 BaseType_t MPU_xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify,
1959 UBaseType_t uxIndexToNotify,
1961 eNotifyAction eAction,
1962 uint32_t * pulPreviousNotificationValue,
1963 BaseType_t * pxHigherPriorityTaskWoken ) /* PRIVILEGED_FUNCTION */
1965 BaseType_t xReturn = pdFAIL;
1967 TaskHandle_t xInternalTaskHandle = NULL;
1969 lIndex = ( int32_t ) xTaskToNotify;
1971 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
1973 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
1975 if( xInternalTaskHandle != NULL )
1977 xReturn = xTaskGenericNotifyFromISR( xInternalTaskHandle, uxIndexToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken );
1984 #endif /* #if ( configUSE_TASK_NOTIFICATIONS == 1 ) */
1985 /*---------------------------------------------------------------------------------------*/
1987 #if ( configUSE_TASK_NOTIFICATIONS == 1 )
1989 void MPU_vTaskGenericNotifyGiveFromISR( TaskHandle_t xTaskToNotify,
1990 UBaseType_t uxIndexToNotify,
1991 BaseType_t * pxHigherPriorityTaskWoken ) /* PRIVILEGED_FUNCTION */
1994 TaskHandle_t xInternalTaskHandle = NULL;
1996 lIndex = ( int32_t ) xTaskToNotify;
1998 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2000 xInternalTaskHandle = MPU_GetTaskHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2002 if( xInternalTaskHandle != NULL )
2004 vTaskGenericNotifyGiveFromISR( xInternalTaskHandle, uxIndexToNotify, pxHigherPriorityTaskWoken );
2008 #endif /*#if ( configUSE_TASK_NOTIFICATIONS == 1 )*/
2009 /*-----------------------------------------------------------*/
2011 /*-----------------------------------------------------------*/
2012 /* MPU wrappers for queue APIs. */
2013 /*-----------------------------------------------------------*/
2015 BaseType_t MPU_xQueueGenericSendImpl( QueueHandle_t xQueue,
2016 const void * const pvItemToQueue,
2017 TickType_t xTicksToWait,
2018 BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
2020 BaseType_t MPU_xQueueGenericSendImpl( QueueHandle_t xQueue,
2021 const void * const pvItemToQueue,
2022 TickType_t xTicksToWait,
2023 BaseType_t xCopyPosition ) /* PRIVILEGED_FUNCTION */
2026 QueueHandle_t xInternalQueueHandle = NULL;
2027 BaseType_t xReturn = pdFAIL;
2028 BaseType_t xIsItemToQueueReadable = pdFALSE;
2029 BaseType_t xCallingTaskIsAuthorizedToAccessQueue = pdFALSE;
2030 UBaseType_t uxQueueItemSize, uxQueueLength;
2032 lIndex = ( int32_t ) xQueue;
2034 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2036 xCallingTaskIsAuthorizedToAccessQueue = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2038 if( xCallingTaskIsAuthorizedToAccessQueue == pdTRUE )
2040 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2042 if( xInternalQueueHandle != NULL )
2044 uxQueueItemSize = uxQueueGetQueueItemSize( xInternalQueueHandle );
2045 uxQueueLength = uxQueueGetQueueLength( xInternalQueueHandle );
2047 if( ( !( ( pvItemToQueue == NULL ) && ( uxQueueItemSize != ( UBaseType_t ) 0U ) ) ) &&
2048 ( !( ( xCopyPosition == queueOVERWRITE ) && ( uxQueueLength != ( UBaseType_t ) 1U ) ) )
2049 #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
2050 && ( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) )
2054 if( pvItemToQueue != NULL )
2056 xIsItemToQueueReadable = xPortIsAuthorizedToAccessBuffer( pvItemToQueue,
2057 uxQueueGetQueueItemSize( xInternalQueueHandle ),
2058 tskMPU_READ_PERMISSION );
2061 if( ( pvItemToQueue == NULL ) || ( xIsItemToQueueReadable == pdTRUE ) )
2063 xReturn = xQueueGenericSend( xInternalQueueHandle, pvItemToQueue, xTicksToWait, xCopyPosition );
2072 /*-----------------------------------------------------------*/
2074 UBaseType_t MPU_uxQueueMessagesWaitingImpl( const QueueHandle_t pxQueue ) PRIVILEGED_FUNCTION;
2076 UBaseType_t MPU_uxQueueMessagesWaitingImpl( const QueueHandle_t pxQueue ) /* PRIVILEGED_FUNCTION */
2079 QueueHandle_t xInternalQueueHandle = NULL;
2080 UBaseType_t uxReturn = 0;
2081 BaseType_t xCallingTaskIsAuthorizedToAccessQueue = pdFALSE;
2083 lIndex = ( int32_t ) pxQueue;
2085 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2087 xCallingTaskIsAuthorizedToAccessQueue = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2089 if( xCallingTaskIsAuthorizedToAccessQueue == pdTRUE )
2091 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2093 if( xInternalQueueHandle != NULL )
2095 uxReturn = uxQueueMessagesWaiting( xInternalQueueHandle );
2102 /*-----------------------------------------------------------*/
2104 UBaseType_t MPU_uxQueueSpacesAvailableImpl( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
2106 UBaseType_t MPU_uxQueueSpacesAvailableImpl( const QueueHandle_t xQueue ) /* PRIVILEGED_FUNCTION */
2109 QueueHandle_t xInternalQueueHandle = NULL;
2110 UBaseType_t uxReturn = 0;
2111 BaseType_t xCallingTaskIsAuthorizedToAccessQueue = pdFALSE;
2113 lIndex = ( int32_t ) xQueue;
2115 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2117 xCallingTaskIsAuthorizedToAccessQueue = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2119 if( xCallingTaskIsAuthorizedToAccessQueue == pdTRUE )
2121 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2123 if( xInternalQueueHandle != NULL )
2125 uxReturn = uxQueueSpacesAvailable( xInternalQueueHandle );
2132 /*-----------------------------------------------------------*/
2134 BaseType_t MPU_xQueueReceiveImpl( QueueHandle_t pxQueue,
2135 void * const pvBuffer,
2136 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2138 BaseType_t MPU_xQueueReceiveImpl( QueueHandle_t pxQueue,
2139 void * const pvBuffer,
2140 TickType_t xTicksToWait ) /* PRIVILEGED_FUNCTION */
2143 QueueHandle_t xInternalQueueHandle = NULL;
2144 BaseType_t xReturn = pdFAIL;
2145 BaseType_t xIsReceiveBufferWritable = pdFALSE;
2146 BaseType_t xCallingTaskIsAuthorizedToAccessQueue = pdFALSE;
2147 UBaseType_t uxQueueItemSize;
2149 lIndex = ( int32_t ) pxQueue;
2151 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2153 xCallingTaskIsAuthorizedToAccessQueue = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2155 if( xCallingTaskIsAuthorizedToAccessQueue == pdTRUE )
2157 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2159 if( xInternalQueueHandle != NULL )
2161 uxQueueItemSize = uxQueueGetQueueItemSize( xInternalQueueHandle );
2163 if( ( !( ( ( pvBuffer ) == NULL ) && ( uxQueueItemSize != ( UBaseType_t ) 0U ) ) )
2164 #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
2165 && ( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) )
2169 xIsReceiveBufferWritable = xPortIsAuthorizedToAccessBuffer( pvBuffer,
2170 uxQueueGetQueueItemSize( xInternalQueueHandle ),
2171 tskMPU_WRITE_PERMISSION );
2173 if( xIsReceiveBufferWritable == pdTRUE )
2175 xReturn = xQueueReceive( xInternalQueueHandle, pvBuffer, xTicksToWait );
2184 /*-----------------------------------------------------------*/
2186 BaseType_t MPU_xQueuePeekImpl( QueueHandle_t xQueue,
2187 void * const pvBuffer,
2188 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2190 BaseType_t MPU_xQueuePeekImpl( QueueHandle_t xQueue,
2191 void * const pvBuffer,
2192 TickType_t xTicksToWait ) /* PRIVILEGED_FUNCTION */
2195 QueueHandle_t xInternalQueueHandle = NULL;
2196 BaseType_t xReturn = pdFAIL;
2197 BaseType_t xIsReceiveBufferWritable = pdFALSE;
2198 UBaseType_t uxQueueItemSize;
2199 BaseType_t xCallingTaskIsAuthorizedToAccessQueue = pdFALSE;
2201 lIndex = ( int32_t ) xQueue;
2203 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2205 xCallingTaskIsAuthorizedToAccessQueue = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2207 if( xCallingTaskIsAuthorizedToAccessQueue == pdTRUE )
2209 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2211 if( xInternalQueueHandle != NULL )
2213 uxQueueItemSize = uxQueueGetQueueItemSize( xInternalQueueHandle );
2215 if( ( !( ( ( pvBuffer ) == NULL ) && ( uxQueueItemSize != ( UBaseType_t ) 0U ) ) )
2216 #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
2217 && ( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) )
2221 xIsReceiveBufferWritable = xPortIsAuthorizedToAccessBuffer( pvBuffer,
2222 uxQueueGetQueueItemSize( xInternalQueueHandle ),
2223 tskMPU_WRITE_PERMISSION );
2225 if( xIsReceiveBufferWritable == pdTRUE )
2227 xReturn = xQueuePeek( xInternalQueueHandle, pvBuffer, xTicksToWait );
2236 /*-----------------------------------------------------------*/
2238 BaseType_t MPU_xQueueSemaphoreTakeImpl( QueueHandle_t xQueue,
2239 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2241 BaseType_t MPU_xQueueSemaphoreTakeImpl( QueueHandle_t xQueue,
2242 TickType_t xTicksToWait ) /* PRIVILEGED_FUNCTION */
2245 QueueHandle_t xInternalQueueHandle = NULL;
2246 BaseType_t xReturn = pdFAIL;
2247 UBaseType_t uxQueueItemSize;
2248 BaseType_t xCallingTaskIsAuthorizedToAccessQueue = pdFALSE;
2250 lIndex = ( int32_t ) xQueue;
2252 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2254 xCallingTaskIsAuthorizedToAccessQueue = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2256 if( xCallingTaskIsAuthorizedToAccessQueue == pdTRUE )
2258 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2260 if( xInternalQueueHandle != NULL )
2262 uxQueueItemSize = uxQueueGetQueueItemSize( xInternalQueueHandle );
2264 if( ( uxQueueItemSize == 0 )
2265 #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
2266 && ( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) )
2270 xReturn = xQueueSemaphoreTake( xInternalQueueHandle, xTicksToWait );
2278 /*-----------------------------------------------------------*/
2280 #if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )
2282 TaskHandle_t MPU_xQueueGetMutexHolderImpl( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
2284 TaskHandle_t MPU_xQueueGetMutexHolderImpl( QueueHandle_t xSemaphore ) /* PRIVILEGED_FUNCTION */
2286 TaskHandle_t xMutexHolderTaskInternalHandle = NULL;
2287 TaskHandle_t xMutexHolderTaskExternalHandle = NULL;
2288 int32_t lIndex, lMutexHolderTaskIndex;
2289 QueueHandle_t xInternalQueueHandle = NULL;
2290 BaseType_t xCallingTaskIsAuthorizedToAccessQueue = pdFALSE;
2293 lIndex = ( int32_t ) xSemaphore;
2295 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2297 xCallingTaskIsAuthorizedToAccessQueue = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2299 if( xCallingTaskIsAuthorizedToAccessQueue == pdTRUE )
2301 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2303 if( xInternalQueueHandle != NULL )
2305 xMutexHolderTaskInternalHandle = xQueueGetMutexHolder( xInternalQueueHandle );
2307 if( xMutexHolderTaskInternalHandle != NULL )
2309 lMutexHolderTaskIndex = MPU_GetIndexForTaskHandle( xMutexHolderTaskInternalHandle );
2311 if( lMutexHolderTaskIndex != -1 )
2313 xMutexHolderTaskExternalHandle = ( TaskHandle_t ) ( CONVERT_TO_EXTERNAL_INDEX( lMutexHolderTaskIndex ) );
2320 return xMutexHolderTaskExternalHandle;
2323 #endif /* if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) ) */
2324 /*-----------------------------------------------------------*/
2326 #if ( configUSE_RECURSIVE_MUTEXES == 1 )
2328 BaseType_t MPU_xQueueTakeMutexRecursiveImpl( QueueHandle_t xMutex,
2329 TickType_t xBlockTime ) PRIVILEGED_FUNCTION;
2331 BaseType_t MPU_xQueueTakeMutexRecursiveImpl( QueueHandle_t xMutex,
2332 TickType_t xBlockTime ) /* PRIVILEGED_FUNCTION */
2334 BaseType_t xReturn = pdFAIL;
2335 BaseType_t xCallingTaskIsAuthorizedToAccessQueue = pdFALSE;
2337 QueueHandle_t xInternalQueueHandle = NULL;
2339 lIndex = ( int32_t ) xMutex;
2341 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2343 xCallingTaskIsAuthorizedToAccessQueue = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2345 if( xCallingTaskIsAuthorizedToAccessQueue == pdTRUE )
2347 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2349 if( xInternalQueueHandle != NULL )
2351 xReturn = xQueueTakeMutexRecursive( xInternalQueueHandle, xBlockTime );
2359 #endif /* if ( configUSE_RECURSIVE_MUTEXES == 1 ) */
2360 /*-----------------------------------------------------------*/
2362 #if ( configUSE_RECURSIVE_MUTEXES == 1 )
2364 BaseType_t MPU_xQueueGiveMutexRecursiveImpl( QueueHandle_t xMutex ) PRIVILEGED_FUNCTION;
2366 BaseType_t MPU_xQueueGiveMutexRecursiveImpl( QueueHandle_t xMutex ) /* PRIVILEGED_FUNCTION */
2368 BaseType_t xReturn = pdFAIL;
2369 BaseType_t xCallingTaskIsAuthorizedToAccessQueue = pdFALSE;
2371 QueueHandle_t xInternalQueueHandle = NULL;
2373 lIndex = ( int32_t ) xMutex;
2375 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2377 xCallingTaskIsAuthorizedToAccessQueue = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2379 if( xCallingTaskIsAuthorizedToAccessQueue == pdTRUE )
2381 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2383 if( xInternalQueueHandle != NULL )
2385 xReturn = xQueueGiveMutexRecursive( xInternalQueueHandle );
2393 #endif /* if ( configUSE_RECURSIVE_MUTEXES == 1 ) */
2394 /*-----------------------------------------------------------*/
2396 #if ( configUSE_QUEUE_SETS == 1 )
2398 QueueSetMemberHandle_t MPU_xQueueSelectFromSetImpl( QueueSetHandle_t xQueueSet,
2399 TickType_t xBlockTimeTicks ) PRIVILEGED_FUNCTION;
2401 QueueSetMemberHandle_t MPU_xQueueSelectFromSetImpl( QueueSetHandle_t xQueueSet,
2402 TickType_t xBlockTimeTicks ) /* PRIVILEGED_FUNCTION */
2404 QueueSetHandle_t xInternalQueueSetHandle = NULL;
2405 QueueSetMemberHandle_t xSelectedMemberInternal = NULL;
2406 QueueSetMemberHandle_t xSelectedMemberExternal = NULL;
2407 int32_t lIndexQueueSet, lIndexSelectedMember;
2408 BaseType_t xCallingTaskIsAuthorizedToAccessQueueSet = pdFALSE;
2410 lIndexQueueSet = ( int32_t ) xQueueSet;
2412 if( IS_EXTERNAL_INDEX_VALID( lIndexQueueSet ) != pdFALSE )
2414 xCallingTaskIsAuthorizedToAccessQueueSet = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndexQueueSet ) );
2416 if( xCallingTaskIsAuthorizedToAccessQueueSet == pdTRUE )
2418 xInternalQueueSetHandle = MPU_GetQueueSetHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndexQueueSet ) );
2420 if( xInternalQueueSetHandle != NULL )
2422 xSelectedMemberInternal = xQueueSelectFromSet( xInternalQueueSetHandle, xBlockTimeTicks );
2424 if( xSelectedMemberInternal != NULL )
2426 lIndexSelectedMember = MPU_GetIndexForQueueSetMemberHandle( xSelectedMemberInternal );
2428 if( lIndexSelectedMember != -1 )
2430 xSelectedMemberExternal = ( QueueSetMemberHandle_t ) ( CONVERT_TO_EXTERNAL_INDEX( lIndexSelectedMember ) );
2437 return xSelectedMemberExternal;
2440 #endif /* if ( configUSE_QUEUE_SETS == 1 ) */
2441 /*-----------------------------------------------------------*/
2443 #if ( configUSE_QUEUE_SETS == 1 )
2445 BaseType_t MPU_xQueueAddToSetImpl( QueueSetMemberHandle_t xQueueOrSemaphore,
2446 QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
2448 BaseType_t MPU_xQueueAddToSetImpl( QueueSetMemberHandle_t xQueueOrSemaphore,
2449 QueueSetHandle_t xQueueSet ) /* PRIVILEGED_FUNCTION */
2451 BaseType_t xReturn = pdFAIL;
2452 QueueSetMemberHandle_t xInternalQueueSetMemberHandle = NULL;
2453 QueueSetHandle_t xInternalQueueSetHandle = NULL;
2454 int32_t lIndexQueueSet, lIndexQueueSetMember;
2455 BaseType_t xCallingTaskIsAuthorizedToAccessQueueSet = pdFALSE;
2456 BaseType_t xCallingTaskIsAuthorizedToAccessQueueSetMember = pdFALSE;
2458 lIndexQueueSet = ( int32_t ) xQueueSet;
2459 lIndexQueueSetMember = ( int32_t ) xQueueOrSemaphore;
2461 if( ( IS_EXTERNAL_INDEX_VALID( lIndexQueueSet ) != pdFALSE ) &&
2462 ( IS_EXTERNAL_INDEX_VALID( lIndexQueueSetMember ) != pdFALSE ) )
2464 xCallingTaskIsAuthorizedToAccessQueueSet = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndexQueueSet ) );
2465 xCallingTaskIsAuthorizedToAccessQueueSetMember = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndexQueueSetMember ) );
2467 if( ( xCallingTaskIsAuthorizedToAccessQueueSet == pdTRUE ) && ( xCallingTaskIsAuthorizedToAccessQueueSetMember == pdTRUE ) )
2469 xInternalQueueSetHandle = MPU_GetQueueSetHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndexQueueSet ) );
2470 xInternalQueueSetMemberHandle = MPU_GetQueueSetMemberHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndexQueueSetMember ) );
2472 if( ( xInternalQueueSetHandle != NULL ) && ( xInternalQueueSetMemberHandle != NULL ) )
2474 xReturn = xQueueAddToSet( xInternalQueueSetMemberHandle, xInternalQueueSetHandle );
2482 #endif /* if ( configUSE_QUEUE_SETS == 1 ) */
2483 /*-----------------------------------------------------------*/
2485 #if configQUEUE_REGISTRY_SIZE > 0
2487 void MPU_vQueueAddToRegistryImpl( QueueHandle_t xQueue,
2488 const char * pcName ) PRIVILEGED_FUNCTION;
2490 void MPU_vQueueAddToRegistryImpl( QueueHandle_t xQueue,
2491 const char * pcName ) /* PRIVILEGED_FUNCTION */
2494 QueueHandle_t xInternalQueueHandle = NULL;
2495 BaseType_t xCallingTaskIsAuthorizedToAccessQueue = pdFALSE;
2497 lIndex = ( int32_t ) xQueue;
2499 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2501 xCallingTaskIsAuthorizedToAccessQueue = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2503 if( xCallingTaskIsAuthorizedToAccessQueue == pdTRUE )
2505 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2507 if( xInternalQueueHandle != NULL )
2509 vQueueAddToRegistry( xInternalQueueHandle, pcName );
2515 #endif /* if configQUEUE_REGISTRY_SIZE > 0 */
2516 /*-----------------------------------------------------------*/
2518 #if configQUEUE_REGISTRY_SIZE > 0
2520 void MPU_vQueueUnregisterQueueImpl( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
2522 void MPU_vQueueUnregisterQueueImpl( QueueHandle_t xQueue ) /* PRIVILEGED_FUNCTION */
2525 QueueHandle_t xInternalQueueHandle = NULL;
2526 BaseType_t xCallingTaskIsAuthorizedToAccessQueue = pdFALSE;
2528 lIndex = ( int32_t ) xQueue;
2530 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2532 xCallingTaskIsAuthorizedToAccessQueue = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2534 if( xCallingTaskIsAuthorizedToAccessQueue == pdTRUE )
2536 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2538 if( xInternalQueueHandle != NULL )
2540 vQueueUnregisterQueue( xInternalQueueHandle );
2546 #endif /* if configQUEUE_REGISTRY_SIZE > 0 */
2547 /*-----------------------------------------------------------*/
2549 #if configQUEUE_REGISTRY_SIZE > 0
2551 const char * MPU_pcQueueGetNameImpl( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
2553 const char * MPU_pcQueueGetNameImpl( QueueHandle_t xQueue ) /* PRIVILEGED_FUNCTION */
2555 const char * pcReturn = NULL;
2556 QueueHandle_t xInternalQueueHandle = NULL;
2558 BaseType_t xCallingTaskIsAuthorizedToAccessQueue = pdFALSE;
2560 lIndex = ( int32_t ) xQueue;
2562 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2564 xCallingTaskIsAuthorizedToAccessQueue = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2566 if( xCallingTaskIsAuthorizedToAccessQueue == pdTRUE )
2568 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2570 if( xInternalQueueHandle != NULL )
2572 pcReturn = pcQueueGetName( xInternalQueueHandle );
2580 #endif /* if configQUEUE_REGISTRY_SIZE > 0 */
2581 /*-----------------------------------------------------------*/
2583 /* Privileged only wrappers for Queue APIs. These are needed so that
2584 * the application can use opaque handles maintained in mpu_wrappers.c
2585 * with all the APIs. */
2586 /*-----------------------------------------------------------*/
2588 void MPU_vQueueDelete( QueueHandle_t xQueue ) /* PRIVILEGED_FUNCTION */
2590 QueueHandle_t xInternalQueueHandle = NULL;
2593 lIndex = ( int32_t ) xQueue;
2595 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2597 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2599 if( xInternalQueueHandle != NULL )
2601 vQueueDelete( xInternalQueueHandle );
2602 MPU_SetIndexFreeInKernelObjectPool( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2606 /*-----------------------------------------------------------*/
2608 #if ( ( configUSE_MUTEXES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
2610 QueueHandle_t MPU_xQueueCreateMutex( const uint8_t ucQueueType ) /* PRIVILEGED_FUNCTION */
2612 QueueHandle_t xInternalQueueHandle = NULL;
2613 QueueHandle_t xExternalQueueHandle = NULL;
2616 lIndex = MPU_GetFreeIndexInKernelObjectPool();
2620 xInternalQueueHandle = xQueueCreateMutex( ucQueueType );
2622 if( xInternalQueueHandle != NULL )
2624 MPU_StoreQueueHandleAtIndex( lIndex, xInternalQueueHandle );
2625 xExternalQueueHandle = ( QueueHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
2629 MPU_SetIndexFreeInKernelObjectPool( lIndex );
2633 return xExternalQueueHandle;
2636 #endif /* if ( ( configUSE_MUTEXES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */
2637 /*-----------------------------------------------------------*/
2639 #if ( ( configUSE_MUTEXES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
2641 QueueHandle_t MPU_xQueueCreateMutexStatic( const uint8_t ucQueueType,
2642 StaticQueue_t * pxStaticQueue ) /* PRIVILEGED_FUNCTION */
2644 QueueHandle_t xInternalQueueHandle = NULL;
2645 QueueHandle_t xExternalQueueHandle = NULL;
2648 lIndex = MPU_GetFreeIndexInKernelObjectPool();
2652 xInternalQueueHandle = xQueueCreateMutexStatic( ucQueueType, pxStaticQueue );
2654 if( xInternalQueueHandle != NULL )
2656 MPU_StoreQueueHandleAtIndex( lIndex, xInternalQueueHandle );
2657 xExternalQueueHandle = ( QueueHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
2661 MPU_SetIndexFreeInKernelObjectPool( lIndex );
2665 return xExternalQueueHandle;
2668 #endif /* if ( ( configUSE_MUTEXES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) */
2669 /*-----------------------------------------------------------*/
2671 #if ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
2673 QueueHandle_t MPU_xQueueCreateCountingSemaphore( UBaseType_t uxCountValue,
2674 UBaseType_t uxInitialCount ) /* PRIVILEGED_FUNCTION */
2676 QueueHandle_t xInternalQueueHandle = NULL;
2677 QueueHandle_t xExternalQueueHandle = NULL;
2680 lIndex = MPU_GetFreeIndexInKernelObjectPool();
2684 xInternalQueueHandle = xQueueCreateCountingSemaphore( uxCountValue, uxInitialCount );
2686 if( xInternalQueueHandle != NULL )
2688 MPU_StoreQueueHandleAtIndex( lIndex, xInternalQueueHandle );
2689 xExternalQueueHandle = ( QueueHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
2693 MPU_SetIndexFreeInKernelObjectPool( lIndex );
2697 return xExternalQueueHandle;
2700 #endif /* if ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */
2701 /*-----------------------------------------------------------*/
2703 #if ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
2705 QueueHandle_t MPU_xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount,
2706 const UBaseType_t uxInitialCount,
2707 StaticQueue_t * pxStaticQueue ) /* PRIVILEGED_FUNCTION */
2709 QueueHandle_t xInternalQueueHandle = NULL;
2710 QueueHandle_t xExternalQueueHandle = NULL;
2713 lIndex = MPU_GetFreeIndexInKernelObjectPool();
2717 xInternalQueueHandle = xQueueCreateCountingSemaphoreStatic( uxMaxCount, uxInitialCount, pxStaticQueue );
2719 if( xInternalQueueHandle != NULL )
2721 MPU_StoreQueueHandleAtIndex( lIndex, xInternalQueueHandle );
2722 xExternalQueueHandle = ( QueueHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
2726 MPU_SetIndexFreeInKernelObjectPool( lIndex );
2730 return xExternalQueueHandle;
2733 #endif /* if ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) */
2734 /*-----------------------------------------------------------*/
2736 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
2738 QueueHandle_t MPU_xQueueGenericCreate( UBaseType_t uxQueueLength,
2739 UBaseType_t uxItemSize,
2740 uint8_t ucQueueType ) /* PRIVILEGED_FUNCTION */
2742 QueueHandle_t xInternalQueueHandle = NULL;
2743 QueueHandle_t xExternalQueueHandle = NULL;
2746 lIndex = MPU_GetFreeIndexInKernelObjectPool();
2750 xInternalQueueHandle = xQueueGenericCreate( uxQueueLength, uxItemSize, ucQueueType );
2752 if( xInternalQueueHandle != NULL )
2754 MPU_StoreQueueHandleAtIndex( lIndex, xInternalQueueHandle );
2755 xExternalQueueHandle = ( QueueHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
2759 MPU_SetIndexFreeInKernelObjectPool( lIndex );
2763 return xExternalQueueHandle;
2766 #endif /* if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) */
2767 /*-----------------------------------------------------------*/
2769 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
2771 QueueHandle_t MPU_xQueueGenericCreateStatic( const UBaseType_t uxQueueLength,
2772 const UBaseType_t uxItemSize,
2773 uint8_t * pucQueueStorage,
2774 StaticQueue_t * pxStaticQueue,
2775 const uint8_t ucQueueType ) /* PRIVILEGED_FUNCTION */
2777 QueueHandle_t xInternalQueueHandle = NULL;
2778 QueueHandle_t xExternalQueueHandle = NULL;
2781 lIndex = MPU_GetFreeIndexInKernelObjectPool();
2785 xInternalQueueHandle = xQueueGenericCreateStatic( uxQueueLength, uxItemSize, pucQueueStorage, pxStaticQueue, ucQueueType );
2787 if( xInternalQueueHandle != NULL )
2789 MPU_StoreQueueHandleAtIndex( lIndex, xInternalQueueHandle );
2790 xExternalQueueHandle = ( QueueHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
2794 MPU_SetIndexFreeInKernelObjectPool( lIndex );
2798 return xExternalQueueHandle;
2801 #endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
2802 /*-----------------------------------------------------------*/
2804 BaseType_t MPU_xQueueGenericReset( QueueHandle_t xQueue,
2805 BaseType_t xNewQueue ) /* PRIVILEGED_FUNCTION */
2808 QueueHandle_t xInternalQueueHandle = NULL;
2809 BaseType_t xReturn = pdFAIL;
2811 lIndex = ( uint32_t ) xQueue;
2813 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2815 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2817 if( xInternalQueueHandle != NULL )
2819 xReturn = xQueueGenericReset( xInternalQueueHandle, xNewQueue );
2825 /*-----------------------------------------------------------*/
2827 #if ( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
2829 QueueSetHandle_t MPU_xQueueCreateSet( UBaseType_t uxEventQueueLength ) /* PRIVILEGED_FUNCTION */
2831 QueueSetHandle_t xInternalQueueSetHandle = NULL;
2832 QueueSetHandle_t xExternalQueueSetHandle = NULL;
2835 lIndex = MPU_GetFreeIndexInKernelObjectPool();
2839 xInternalQueueSetHandle = xQueueCreateSet( uxEventQueueLength );
2841 if( xInternalQueueSetHandle != NULL )
2843 MPU_StoreQueueSetHandleAtIndex( lIndex, xInternalQueueSetHandle );
2844 xExternalQueueSetHandle = ( QueueSetHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
2848 MPU_SetIndexFreeInKernelObjectPool( lIndex );
2852 return xExternalQueueSetHandle;
2855 #endif /* if ( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */
2856 /*-----------------------------------------------------------*/
2858 #if ( configUSE_QUEUE_SETS == 1 )
2860 BaseType_t MPU_xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore,
2861 QueueSetHandle_t xQueueSet ) /* PRIVILEGED_FUNCTION */
2863 BaseType_t xReturn = pdFAIL;
2864 QueueSetMemberHandle_t xInternalQueueSetMemberHandle = NULL;
2865 QueueSetHandle_t xInternalQueueSetHandle = NULL;
2866 int32_t lIndexQueueSet, lIndexQueueSetMember;
2868 lIndexQueueSet = ( int32_t ) xQueueSet;
2869 lIndexQueueSetMember = ( int32_t ) xQueueOrSemaphore;
2871 if( ( IS_EXTERNAL_INDEX_VALID( lIndexQueueSet ) != pdFALSE ) &&
2872 ( IS_EXTERNAL_INDEX_VALID( lIndexQueueSetMember ) != pdFALSE ) )
2874 xInternalQueueSetHandle = MPU_GetQueueSetHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndexQueueSet ) );
2875 xInternalQueueSetMemberHandle = MPU_GetQueueSetMemberHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndexQueueSetMember ) );
2877 if( ( xInternalQueueSetHandle != NULL ) && ( xInternalQueueSetMemberHandle != NULL ) )
2879 xReturn = xQueueRemoveFromSet( xInternalQueueSetMemberHandle, xInternalQueueSetHandle );
2886 #endif /* if ( configUSE_QUEUE_SETS == 1 ) */
2887 /*-----------------------------------------------------------*/
2889 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
2891 BaseType_t MPU_xQueueGenericGetStaticBuffers( QueueHandle_t xQueue,
2892 uint8_t ** ppucQueueStorage,
2893 StaticQueue_t ** ppxStaticQueue ) /* PRIVILEGED_FUNCTION */
2896 QueueHandle_t xInternalQueueHandle = NULL;
2897 BaseType_t xReturn = pdFALSE;
2899 lIndex = ( int32_t ) xQueue;
2901 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2903 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2905 if( xInternalQueueHandle != NULL )
2907 xReturn = xQueueGenericGetStaticBuffers( xInternalQueueHandle, ppucQueueStorage, ppxStaticQueue );
2914 #endif /*if ( configSUPPORT_STATIC_ALLOCATION == 1 )*/
2915 /*-----------------------------------------------------------*/
2917 BaseType_t MPU_xQueueGenericSendFromISR( QueueHandle_t xQueue,
2918 const void * const pvItemToQueue,
2919 BaseType_t * const pxHigherPriorityTaskWoken,
2920 const BaseType_t xCopyPosition ) /* PRIVILEGED_FUNCTION */
2922 BaseType_t xReturn = pdFAIL;
2924 QueueHandle_t xInternalQueueHandle = NULL;
2926 lIndex = ( int32_t ) xQueue;
2928 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2930 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2932 if( xInternalQueueHandle != NULL )
2934 xReturn = xQueueGenericSendFromISR( xInternalQueueHandle, pvItemToQueue, pxHigherPriorityTaskWoken, xCopyPosition );
2941 /*-----------------------------------------------------------*/
2943 BaseType_t MPU_xQueueGiveFromISR( QueueHandle_t xQueue,
2944 BaseType_t * const pxHigherPriorityTaskWoken ) /* PRIVILEGED_FUNCTION */
2946 BaseType_t xReturn = pdFAIL;
2948 QueueHandle_t xInternalQueueHandle = NULL;
2950 lIndex = ( int32_t ) xQueue;
2952 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2954 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2956 if( xInternalQueueHandle != NULL )
2958 xReturn = xQueueGiveFromISR( xInternalQueueHandle, pxHigherPriorityTaskWoken );
2965 /*-----------------------------------------------------------*/
2967 BaseType_t MPU_xQueuePeekFromISR( QueueHandle_t xQueue,
2968 void * const pvBuffer ) /* PRIVILEGED_FUNCTION */
2970 BaseType_t xReturn = pdFAIL;
2972 QueueHandle_t xInternalQueueHandle = NULL;
2974 lIndex = ( int32_t ) xQueue;
2976 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
2978 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
2980 if( xInternalQueueHandle != NULL )
2982 xReturn = xQueuePeekFromISR( xInternalQueueHandle, pvBuffer );
2989 /*-----------------------------------------------------------*/
2991 BaseType_t MPU_xQueueReceiveFromISR( QueueHandle_t xQueue,
2992 void * const pvBuffer,
2993 BaseType_t * const pxHigherPriorityTaskWoken ) /* PRIVILEGED_FUNCTION */
2995 BaseType_t xReturn = pdFAIL;
2997 QueueHandle_t xInternalQueueHandle = NULL;
2999 lIndex = ( int32_t ) xQueue;
3001 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3003 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3005 if( xInternalQueueHandle != NULL )
3007 xReturn = xQueueReceiveFromISR( xInternalQueueHandle, pvBuffer, pxHigherPriorityTaskWoken );
3014 /*-----------------------------------------------------------*/
3016 BaseType_t MPU_xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue ) /* PRIVILEGED_FUNCTION */
3018 BaseType_t xReturn = pdFAIL;
3020 QueueHandle_t xInternalQueueHandle = NULL;
3022 lIndex = ( int32_t ) xQueue;
3024 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3026 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3028 if( xInternalQueueHandle != NULL )
3030 xReturn = xQueueIsQueueEmptyFromISR( xInternalQueueHandle );
3036 /*-----------------------------------------------------------*/
3038 BaseType_t MPU_xQueueIsQueueFullFromISR( const QueueHandle_t xQueue ) /* PRIVILEGED_FUNCTION */
3040 BaseType_t xReturn = pdFAIL;
3042 QueueHandle_t xInternalQueueHandle = NULL;
3044 lIndex = ( int32_t ) xQueue;
3046 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3048 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3050 if( xInternalQueueHandle != NULL )
3052 xReturn = xQueueIsQueueFullFromISR( xInternalQueueHandle );
3059 /*-----------------------------------------------------------*/
3061 UBaseType_t MPU_uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue ) /* PRIVILEGED_FUNCTION */
3063 UBaseType_t uxReturn = 0;
3065 QueueHandle_t xInternalQueueHandle = NULL;
3067 lIndex = ( int32_t ) xQueue;
3069 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3071 xInternalQueueHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3073 if( xInternalQueueHandle != NULL )
3075 uxReturn = uxQueueMessagesWaitingFromISR( xInternalQueueHandle );
3082 /*-----------------------------------------------------------*/
3084 #if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )
3086 TaskHandle_t MPU_xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore ) /* PRIVILEGED_FUNCTION */
3088 TaskHandle_t xMutexHolderTaskInternalHandle = NULL;
3089 TaskHandle_t xMutexHolderTaskExternalHandle = NULL;
3090 int32_t lIndex, lMutexHolderTaskIndex;
3091 QueueHandle_t xInternalSemaphoreHandle = NULL;
3093 lIndex = ( int32_t ) xSemaphore;
3095 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3097 xInternalSemaphoreHandle = MPU_GetQueueHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3099 if( xInternalSemaphoreHandle != NULL )
3101 xMutexHolderTaskInternalHandle = xQueueGetMutexHolder( xInternalSemaphoreHandle );
3103 if( xMutexHolderTaskInternalHandle != NULL )
3105 lMutexHolderTaskIndex = MPU_GetIndexForTaskHandle( xMutexHolderTaskInternalHandle );
3107 if( lMutexHolderTaskIndex != -1 )
3109 xMutexHolderTaskExternalHandle = ( TaskHandle_t ) ( CONVERT_TO_EXTERNAL_INDEX( lMutexHolderTaskIndex ) );
3115 return xMutexHolderTaskExternalHandle;
3118 #endif /* #if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) ) */
3119 /*-----------------------------------------------------------*/
3121 #if ( configUSE_QUEUE_SETS == 1 )
3123 QueueSetMemberHandle_t MPU_xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet ) /* PRIVILEGED_FUNCTION */
3125 QueueSetHandle_t xInternalQueueSetHandle = NULL;
3126 QueueSetMemberHandle_t xSelectedMemberInternal = NULL;
3127 QueueSetMemberHandle_t xSelectedMemberExternal = NULL;
3128 int32_t lIndexQueueSet, lIndexSelectedMember;
3130 lIndexQueueSet = ( int32_t ) xQueueSet;
3132 if( IS_EXTERNAL_INDEX_VALID( lIndexQueueSet ) != pdFALSE )
3134 xInternalQueueSetHandle = MPU_GetQueueSetHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndexQueueSet ) );
3136 if( xInternalQueueSetHandle != NULL )
3138 xSelectedMemberInternal = xQueueSelectFromSetFromISR( xInternalQueueSetHandle );
3140 if( xSelectedMemberInternal != NULL )
3142 lIndexSelectedMember = MPU_GetIndexForQueueSetMemberHandle( xSelectedMemberInternal );
3144 if( lIndexSelectedMember != -1 )
3146 xSelectedMemberExternal = ( QueueSetMemberHandle_t ) ( CONVERT_TO_EXTERNAL_INDEX( lIndexSelectedMember ) );
3152 return xSelectedMemberExternal;
3155 #endif /* if ( configUSE_QUEUE_SETS == 1 ) */
3156 /*-----------------------------------------------------------*/
3158 /*-----------------------------------------------------------*/
3159 /* MPU wrappers for timers APIs. */
3160 /*-----------------------------------------------------------*/
3162 #if ( configUSE_TIMERS == 1 )
3164 void * MPU_pvTimerGetTimerIDImpl( const TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
3166 void * MPU_pvTimerGetTimerIDImpl( const TimerHandle_t xTimer ) /* PRIVILEGED_FUNCTION */
3168 void * pvReturn = NULL;
3169 TimerHandle_t xInternalTimerHandle = NULL;
3171 BaseType_t xCallingTaskIsAuthorizedToAccessTimer = pdFALSE;
3173 lIndex = ( int32_t ) xTimer;
3175 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3177 xCallingTaskIsAuthorizedToAccessTimer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3179 if( xCallingTaskIsAuthorizedToAccessTimer == pdTRUE )
3181 xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3183 if( xInternalTimerHandle != NULL )
3185 pvReturn = pvTimerGetTimerID( xInternalTimerHandle );
3193 #endif /* if ( configUSE_TIMERS == 1 ) */
3194 /*-----------------------------------------------------------*/
3196 #if ( configUSE_TIMERS == 1 )
3198 void MPU_vTimerSetTimerIDImpl( TimerHandle_t xTimer,
3199 void * pvNewID ) PRIVILEGED_FUNCTION;
3201 void MPU_vTimerSetTimerIDImpl( TimerHandle_t xTimer,
3202 void * pvNewID ) /* PRIVILEGED_FUNCTION */
3204 TimerHandle_t xInternalTimerHandle = NULL;
3206 BaseType_t xCallingTaskIsAuthorizedToAccessTimer = pdFALSE;
3208 lIndex = ( int32_t ) xTimer;
3210 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3212 xCallingTaskIsAuthorizedToAccessTimer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3214 if( xCallingTaskIsAuthorizedToAccessTimer == pdTRUE )
3216 xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3218 if( xInternalTimerHandle != NULL )
3220 vTimerSetTimerID( xInternalTimerHandle, pvNewID );
3226 #endif /* if ( configUSE_TIMERS == 1 ) */
3227 /*-----------------------------------------------------------*/
3229 #if ( configUSE_TIMERS == 1 )
3231 BaseType_t MPU_xTimerIsTimerActiveImpl( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
3233 BaseType_t MPU_xTimerIsTimerActiveImpl( TimerHandle_t xTimer ) /* PRIVILEGED_FUNCTION */
3235 BaseType_t xReturn = pdFALSE;
3236 TimerHandle_t xInternalTimerHandle = NULL;
3238 BaseType_t xCallingTaskIsAuthorizedToAccessTimer = pdFALSE;
3240 lIndex = ( int32_t ) xTimer;
3242 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3244 xCallingTaskIsAuthorizedToAccessTimer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3246 if( xCallingTaskIsAuthorizedToAccessTimer == pdTRUE )
3248 xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3250 if( xInternalTimerHandle != NULL )
3252 xReturn = xTimerIsTimerActive( xInternalTimerHandle );
3260 #endif /* if ( configUSE_TIMERS == 1 ) */
3261 /*-----------------------------------------------------------*/
3263 #if ( configUSE_TIMERS == 1 )
3265 TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandleImpl( void ) PRIVILEGED_FUNCTION;
3267 TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandleImpl( void ) /* PRIVILEGED_FUNCTION */
3269 TaskHandle_t xReturn;
3271 xReturn = xTimerGetTimerDaemonTaskHandle();
3276 #endif /* if ( configUSE_TIMERS == 1 ) */
3277 /*-----------------------------------------------------------*/
3279 #if ( configUSE_TIMERS == 1 )
3281 BaseType_t MPU_xTimerGenericCommandFromTaskImpl( TimerHandle_t xTimer,
3282 const BaseType_t xCommandID,
3283 const TickType_t xOptionalValue,
3284 BaseType_t * const pxHigherPriorityTaskWoken,
3285 const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
3287 BaseType_t MPU_xTimerGenericCommandFromTaskImpl( TimerHandle_t xTimer,
3288 const BaseType_t xCommandID,
3289 const TickType_t xOptionalValue,
3290 BaseType_t * const pxHigherPriorityTaskWoken,
3291 const TickType_t xTicksToWait ) /* PRIVILEGED_FUNCTION */
3293 BaseType_t xReturn = pdFALSE;
3294 TimerHandle_t xInternalTimerHandle = NULL;
3296 BaseType_t xIsHigherPriorityTaskWokenWriteable = pdFALSE;
3297 BaseType_t xCallingTaskIsAuthorizedToAccessTimer = pdFALSE;
3299 if( xCommandID < tmrFIRST_FROM_ISR_COMMAND )
3301 if( pxHigherPriorityTaskWoken != NULL )
3303 xIsHigherPriorityTaskWokenWriteable = xPortIsAuthorizedToAccessBuffer( pxHigherPriorityTaskWoken,
3304 sizeof( BaseType_t ),
3305 tskMPU_WRITE_PERMISSION );
3308 if( ( pxHigherPriorityTaskWoken == NULL ) || ( xIsHigherPriorityTaskWokenWriteable == pdTRUE ) )
3310 lIndex = ( int32_t ) xTimer;
3312 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3314 xCallingTaskIsAuthorizedToAccessTimer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3316 if( xCallingTaskIsAuthorizedToAccessTimer == pdTRUE )
3318 xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3320 if( xInternalTimerHandle != NULL )
3322 xReturn = xTimerGenericCommandFromTask( xInternalTimerHandle, xCommandID, xOptionalValue, pxHigherPriorityTaskWoken, xTicksToWait );
3332 #endif /* if ( configUSE_TIMERS == 1 ) */
3333 /*-----------------------------------------------------------*/
3335 #if ( configUSE_TIMERS == 1 )
3337 const char * MPU_pcTimerGetNameImpl( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
3339 const char * MPU_pcTimerGetNameImpl( TimerHandle_t xTimer ) /* PRIVILEGED_FUNCTION */
3341 const char * pcReturn = NULL;
3342 TimerHandle_t xInternalTimerHandle = NULL;
3344 BaseType_t xCallingTaskIsAuthorizedToAccessTimer = pdFALSE;
3346 lIndex = ( int32_t ) xTimer;
3348 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3350 xCallingTaskIsAuthorizedToAccessTimer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3352 if( xCallingTaskIsAuthorizedToAccessTimer == pdTRUE )
3354 xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3356 if( xInternalTimerHandle != NULL )
3358 pcReturn = pcTimerGetName( xInternalTimerHandle );
3366 #endif /* if ( configUSE_TIMERS == 1 ) */
3367 /*-----------------------------------------------------------*/
3369 #if ( configUSE_TIMERS == 1 )
3371 void MPU_vTimerSetReloadModeImpl( TimerHandle_t xTimer,
3372 const UBaseType_t uxAutoReload ) PRIVILEGED_FUNCTION;
3374 void MPU_vTimerSetReloadModeImpl( TimerHandle_t xTimer,
3375 const UBaseType_t uxAutoReload ) /* PRIVILEGED_FUNCTION */
3377 TimerHandle_t xInternalTimerHandle = NULL;
3379 BaseType_t xCallingTaskIsAuthorizedToAccessTimer = pdFALSE;
3381 lIndex = ( int32_t ) xTimer;
3383 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3385 xCallingTaskIsAuthorizedToAccessTimer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3387 if( xCallingTaskIsAuthorizedToAccessTimer == pdTRUE )
3389 xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3391 if( xInternalTimerHandle != NULL )
3393 vTimerSetReloadMode( xInternalTimerHandle, uxAutoReload );
3399 #endif /* if ( configUSE_TIMERS == 1 ) */
3400 /*-----------------------------------------------------------*/
3402 #if ( configUSE_TIMERS == 1 )
3404 BaseType_t MPU_xTimerGetReloadModeImpl( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
3406 BaseType_t MPU_xTimerGetReloadModeImpl( TimerHandle_t xTimer ) /* PRIVILEGED_FUNCTION */
3408 BaseType_t xReturn = pdFALSE;
3409 TimerHandle_t xInternalTimerHandle = NULL;
3411 BaseType_t xCallingTaskIsAuthorizedToAccessTimer = pdFALSE;
3413 lIndex = ( int32_t ) xTimer;
3415 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3417 xCallingTaskIsAuthorizedToAccessTimer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3419 if( xCallingTaskIsAuthorizedToAccessTimer == pdTRUE )
3421 xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3423 if( xInternalTimerHandle != NULL )
3425 xReturn = xTimerGetReloadMode( xInternalTimerHandle );
3433 #endif /* if ( configUSE_TIMERS == 1 ) */
3434 /*-----------------------------------------------------------*/
3436 #if ( configUSE_TIMERS == 1 )
3438 UBaseType_t MPU_uxTimerGetReloadModeImpl( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
3440 UBaseType_t MPU_uxTimerGetReloadModeImpl( TimerHandle_t xTimer ) /* PRIVILEGED_FUNCTION */
3442 UBaseType_t uxReturn = 0;
3443 TimerHandle_t xInternalTimerHandle = NULL;
3445 BaseType_t xCallingTaskIsAuthorizedToAccessTimer = pdFALSE;
3447 lIndex = ( int32_t ) xTimer;
3449 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3451 xCallingTaskIsAuthorizedToAccessTimer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3453 if( xCallingTaskIsAuthorizedToAccessTimer == pdTRUE )
3455 xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3457 if( xInternalTimerHandle != NULL )
3459 uxReturn = uxTimerGetReloadMode( xInternalTimerHandle );
3467 #endif /* if ( configUSE_TIMERS == 1 ) */
3468 /*-----------------------------------------------------------*/
3470 #if ( configUSE_TIMERS == 1 )
3472 TickType_t MPU_xTimerGetPeriodImpl( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
3474 TickType_t MPU_xTimerGetPeriodImpl( TimerHandle_t xTimer ) /* PRIVILEGED_FUNCTION */
3476 TickType_t xReturn = 0;
3477 TimerHandle_t xInternalTimerHandle = NULL;
3479 BaseType_t xCallingTaskIsAuthorizedToAccessTimer = pdFALSE;
3481 lIndex = ( int32_t ) xTimer;
3483 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3485 xCallingTaskIsAuthorizedToAccessTimer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3487 if( xCallingTaskIsAuthorizedToAccessTimer == pdTRUE )
3489 xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3491 if( xInternalTimerHandle != NULL )
3493 xReturn = xTimerGetPeriod( xInternalTimerHandle );
3501 #endif /* if ( configUSE_TIMERS == 1 ) */
3502 /*-----------------------------------------------------------*/
3504 #if ( configUSE_TIMERS == 1 )
3506 TickType_t MPU_xTimerGetExpiryTimeImpl( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
3508 TickType_t MPU_xTimerGetExpiryTimeImpl( TimerHandle_t xTimer ) /* PRIVILEGED_FUNCTION */
3510 TickType_t xReturn = 0;
3511 TimerHandle_t xInternalTimerHandle = NULL;
3513 BaseType_t xCallingTaskIsAuthorizedToAccessTimer = pdFALSE;
3515 lIndex = ( int32_t ) xTimer;
3517 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3519 xCallingTaskIsAuthorizedToAccessTimer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3521 if( xCallingTaskIsAuthorizedToAccessTimer == pdTRUE )
3523 xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3525 if( xInternalTimerHandle != NULL )
3527 xReturn = xTimerGetExpiryTime( xInternalTimerHandle );
3535 #endif /* if ( configUSE_TIMERS == 1 ) */
3536 /*-----------------------------------------------------------*/
3538 /* Privileged only wrappers for Timer APIs. These are needed so that
3539 * the application can use opaque handles maintained in mpu_wrappers.c
3540 * with all the APIs. */
3541 /*-----------------------------------------------------------*/
3543 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configUSE_TIMERS == 1 )
3545 TimerHandle_t MPU_xTimerCreate( const char * const pcTimerName,
3546 const TickType_t xTimerPeriodInTicks,
3547 const UBaseType_t uxAutoReload,
3548 void * const pvTimerID,
3549 TimerCallbackFunction_t pxCallbackFunction ) /* PRIVILEGED_FUNCTION */
3551 TimerHandle_t xInternalTimerHandle = NULL;
3552 TimerHandle_t xExternalTimerHandle = NULL;
3555 lIndex = MPU_GetFreeIndexInKernelObjectPool();
3559 xInternalTimerHandle = xTimerCreate( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, MPU_TimerCallback );
3561 if( xInternalTimerHandle != NULL )
3563 MPU_StoreTimerHandleAtIndex( lIndex, xInternalTimerHandle, pxCallbackFunction );
3564 xExternalTimerHandle = ( TimerHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
3568 MPU_SetIndexFreeInKernelObjectPool( lIndex );
3572 return xExternalTimerHandle;
3575 #endif /* if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configUSE_TIMERS == 1 ) */
3576 /*-----------------------------------------------------------*/
3578 #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_TIMERS == 1 )
3580 TimerHandle_t MPU_xTimerCreateStatic( const char * const pcTimerName,
3581 const TickType_t xTimerPeriodInTicks,
3582 const UBaseType_t uxAutoReload,
3583 void * const pvTimerID,
3584 TimerCallbackFunction_t pxCallbackFunction,
3585 StaticTimer_t * pxTimerBuffer ) /* PRIVILEGED_FUNCTION */
3587 TimerHandle_t xInternalTimerHandle = NULL;
3588 TimerHandle_t xExternalTimerHandle = NULL;
3591 lIndex = MPU_GetFreeIndexInKernelObjectPool();
3595 xInternalTimerHandle = xTimerCreateStatic( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, MPU_TimerCallback, pxTimerBuffer );
3597 if( xInternalTimerHandle != NULL )
3599 MPU_StoreTimerHandleAtIndex( lIndex, xInternalTimerHandle, pxCallbackFunction );
3600 xExternalTimerHandle = ( TimerHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
3604 MPU_SetIndexFreeInKernelObjectPool( lIndex );
3608 return xExternalTimerHandle;
3611 #endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_TIMERS == 1 ) */
3612 /*-----------------------------------------------------------*/
3614 #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_TIMERS == 1 )
3616 BaseType_t MPU_xTimerGetStaticBuffer( TimerHandle_t xTimer,
3617 StaticTimer_t ** ppxTimerBuffer ) /* PRIVILEGED_FUNCTION */
3619 TimerHandle_t xInternalTimerHandle = NULL;
3621 BaseType_t xReturn = pdFALSE;
3623 lIndex = ( int32_t ) xTimer;
3625 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3627 xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3629 if( xInternalTimerHandle != NULL )
3631 xReturn = xTimerGetStaticBuffer( xInternalTimerHandle, ppxTimerBuffer );
3638 #endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_TIMERS == 1 ) */
3639 /*-----------------------------------------------------------*/
3641 #if ( configUSE_TIMERS == 1 )
3643 BaseType_t MPU_xTimerGenericCommandFromISR( TimerHandle_t xTimer,
3644 const BaseType_t xCommandID,
3645 const TickType_t xOptionalValue,
3646 BaseType_t * const pxHigherPriorityTaskWoken,
3647 const TickType_t xTicksToWait ) /* PRIVILEGED_FUNCTION */
3649 BaseType_t xReturn = pdFALSE;
3650 TimerHandle_t xInternalTimerHandle = NULL;
3652 BaseType_t xIsHigherPriorityTaskWokenWriteable = pdFALSE;
3654 if( pxHigherPriorityTaskWoken != NULL )
3656 xIsHigherPriorityTaskWokenWriteable = xPortIsAuthorizedToAccessBuffer( pxHigherPriorityTaskWoken,
3657 sizeof( BaseType_t ),
3658 tskMPU_WRITE_PERMISSION );
3661 if( ( pxHigherPriorityTaskWoken == NULL ) || ( xIsHigherPriorityTaskWokenWriteable == pdTRUE ) )
3663 lIndex = ( int32_t ) xTimer;
3665 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3667 xInternalTimerHandle = MPU_GetTimerHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3669 if( xInternalTimerHandle != NULL )
3671 xReturn = xTimerGenericCommandFromISR( xInternalTimerHandle, xCommandID, xOptionalValue, pxHigherPriorityTaskWoken, xTicksToWait );
3679 #endif /* if ( configUSE_TIMERS == 1 ) */
3680 /*-----------------------------------------------------------*/
3682 /*-----------------------------------------------------------*/
3683 /* MPU wrappers for event group APIs. */
3684 /*-----------------------------------------------------------*/
3686 EventBits_t MPU_xEventGroupWaitBitsImpl( EventGroupHandle_t xEventGroup,
3687 const EventBits_t uxBitsToWaitFor,
3688 const BaseType_t xClearOnExit,
3689 const BaseType_t xWaitForAllBits,
3690 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
3692 EventBits_t MPU_xEventGroupWaitBitsImpl( EventGroupHandle_t xEventGroup,
3693 const EventBits_t uxBitsToWaitFor,
3694 const BaseType_t xClearOnExit,
3695 const BaseType_t xWaitForAllBits,
3696 TickType_t xTicksToWait ) /* PRIVILEGED_FUNCTION */
3698 EventBits_t xReturn = 0;
3699 EventGroupHandle_t xInternalEventGroupHandle = NULL;
3701 BaseType_t xCallingTaskIsAuthorizedToAccessEventGroup = pdFALSE;
3703 if( ( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 ) &&
3704 ( uxBitsToWaitFor != 0 )
3705 #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
3706 && ( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) )
3710 lIndex = ( int32_t ) xEventGroup;
3712 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3714 xCallingTaskIsAuthorizedToAccessEventGroup = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3716 if( xCallingTaskIsAuthorizedToAccessEventGroup == pdTRUE )
3718 xInternalEventGroupHandle = MPU_GetEventGroupHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3720 if( xInternalEventGroupHandle != NULL )
3722 xReturn = xEventGroupWaitBits( xInternalEventGroupHandle, uxBitsToWaitFor, xClearOnExit, xWaitForAllBits, xTicksToWait );
3730 /*-----------------------------------------------------------*/
3732 EventBits_t MPU_xEventGroupClearBitsImpl( EventGroupHandle_t xEventGroup,
3733 const EventBits_t uxBitsToClear ) PRIVILEGED_FUNCTION;
3735 EventBits_t MPU_xEventGroupClearBitsImpl( EventGroupHandle_t xEventGroup,
3736 const EventBits_t uxBitsToClear ) /* PRIVILEGED_FUNCTION */
3738 EventBits_t xReturn = 0;
3739 EventGroupHandle_t xInternalEventGroupHandle = NULL;
3741 BaseType_t xCallingTaskIsAuthorizedToAccessEventGroup = pdFALSE;
3743 if( ( uxBitsToClear & eventEVENT_BITS_CONTROL_BYTES ) == 0 )
3745 lIndex = ( int32_t ) xEventGroup;
3747 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3749 xCallingTaskIsAuthorizedToAccessEventGroup = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3751 if( xCallingTaskIsAuthorizedToAccessEventGroup == pdTRUE )
3753 xInternalEventGroupHandle = MPU_GetEventGroupHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3755 if( xInternalEventGroupHandle != NULL )
3757 xReturn = xEventGroupClearBits( xInternalEventGroupHandle, uxBitsToClear );
3765 /*-----------------------------------------------------------*/
3767 EventBits_t MPU_xEventGroupSetBitsImpl( EventGroupHandle_t xEventGroup,
3768 const EventBits_t uxBitsToSet ) PRIVILEGED_FUNCTION;
3770 EventBits_t MPU_xEventGroupSetBitsImpl( EventGroupHandle_t xEventGroup,
3771 const EventBits_t uxBitsToSet ) /* PRIVILEGED_FUNCTION */
3773 EventBits_t xReturn = 0;
3774 EventGroupHandle_t xInternalEventGroupHandle = NULL;
3776 BaseType_t xCallingTaskIsAuthorizedToAccessEventGroup = pdFALSE;
3778 if( ( uxBitsToSet & eventEVENT_BITS_CONTROL_BYTES ) == 0 )
3780 lIndex = ( int32_t ) xEventGroup;
3782 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3784 xCallingTaskIsAuthorizedToAccessEventGroup = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3786 if( xCallingTaskIsAuthorizedToAccessEventGroup == pdTRUE )
3788 xInternalEventGroupHandle = MPU_GetEventGroupHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3790 if( xInternalEventGroupHandle != NULL )
3792 xReturn = xEventGroupSetBits( xInternalEventGroupHandle, uxBitsToSet );
3800 /*-----------------------------------------------------------*/
3802 EventBits_t MPU_xEventGroupSyncImpl( EventGroupHandle_t xEventGroup,
3803 const EventBits_t uxBitsToSet,
3804 const EventBits_t uxBitsToWaitFor,
3805 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
3807 EventBits_t MPU_xEventGroupSyncImpl( EventGroupHandle_t xEventGroup,
3808 const EventBits_t uxBitsToSet,
3809 const EventBits_t uxBitsToWaitFor,
3810 TickType_t xTicksToWait ) /* PRIVILEGED_FUNCTION */
3812 EventBits_t xReturn = 0;
3813 EventGroupHandle_t xInternalEventGroupHandle = NULL;
3815 BaseType_t xCallingTaskIsAuthorizedToAccessEventGroup = pdFALSE;
3817 if( ( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 ) &&
3818 ( uxBitsToWaitFor != 0 )
3819 #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
3820 && ( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) )
3824 lIndex = ( int32_t ) xEventGroup;
3826 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3828 xCallingTaskIsAuthorizedToAccessEventGroup = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3830 if( xCallingTaskIsAuthorizedToAccessEventGroup == pdTRUE )
3832 xInternalEventGroupHandle = MPU_GetEventGroupHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3834 if( xInternalEventGroupHandle != NULL )
3836 xReturn = xEventGroupSync( xInternalEventGroupHandle, uxBitsToSet, uxBitsToWaitFor, xTicksToWait );
3844 /*-----------------------------------------------------------*/
3846 #if ( configUSE_TRACE_FACILITY == 1 )
3848 UBaseType_t MPU_uxEventGroupGetNumberImpl( void * xEventGroup ) PRIVILEGED_FUNCTION;
3850 UBaseType_t MPU_uxEventGroupGetNumberImpl( void * xEventGroup ) /* PRIVILEGED_FUNCTION */
3852 UBaseType_t xReturn = 0;
3853 EventGroupHandle_t xInternalEventGroupHandle = NULL;
3855 BaseType_t xCallingTaskIsAuthorizedToAccessEventGroup = pdFALSE;
3857 lIndex = ( int32_t ) xEventGroup;
3859 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3861 xCallingTaskIsAuthorizedToAccessEventGroup = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3863 if( xCallingTaskIsAuthorizedToAccessEventGroup == pdTRUE )
3865 xInternalEventGroupHandle = MPU_GetEventGroupHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3867 if( xInternalEventGroupHandle != NULL )
3869 xReturn = uxEventGroupGetNumber( xInternalEventGroupHandle );
3877 #endif /*( configUSE_TRACE_FACILITY == 1 )*/
3878 /*-----------------------------------------------------------*/
3880 #if ( configUSE_TRACE_FACILITY == 1 )
3882 void MPU_vEventGroupSetNumberImpl( void * xEventGroup,
3883 UBaseType_t uxEventGroupNumber ) PRIVILEGED_FUNCTION;
3885 void MPU_vEventGroupSetNumberImpl( void * xEventGroup,
3886 UBaseType_t uxEventGroupNumber ) /* PRIVILEGED_FUNCTION */
3888 EventGroupHandle_t xInternalEventGroupHandle = NULL;
3890 BaseType_t xCallingTaskIsAuthorizedToAccessEventGroup = pdFALSE;
3892 lIndex = ( int32_t ) xEventGroup;
3894 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3896 xCallingTaskIsAuthorizedToAccessEventGroup = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3898 if( xCallingTaskIsAuthorizedToAccessEventGroup == pdTRUE )
3900 xInternalEventGroupHandle = MPU_GetEventGroupHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3902 if( xInternalEventGroupHandle != NULL )
3904 vEventGroupSetNumber( xInternalEventGroupHandle, uxEventGroupNumber );
3910 #endif /*( configUSE_TRACE_FACILITY == 1 )*/
3911 /*-----------------------------------------------------------*/
3913 /* Privileged only wrappers for Event Group APIs. These are needed so that
3914 * the application can use opaque handles maintained in mpu_wrappers.c
3915 * with all the APIs. */
3916 /*-----------------------------------------------------------*/
3918 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
3920 EventGroupHandle_t MPU_xEventGroupCreate( void ) /* PRIVILEGED_FUNCTION */
3922 EventGroupHandle_t xInternalEventGroupHandle = NULL;
3923 EventGroupHandle_t xExternalEventGroupHandle = NULL;
3926 lIndex = MPU_GetFreeIndexInKernelObjectPool();
3930 xInternalEventGroupHandle = xEventGroupCreate();
3932 if( xInternalEventGroupHandle != NULL )
3934 MPU_StoreEventGroupHandleAtIndex( lIndex, xInternalEventGroupHandle );
3935 xExternalEventGroupHandle = ( EventGroupHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
3939 MPU_SetIndexFreeInKernelObjectPool( lIndex );
3943 return xExternalEventGroupHandle;
3946 #endif /* if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) */
3947 /*-----------------------------------------------------------*/
3949 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
3951 EventGroupHandle_t MPU_xEventGroupCreateStatic( StaticEventGroup_t * pxEventGroupBuffer ) /* PRIVILEGED_FUNCTION */
3953 EventGroupHandle_t xInternalEventGroupHandle = NULL;
3954 EventGroupHandle_t xExternalEventGroupHandle = NULL;
3957 lIndex = MPU_GetFreeIndexInKernelObjectPool();
3961 xInternalEventGroupHandle = xEventGroupCreateStatic( pxEventGroupBuffer );
3963 if( xInternalEventGroupHandle != NULL )
3965 MPU_StoreEventGroupHandleAtIndex( lIndex, xInternalEventGroupHandle );
3966 xExternalEventGroupHandle = ( EventGroupHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
3970 MPU_SetIndexFreeInKernelObjectPool( lIndex );
3974 return xExternalEventGroupHandle;
3977 #endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
3978 /*-----------------------------------------------------------*/
3980 void MPU_vEventGroupDelete( EventGroupHandle_t xEventGroup ) /* PRIVILEGED_FUNCTION */
3982 EventGroupHandle_t xInternalEventGroupHandle = NULL;
3985 lIndex = ( int32_t ) xEventGroup;
3987 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
3989 xInternalEventGroupHandle = MPU_GetEventGroupHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3991 if( xInternalEventGroupHandle != NULL )
3993 vEventGroupDelete( xInternalEventGroupHandle );
3994 MPU_SetIndexFreeInKernelObjectPool( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
3998 /*-----------------------------------------------------------*/
4000 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
4002 BaseType_t MPU_xEventGroupGetStaticBuffer( EventGroupHandle_t xEventGroup,
4003 StaticEventGroup_t ** ppxEventGroupBuffer ) /* PRIVILEGED_FUNCTION */
4005 BaseType_t xReturn = pdFALSE;
4006 EventGroupHandle_t xInternalEventGroupHandle = NULL;
4009 lIndex = ( int32_t ) xEventGroup;
4011 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4013 xInternalEventGroupHandle = MPU_GetEventGroupHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4015 if( xInternalEventGroupHandle != NULL )
4017 xReturn = xEventGroupGetStaticBuffer( xInternalEventGroupHandle, ppxEventGroupBuffer );
4024 #endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
4025 /*-----------------------------------------------------------*/
4027 #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) )
4029 BaseType_t MPU_xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup,
4030 const EventBits_t uxBitsToClear ) /* PRIVILEGED_FUNCTION */
4032 BaseType_t xReturn = pdFALSE;
4033 EventGroupHandle_t xInternalEventGroupHandle = NULL;
4036 lIndex = ( int32_t ) xEventGroup;
4038 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4040 xInternalEventGroupHandle = MPU_GetEventGroupHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4042 if( xInternalEventGroupHandle != NULL )
4044 xReturn = xEventGroupClearBitsFromISR( xInternalEventGroupHandle, uxBitsToClear );
4051 #endif /* #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) ) */
4052 /*-----------------------------------------------------------*/
4054 #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) )
4056 BaseType_t MPU_xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup,
4057 const EventBits_t uxBitsToSet,
4058 BaseType_t * pxHigherPriorityTaskWoken ) /* PRIVILEGED_FUNCTION */
4060 BaseType_t xReturn = pdFALSE;
4061 EventGroupHandle_t xInternalEventGroupHandle = NULL;
4064 lIndex = ( int32_t ) xEventGroup;
4066 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4068 xInternalEventGroupHandle = MPU_GetEventGroupHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4070 if( xInternalEventGroupHandle != NULL )
4072 xReturn = xEventGroupSetBitsFromISR( xInternalEventGroupHandle, uxBitsToSet, pxHigherPriorityTaskWoken );
4079 #endif /* #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) ) */
4080 /*-----------------------------------------------------------*/
4082 EventBits_t MPU_xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup ) /* PRIVILEGED_FUNCTION */
4084 EventBits_t xReturn = 0;
4085 EventGroupHandle_t xInternalEventGroupHandle = NULL;
4088 lIndex = ( int32_t ) xEventGroup;
4090 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4092 xInternalEventGroupHandle = MPU_GetEventGroupHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4094 if( xInternalEventGroupHandle != NULL )
4096 xReturn = xEventGroupGetBitsFromISR( xInternalEventGroupHandle );
4102 /*-----------------------------------------------------------*/
4104 /*-----------------------------------------------------------*/
4105 /* MPU wrappers for stream buffer APIs. */
4106 /*-----------------------------------------------------------*/
4108 size_t MPU_xStreamBufferSendImpl( StreamBufferHandle_t xStreamBuffer,
4109 const void * pvTxData,
4110 size_t xDataLengthBytes,
4111 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
4113 size_t MPU_xStreamBufferSendImpl( StreamBufferHandle_t xStreamBuffer,
4114 const void * pvTxData,
4115 size_t xDataLengthBytes,
4116 TickType_t xTicksToWait ) /* PRIVILEGED_FUNCTION */
4119 StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4121 BaseType_t xIsTxDataBufferReadable = pdFALSE;
4122 BaseType_t xCallingTaskIsAuthorizedToAccessStreamBuffer = pdFALSE;
4124 if( pvTxData != NULL )
4126 xIsTxDataBufferReadable = xPortIsAuthorizedToAccessBuffer( pvTxData,
4128 tskMPU_READ_PERMISSION );
4130 if( xIsTxDataBufferReadable == pdTRUE )
4132 lIndex = ( int32_t ) xStreamBuffer;
4134 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4136 xCallingTaskIsAuthorizedToAccessStreamBuffer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4138 if( xCallingTaskIsAuthorizedToAccessStreamBuffer == pdTRUE )
4140 xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4142 if( xInternalStreamBufferHandle != NULL )
4144 xReturn = xStreamBufferSend( xInternalStreamBufferHandle, pvTxData, xDataLengthBytes, xTicksToWait );
4153 /*-----------------------------------------------------------*/
4155 size_t MPU_xStreamBufferReceiveImpl( StreamBufferHandle_t xStreamBuffer,
4157 size_t xBufferLengthBytes,
4158 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
4160 size_t MPU_xStreamBufferReceiveImpl( StreamBufferHandle_t xStreamBuffer,
4162 size_t xBufferLengthBytes,
4163 TickType_t xTicksToWait ) /* PRIVILEGED_FUNCTION */
4166 StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4168 BaseType_t xIsRxDataBufferWriteable = pdFALSE;
4169 BaseType_t xCallingTaskIsAuthorizedToAccessStreamBuffer = pdFALSE;
4171 if( pvRxData != NULL )
4173 xIsRxDataBufferWriteable = xPortIsAuthorizedToAccessBuffer( pvRxData,
4175 tskMPU_WRITE_PERMISSION );
4177 if( xIsRxDataBufferWriteable == pdTRUE )
4179 lIndex = ( int32_t ) xStreamBuffer;
4181 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4183 xCallingTaskIsAuthorizedToAccessStreamBuffer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4185 if( xCallingTaskIsAuthorizedToAccessStreamBuffer == pdTRUE )
4187 xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4189 if( xInternalStreamBufferHandle != NULL )
4191 xReturn = xStreamBufferReceive( xInternalStreamBufferHandle, pvRxData, xBufferLengthBytes, xTicksToWait );
4200 /*-----------------------------------------------------------*/
4202 BaseType_t MPU_xStreamBufferIsFullImpl( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
4204 BaseType_t MPU_xStreamBufferIsFullImpl( StreamBufferHandle_t xStreamBuffer ) /* PRIVILEGED_FUNCTION */
4206 BaseType_t xReturn = pdFALSE;
4207 StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4209 BaseType_t xCallingTaskIsAuthorizedToAccessStreamBuffer = pdFALSE;
4211 lIndex = ( int32_t ) xStreamBuffer;
4213 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4215 xCallingTaskIsAuthorizedToAccessStreamBuffer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4217 if( xCallingTaskIsAuthorizedToAccessStreamBuffer == pdTRUE )
4219 xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4221 if( xInternalStreamBufferHandle != NULL )
4223 xReturn = xStreamBufferIsFull( xInternalStreamBufferHandle );
4230 /*-----------------------------------------------------------*/
4232 BaseType_t MPU_xStreamBufferIsEmptyImpl( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
4234 BaseType_t MPU_xStreamBufferIsEmptyImpl( StreamBufferHandle_t xStreamBuffer ) /* PRIVILEGED_FUNCTION */
4236 BaseType_t xReturn = pdFALSE;
4237 StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4239 BaseType_t xCallingTaskIsAuthorizedToAccessStreamBuffer = pdFALSE;
4241 lIndex = ( int32_t ) xStreamBuffer;
4243 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4245 xCallingTaskIsAuthorizedToAccessStreamBuffer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4247 if( xCallingTaskIsAuthorizedToAccessStreamBuffer == pdTRUE )
4249 xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4251 if( xInternalStreamBufferHandle != NULL )
4253 xReturn = xStreamBufferIsEmpty( xInternalStreamBufferHandle );
4260 /*-----------------------------------------------------------*/
4262 size_t MPU_xStreamBufferSpacesAvailableImpl( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
4264 size_t MPU_xStreamBufferSpacesAvailableImpl( StreamBufferHandle_t xStreamBuffer ) /* PRIVILEGED_FUNCTION */
4267 StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4269 BaseType_t xCallingTaskIsAuthorizedToAccessStreamBuffer = pdFALSE;
4271 lIndex = ( int32_t ) xStreamBuffer;
4273 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4275 xCallingTaskIsAuthorizedToAccessStreamBuffer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4277 if( xCallingTaskIsAuthorizedToAccessStreamBuffer == pdTRUE )
4279 xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4281 if( xInternalStreamBufferHandle != NULL )
4283 xReturn = xStreamBufferSpacesAvailable( xInternalStreamBufferHandle );
4290 /*-----------------------------------------------------------*/
4292 size_t MPU_xStreamBufferBytesAvailableImpl( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
4294 size_t MPU_xStreamBufferBytesAvailableImpl( StreamBufferHandle_t xStreamBuffer ) /* PRIVILEGED_FUNCTION */
4297 StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4299 BaseType_t xCallingTaskIsAuthorizedToAccessStreamBuffer = pdFALSE;
4301 lIndex = ( int32_t ) xStreamBuffer;
4303 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4305 xCallingTaskIsAuthorizedToAccessStreamBuffer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4307 if( xCallingTaskIsAuthorizedToAccessStreamBuffer == pdTRUE )
4309 xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4311 if( xInternalStreamBufferHandle != NULL )
4313 xReturn = xStreamBufferBytesAvailable( xInternalStreamBufferHandle );
4320 /*-----------------------------------------------------------*/
4322 BaseType_t MPU_xStreamBufferSetTriggerLevelImpl( StreamBufferHandle_t xStreamBuffer,
4323 size_t xTriggerLevel ) PRIVILEGED_FUNCTION;
4325 BaseType_t MPU_xStreamBufferSetTriggerLevelImpl( StreamBufferHandle_t xStreamBuffer,
4326 size_t xTriggerLevel ) /* PRIVILEGED_FUNCTION */
4328 BaseType_t xReturn = pdFALSE;
4329 StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4331 BaseType_t xCallingTaskIsAuthorizedToAccessStreamBuffer = pdFALSE;
4333 lIndex = ( int32_t ) xStreamBuffer;
4335 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4337 xCallingTaskIsAuthorizedToAccessStreamBuffer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4339 if( xCallingTaskIsAuthorizedToAccessStreamBuffer == pdTRUE )
4341 xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4343 if( xInternalStreamBufferHandle != NULL )
4345 xReturn = xStreamBufferSetTriggerLevel( xInternalStreamBufferHandle, xTriggerLevel );
4352 /*-----------------------------------------------------------*/
4354 size_t MPU_xStreamBufferNextMessageLengthBytesImpl( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
4356 size_t MPU_xStreamBufferNextMessageLengthBytesImpl( StreamBufferHandle_t xStreamBuffer ) /* PRIVILEGED_FUNCTION */
4359 StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4361 BaseType_t xCallingTaskIsAuthorizedToAccessStreamBuffer = pdFALSE;
4363 lIndex = ( int32_t ) xStreamBuffer;
4365 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4367 xCallingTaskIsAuthorizedToAccessStreamBuffer = xPortIsAuthorizedToAccessKernelObject( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4369 if( xCallingTaskIsAuthorizedToAccessStreamBuffer == pdTRUE )
4371 xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4373 if( xInternalStreamBufferHandle != NULL )
4375 xReturn = xStreamBufferNextMessageLengthBytes( xInternalStreamBufferHandle );
4382 /*-----------------------------------------------------------*/
4384 /* Privileged only wrappers for Stream Buffer APIs. These are needed so that
4385 * the application can use opaque handles maintained in mpu_wrappers.c
4386 * with all the APIs. */
4387 /*-----------------------------------------------------------*/
4389 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
4391 StreamBufferHandle_t MPU_xStreamBufferGenericCreate( size_t xBufferSizeBytes,
4392 size_t xTriggerLevelBytes,
4393 BaseType_t xIsMessageBuffer,
4394 StreamBufferCallbackFunction_t pxSendCompletedCallback,
4395 StreamBufferCallbackFunction_t pxReceiveCompletedCallback ) /* PRIVILEGED_FUNCTION */
4397 StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4398 StreamBufferHandle_t xExternalStreamBufferHandle = NULL;
4402 * Stream buffer application level callback functionality is disabled for MPU
4405 configASSERT( ( pxSendCompletedCallback == NULL ) &&
4406 ( pxReceiveCompletedCallback == NULL ) );
4408 if( ( pxSendCompletedCallback == NULL ) &&
4409 ( pxReceiveCompletedCallback == NULL ) )
4411 lIndex = MPU_GetFreeIndexInKernelObjectPool();
4415 xInternalStreamBufferHandle = xStreamBufferGenericCreate( xBufferSizeBytes,
4421 if( xInternalStreamBufferHandle != NULL )
4423 MPU_StoreStreamBufferHandleAtIndex( lIndex, xInternalStreamBufferHandle );
4424 xExternalStreamBufferHandle = ( StreamBufferHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
4428 MPU_SetIndexFreeInKernelObjectPool( lIndex );
4434 traceSTREAM_BUFFER_CREATE_FAILED( xIsMessageBuffer );
4435 xExternalStreamBufferHandle = NULL;
4438 return xExternalStreamBufferHandle;
4441 #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
4442 /*-----------------------------------------------------------*/
4444 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
4446 StreamBufferHandle_t MPU_xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes,
4447 size_t xTriggerLevelBytes,
4448 BaseType_t xIsMessageBuffer,
4449 uint8_t * const pucStreamBufferStorageArea,
4450 StaticStreamBuffer_t * const pxStaticStreamBuffer,
4451 StreamBufferCallbackFunction_t pxSendCompletedCallback,
4452 StreamBufferCallbackFunction_t pxReceiveCompletedCallback ) /* PRIVILEGED_FUNCTION */
4454 StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4455 StreamBufferHandle_t xExternalStreamBufferHandle = NULL;
4459 * Stream buffer application level callback functionality is disabled for MPU
4462 configASSERT( ( pxSendCompletedCallback == NULL ) &&
4463 ( pxReceiveCompletedCallback == NULL ) );
4465 if( ( pxSendCompletedCallback == NULL ) &&
4466 ( pxReceiveCompletedCallback == NULL ) )
4468 lIndex = MPU_GetFreeIndexInKernelObjectPool();
4472 xInternalStreamBufferHandle = xStreamBufferGenericCreateStatic( xBufferSizeBytes,
4475 pucStreamBufferStorageArea,
4476 pxStaticStreamBuffer,
4480 if( xInternalStreamBufferHandle != NULL )
4482 MPU_StoreStreamBufferHandleAtIndex( lIndex, xInternalStreamBufferHandle );
4483 xExternalStreamBufferHandle = ( StreamBufferHandle_t ) CONVERT_TO_EXTERNAL_INDEX( lIndex );
4487 MPU_SetIndexFreeInKernelObjectPool( lIndex );
4493 traceSTREAM_BUFFER_CREATE_STATIC_FAILED( xReturn, xIsMessageBuffer );
4494 xExternalStreamBufferHandle = NULL;
4497 return xExternalStreamBufferHandle;
4500 #endif /* configSUPPORT_STATIC_ALLOCATION */
4501 /*-----------------------------------------------------------*/
4503 void MPU_vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer ) /* PRIVILEGED_FUNCTION */
4505 StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4508 lIndex = ( int32_t ) xStreamBuffer;
4510 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4512 xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4514 if( xInternalStreamBufferHandle != NULL )
4516 vStreamBufferDelete( xInternalStreamBufferHandle );
4519 MPU_SetIndexFreeInKernelObjectPool( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4522 /*-----------------------------------------------------------*/
4524 BaseType_t MPU_xStreamBufferReset( StreamBufferHandle_t xStreamBuffer ) /* PRIVILEGED_FUNCTION */
4526 BaseType_t xReturn = pdFALSE;
4527 StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4530 lIndex = ( int32_t ) xStreamBuffer;
4532 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4534 xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4536 if( xInternalStreamBufferHandle != NULL )
4538 xReturn = xStreamBufferReset( xInternalStreamBufferHandle );
4544 /*-----------------------------------------------------------*/
4546 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
4548 BaseType_t MPU_xStreamBufferGetStaticBuffers( StreamBufferHandle_t xStreamBuffers,
4549 uint8_t * ppucStreamBufferStorageArea,
4550 StaticStreamBuffer_t * ppxStaticStreamBuffer ) /* PRIVILEGED_FUNCTION */
4552 BaseType_t xReturn = pdFALSE;
4553 StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4556 lIndex = ( int32_t ) xStreamBuffers;
4558 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4560 xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4562 if( xInternalStreamBufferHandle != NULL )
4564 xReturn = MPU_xStreamBufferGetStaticBuffers( xInternalStreamBufferHandle, ppucStreamBufferStorageArea, ppxStaticStreamBuffer );
4571 #endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
4572 /*-----------------------------------------------------------*/
4574 size_t MPU_xStreamBufferSendFromISR( StreamBufferHandle_t xStreamBuffer,
4575 const void * pvTxData,
4576 size_t xDataLengthBytes,
4577 BaseType_t * const pxHigherPriorityTaskWoken ) /* PRIVILEGED_FUNCTION */
4580 StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4583 lIndex = ( int32_t ) xStreamBuffer;
4585 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4587 xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4589 if( xInternalStreamBufferHandle != NULL )
4591 xReturn = xStreamBufferSendFromISR( xInternalStreamBufferHandle, pvTxData, xDataLengthBytes, pxHigherPriorityTaskWoken );
4597 /*-----------------------------------------------------------*/
4599 size_t MPU_xStreamBufferReceiveFromISR( StreamBufferHandle_t xStreamBuffer,
4601 size_t xBufferLengthBytes,
4602 BaseType_t * const pxHigherPriorityTaskWoken ) /* PRIVILEGED_FUNCTION */
4605 StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4608 lIndex = ( int32_t ) xStreamBuffer;
4610 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4612 xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4614 if( xInternalStreamBufferHandle != NULL )
4616 xReturn = xStreamBufferReceiveFromISR( xInternalStreamBufferHandle, pvRxData, xBufferLengthBytes, pxHigherPriorityTaskWoken );
4622 /*-----------------------------------------------------------*/
4624 BaseType_t MPU_xStreamBufferSendCompletedFromISR( StreamBufferHandle_t xStreamBuffer,
4625 BaseType_t * pxHigherPriorityTaskWoken ) /* PRIVILEGED_FUNCTION */
4627 BaseType_t xReturn = pdFALSE;
4628 StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4631 lIndex = ( int32_t ) xStreamBuffer;
4633 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4635 xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4637 if( xInternalStreamBufferHandle != NULL )
4639 xReturn = xStreamBufferSendCompletedFromISR( xInternalStreamBufferHandle, pxHigherPriorityTaskWoken );
4645 /*-----------------------------------------------------------*/
4647 BaseType_t MPU_xStreamBufferReceiveCompletedFromISR( StreamBufferHandle_t xStreamBuffer,
4648 BaseType_t * pxHigherPriorityTaskWoken ) /*PRIVILEGED_FUNCTION */
4650 BaseType_t xReturn = pdFALSE;
4651 StreamBufferHandle_t xInternalStreamBufferHandle = NULL;
4654 lIndex = ( int32_t ) xStreamBuffer;
4656 if( IS_EXTERNAL_INDEX_VALID( lIndex ) != pdFALSE )
4658 xInternalStreamBufferHandle = MPU_GetStreamBufferHandleAtIndex( CONVERT_TO_INTERNAL_INDEX( lIndex ) );
4660 if( xInternalStreamBufferHandle != NULL )
4662 xReturn = xStreamBufferReceiveCompletedFromISR( xInternalStreamBufferHandle, pxHigherPriorityTaskWoken );
4669 /*-----------------------------------------------------------*/
4671 /* Functions that the application writer wants to execute in privileged mode
4672 * can be defined in application_defined_privileged_functions.h. */
4674 #if configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS == 1
4675 #include "application_defined_privileged_functions.h"
4677 /*-----------------------------------------------------------*/
4679 #endif /* #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) ) */
4680 /*-----------------------------------------------------------*/