diff options
Diffstat (limited to 'FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/RegTests/reg_tests.c')
-rw-r--r-- | FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/RegTests/reg_tests.c | 144 |
1 files changed, 89 insertions, 55 deletions
diff --git a/FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/RegTests/reg_tests.c b/FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/RegTests/reg_tests.c index 9cda7f753..7ae69babd 100644 --- a/FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/RegTests/reg_tests.c +++ b/FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/RegTests/reg_tests.c @@ -31,7 +31,9 @@ /* Reg test includes. */ #include "reg_tests.h" #include "reg_test_asm.h" -#include "secure_reg_test_asm.h" +#if( configENABLE_TRUSTZONE == 1 ) + #include "secure_reg_test_asm.h" +#endif /* Device includes. */ #include "NuMicro.h" @@ -41,9 +43,10 @@ */ static void prvRegTest1_Task( void * pvParameters ); static void prvRegTest2_Task( void * pvParameters ); -static void prvRegTest_Secure_Task( void * pvParameters ); -static void prvRegTest_NonSecureCallback_Task( void * pvParameters ); - +#if( configENABLE_TRUSTZONE == 1 ) + static void prvRegTest_Secure_Task( void * pvParameters ); + static void prvRegTest_NonSecureCallback_Task( void * pvParameters ); +#endif /* * Check task periodically checks that reg tests tasks * are running fine. @@ -54,8 +57,13 @@ static void prvCheckTask( void * pvParameters ); /* * On board LEDs. */ -#define YELLOW_LED PA11_NS -#define GREEN_LED PA10_NS +#if( configENABLE_TRUSTZONE == 1 ) + #define YELLOW_LED PA11_NS + #define GREEN_LED PA10_NS +#else + #define YELLOW_LED PA11 + #define GREEN_LED PA10 +#endif /* * Priority of the check task. @@ -84,8 +92,10 @@ static void prvCheckTask( void * pvParameters ); * incrementing, then an error has been found. */ volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL; -volatile unsigned long ulRegTestSecureLoopCounter = 0UL; -volatile unsigned long ulRegTestNonSecureCallbackLoopCounter = 0UL; +#if( configENABLE_TRUSTZONE == 1 ) + volatile unsigned long ulRegTestSecureLoopCounter = 0UL; + volatile unsigned long ulRegTestNonSecureCallbackLoopCounter = 0UL; +#endif /** * Counter to keep a count of how may times the check task loop has detected @@ -98,9 +108,11 @@ void vStartRegTests( void ) { static StackType_t xRegTest1TaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) ); static StackType_t xRegTest2TaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) ); -static StackType_t xRegTestSecureTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) ); -static StackType_t xRegTestNonSecureCallbackTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) ); static StackType_t xCheckTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) ); +#if( configENABLE_TRUSTZONE == 1 ) + static StackType_t xRegTestSecureTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) ); + static StackType_t xRegTestNonSecureCallbackTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) ); +#endif TaskParameters_t xRegTest1TaskParameters = { @@ -130,35 +142,6 @@ TaskParameters_t xRegTest2TaskParameters = { 0, 0, 0 } } }; -TaskParameters_t xRegTestSecureTaskParameters = -{ - .pvTaskCode = prvRegTest_Secure_Task, - .pcName = "RegTestSecure", - .usStackDepth = configMINIMAL_STACK_SIZE, - .pvParameters = REG_TEST_SECURE_TASK_PARAMETER, - .uxPriority = tskIDLE_PRIORITY | portPRIVILEGE_BIT, - .puxStackBuffer = xRegTestSecureTaskStack, - .xRegions = { - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 } - } -}; -TaskParameters_t xRegTestNonSecureCallbackTaskParameters = -{ - .pvTaskCode = prvRegTest_NonSecureCallback_Task, - .pcName = "RegTestNonSecureCallback", - .usStackDepth = configMINIMAL_STACK_SIZE, - .pvParameters = REG_TEST_NON_SECURE_CALLBACK_TASK_PARAMETER, - .uxPriority = tskIDLE_PRIORITY | portPRIVILEGE_BIT, - .puxStackBuffer = xRegTestNonSecureCallbackTaskStack, - .xRegions = { - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 } - } -}; - TaskParameters_t xCheckTaskParameters = { .pvTaskCode = prvCheckTask, @@ -174,8 +157,43 @@ TaskParameters_t xCheckTaskParameters = } }; +#if( configENABLE_TRUSTZONE == 1 ) + TaskParameters_t xRegTestSecureTaskParameters = + { + .pvTaskCode = prvRegTest_Secure_Task, + .pcName = "RegTestSecure", + .usStackDepth = configMINIMAL_STACK_SIZE, + .pvParameters = REG_TEST_SECURE_TASK_PARAMETER, + .uxPriority = tskIDLE_PRIORITY | portPRIVILEGE_BIT, + .puxStackBuffer = xRegTestSecureTaskStack, + .xRegions = { + { 0, 0, 0 }, + { 0, 0, 0 }, + { 0, 0, 0 } + } + }; + TaskParameters_t xRegTestNonSecureCallbackTaskParameters = + { + .pvTaskCode = prvRegTest_NonSecureCallback_Task, + .pcName = "RegTestNonSecureCallback", + .usStackDepth = configMINIMAL_STACK_SIZE, + .pvParameters = REG_TEST_NON_SECURE_CALLBACK_TASK_PARAMETER, + .uxPriority = tskIDLE_PRIORITY | portPRIVILEGE_BIT, + .puxStackBuffer = xRegTestNonSecureCallbackTaskStack, + .xRegions = { + { 0, 0, 0 }, + { 0, 0, 0 }, + { 0, 0, 0 } + } + }; +#endif /* configENABLE_TRUSTZONE */ + /* Configure pins in output mode to drive external LEDs. */ - GPIO_SetMode( PA_NS, BIT10 | BIT11, GPIO_MODE_OUTPUT ); + #if( configENABLE_TRUSTZONE == 1 ) + GPIO_SetMode( PA_NS, BIT10 | BIT11, GPIO_MODE_OUTPUT ); + #else + GPIO_SetMode( PA, BIT10 | BIT11, GPIO_MODE_OUTPUT ); + #endif /* Start with both LEDs off. */ YELLOW_LED = 1; @@ -183,9 +201,11 @@ TaskParameters_t xCheckTaskParameters = xTaskCreateRestricted( &( xRegTest1TaskParameters ), NULL ); xTaskCreateRestricted( &( xRegTest2TaskParameters ), NULL ); - xTaskCreateRestricted( &( xRegTestSecureTaskParameters ), NULL ); - xTaskCreateRestricted( &( xRegTestNonSecureCallbackTaskParameters ), NULL ); xTaskCreateRestricted( &( xCheckTaskParameters ), NULL ); + #if( configENABLE_TRUSTZONE == 1 ) + xTaskCreateRestricted( &( xRegTestSecureTaskParameters ), NULL ); + xTaskCreateRestricted( &( xRegTestNonSecureCallbackTaskParameters ), NULL ); + #endif } /*-----------------------------------------------------------*/ @@ -227,6 +247,8 @@ static void prvRegTest2_Task( void * pvParameters ) } /*-----------------------------------------------------------*/ +#if( configENABLE_TRUSTZONE == 1 ) + static void prvRegTest_Secure_Task( void * pvParameters ) { /* This task is going to call secure side functions. */ @@ -257,8 +279,12 @@ static void prvRegTest_Secure_Task( void * pvParameters ) * an error. */ vTaskDelete( NULL ); } + +#endif /*-----------------------------------------------------------*/ +#if( configENABLE_TRUSTZONE == 1 ) + static void prvRegTest_NonSecureCallback_Task( void * pvParameters ) { /* This task is going to call secure side functions. */ @@ -290,6 +316,8 @@ static void prvRegTest_NonSecureCallback_Task( void * pvParameters ) * an error. */ vTaskDelete( NULL ); } + +#endif /*-----------------------------------------------------------*/ static void prvCheckTask( void * pvParameters ) @@ -298,7 +326,9 @@ TickType_t xDelayPeriod = NO_ERROR_CHECK_TASK_PERIOD; TickType_t xLastExecutionTime; unsigned long ulErrorFound = pdFALSE; static unsigned long ulLastRegTest1Value = 0, ulLastRegTest2Value = 0; -static unsigned long ulLastRegTestSecureValue = 0, ulLastRegTestNonSecureCallbackValue = 0; +#if( configENABLE_TRUSTZONE == 1 ) + static unsigned long ulLastRegTestSecureValue = 0, ulLastRegTestNonSecureCallbackValue = 0; +#endif /* Just to stop compiler warnings. */ ( void ) pvParameters; @@ -332,20 +362,24 @@ static unsigned long ulLastRegTestSecureValue = 0, ulLastRegTestNonSecureCallbac } ulLastRegTest2Value = ulRegTest2LoopCounter; - /* Check that the register test secure task is still running. */ - if( ulLastRegTestSecureValue == ulRegTestSecureLoopCounter ) - { - ulErrorFound |= 1UL << 2UL; - } - ulLastRegTestSecureValue = ulRegTestSecureLoopCounter; - - /* Check that the register test non-secure callback task is - * still running. */ - if( ulLastRegTestNonSecureCallbackValue == ulRegTestNonSecureCallbackLoopCounter ) + #if( configENABLE_TRUSTZONE == 1 ) { - ulErrorFound |= 1UL << 3UL; + /* Check that the register test secure task is still running. */ + if( ulLastRegTestSecureValue == ulRegTestSecureLoopCounter ) + { + ulErrorFound |= 1UL << 2UL; + } + ulLastRegTestSecureValue = ulRegTestSecureLoopCounter; + + /* Check that the register test non-secure callback task is + * still running. */ + if( ulLastRegTestNonSecureCallbackValue == ulRegTestNonSecureCallbackLoopCounter ) + { + ulErrorFound |= 1UL << 3UL; + } + ulLastRegTestNonSecureCallbackValue = ulRegTestNonSecureCallbackLoopCounter; } - ulLastRegTestNonSecureCallbackValue = ulRegTestNonSecureCallbackLoopCounter; + #endif /* configENABLE_TRUSTZONE */ /* Toggle the green LED to give an indication of the system status. * If the LED toggles every NO_ERROR_CHECK_TASK_PERIOD milliseconds |