2 FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
70 /*-----------------------------------------------------------
\r
71 * Implementation of functions defined in portable.h for the ARM CM3 port.
\r
72 *----------------------------------------------------------*/
\r
74 /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
\r
75 all the API functions to use the MPU wrappers. That should only be done when
\r
76 task.h is included from an application file. */
\r
77 #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
\r
79 /* Scheduler includes. */
\r
80 #include "FreeRTOS.h"
\r
84 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
\r
86 /* Constants required to access and manipulate the NVIC. */
\r
87 #define portNVIC_SYSTICK_CTRL ( ( volatile uint32_t * ) 0xe000e010 )
\r
88 #define portNVIC_SYSTICK_LOAD ( ( volatile uint32_t * ) 0xe000e014 )
\r
89 #define portNVIC_SYSPRI2 ( ( volatile uint32_t * ) 0xe000ed20 )
\r
90 #define portNVIC_SYSPRI1 ( ( volatile uint32_t * ) 0xe000ed1c )
\r
91 #define portNVIC_SYS_CTRL_STATE ( ( volatile uint32_t * ) 0xe000ed24 )
\r
92 #define portNVIC_MEM_FAULT_ENABLE ( 1UL << 16UL )
\r
94 /* Constants required to access and manipulate the MPU. */
\r
95 #define portMPU_TYPE ( ( volatile uint32_t * ) 0xe000ed90 )
\r
96 #define portMPU_REGION_BASE_ADDRESS ( ( volatile uint32_t * ) 0xe000ed9C )
\r
97 #define portMPU_REGION_ATTRIBUTE ( ( volatile uint32_t * ) 0xe000edA0 )
\r
98 #define portMPU_CTRL ( ( volatile uint32_t * ) 0xe000ed94 )
\r
99 #define portEXPECTED_MPU_TYPE_VALUE ( 8UL << 8UL ) /* 8 regions, unified. */
\r
100 #define portMPU_ENABLE ( 0x01UL )
\r
101 #define portMPU_BACKGROUND_ENABLE ( 1UL << 2UL )
\r
102 #define portPRIVILEGED_EXECUTION_START_ADDRESS ( 0UL )
\r
103 #define portMPU_REGION_VALID ( 0x10UL )
\r
104 #define portMPU_REGION_ENABLE ( 0x01UL )
\r
105 #define portPERIPHERALS_START_ADDRESS 0x40000000UL
\r
106 #define portPERIPHERALS_END_ADDRESS 0x5FFFFFFFUL
\r
108 /* Constants required to access and manipulate the SysTick. */
\r
109 #define portNVIC_SYSTICK_CLK ( 0x00000004UL )
\r
110 #define portNVIC_SYSTICK_INT ( 0x00000002UL )
\r
111 #define portNVIC_SYSTICK_ENABLE ( 0x00000001UL )
\r
112 #define portNVIC_PENDSV_PRI ( ( ( uint32_t ) configKERNEL_INTERRUPT_PRIORITY ) << 16UL )
\r
113 #define portNVIC_SYSTICK_PRI ( ( ( uint32_t ) configKERNEL_INTERRUPT_PRIORITY ) << 24UL )
\r
114 #define portNVIC_SVC_PRI ( ( ( uint32_t ) configKERNEL_INTERRUPT_PRIORITY ) << 24UL )
\r
116 /* Constants required to set up the initial stack. */
\r
117 #define portINITIAL_XPSR ( 0x01000000 )
\r
118 #define portINITIAL_CONTROL_IF_UNPRIVILEGED ( 0x03 )
\r
119 #define portINITIAL_CONTROL_IF_PRIVILEGED ( 0x02 )
\r
121 /* Offsets in the stack to the parameters when inside the SVC handler. */
\r
122 #define portOFFSET_TO_PC ( 6 )
\r
124 /* Set the privilege level to user mode if xRunningPrivileged is false. */
\r
125 #define portRESET_PRIVILEGE( xRunningPrivileged ) if( xRunningPrivileged != pdTRUE ) __asm volatile ( " mrs r0, control \n orr r0, #1 \n msr control, r0" :::"r0" )
\r
127 /* For strict compliance with the Cortex-M spec the task start address should
\r
128 have bit-0 clear, as it is loaded into the PC on exit from an ISR. */
\r
129 #define portSTART_ADDRESS_MASK ( ( StackType_t ) 0xfffffffeUL )
\r
131 /* Each task maintains its own interrupt status in the critical nesting
\r
132 variable. Note this is not saved as part of the task context as context
\r
133 switches can only occur when uxCriticalNesting is zero. */
\r
134 static UBaseType_t uxCriticalNesting = 0xaaaaaaaa;
\r
137 * Setup the timer to generate the tick interrupts.
\r
139 static void prvSetupTimerInterrupt( void ) PRIVILEGED_FUNCTION;
\r
142 * Configure a number of standard MPU regions that are used by all tasks.
\r
144 static void prvSetupMPU( void ) PRIVILEGED_FUNCTION;
\r
147 * Return the smallest MPU region size that a given number of bytes will fit
\r
148 * into. The region size is returned as the value that should be programmed
\r
149 * into the region attribute register for that region.
\r
151 static uint32_t prvGetMPURegionSizeSetting( uint32_t ulActualSizeInBytes ) PRIVILEGED_FUNCTION;
\r
154 * Checks to see if being called from the context of an unprivileged task, and
\r
155 * if so raises the privilege level and returns false - otherwise does nothing
\r
156 * other than return true.
\r
158 static BaseType_t prvRaisePrivilege( void ) __attribute__(( naked ));
\r
161 * Standard FreeRTOS exception handlers.
\r
163 void xPortPendSVHandler( void ) __attribute__ (( naked )) PRIVILEGED_FUNCTION;
\r
164 void xPortSysTickHandler( void ) __attribute__ ((optimize("3"))) PRIVILEGED_FUNCTION;
\r
165 void vPortSVCHandler( void ) __attribute__ (( naked )) PRIVILEGED_FUNCTION;
\r
168 * Starts the scheduler by restoring the context of the first task to run.
\r
170 static void prvRestoreContextOfFirstTask( void ) __attribute__(( naked )) PRIVILEGED_FUNCTION;
\r
173 * C portion of the SVC handler. The SVC handler is split between an asm entry
\r
174 * and a C wrapper for simplicity of coding and maintenance.
\r
176 static void prvSVCHandler( uint32_t *pulRegisters ) __attribute__(( noinline )) PRIVILEGED_FUNCTION;
\r
179 * Prototypes for all the MPU wrappers.
\r
181 BaseType_t MPU_xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask );
\r
182 BaseType_t MPU_xTaskCreate( TaskFunction_t pvTaskCode, const char * const pcName, uint16_t usStackDepth, void *pvParameters, UBaseType_t uxPriority, TaskHandle_t *pxCreatedTask );
\r
183 void MPU_vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const xRegions );
\r
184 void MPU_vTaskDelete( TaskHandle_t pxTaskToDelete );
\r
185 void MPU_vTaskDelayUntil( TickType_t * const pxPreviousWakeTime, TickType_t xTimeIncrement );
\r
186 void MPU_vTaskDelay( TickType_t xTicksToDelay );
\r
187 UBaseType_t MPU_uxTaskPriorityGet( TaskHandle_t pxTask );
\r
188 void MPU_vTaskPrioritySet( TaskHandle_t pxTask, UBaseType_t uxNewPriority );
\r
189 eTaskState MPU_eTaskGetState( TaskHandle_t pxTask );
\r
190 void MPU_vTaskSuspend( TaskHandle_t pxTaskToSuspend );
\r
191 void MPU_vTaskResume( TaskHandle_t pxTaskToResume );
\r
192 void MPU_vTaskSuspendAll( void );
\r
193 BaseType_t MPU_xTaskResumeAll( void );
\r
194 TickType_t MPU_xTaskGetTickCount( void );
\r
195 UBaseType_t MPU_uxTaskGetNumberOfTasks( void );
\r
196 void MPU_vTaskList( char *pcWriteBuffer );
\r
197 void MPU_vTaskGetRunTimeStats( char *pcWriteBuffer );
\r
198 void MPU_vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxTagValue );
\r
199 TaskHookFunction_t MPU_xTaskGetApplicationTaskTag( TaskHandle_t xTask );
\r
200 BaseType_t MPU_xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter );
\r
201 UBaseType_t MPU_uxTaskGetStackHighWaterMark( TaskHandle_t xTask );
\r
202 TaskHandle_t MPU_xTaskGetCurrentTaskHandle( void );
\r
203 BaseType_t MPU_xTaskGetSchedulerState( void );
\r
204 TaskHandle_t MPU_xTaskGetIdleTaskHandle( void );
\r
205 UBaseType_t MPU_uxTaskGetSystemState( TaskStatus_t *pxTaskStatusArray, UBaseType_t uxArraySize, uint32_t *pulTotalRunTime );
\r
206 QueueHandle_t MPU_xQueueGenericCreate( UBaseType_t uxQueueLength, UBaseType_t uxItemSize, uint8_t ucQueueType );
\r
207 BaseType_t MPU_xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait, BaseType_t xCopyPosition );
\r
208 BaseType_t MPU_xQueueGenericReset( QueueHandle_t pxQueue, BaseType_t xNewQueue );
\r
209 UBaseType_t MPU_uxQueueMessagesWaiting( const QueueHandle_t pxQueue );
\r
210 BaseType_t MPU_xQueueGenericReceive( QueueHandle_t pxQueue, void * const pvBuffer, TickType_t xTicksToWait, BaseType_t xJustPeeking );
\r
211 QueueHandle_t MPU_xQueueCreateMutex( void );
\r
212 QueueHandle_t MPU_xQueueCreateCountingSemaphore( UBaseType_t uxCountValue, UBaseType_t uxInitialCount );
\r
213 BaseType_t MPU_xQueueTakeMutexRecursive( QueueHandle_t xMutex, TickType_t xBlockTime );
\r
214 BaseType_t MPU_xQueueGiveMutexRecursive( QueueHandle_t xMutex );
\r
215 void MPU_vQueueAddToRegistry( QueueHandle_t xQueue, char *pcName );
\r
216 void MPU_vQueueDelete( QueueHandle_t xQueue );
\r
217 void *MPU_pvPortMalloc( size_t xSize );
\r
218 void MPU_vPortFree( void *pv );
\r
219 void MPU_vPortInitialiseBlocks( void );
\r
220 size_t MPU_xPortGetFreeHeapSize( void );
\r
221 QueueSetHandle_t MPU_xQueueCreateSet( UBaseType_t uxEventQueueLength );
\r
222 QueueSetMemberHandle_t MPU_xQueueSelectFromSet( QueueSetHandle_t xQueueSet, TickType_t xBlockTimeTicks );
\r
223 BaseType_t MPU_xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet );
\r
224 BaseType_t MPU_xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet );
\r
225 BaseType_t MPU_xQueuePeekFromISR( QueueHandle_t xQueue, void * const pvBuffer );
\r
226 void* MPU_xQueueGetMutexHolder( QueueHandle_t xSemaphore );
\r
228 /*-----------------------------------------------------------*/
\r
231 * See header file for description.
\r
233 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters, BaseType_t xRunPrivileged )
\r
235 /* Simulate the stack frame as it would be created by a context switch
\r
237 pxTopOfStack--; /* Offset added to account for the way the MCU uses the stack on entry/exit of interrupts. */
\r
238 *pxTopOfStack = portINITIAL_XPSR; /* xPSR */
\r
240 *pxTopOfStack = ( ( StackType_t ) pxCode ) & portSTART_ADDRESS_MASK; /* PC */
\r
242 *pxTopOfStack = 0; /* LR */
\r
243 pxTopOfStack -= 5; /* R12, R3, R2 and R1. */
\r
244 *pxTopOfStack = ( StackType_t ) pvParameters; /* R0 */
\r
245 pxTopOfStack -= 9; /* R11, R10, R9, R8, R7, R6, R5 and R4. */
\r
247 if( xRunPrivileged == pdTRUE )
\r
249 *pxTopOfStack = portINITIAL_CONTROL_IF_PRIVILEGED;
\r
253 *pxTopOfStack = portINITIAL_CONTROL_IF_UNPRIVILEGED;
\r
256 return pxTopOfStack;
\r
258 /*-----------------------------------------------------------*/
\r
260 void vPortSVCHandler( void )
\r
262 /* Assumes psp was in use. */
\r
265 #ifndef USE_PROCESS_STACK /* Code should not be required if a main() is using the process stack. */
\r
268 " mrseq r0, msp \n"
\r
269 " mrsne r0, psp \n"
\r
274 ::"i"(prvSVCHandler):"r0"
\r
277 /*-----------------------------------------------------------*/
\r
279 static void prvSVCHandler( uint32_t *pulParam )
\r
281 uint8_t ucSVCNumber;
\r
283 /* The stack contains: r0, r1, r2, r3, r12, r14, the return address and
\r
284 xPSR. The first argument (r0) is pulParam[ 0 ]. */
\r
285 ucSVCNumber = ( ( uint8_t * ) pulParam[ portOFFSET_TO_PC ] )[ -2 ];
\r
286 switch( ucSVCNumber )
\r
288 case portSVC_START_SCHEDULER : *(portNVIC_SYSPRI1) |= portNVIC_SVC_PRI;
\r
289 prvRestoreContextOfFirstTask();
\r
292 case portSVC_YIELD : *(portNVIC_INT_CTRL) = portNVIC_PENDSVSET;
\r
293 /* Barriers are normally not required
\r
294 but do ensure the code is completely
\r
295 within the specified behaviour for the
\r
297 __asm volatile( "dsb" );
\r
298 __asm volatile( "isb" );
\r
302 case portSVC_RAISE_PRIVILEGE : __asm volatile
\r
304 " mrs r1, control \n" /* Obtain current control value. */
\r
305 " bic r1, #1 \n" /* Set privilege bit. */
\r
306 " msr control, r1 \n" /* Write back new control value. */
\r
311 default : /* Unknown SVC call. */
\r
315 /*-----------------------------------------------------------*/
\r
317 static void prvRestoreContextOfFirstTask( void )
\r
321 " ldr r0, =0xE000ED08 \n" /* Use the NVIC offset register to locate the stack. */
\r
324 " msr msp, r0 \n" /* Set the msp back to the start of the stack. */
\r
325 " ldr r3, pxCurrentTCBConst2 \n" /* Restore the context. */
\r
327 " ldr r0, [r1] \n" /* The first item in the TCB is the task top of stack. */
\r
328 " add r1, r1, #4 \n" /* Move onto the second item in the TCB... */
\r
329 " ldr r2, =0xe000ed9c \n" /* Region Base Address register. */
\r
330 " ldmia r1!, {r4-r11} \n" /* Read 4 sets of MPU registers. */
\r
331 " stmia r2!, {r4-r11} \n" /* Write 4 sets of MPU registers. */
\r
332 " ldmia r0!, {r3, r4-r11} \n" /* Pop the registers that are not automatically saved on exception entry. */
\r
333 " msr control, r3 \n"
\r
334 " msr psp, r0 \n" /* Restore the task stack pointer. */
\r
336 " msr basepri, r0 \n"
\r
337 " ldr r14, =0xfffffffd \n" /* Load exec return code. */
\r
341 "pxCurrentTCBConst2: .word pxCurrentTCB \n"
\r
344 /*-----------------------------------------------------------*/
\r
347 * See header file for description.
\r
349 BaseType_t xPortStartScheduler( void )
\r
351 /* configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to 0. See
\r
352 http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
\r
353 configASSERT( ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) );
\r
355 /* Make PendSV and SysTick the same priority as the kernel. */
\r
356 *(portNVIC_SYSPRI2) |= portNVIC_PENDSV_PRI;
\r
357 *(portNVIC_SYSPRI2) |= portNVIC_SYSTICK_PRI;
\r
359 /* Configure the regions in the MPU that are common to all tasks. */
\r
362 /* Start the timer that generates the tick ISR. Interrupts are disabled
\r
364 prvSetupTimerInterrupt();
\r
366 /* Initialise the critical nesting count ready for the first task. */
\r
367 uxCriticalNesting = 0;
\r
369 /* Start the first task. */
\r
370 __asm volatile( " svc %0 \n"
\r
371 :: "i" (portSVC_START_SCHEDULER) );
\r
373 /* Should not get here! */
\r
376 /*-----------------------------------------------------------*/
\r
378 void vPortEndScheduler( void )
\r
380 /* Not implemented in ports where there is nothing to return to.
\r
381 Artificially force an assert. */
\r
382 configASSERT( uxCriticalNesting == 1000UL );
\r
384 /*-----------------------------------------------------------*/
\r
386 void vPortEnterCritical( void )
\r
388 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
390 portDISABLE_INTERRUPTS();
\r
391 uxCriticalNesting++;
\r
393 portRESET_PRIVILEGE( xRunningPrivileged );
\r
395 /*-----------------------------------------------------------*/
\r
397 void vPortExitCritical( void )
\r
399 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
401 configASSERT( uxCriticalNesting );
\r
402 uxCriticalNesting--;
\r
403 if( uxCriticalNesting == 0 )
\r
405 portENABLE_INTERRUPTS();
\r
407 portRESET_PRIVILEGE( xRunningPrivileged );
\r
409 /*-----------------------------------------------------------*/
\r
411 void xPortPendSVHandler( void )
\r
413 /* This is a naked function. */
\r
419 " ldr r3, pxCurrentTCBConst \n" /* Get the location of the current TCB. */
\r
422 " mrs r1, control \n"
\r
423 " stmdb r0!, {r1, r4-r11} \n" /* Save the remaining registers. */
\r
424 " str r0, [r2] \n" /* Save the new top of stack into the first member of the TCB. */
\r
426 " stmdb sp!, {r3, r14} \n"
\r
428 " msr basepri, r0 \n"
\r
429 " bl vTaskSwitchContext \n"
\r
431 " msr basepri, r0 \n"
\r
432 " ldmia sp!, {r3, r14} \n"
\r
433 " \n" /* Restore the context. */
\r
435 " ldr r0, [r1] \n" /* The first item in the TCB is the task top of stack. */
\r
436 " add r1, r1, #4 \n" /* Move onto the second item in the TCB... */
\r
437 " ldr r2, =0xe000ed9c \n" /* Region Base Address register. */
\r
438 " ldmia r1!, {r4-r11} \n" /* Read 4 sets of MPU registers. */
\r
439 " stmia r2!, {r4-r11} \n" /* Write 4 sets of MPU registers. */
\r
440 " ldmia r0!, {r3, r4-r11} \n" /* Pop the registers that are not automatically saved on exception entry. */
\r
441 " msr control, r3 \n"
\r
447 "pxCurrentTCBConst: .word pxCurrentTCB \n"
\r
448 ::"i"(configMAX_SYSCALL_INTERRUPT_PRIORITY)
\r
451 /*-----------------------------------------------------------*/
\r
453 void xPortSysTickHandler( void )
\r
457 ulDummy = portSET_INTERRUPT_MASK_FROM_ISR();
\r
459 /* Increment the RTOS tick. */
\r
460 if( xTaskIncrementTick() != pdFALSE )
\r
462 /* Pend a context switch. */
\r
463 *(portNVIC_INT_CTRL) = portNVIC_PENDSVSET;
\r
466 portCLEAR_INTERRUPT_MASK_FROM_ISR( ulDummy );
\r
468 /*-----------------------------------------------------------*/
\r
471 * Setup the systick timer to generate the tick interrupts at the required
\r
474 static void prvSetupTimerInterrupt( void )
\r
476 /* Configure SysTick to interrupt at the requested rate. */
\r
477 *(portNVIC_SYSTICK_LOAD) = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL;
\r
478 *(portNVIC_SYSTICK_CTRL) = portNVIC_SYSTICK_CLK | portNVIC_SYSTICK_INT | portNVIC_SYSTICK_ENABLE;
\r
480 /*-----------------------------------------------------------*/
\r
482 static void prvSetupMPU( void )
\r
484 extern uint32_t __privileged_functions_end__[];
\r
485 extern uint32_t __FLASH_segment_start__[];
\r
486 extern uint32_t __FLASH_segment_end__[];
\r
487 extern uint32_t __privileged_data_start__[];
\r
488 extern uint32_t __privileged_data_end__[];
\r
490 /* Check the expected MPU is present. */
\r
491 if( *portMPU_TYPE == portEXPECTED_MPU_TYPE_VALUE )
\r
493 /* First setup the entire flash for unprivileged read only access. */
\r
494 *portMPU_REGION_BASE_ADDRESS = ( ( uint32_t ) __FLASH_segment_start__ ) | /* Base address. */
\r
495 ( portMPU_REGION_VALID ) |
\r
496 ( portUNPRIVILEGED_FLASH_REGION );
\r
498 *portMPU_REGION_ATTRIBUTE = ( portMPU_REGION_READ_ONLY ) |
\r
499 ( portMPU_REGION_CACHEABLE_BUFFERABLE ) |
\r
500 ( prvGetMPURegionSizeSetting( ( uint32_t ) __FLASH_segment_end__ - ( uint32_t ) __FLASH_segment_start__ ) ) |
\r
501 ( portMPU_REGION_ENABLE );
\r
503 /* Setup the first 16K for privileged only access (even though less
\r
504 than 10K is actually being used). This is where the kernel code is
\r
506 *portMPU_REGION_BASE_ADDRESS = ( ( uint32_t ) __FLASH_segment_start__ ) | /* Base address. */
\r
507 ( portMPU_REGION_VALID ) |
\r
508 ( portPRIVILEGED_FLASH_REGION );
\r
510 *portMPU_REGION_ATTRIBUTE = ( portMPU_REGION_PRIVILEGED_READ_ONLY ) |
\r
511 ( portMPU_REGION_CACHEABLE_BUFFERABLE ) |
\r
512 ( prvGetMPURegionSizeSetting( ( uint32_t ) __privileged_functions_end__ - ( uint32_t ) __FLASH_segment_start__ ) ) |
\r
513 ( portMPU_REGION_ENABLE );
\r
515 /* Setup the privileged data RAM region. This is where the kernel data
\r
517 *portMPU_REGION_BASE_ADDRESS = ( ( uint32_t ) __privileged_data_start__ ) | /* Base address. */
\r
518 ( portMPU_REGION_VALID ) |
\r
519 ( portPRIVILEGED_RAM_REGION );
\r
521 *portMPU_REGION_ATTRIBUTE = ( portMPU_REGION_PRIVILEGED_READ_WRITE ) |
\r
522 ( portMPU_REGION_CACHEABLE_BUFFERABLE ) |
\r
523 prvGetMPURegionSizeSetting( ( uint32_t ) __privileged_data_end__ - ( uint32_t ) __privileged_data_start__ ) |
\r
524 ( portMPU_REGION_ENABLE );
\r
526 /* By default allow everything to access the general peripherals. The
\r
527 system peripherals and registers are protected. */
\r
528 *portMPU_REGION_BASE_ADDRESS = ( portPERIPHERALS_START_ADDRESS ) |
\r
529 ( portMPU_REGION_VALID ) |
\r
530 ( portGENERAL_PERIPHERALS_REGION );
\r
532 *portMPU_REGION_ATTRIBUTE = ( portMPU_REGION_READ_WRITE | portMPU_REGION_EXECUTE_NEVER ) |
\r
533 ( prvGetMPURegionSizeSetting( portPERIPHERALS_END_ADDRESS - portPERIPHERALS_START_ADDRESS ) ) |
\r
534 ( portMPU_REGION_ENABLE );
\r
536 /* Enable the memory fault exception. */
\r
537 *portNVIC_SYS_CTRL_STATE |= portNVIC_MEM_FAULT_ENABLE;
\r
539 /* Enable the MPU with the background region configured. */
\r
540 *portMPU_CTRL |= ( portMPU_ENABLE | portMPU_BACKGROUND_ENABLE );
\r
543 /*-----------------------------------------------------------*/
\r
545 static uint32_t prvGetMPURegionSizeSetting( uint32_t ulActualSizeInBytes )
\r
547 uint32_t ulRegionSize, ulReturnValue = 4;
\r
549 /* 32 is the smallest region size, 31 is the largest valid value for
\r
551 for( ulRegionSize = 32UL; ulReturnValue < 31UL; ( ulRegionSize <<= 1UL ) )
\r
553 if( ulActualSizeInBytes <= ulRegionSize )
\r
563 /* Shift the code by one before returning so it can be written directly
\r
564 into the the correct bit position of the attribute register. */
\r
565 return ( ulReturnValue << 1UL );
\r
567 /*-----------------------------------------------------------*/
\r
569 static BaseType_t prvRaisePrivilege( void )
\r
573 " mrs r0, control \n"
\r
574 " tst r0, #1 \n" /* Is the task running privileged? */
\r
576 " movne r0, #0 \n" /* CONTROL[0]!=0, return false. */
\r
577 " svcne %0 \n" /* Switch to privileged. */
\r
578 " moveq r0, #1 \n" /* CONTROL[0]==0, return true. */
\r
580 :: "i" (portSVC_RAISE_PRIVILEGE) : "r0"
\r
585 /*-----------------------------------------------------------*/
\r
587 void vPortStoreTaskMPUSettings( xMPU_SETTINGS *xMPUSettings, const struct xMEMORY_REGION * const xRegions, StackType_t *pxBottomOfStack, uint32_t ulStackDepth )
\r
589 extern uint32_t __SRAM_segment_start__[];
\r
590 extern uint32_t __SRAM_segment_end__[];
\r
591 extern uint32_t __privileged_data_start__[];
\r
592 extern uint32_t __privileged_data_end__[];
\r
596 if( xRegions == NULL )
\r
598 /* No MPU regions are specified so allow access to all RAM. */
\r
599 xMPUSettings->xRegion[ 0 ].ulRegionBaseAddress =
\r
600 ( ( uint32_t ) __SRAM_segment_start__ ) | /* Base address. */
\r
601 ( portMPU_REGION_VALID ) |
\r
602 ( portSTACK_REGION );
\r
604 xMPUSettings->xRegion[ 0 ].ulRegionAttribute =
\r
605 ( portMPU_REGION_READ_WRITE ) |
\r
606 ( portMPU_REGION_CACHEABLE_BUFFERABLE ) |
\r
607 ( prvGetMPURegionSizeSetting( ( uint32_t ) __SRAM_segment_end__ - ( uint32_t ) __SRAM_segment_start__ ) ) |
\r
608 ( portMPU_REGION_ENABLE );
\r
610 /* Re-instate the privileged only RAM region as xRegion[ 0 ] will have
\r
611 just removed the privileged only parameters. */
\r
612 xMPUSettings->xRegion[ 1 ].ulRegionBaseAddress =
\r
613 ( ( uint32_t ) __privileged_data_start__ ) | /* Base address. */
\r
614 ( portMPU_REGION_VALID ) |
\r
615 ( portSTACK_REGION + 1 );
\r
617 xMPUSettings->xRegion[ 1 ].ulRegionAttribute =
\r
618 ( portMPU_REGION_PRIVILEGED_READ_WRITE ) |
\r
619 ( portMPU_REGION_CACHEABLE_BUFFERABLE ) |
\r
620 prvGetMPURegionSizeSetting( ( uint32_t ) __privileged_data_end__ - ( uint32_t ) __privileged_data_start__ ) |
\r
621 ( portMPU_REGION_ENABLE );
\r
623 /* Invalidate all other regions. */
\r
624 for( ul = 2; ul <= portNUM_CONFIGURABLE_REGIONS; ul++ )
\r
626 xMPUSettings->xRegion[ ul ].ulRegionBaseAddress = ( portSTACK_REGION + ul ) | portMPU_REGION_VALID;
\r
627 xMPUSettings->xRegion[ ul ].ulRegionAttribute = 0UL;
\r
632 /* This function is called automatically when the task is created - in
\r
633 which case the stack region parameters will be valid. At all other
\r
634 times the stack parameters will not be valid and it is assumed that the
\r
635 stack region has already been configured. */
\r
636 if( ulStackDepth > 0 )
\r
638 /* Define the region that allows access to the stack. */
\r
639 xMPUSettings->xRegion[ 0 ].ulRegionBaseAddress =
\r
640 ( ( uint32_t ) pxBottomOfStack ) |
\r
641 ( portMPU_REGION_VALID ) |
\r
642 ( portSTACK_REGION ); /* Region number. */
\r
644 xMPUSettings->xRegion[ 0 ].ulRegionAttribute =
\r
645 ( portMPU_REGION_READ_WRITE ) | /* Read and write. */
\r
646 ( prvGetMPURegionSizeSetting( ulStackDepth * ( uint32_t ) sizeof( StackType_t ) ) ) |
\r
647 ( portMPU_REGION_CACHEABLE_BUFFERABLE ) |
\r
648 ( portMPU_REGION_ENABLE );
\r
653 for( ul = 1; ul <= portNUM_CONFIGURABLE_REGIONS; ul++ )
\r
655 if( ( xRegions[ lIndex ] ).ulLengthInBytes > 0UL )
\r
657 /* Translate the generic region definition contained in
\r
658 xRegions into the CM3 specific MPU settings that are then
\r
659 stored in xMPUSettings. */
\r
660 xMPUSettings->xRegion[ ul ].ulRegionBaseAddress =
\r
661 ( ( uint32_t ) xRegions[ lIndex ].pvBaseAddress ) |
\r
662 ( portMPU_REGION_VALID ) |
\r
663 ( portSTACK_REGION + ul ); /* Region number. */
\r
665 xMPUSettings->xRegion[ ul ].ulRegionAttribute =
\r
666 ( prvGetMPURegionSizeSetting( xRegions[ lIndex ].ulLengthInBytes ) ) |
\r
667 ( xRegions[ lIndex ].ulParameters ) |
\r
668 ( portMPU_REGION_ENABLE );
\r
672 /* Invalidate the region. */
\r
673 xMPUSettings->xRegion[ ul ].ulRegionBaseAddress = ( portSTACK_REGION + ul ) | portMPU_REGION_VALID;
\r
674 xMPUSettings->xRegion[ ul ].ulRegionAttribute = 0UL;
\r
681 /*-----------------------------------------------------------*/
\r
683 BaseType_t MPU_xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask )
\r
685 BaseType_t xReturn;
\r
686 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
688 xReturn = xTaskCreateRestricted( pxTaskDefinition, pxCreatedTask );
\r
689 portRESET_PRIVILEGE( xRunningPrivileged );
\r
692 /*-----------------------------------------------------------*/
\r
694 BaseType_t MPU_xTaskCreate( TaskFunction_t pvTaskCode, const char * const pcName, uint16_t usStackDepth, void *pvParameters, UBaseType_t uxPriority, TaskHandle_t *pxCreatedTask )
\r
696 BaseType_t xReturn;
\r
697 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
699 xReturn = xTaskCreate( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask );
\r
700 portRESET_PRIVILEGE( xRunningPrivileged );
\r
703 /*-----------------------------------------------------------*/
\r
705 void MPU_vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const xRegions )
\r
707 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
709 vTaskAllocateMPURegions( xTask, xRegions );
\r
710 portRESET_PRIVILEGE( xRunningPrivileged );
\r
712 /*-----------------------------------------------------------*/
\r
714 #if ( INCLUDE_vTaskDelete == 1 )
\r
715 void MPU_vTaskDelete( TaskHandle_t pxTaskToDelete )
\r
717 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
719 vTaskDelete( pxTaskToDelete );
\r
720 portRESET_PRIVILEGE( xRunningPrivileged );
\r
723 /*-----------------------------------------------------------*/
\r
725 #if ( INCLUDE_vTaskDelayUntil == 1 )
\r
726 void MPU_vTaskDelayUntil( TickType_t * const pxPreviousWakeTime, TickType_t xTimeIncrement )
\r
728 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
730 vTaskDelayUntil( pxPreviousWakeTime, xTimeIncrement );
\r
731 portRESET_PRIVILEGE( xRunningPrivileged );
\r
734 /*-----------------------------------------------------------*/
\r
736 #if ( INCLUDE_vTaskDelay == 1 )
\r
737 void MPU_vTaskDelay( TickType_t xTicksToDelay )
\r
739 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
741 vTaskDelay( xTicksToDelay );
\r
742 portRESET_PRIVILEGE( xRunningPrivileged );
\r
745 /*-----------------------------------------------------------*/
\r
747 #if ( INCLUDE_uxTaskPriorityGet == 1 )
\r
748 UBaseType_t MPU_uxTaskPriorityGet( TaskHandle_t pxTask )
\r
750 UBaseType_t uxReturn;
\r
751 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
753 uxReturn = uxTaskPriorityGet( pxTask );
\r
754 portRESET_PRIVILEGE( xRunningPrivileged );
\r
758 /*-----------------------------------------------------------*/
\r
760 #if ( INCLUDE_vTaskPrioritySet == 1 )
\r
761 void MPU_vTaskPrioritySet( TaskHandle_t pxTask, UBaseType_t uxNewPriority )
\r
763 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
765 vTaskPrioritySet( pxTask, uxNewPriority );
\r
766 portRESET_PRIVILEGE( xRunningPrivileged );
\r
769 /*-----------------------------------------------------------*/
\r
771 #if ( INCLUDE_eTaskGetState == 1 )
\r
772 eTaskState MPU_eTaskGetState( TaskHandle_t pxTask )
\r
774 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
775 eTaskState eReturn;
\r
777 eReturn = eTaskGetState( pxTask );
\r
778 portRESET_PRIVILEGE( xRunningPrivileged );
\r
782 /*-----------------------------------------------------------*/
\r
784 #if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )
\r
785 TaskHandle_t MPU_xTaskGetIdleTaskHandle( void )
\r
787 TaskHandle_t xReturn;
\r
788 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
790 xReturn = xTaskGetIdleTaskHandle();
\r
791 portRESET_PRIVILEGE( xRunningPrivileged );
\r
795 /*-----------------------------------------------------------*/
\r
797 #if ( INCLUDE_vTaskSuspend == 1 )
\r
798 void MPU_vTaskSuspend( TaskHandle_t pxTaskToSuspend )
\r
800 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
802 vTaskSuspend( pxTaskToSuspend );
\r
803 portRESET_PRIVILEGE( xRunningPrivileged );
\r
806 /*-----------------------------------------------------------*/
\r
808 #if ( INCLUDE_vTaskSuspend == 1 )
\r
809 void MPU_vTaskResume( TaskHandle_t pxTaskToResume )
\r
811 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
813 vTaskResume( pxTaskToResume );
\r
814 portRESET_PRIVILEGE( xRunningPrivileged );
\r
817 /*-----------------------------------------------------------*/
\r
819 void MPU_vTaskSuspendAll( void )
\r
821 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
824 portRESET_PRIVILEGE( xRunningPrivileged );
\r
826 /*-----------------------------------------------------------*/
\r
828 BaseType_t MPU_xTaskResumeAll( void )
\r
830 BaseType_t xReturn;
\r
831 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
833 xReturn = xTaskResumeAll();
\r
834 portRESET_PRIVILEGE( xRunningPrivileged );
\r
837 /*-----------------------------------------------------------*/
\r
839 TickType_t MPU_xTaskGetTickCount( void )
\r
841 TickType_t xReturn;
\r
842 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
844 xReturn = xTaskGetTickCount();
\r
845 portRESET_PRIVILEGE( xRunningPrivileged );
\r
848 /*-----------------------------------------------------------*/
\r
850 UBaseType_t MPU_uxTaskGetNumberOfTasks( void )
\r
852 UBaseType_t uxReturn;
\r
853 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
855 uxReturn = uxTaskGetNumberOfTasks();
\r
856 portRESET_PRIVILEGE( xRunningPrivileged );
\r
859 /*-----------------------------------------------------------*/
\r
861 #if ( configUSE_TRACE_FACILITY == 1 )
\r
862 void MPU_vTaskList( char *pcWriteBuffer )
\r
864 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
866 vTaskList( pcWriteBuffer );
\r
867 portRESET_PRIVILEGE( xRunningPrivileged );
\r
870 /*-----------------------------------------------------------*/
\r
872 #if ( configGENERATE_RUN_TIME_STATS == 1 )
\r
873 void MPU_vTaskGetRunTimeStats( char *pcWriteBuffer )
\r
875 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
877 vTaskGetRunTimeStats( pcWriteBuffer );
\r
878 portRESET_PRIVILEGE( xRunningPrivileged );
\r
881 /*-----------------------------------------------------------*/
\r
883 #if ( configUSE_APPLICATION_TASK_TAG == 1 )
\r
884 void MPU_vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxTagValue )
\r
886 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
888 vTaskSetApplicationTaskTag( xTask, pxTagValue );
\r
889 portRESET_PRIVILEGE( xRunningPrivileged );
\r
892 /*-----------------------------------------------------------*/
\r
894 #if ( configUSE_APPLICATION_TASK_TAG == 1 )
\r
895 TaskHookFunction_t MPU_xTaskGetApplicationTaskTag( TaskHandle_t xTask )
\r
897 TaskHookFunction_t xReturn;
\r
898 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
900 xReturn = xTaskGetApplicationTaskTag( xTask );
\r
901 portRESET_PRIVILEGE( xRunningPrivileged );
\r
905 /*-----------------------------------------------------------*/
\r
907 #if ( configUSE_APPLICATION_TASK_TAG == 1 )
\r
908 BaseType_t MPU_xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter )
\r
910 BaseType_t xReturn;
\r
911 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
913 xReturn = xTaskCallApplicationTaskHook( xTask, pvParameter );
\r
914 portRESET_PRIVILEGE( xRunningPrivileged );
\r
918 /*-----------------------------------------------------------*/
\r
920 #if ( configUSE_TRACE_FACILITY == 1 )
\r
921 UBaseType_t MPU_uxTaskGetSystemState( TaskStatus_t *pxTaskStatusArray, UBaseType_t uxArraySize, uint32_t *pulTotalRunTime )
\r
923 UBaseType_t uxReturn;
\r
924 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
926 uxReturn = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, pulTotalRunTime );
\r
927 portRESET_PRIVILEGE( xRunningPrivileged );
\r
931 /*-----------------------------------------------------------*/
\r
933 #if ( INCLUDE_uxTaskGetStackHighWaterMark == 1 )
\r
934 UBaseType_t MPU_uxTaskGetStackHighWaterMark( TaskHandle_t xTask )
\r
936 UBaseType_t uxReturn;
\r
937 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
939 uxReturn = uxTaskGetStackHighWaterMark( xTask );
\r
940 portRESET_PRIVILEGE( xRunningPrivileged );
\r
944 /*-----------------------------------------------------------*/
\r
946 #if ( INCLUDE_xTaskGetCurrentTaskHandle == 1 )
\r
947 TaskHandle_t MPU_xTaskGetCurrentTaskHandle( void )
\r
949 TaskHandle_t xReturn;
\r
950 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
952 xReturn = xTaskGetCurrentTaskHandle();
\r
953 portRESET_PRIVILEGE( xRunningPrivileged );
\r
957 /*-----------------------------------------------------------*/
\r
959 #if ( INCLUDE_xTaskGetSchedulerState == 1 )
\r
960 BaseType_t MPU_xTaskGetSchedulerState( void )
\r
962 BaseType_t xReturn;
\r
963 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
965 xReturn = xTaskGetSchedulerState();
\r
966 portRESET_PRIVILEGE( xRunningPrivileged );
\r
970 /*-----------------------------------------------------------*/
\r
972 QueueHandle_t MPU_xQueueGenericCreate( UBaseType_t uxQueueLength, UBaseType_t uxItemSize, uint8_t ucQueueType )
\r
974 QueueHandle_t xReturn;
\r
975 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
977 xReturn = xQueueGenericCreate( uxQueueLength, uxItemSize, ucQueueType );
\r
978 portRESET_PRIVILEGE( xRunningPrivileged );
\r
981 /*-----------------------------------------------------------*/
\r
983 BaseType_t MPU_xQueueGenericReset( QueueHandle_t pxQueue, BaseType_t xNewQueue )
\r
985 BaseType_t xReturn;
\r
986 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
988 xReturn = xQueueGenericReset( pxQueue, xNewQueue );
\r
989 portRESET_PRIVILEGE( xRunningPrivileged );
\r
992 /*-----------------------------------------------------------*/
\r
994 BaseType_t MPU_xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait, BaseType_t xCopyPosition )
\r
996 BaseType_t xReturn;
\r
997 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
999 xReturn = xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, xCopyPosition );
\r
1000 portRESET_PRIVILEGE( xRunningPrivileged );
\r
1003 /*-----------------------------------------------------------*/
\r
1005 UBaseType_t MPU_uxQueueMessagesWaiting( const QueueHandle_t pxQueue )
\r
1007 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
1008 UBaseType_t uxReturn;
\r
1010 uxReturn = uxQueueMessagesWaiting( pxQueue );
\r
1011 portRESET_PRIVILEGE( xRunningPrivileged );
\r
1014 /*-----------------------------------------------------------*/
\r
1016 BaseType_t MPU_xQueueGenericReceive( QueueHandle_t pxQueue, void * const pvBuffer, TickType_t xTicksToWait, BaseType_t xJustPeeking )
\r
1018 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
1019 BaseType_t xReturn;
\r
1021 xReturn = xQueueGenericReceive( pxQueue, pvBuffer, xTicksToWait, xJustPeeking );
\r
1022 portRESET_PRIVILEGE( xRunningPrivileged );
\r
1025 /*-----------------------------------------------------------*/
\r
1027 BaseType_t MPU_xQueuePeekFromISR( QueueHandle_t pxQueue, void * const pvBuffer )
\r
1029 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
1030 BaseType_t xReturn;
\r
1032 xReturn = xQueuePeekFromISR( pxQueue, pvBuffer );
\r
1033 portRESET_PRIVILEGE( xRunningPrivileged );
\r
1036 /*-----------------------------------------------------------*/
\r
1038 void* MPU_xQueueGetMutexHolder( QueueHandle_t xSemaphore )
\r
1040 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
1043 xReturn = ( void * ) xQueueGetMutexHolder( xSemaphore );
\r
1044 portRESET_PRIVILEGE( xRunningPrivileged );
\r
1047 /*-----------------------------------------------------------*/
\r
1049 #if ( configUSE_MUTEXES == 1 )
\r
1050 QueueHandle_t MPU_xQueueCreateMutex( void )
\r
1052 QueueHandle_t xReturn;
\r
1053 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
1055 xReturn = xQueueCreateMutex( queueQUEUE_TYPE_MUTEX );
\r
1056 portRESET_PRIVILEGE( xRunningPrivileged );
\r
1060 /*-----------------------------------------------------------*/
\r
1062 #if configUSE_COUNTING_SEMAPHORES == 1
\r
1063 QueueHandle_t MPU_xQueueCreateCountingSemaphore( UBaseType_t uxCountValue, UBaseType_t uxInitialCount )
\r
1065 QueueHandle_t xReturn;
\r
1066 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
1068 xReturn = xQueueCreateCountingSemaphore( uxCountValue, uxInitialCount );
\r
1069 portRESET_PRIVILEGE( xRunningPrivileged );
\r
1073 /*-----------------------------------------------------------*/
\r
1075 #if ( configUSE_MUTEXES == 1 )
\r
1076 BaseType_t MPU_xQueueTakeMutexRecursive( QueueHandle_t xMutex, TickType_t xBlockTime )
\r
1078 BaseType_t xReturn;
\r
1079 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
1081 xReturn = xQueueTakeMutexRecursive( xMutex, xBlockTime );
\r
1082 portRESET_PRIVILEGE( xRunningPrivileged );
\r
1086 /*-----------------------------------------------------------*/
\r
1088 #if ( configUSE_MUTEXES == 1 )
\r
1089 BaseType_t MPU_xQueueGiveMutexRecursive( QueueHandle_t xMutex )
\r
1091 BaseType_t xReturn;
\r
1092 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
1094 xReturn = xQueueGiveMutexRecursive( xMutex );
\r
1095 portRESET_PRIVILEGE( xRunningPrivileged );
\r
1099 /*-----------------------------------------------------------*/
\r
1101 #if ( configUSE_QUEUE_SETS == 1 )
\r
1102 QueueSetHandle_t MPU_xQueueCreateSet( UBaseType_t uxEventQueueLength )
\r
1104 QueueSetHandle_t xReturn;
\r
1105 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
1107 xReturn = xQueueCreateSet( uxEventQueueLength );
\r
1108 portRESET_PRIVILEGE( xRunningPrivileged );
\r
1112 /*-----------------------------------------------------------*/
\r
1114 #if ( configUSE_QUEUE_SETS == 1 )
\r
1115 QueueSetMemberHandle_t MPU_xQueueSelectFromSet( QueueSetHandle_t xQueueSet, TickType_t xBlockTimeTicks )
\r
1117 QueueSetMemberHandle_t xReturn;
\r
1118 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
1120 xReturn = xQueueSelectFromSet( xQueueSet, xBlockTimeTicks );
\r
1121 portRESET_PRIVILEGE( xRunningPrivileged );
\r
1125 /*-----------------------------------------------------------*/
\r
1127 #if ( configUSE_QUEUE_SETS == 1 )
\r
1128 BaseType_t MPU_xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet )
\r
1130 BaseType_t xReturn;
\r
1131 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
1133 xReturn = xQueueAddToSet( xQueueOrSemaphore, xQueueSet );
\r
1134 portRESET_PRIVILEGE( xRunningPrivileged );
\r
1138 /*-----------------------------------------------------------*/
\r
1140 #if ( configUSE_QUEUE_SETS == 1 )
\r
1141 BaseType_t MPU_xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet )
\r
1143 BaseType_t xReturn;
\r
1144 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
1146 xReturn = xQueueRemoveFromSet( xQueueOrSemaphore, xQueueSet );
\r
1147 portRESET_PRIVILEGE( xRunningPrivileged );
\r
1151 /*-----------------------------------------------------------*/
\r
1153 #if configQUEUE_REGISTRY_SIZE > 0
\r
1154 void MPU_vQueueAddToRegistry( QueueHandle_t xQueue, char *pcName )
\r
1156 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
1158 vQueueAddToRegistry( xQueue, pcName );
\r
1160 portRESET_PRIVILEGE( xRunningPrivileged );
\r
1163 /*-----------------------------------------------------------*/
\r
1165 void MPU_vQueueDelete( QueueHandle_t xQueue )
\r
1167 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
1169 vQueueDelete( xQueue );
\r
1171 portRESET_PRIVILEGE( xRunningPrivileged );
\r
1173 /*-----------------------------------------------------------*/
\r
1175 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
\r
1177 void *MPU_pvPortMalloc( size_t xSize )
\r
1180 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
1182 pvReturn = pvPortMalloc( xSize );
\r
1184 portRESET_PRIVILEGE( xRunningPrivileged );
\r
1189 #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
\r
1190 /*-----------------------------------------------------------*/
\r
1192 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
\r
1194 void MPU_vPortFree( void *pv )
\r
1196 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
1200 portRESET_PRIVILEGE( xRunningPrivileged );
\r
1203 #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
\r
1204 /*-----------------------------------------------------------*/
\r
1206 void MPU_vPortInitialiseBlocks( void )
\r
1208 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
1210 vPortInitialiseBlocks();
\r
1212 portRESET_PRIVILEGE( xRunningPrivileged );
\r
1214 /*-----------------------------------------------------------*/
\r
1216 size_t MPU_xPortGetFreeHeapSize( void )
\r
1219 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
1221 xReturn = xPortGetFreeHeapSize();
\r
1223 portRESET_PRIVILEGE( xRunningPrivileged );
\r
1228 /* Functions that the application writer wants to execute in privileged mode
\r
1229 can be defined in application_defined_privileged_functions.h. The functions
\r
1230 must take the same format as those above whereby the privilege state on exit
\r
1231 equals the privilege state on entry. For example:
\r
1233 void MPU_FunctionName( [parameters ] )
\r
1235 BaseType_t xRunningPrivileged = prvRaisePrivilege();
\r
1237 FunctionName( [parameters ] );
\r
1239 portRESET_PRIVILEGE( xRunningPrivileged );
\r
1243 #if configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS == 1
\r
1244 #include "application_defined_privileged_functions.h"
\r