Add support for running FreeRTOS on Secure Side only in Cortex M33 port. Also, change spaces to tabs.
This commit is contained in:
@ -26,8 +26,8 @@
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
See http://www.freertos.org/a00110.html for an explanation of the
|
||||
definitions contained in this file.
|
||||
See http://www.freertos.org/a00110.html for an explanation of the
|
||||
definitions contained in this file.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef FREERTOS_CONFIG_H
|
||||
@ -47,123 +47,123 @@
|
||||
extern uint32_t SystemCoreClock;
|
||||
|
||||
/* Cortex M33 port configuration. */
|
||||
#define configENABLE_MPU 1
|
||||
#define configENABLE_FPU 1
|
||||
#define configENABLE_TRUSTZONE 1
|
||||
#define configENABLE_MPU 1
|
||||
#define configENABLE_FPU 1
|
||||
#define configENABLE_TRUSTZONE 1
|
||||
|
||||
/* Constants related to the behaviour or the scheduler. */
|
||||
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
|
||||
#define configUSE_PREEMPTION 1
|
||||
#define configUSE_TIME_SLICING 1
|
||||
#define configMAX_PRIORITIES ( 5 )
|
||||
#define configIDLE_SHOULD_YIELD 1
|
||||
#define configUSE_16_BIT_TICKS 0 /* Only for 8 and 16-bit hardware. */
|
||||
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
|
||||
#define configUSE_PREEMPTION 1
|
||||
#define configUSE_TIME_SLICING 1
|
||||
#define configMAX_PRIORITIES ( 5 )
|
||||
#define configIDLE_SHOULD_YIELD 1
|
||||
#define configUSE_16_BIT_TICKS 0 /* Only for 8 and 16-bit hardware. */
|
||||
|
||||
/* Constants that describe the hardware and memory usage. */
|
||||
#define configCPU_CLOCK_HZ SystemCoreClock
|
||||
#define configMINIMAL_STACK_SIZE ( ( uint16_t ) 128 )
|
||||
#define configMINIMAL_SECURE_STACK_SIZE ( 1024 )
|
||||
#define configMAX_TASK_NAME_LEN ( 12 )
|
||||
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 50 * 1024 ) )
|
||||
#define configCPU_CLOCK_HZ SystemCoreClock
|
||||
#define configMINIMAL_STACK_SIZE ( ( uint16_t ) 128 )
|
||||
#define configMINIMAL_SECURE_STACK_SIZE ( 1024 )
|
||||
#define configMAX_TASK_NAME_LEN ( 12 )
|
||||
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 50 * 1024 ) )
|
||||
|
||||
/* Constants that build features in or out. */
|
||||
#define configUSE_MUTEXES 1
|
||||
#define configUSE_TICKLESS_IDLE 1
|
||||
#define configUSE_APPLICATION_TASK_TAG 0
|
||||
#define configUSE_NEWLIB_REENTRANT 0
|
||||
#define configUSE_CO_ROUTINES 0
|
||||
#define configUSE_COUNTING_SEMAPHORES 1
|
||||
#define configUSE_RECURSIVE_MUTEXES 1
|
||||
#define configUSE_QUEUE_SETS 0
|
||||
#define configUSE_TASK_NOTIFICATIONS 1
|
||||
#define configUSE_TRACE_FACILITY 1
|
||||
#define configUSE_MUTEXES 1
|
||||
#define configUSE_TICKLESS_IDLE 1
|
||||
#define configUSE_APPLICATION_TASK_TAG 0
|
||||
#define configUSE_NEWLIB_REENTRANT 0
|
||||
#define configUSE_CO_ROUTINES 0
|
||||
#define configUSE_COUNTING_SEMAPHORES 1
|
||||
#define configUSE_RECURSIVE_MUTEXES 1
|
||||
#define configUSE_QUEUE_SETS 0
|
||||
#define configUSE_TASK_NOTIFICATIONS 1
|
||||
#define configUSE_TRACE_FACILITY 1
|
||||
|
||||
/* Constants that define which hook (callback) functions should be used. */
|
||||
#define configUSE_IDLE_HOOK 0
|
||||
#define configUSE_TICK_HOOK 0
|
||||
#define configUSE_MALLOC_FAILED_HOOK 0
|
||||
#define configUSE_IDLE_HOOK 0
|
||||
#define configUSE_TICK_HOOK 0
|
||||
#define configUSE_MALLOC_FAILED_HOOK 0
|
||||
|
||||
/* Constants provided for debugging and optimisation assistance. */
|
||||
#define configCHECK_FOR_STACK_OVERFLOW 2
|
||||
#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }
|
||||
#define configQUEUE_REGISTRY_SIZE 0
|
||||
#define configCHECK_FOR_STACK_OVERFLOW 2
|
||||
#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }
|
||||
#define configQUEUE_REGISTRY_SIZE 0
|
||||
|
||||
/* Software timer definitions. */
|
||||
#define configUSE_TIMERS 1
|
||||
#define configTIMER_TASK_PRIORITY ( 3 )
|
||||
#define configTIMER_QUEUE_LENGTH 5
|
||||
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE )
|
||||
#define configUSE_TIMERS 1
|
||||
#define configTIMER_TASK_PRIORITY ( 3 )
|
||||
#define configTIMER_QUEUE_LENGTH 5
|
||||
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE )
|
||||
|
||||
/* Set the following definitions to 1 to include the API function, or zero
|
||||
* to exclude the API function. NOTE: Setting an INCLUDE_ parameter to 0 is
|
||||
* only necessary if the linker does not automatically remove functions that are
|
||||
* not referenced anyway. */
|
||||
#define INCLUDE_vTaskPrioritySet 1
|
||||
#define INCLUDE_uxTaskPriorityGet 1
|
||||
#define INCLUDE_vTaskDelete 1
|
||||
#define INCLUDE_vTaskCleanUpResources 0
|
||||
#define INCLUDE_vTaskSuspend 1
|
||||
#define INCLUDE_vTaskDelayUntil 1
|
||||
#define INCLUDE_vTaskDelay 1
|
||||
#define INCLUDE_uxTaskGetStackHighWaterMark 0
|
||||
#define INCLUDE_xTaskGetIdleTaskHandle 0
|
||||
#define INCLUDE_eTaskGetState 1
|
||||
#define INCLUDE_xTaskResumeFromISR 0
|
||||
#define INCLUDE_xTaskGetCurrentTaskHandle 1
|
||||
#define INCLUDE_xTaskGetSchedulerState 0
|
||||
#define INCLUDE_xSemaphoreGetMutexHolder 0
|
||||
#define INCLUDE_xTimerPendFunctionCall 1
|
||||
#define INCLUDE_vTaskPrioritySet 1
|
||||
#define INCLUDE_uxTaskPriorityGet 1
|
||||
#define INCLUDE_vTaskDelete 1
|
||||
#define INCLUDE_vTaskCleanUpResources 0
|
||||
#define INCLUDE_vTaskSuspend 1
|
||||
#define INCLUDE_vTaskDelayUntil 1
|
||||
#define INCLUDE_vTaskDelay 1
|
||||
#define INCLUDE_uxTaskGetStackHighWaterMark 0
|
||||
#define INCLUDE_xTaskGetIdleTaskHandle 0
|
||||
#define INCLUDE_eTaskGetState 1
|
||||
#define INCLUDE_xTaskResumeFromISR 0
|
||||
#define INCLUDE_xTaskGetCurrentTaskHandle 1
|
||||
#define INCLUDE_xTaskGetSchedulerState 0
|
||||
#define INCLUDE_xSemaphoreGetMutexHolder 0
|
||||
#define INCLUDE_xTimerPendFunctionCall 1
|
||||
|
||||
/* This demo makes use of one or more example stats formatting functions. These
|
||||
* format the raw data provided by the uxTaskGetSystemState() function in to
|
||||
* human readable ASCII form. See the notes in the implementation of vTaskList()
|
||||
* within FreeRTOS/Source/tasks.c for limitations. */
|
||||
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
|
||||
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
|
||||
|
||||
/* Dimensions a buffer that can be used by the FreeRTOS+CLI command interpreter.
|
||||
* See the FreeRTOS+CLI documentation for more information:
|
||||
* http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_CLI/ */
|
||||
#define configCOMMAND_INT_MAX_OUTPUT_SIZE 2048
|
||||
#define configCOMMAND_INT_MAX_OUTPUT_SIZE 2048
|
||||
|
||||
/* Interrupt priority configuration follows...................... */
|
||||
|
||||
/* Use the system definition, if there is one. */
|
||||
#ifdef __NVIC_PRIO_BITS
|
||||
#define configPRIO_BITS __NVIC_PRIO_BITS
|
||||
#define configPRIO_BITS __NVIC_PRIO_BITS
|
||||
#else
|
||||
#define configPRIO_BITS 3 /* 8 priority levels. */
|
||||
#define configPRIO_BITS 3 /* 8 priority levels. */
|
||||
#endif
|
||||
|
||||
/* The lowest interrupt priority that can be used in a call to a "set priority"
|
||||
* function. */
|
||||
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 0x07
|
||||
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 0x07
|
||||
|
||||
/* The highest interrupt priority that can be used by any interrupt service
|
||||
* routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT
|
||||
* CALL INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A
|
||||
* HIGHER PRIORITY THAN THIS! (higher priorities are lower numeric values). */
|
||||
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5
|
||||
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5
|
||||
|
||||
/* Interrupt priorities used by the kernel port layer itself. These are generic
|
||||
* to all Cortex-M ports, and do not rely on any particular library functions. */
|
||||
#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << ( 8 - configPRIO_BITS ) )
|
||||
#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << ( 8 - configPRIO_BITS ) )
|
||||
|
||||
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
|
||||
* See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
|
||||
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << ( 8 - configPRIO_BITS ) )
|
||||
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << ( 8 - configPRIO_BITS ) )
|
||||
|
||||
/* The #ifdef guards against the file being included from IAR assembly files. */
|
||||
#ifndef __IASMARM__
|
||||
|
||||
/* Constants related to the generation of run time stats. */
|
||||
#define configGENERATE_RUN_TIME_STATS 0
|
||||
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()
|
||||
#define portGET_RUN_TIME_COUNTER_VALUE() 0
|
||||
#define configTICK_RATE_HZ ( ( TickType_t ) 100 )
|
||||
/* Constants related to the generation of run time stats. */
|
||||
#define configGENERATE_RUN_TIME_STATS 0
|
||||
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()
|
||||
#define portGET_RUN_TIME_COUNTER_VALUE() 0
|
||||
#define configTICK_RATE_HZ ( ( TickType_t ) 100 )
|
||||
|
||||
#endif /* __IASMARM__ */
|
||||
|
||||
/* Enable static allocation. */
|
||||
#define configSUPPORT_STATIC_ALLOCATION 1
|
||||
#define configSUPPORT_STATIC_ALLOCATION 1
|
||||
|
||||
#endif /* FREERTOS_CONFIG_H */
|
||||
|
@ -36,27 +36,27 @@
|
||||
/* Externs needed by the MPU setup code. These must match the memory map as
|
||||
* specified in Scatter-Loading description file (FreeRTOSDemo_ns.sct). */
|
||||
/* Privileged flash. */
|
||||
const uint32_t * __privileged_functions_start__ = ( uint32_t * ) ( 0x00200000 );
|
||||
const uint32_t * __privileged_functions_end__ = ( uint32_t * ) ( 0x00208000 - 0x1 ); /* Last address in privileged Flash region. */
|
||||
const uint32_t * __privileged_functions_start__ = ( uint32_t * ) ( 0x00200000 );
|
||||
const uint32_t * __privileged_functions_end__ = ( uint32_t * ) ( 0x00208000 - 0x1 ); /* Last address in privileged Flash region. */
|
||||
|
||||
/* Flash containing system calls. */
|
||||
const uint32_t * __syscalls_flash_start__ = ( uint32_t * ) ( 0x00208000 );
|
||||
const uint32_t * __syscalls_flash_end__ = ( uint32_t * ) ( 0x00209000 - 0x1 ); /* Last address in Flash region containing system calls. */
|
||||
const uint32_t * __syscalls_flash_start__ = ( uint32_t * ) ( 0x00208000 );
|
||||
const uint32_t * __syscalls_flash_end__ = ( uint32_t * ) ( 0x00209000 - 0x1 ); /* Last address in Flash region containing system calls. */
|
||||
|
||||
/* Unprivileged flash. Note that the section containing
|
||||
* system calls is unprivilged so that unprivleged tasks
|
||||
* can make system calls. */
|
||||
const uint32_t * __unprivileged_flash_start__ = ( uint32_t * ) ( 0x00209000 );
|
||||
const uint32_t * __unprivileged_flash_end__ = ( uint32_t * ) ( 0x00400000 - 0x1 ); /* Last address in un-privileged Flash region. */
|
||||
const uint32_t * __unprivileged_flash_start__ = ( uint32_t * ) ( 0x00209000 );
|
||||
const uint32_t * __unprivileged_flash_end__ = ( uint32_t * ) ( 0x00400000 - 0x1 ); /* Last address in un-privileged Flash region. */
|
||||
|
||||
/* 512 bytes (0x200) of RAM starting at 0x30008000 is
|
||||
* priviledged access only. This contains kernel data. */
|
||||
const uint32_t * __privileged_sram_start__ = ( uint32_t * ) ( 0x20200000 );
|
||||
const uint32_t * __privileged_sram_end__ = ( uint32_t * ) ( 0x20201000 - 0x1 ); /* Last address in privileged RAM. */
|
||||
const uint32_t * __privileged_sram_start__ = ( uint32_t * ) ( 0x20200000 );
|
||||
const uint32_t * __privileged_sram_end__ = ( uint32_t * ) ( 0x20201000 - 0x1 ); /* Last address in privileged RAM. */
|
||||
;
|
||||
/* Unprivileged RAM. */
|
||||
const uint32_t * __unprivileged_sram_start__ = ( uint32_t * ) ( 0x20201000 );
|
||||
const uint32_t * __unprivileged_sram_end__ = ( uint32_t * ) ( 0x20220000 - 0x1 ); /* Last address in un-privileged RAM. */
|
||||
const uint32_t * __unprivileged_sram_start__ = ( uint32_t * ) ( 0x20201000 );
|
||||
const uint32_t * __unprivileged_sram_end__ = ( uint32_t * ) ( 0x20220000 - 0x1 ); /* Last address in un-privileged RAM. */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
@ -67,11 +67,11 @@ static void prvCreateTasks( void );
|
||||
|
||||
static void prvCreateTasks( void )
|
||||
{
|
||||
/* Create tasks for the MPU Demo. */
|
||||
vStartMPUDemo();
|
||||
/* Create tasks for the MPU Demo. */
|
||||
vStartMPUDemo();
|
||||
|
||||
/* Create tasks for the TZ Demo. */
|
||||
vStartTZDemo();
|
||||
/* Create tasks for the TZ Demo. */
|
||||
vStartTZDemo();
|
||||
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
@ -79,51 +79,51 @@ static void prvCreateTasks( void )
|
||||
/* Stack overflow hook. */
|
||||
void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName )
|
||||
{
|
||||
/* Force an assert. */
|
||||
configASSERT( pcTaskName == 0 );
|
||||
/* Force an assert. */
|
||||
configASSERT( pcTaskName == 0 );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Non-Secure main. */
|
||||
int main( void )
|
||||
{
|
||||
/* Create tasks. */
|
||||
prvCreateTasks();
|
||||
/* Create tasks. */
|
||||
prvCreateTasks();
|
||||
|
||||
/* Start scheduler. */
|
||||
vTaskStartScheduler();
|
||||
/* Start scheduler. */
|
||||
vTaskStartScheduler();
|
||||
|
||||
/* Should not reach here as the schedular is already started. */
|
||||
for( ; ; )
|
||||
{
|
||||
}
|
||||
/* Should not reach here as the schedular is already started. */
|
||||
for( ; ; )
|
||||
{
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an
|
||||
* implementation of vApplicationGetIdleTaskMemory() to provide the memory that
|
||||
* is used by the Idle task. */
|
||||
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
|
||||
StackType_t ** ppxIdleTaskStackBuffer,
|
||||
uint32_t * pulIdleTaskStackSize )
|
||||
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
|
||||
StackType_t ** ppxIdleTaskStackBuffer,
|
||||
uint32_t * pulIdleTaskStackSize )
|
||||
{
|
||||
/* If the buffers to be provided to the Idle task are declared inside this
|
||||
* function then they must be declared static - otherwise they will be
|
||||
* allocated on the stack and so not exists after this function exits. */
|
||||
static StaticTask_t xIdleTaskTCB;
|
||||
static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__((aligned(32)));
|
||||
/* If the buffers to be provided to the Idle task are declared inside this
|
||||
* function then they must be declared static - otherwise they will be
|
||||
* allocated on the stack and so not exists after this function exits. */
|
||||
static StaticTask_t xIdleTaskTCB;
|
||||
static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__((aligned(32)));
|
||||
|
||||
/* Pass out a pointer to the StaticTask_t structure in which the Idle
|
||||
* task's state will be stored. */
|
||||
*ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
|
||||
/* Pass out a pointer to the StaticTask_t structure in which the Idle
|
||||
* task's state will be stored. */
|
||||
*ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
|
||||
|
||||
/* Pass out the array that will be used as the Idle task's stack. */
|
||||
*ppxIdleTaskStackBuffer = uxIdleTaskStack;
|
||||
/* Pass out the array that will be used as the Idle task's stack. */
|
||||
*ppxIdleTaskStackBuffer = uxIdleTaskStack;
|
||||
|
||||
/* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
|
||||
* Note that, as the array is necessarily of type StackType_t,
|
||||
* configMINIMAL_STACK_SIZE is specified in words, not bytes. */
|
||||
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
|
||||
/* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
|
||||
* Note that, as the array is necessarily of type StackType_t,
|
||||
* configMINIMAL_STACK_SIZE is specified in words, not bytes. */
|
||||
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
@ -131,26 +131,26 @@ void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
|
||||
* application must provide an implementation of vApplicationGetTimerTaskMemory()
|
||||
* to provide the memory that is used by the Timer service task. */
|
||||
void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
|
||||
StackType_t ** ppxTimerTaskStackBuffer,
|
||||
uint32_t * pulTimerTaskStackSize )
|
||||
StackType_t ** ppxTimerTaskStackBuffer,
|
||||
uint32_t * pulTimerTaskStackSize )
|
||||
{
|
||||
/* If the buffers to be provided to the Timer task are declared inside this
|
||||
* function then they must be declared static - otherwise they will be
|
||||
* allocated on the stack and so not exists after this function exits. */
|
||||
static StaticTask_t xTimerTaskTCB;
|
||||
static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ] __attribute__((aligned(32)));
|
||||
/* If the buffers to be provided to the Timer task are declared inside this
|
||||
* function then they must be declared static - otherwise they will be
|
||||
* allocated on the stack and so not exists after this function exits. */
|
||||
static StaticTask_t xTimerTaskTCB;
|
||||
static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ] __attribute__((aligned(32)));
|
||||
|
||||
/* Pass out a pointer to the StaticTask_t structure in which the Timer
|
||||
* task's state will be stored. */
|
||||
*ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
|
||||
/* Pass out a pointer to the StaticTask_t structure in which the Timer
|
||||
* task's state will be stored. */
|
||||
*ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
|
||||
|
||||
/* Pass out the array that will be used as the Timer task's stack. */
|
||||
*ppxTimerTaskStackBuffer = uxTimerTaskStack;
|
||||
/* Pass out the array that will be used as the Timer task's stack. */
|
||||
*ppxTimerTaskStackBuffer = uxTimerTaskStack;
|
||||
|
||||
/* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
|
||||
* Note that, as the array is necessarily of type StackType_t,
|
||||
* configTIMER_TASK_STACK_DEPTH is specified in words, not bytes. */
|
||||
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
|
||||
/* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
|
||||
* Note that, as the array is necessarily of type StackType_t,
|
||||
* configTIMER_TASK_STACK_DEPTH is specified in words, not bytes. */
|
||||
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
@ -160,16 +160,16 @@ void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
|
||||
*/
|
||||
void MemManage_Handler( void )
|
||||
{
|
||||
__asm volatile
|
||||
(
|
||||
" tst lr, #4 \n"
|
||||
" ite eq \n"
|
||||
" mrseq r0, msp \n"
|
||||
" mrsne r0, psp \n"
|
||||
" ldr r1, handler_address_const \n"
|
||||
" bx r1 \n"
|
||||
" \n"
|
||||
" handler_address_const: .word vHandleMemoryFault \n"
|
||||
);
|
||||
__asm volatile
|
||||
(
|
||||
" tst lr, #4 \n"
|
||||
" ite eq \n"
|
||||
" mrseq r0, msp \n"
|
||||
" mrsne r0, psp \n"
|
||||
" ldr r1, handler_address_const \n"
|
||||
" bx r1 \n"
|
||||
" \n"
|
||||
" handler_address_const: .word vHandleMemoryFault \n"
|
||||
);
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
@ -34,10 +34,10 @@
|
||||
#include "secure_port_macros.h"
|
||||
|
||||
/* Start address of non-secure application. */
|
||||
#define mainNONSECURE_APP_START_ADDRESS ( 0x200000U )
|
||||
#define mainNONSECURE_APP_START_ADDRESS ( 0x200000U )
|
||||
|
||||
/* typedef for non-secure Reset Handler. */
|
||||
typedef void ( *NonSecureResetHandler_t ) ( void ) __attribute__( ( cmse_nonsecure_call ) );
|
||||
typedef void ( *NonSecureResetHandler_t ) ( void ) __attribute__( ( cmse_nonsecure_call ) );
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Boot into the non-secure code. */
|
||||
@ -46,34 +46,34 @@ void BootNonSecure( uint32_t ulNonSecureStartAddress );
|
||||
|
||||
void BootNonSecure( uint32_t ulNonSecureStartAddress )
|
||||
{
|
||||
NonSecureResetHandler_t pxNonSecureResetHandler;
|
||||
NonSecureResetHandler_t pxNonSecureResetHandler;
|
||||
|
||||
/* Main Stack Pointer value for the non-secure side is the first entry in
|
||||
* the non-secure vector table. Read the first entry and assign the same to
|
||||
* the non-secure main stack pointer(MSP_NS). */
|
||||
secureportSET_MSP_NS( *( ( uint32_t * )( ulNonSecureStartAddress ) ) );
|
||||
/* Main Stack Pointer value for the non-secure side is the first entry in
|
||||
* the non-secure vector table. Read the first entry and assign the same to
|
||||
* the non-secure main stack pointer(MSP_NS). */
|
||||
secureportSET_MSP_NS( *( ( uint32_t * )( ulNonSecureStartAddress ) ) );
|
||||
|
||||
/* Non secure Reset Handler is the second entry in the non-secure vector
|
||||
* table. Read the non-secure reset handler.
|
||||
*/
|
||||
pxNonSecureResetHandler = ( NonSecureResetHandler_t )( * ( ( uint32_t * ) ( ( ulNonSecureStartAddress ) + 4U ) ) );
|
||||
/* Non secure Reset Handler is the second entry in the non-secure vector
|
||||
* table. Read the non-secure reset handler.
|
||||
*/
|
||||
pxNonSecureResetHandler = ( NonSecureResetHandler_t )( * ( ( uint32_t * ) ( ( ulNonSecureStartAddress ) + 4U ) ) );
|
||||
|
||||
/* Start non-secure software application by jumping to the non-secure Reset
|
||||
* Handler. */
|
||||
pxNonSecureResetHandler();
|
||||
/* Start non-secure software application by jumping to the non-secure Reset
|
||||
* Handler. */
|
||||
pxNonSecureResetHandler();
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Secure main() */
|
||||
int main( void )
|
||||
{
|
||||
/* Boot the non-secure code. */
|
||||
BootNonSecure( mainNONSECURE_APP_START_ADDRESS );
|
||||
/* Boot the non-secure code. */
|
||||
BootNonSecure( mainNONSECURE_APP_START_ADDRESS );
|
||||
|
||||
/* Non-secure software does not return, this code is not executed. */
|
||||
for( ; ; )
|
||||
{
|
||||
/* Should not reach here. */
|
||||
}
|
||||
/* Non-secure software does not return, this code is not executed. */
|
||||
for( ; ; )
|
||||
{
|
||||
/* Should not reach here. */
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
@ -76,48 +76,48 @@ static void prvROAccessTask( void * pvParameters )
|
||||
{
|
||||
uint8_t ucVal;
|
||||
|
||||
/* Unused parameters. */
|
||||
( void ) pvParameters;
|
||||
/* Unused parameters. */
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ; ; )
|
||||
{
|
||||
/* This task has RO access to ucSharedMemory and therefore it can read
|
||||
* it but cannot modify it. */
|
||||
ucVal = ucSharedMemory[ 0 ];
|
||||
for( ; ; )
|
||||
{
|
||||
/* This task has RO access to ucSharedMemory and therefore it can read
|
||||
* it but cannot modify it. */
|
||||
ucVal = ucSharedMemory[ 0 ];
|
||||
|
||||
/* Silent compiler warnings about unused variables. */
|
||||
( void ) ucVal;
|
||||
/* Silent compiler warnings about unused variables. */
|
||||
( void ) ucVal;
|
||||
|
||||
/* Since this task has Read Only access to the ucSharedMemory region,
|
||||
* writing to it results in Memory Fault. Set ucROTaskFaultTracker[ 0 ]
|
||||
* to 1 to tell the Memory Fault Handler that this is an expected fault.
|
||||
* The handler will recover from this fault gracefully by jumping to the
|
||||
* next instruction. */
|
||||
ucROTaskFaultTracker[ 0 ] = 1;
|
||||
/* Since this task has Read Only access to the ucSharedMemory region,
|
||||
* writing to it results in Memory Fault. Set ucROTaskFaultTracker[ 0 ]
|
||||
* to 1 to tell the Memory Fault Handler that this is an expected fault.
|
||||
* The handler will recover from this fault gracefully by jumping to the
|
||||
* next instruction. */
|
||||
ucROTaskFaultTracker[ 0 ] = 1;
|
||||
|
||||
/* Illegal access to generate Memory Fault. */
|
||||
ucSharedMemory[ 0 ] = 0;
|
||||
/* Illegal access to generate Memory Fault. */
|
||||
ucSharedMemory[ 0 ] = 0;
|
||||
|
||||
/* Wait for a second. */
|
||||
vTaskDelay( pdMS_TO_TICKS( 1000 ) );
|
||||
}
|
||||
/* Wait for a second. */
|
||||
vTaskDelay( pdMS_TO_TICKS( 1000 ) );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvRWAccessTask( void * pvParameters )
|
||||
{
|
||||
/* Unused parameters. */
|
||||
( void ) pvParameters;
|
||||
/* Unused parameters. */
|
||||
( void ) pvParameters;
|
||||
|
||||
for( ; ; )
|
||||
{
|
||||
/* This task has RW access to ucSharedMemory and therefore can write to
|
||||
* it. */
|
||||
ucSharedMemory[ 0 ] = 0;
|
||||
for( ; ; )
|
||||
{
|
||||
/* This task has RW access to ucSharedMemory and therefore can write to
|
||||
* it. */
|
||||
ucSharedMemory[ 0 ] = 0;
|
||||
|
||||
/* Wait for a second. */
|
||||
vTaskDelay( pdMS_TO_TICKS( 1000 ) );
|
||||
}
|
||||
/* Wait for a second. */
|
||||
vTaskDelay( pdMS_TO_TICKS( 1000 ) );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
@ -127,38 +127,38 @@ static StackType_t xROAccessTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__(
|
||||
static StackType_t xRWAccessTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) );
|
||||
TaskParameters_t xROAccessTaskParameters =
|
||||
{
|
||||
.pvTaskCode = prvROAccessTask,
|
||||
.pcName = "ROAccess",
|
||||
.usStackDepth = configMINIMAL_STACK_SIZE,
|
||||
.pvParameters = NULL,
|
||||
.uxPriority = tskIDLE_PRIORITY,
|
||||
.puxStackBuffer = xROAccessTaskStack,
|
||||
.xRegions = {
|
||||
{ ucSharedMemory, 32, tskMPU_REGION_READ_ONLY | tskMPU_REGION_EXECUTE_NEVER },
|
||||
{ ucROTaskFaultTracker, 32, tskMPU_REGION_READ_WRITE | tskMPU_REGION_EXECUTE_NEVER },
|
||||
{ 0, 0, 0 },
|
||||
}
|
||||
.pvTaskCode = prvROAccessTask,
|
||||
.pcName = "ROAccess",
|
||||
.usStackDepth = configMINIMAL_STACK_SIZE,
|
||||
.pvParameters = NULL,
|
||||
.uxPriority = tskIDLE_PRIORITY,
|
||||
.puxStackBuffer = xROAccessTaskStack,
|
||||
.xRegions = {
|
||||
{ ucSharedMemory, 32, tskMPU_REGION_READ_ONLY | tskMPU_REGION_EXECUTE_NEVER },
|
||||
{ ucROTaskFaultTracker, 32, tskMPU_REGION_READ_WRITE | tskMPU_REGION_EXECUTE_NEVER },
|
||||
{ 0, 0, 0 },
|
||||
}
|
||||
};
|
||||
TaskParameters_t xRWAccessTaskParameters =
|
||||
{
|
||||
.pvTaskCode = prvRWAccessTask,
|
||||
.pcName = "RWAccess",
|
||||
.usStackDepth = configMINIMAL_STACK_SIZE,
|
||||
.pvParameters = NULL,
|
||||
.uxPriority = tskIDLE_PRIORITY,
|
||||
.puxStackBuffer = xRWAccessTaskStack,
|
||||
.xRegions = {
|
||||
{ ucSharedMemory, 32, tskMPU_REGION_READ_WRITE | tskMPU_REGION_EXECUTE_NEVER },
|
||||
{ 0, 0, 0 },
|
||||
{ 0, 0, 0 },
|
||||
}
|
||||
.pvTaskCode = prvRWAccessTask,
|
||||
.pcName = "RWAccess",
|
||||
.usStackDepth = configMINIMAL_STACK_SIZE,
|
||||
.pvParameters = NULL,
|
||||
.uxPriority = tskIDLE_PRIORITY,
|
||||
.puxStackBuffer = xRWAccessTaskStack,
|
||||
.xRegions = {
|
||||
{ ucSharedMemory, 32, tskMPU_REGION_READ_WRITE | tskMPU_REGION_EXECUTE_NEVER },
|
||||
{ 0, 0, 0 },
|
||||
{ 0, 0, 0 },
|
||||
}
|
||||
};
|
||||
|
||||
/* Create an unprivileged task with RO access to ucSharedMemory. */
|
||||
xTaskCreateRestricted( &( xROAccessTaskParameters ), NULL );
|
||||
/* Create an unprivileged task with RO access to ucSharedMemory. */
|
||||
xTaskCreateRestricted( &( xROAccessTaskParameters ), NULL );
|
||||
|
||||
/* Create an unprivileged task with RW access to ucSharedMemory. */
|
||||
xTaskCreateRestricted( &( xRWAccessTaskParameters ), NULL );
|
||||
/* Create an unprivileged task with RW access to ucSharedMemory. */
|
||||
xTaskCreateRestricted( &( xRWAccessTaskParameters ), NULL );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
@ -166,27 +166,27 @@ void vHandleMemoryFault( uint32_t * pulFaultStackAddress )
|
||||
{
|
||||
uint32_t ulPC;
|
||||
|
||||
/* Is this an expected fault? */
|
||||
if( ucROTaskFaultTracker[ 0 ] == 1 )
|
||||
{
|
||||
/* Read program counter. */
|
||||
ulPC = pulFaultStackAddress[ 6 ];
|
||||
/* Is this an expected fault? */
|
||||
if( ucROTaskFaultTracker[ 0 ] == 1 )
|
||||
{
|
||||
/* Read program counter. */
|
||||
ulPC = pulFaultStackAddress[ 6 ];
|
||||
|
||||
/* Increment the program counter by 2 to move to the next instruction. */
|
||||
ulPC += 2;
|
||||
/* Increment the program counter by 2 to move to the next instruction. */
|
||||
ulPC += 2;
|
||||
|
||||
/* Save the new program counter on the stack. */
|
||||
pulFaultStackAddress[ 6 ] = ulPC;
|
||||
/* Save the new program counter on the stack. */
|
||||
pulFaultStackAddress[ 6 ] = ulPC;
|
||||
|
||||
/* Mark the fault as handled. */
|
||||
ucROTaskFaultTracker[ 0 ] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This is an unexpected fault - loop forever. */
|
||||
for( ; ; )
|
||||
{
|
||||
}
|
||||
}
|
||||
/* Mark the fault as handled. */
|
||||
ucROTaskFaultTracker[ 0 ] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This is an unexpected fault - loop forever. */
|
||||
for( ; ; )
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
@ -44,16 +44,16 @@ secureportNON_SECURE_CALLABLE uint32_t NSCFunction( Callback_t pxCallback )
|
||||
{
|
||||
NonSecureCallback_t pxNonSecureCallback;
|
||||
|
||||
/* Return function pointer with cleared LSB. */
|
||||
pxNonSecureCallback = ( NonSecureCallback_t ) cmse_nsfptr_create( pxCallback );
|
||||
/* Return function pointer with cleared LSB. */
|
||||
pxNonSecureCallback = ( NonSecureCallback_t ) cmse_nsfptr_create( pxCallback );
|
||||
|
||||
/* Invoke the supplied callback. */
|
||||
pxNonSecureCallback();
|
||||
/* Invoke the supplied callback. */
|
||||
pxNonSecureCallback();
|
||||
|
||||
/* Increment the secure side counter. */
|
||||
ulSecureCounter += 1;
|
||||
/* Increment the secure side counter. */
|
||||
ulSecureCounter += 1;
|
||||
|
||||
/* Return the secure side counter. */
|
||||
return ulSecureCounter;
|
||||
/* Return the secure side counter. */
|
||||
return ulSecureCounter;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
@ -71,30 +71,30 @@ void vStartTZDemo( void )
|
||||
static StackType_t xSecureCallingTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) );
|
||||
TaskParameters_t xSecureCallingTaskParameters =
|
||||
{
|
||||
.pvTaskCode = prvSecureCallingTask,
|
||||
.pcName = "SecCalling",
|
||||
.usStackDepth = configMINIMAL_STACK_SIZE,
|
||||
.pvParameters = NULL,
|
||||
.uxPriority = tskIDLE_PRIORITY,
|
||||
.puxStackBuffer = xSecureCallingTaskStack,
|
||||
.xRegions = {
|
||||
{ ulNonSecureCounter, 32, tskMPU_REGION_READ_WRITE | tskMPU_REGION_EXECUTE_NEVER },
|
||||
{ 0, 0, 0 },
|
||||
{ 0, 0, 0 },
|
||||
}
|
||||
.pvTaskCode = prvSecureCallingTask,
|
||||
.pcName = "SecCalling",
|
||||
.usStackDepth = configMINIMAL_STACK_SIZE,
|
||||
.pvParameters = NULL,
|
||||
.uxPriority = tskIDLE_PRIORITY,
|
||||
.puxStackBuffer = xSecureCallingTaskStack,
|
||||
.xRegions = {
|
||||
{ ulNonSecureCounter, 32, tskMPU_REGION_READ_WRITE | tskMPU_REGION_EXECUTE_NEVER },
|
||||
{ 0, 0, 0 },
|
||||
{ 0, 0, 0 },
|
||||
}
|
||||
};
|
||||
|
||||
/* Create an unprivileged task which calls secure functions. */
|
||||
xTaskCreateRestricted( &( xSecureCallingTaskParameters ), NULL );
|
||||
/* Create an unprivileged task which calls secure functions. */
|
||||
xTaskCreateRestricted( &( xSecureCallingTaskParameters ), NULL );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvCallback( void )
|
||||
{
|
||||
/* This function is called from the secure side. Just increment the counter
|
||||
* here. The check that this counter keeps incrementing is performed in the
|
||||
* prvSecureCallingTask. */
|
||||
ulNonSecureCounter[ 0 ] += 1;
|
||||
/* This function is called from the secure side. Just increment the counter
|
||||
* here. The check that this counter keeps incrementing is performed in the
|
||||
* prvSecureCallingTask. */
|
||||
ulNonSecureCounter[ 0 ] += 1;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
@ -103,31 +103,31 @@ static void prvSecureCallingTask( void * pvParameters )
|
||||
uint32_t ulLastSecureCounter = 0, ulLastNonSecureCounter = 0;
|
||||
uint32_t ulCurrentSecureCounter = 0;
|
||||
|
||||
/* This task calls secure side functions. So allocate a secure context for
|
||||
* it. */
|
||||
portALLOCATE_SECURE_CONTEXT( configMINIMAL_SECURE_STACK_SIZE );
|
||||
/* This task calls secure side functions. So allocate a secure context for
|
||||
* it. */
|
||||
portALLOCATE_SECURE_CONTEXT( configMINIMAL_SECURE_STACK_SIZE );
|
||||
|
||||
for( ; ; )
|
||||
{
|
||||
/* Call the secure side function. It does two things:
|
||||
* - It calls the supplied function (prvCallback) which in turn
|
||||
* increments the non-secure counter.
|
||||
* - It increments the secure counter and returns the incremented value.
|
||||
* Therefore at the end of this function call both the secure and
|
||||
* non-secure counters must have been incremented.
|
||||
*/
|
||||
ulCurrentSecureCounter = NSCFunction( prvCallback );
|
||||
for( ; ; )
|
||||
{
|
||||
/* Call the secure side function. It does two things:
|
||||
* - It calls the supplied function (prvCallback) which in turn
|
||||
* increments the non-secure counter.
|
||||
* - It increments the secure counter and returns the incremented value.
|
||||
* Therefore at the end of this function call both the secure and
|
||||
* non-secure counters must have been incremented.
|
||||
*/
|
||||
ulCurrentSecureCounter = NSCFunction( prvCallback );
|
||||
|
||||
/* Make sure that both the counters are incremented. */
|
||||
configASSERT( ulCurrentSecureCounter == ulLastSecureCounter + 1 );
|
||||
configASSERT( ulNonSecureCounter[ 0 ] == ulLastNonSecureCounter + 1 );
|
||||
/* Make sure that both the counters are incremented. */
|
||||
configASSERT( ulCurrentSecureCounter == ulLastSecureCounter + 1 );
|
||||
configASSERT( ulNonSecureCounter[ 0 ] == ulLastNonSecureCounter + 1 );
|
||||
|
||||
/* Update the last values for both the counters. */
|
||||
ulLastSecureCounter = ulCurrentSecureCounter;
|
||||
ulLastNonSecureCounter = ulNonSecureCounter[ 0 ];
|
||||
/* Update the last values for both the counters. */
|
||||
ulLastSecureCounter = ulCurrentSecureCounter;
|
||||
ulLastNonSecureCounter = ulNonSecureCounter[ 0 ];
|
||||
|
||||
/* Wait for a second. */
|
||||
vTaskDelay( pdMS_TO_TICKS( 1000 ) );
|
||||
}
|
||||
/* Wait for a second. */
|
||||
vTaskDelay( pdMS_TO_TICKS( 1000 ) );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
Reference in New Issue
Block a user