summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>2023-04-24 11:14:18 +0530
committerGitHub <noreply@github.com>2023-04-24 11:14:18 +0530
commit87a85a8ee5de839c33386092562f78e090f12d39 (patch)
tree7cc8f9c6f5c20cf64b70ce47d0604a19c4d178bb
parent5b403a6a0737d2f7d0147750a02f3a1140f68c37 (diff)
downloadfreertos-git-87a85a8ee5de839c33386092562f78e090f12d39.tar.gz
Add reg tests to nRF9160 projects (#1001)
Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
-rw-r--r--FreeRTOS/Demo/CORTEX_MPU_M33F_NTZ_Nordic_NRF9160_SES/FreeRTOSDemo.emProject81
-rw-r--r--FreeRTOS/Demo/CORTEX_MPU_M33F_NTZ_Nordic_NRF9160_SES/Source/main.c4
-rw-r--r--FreeRTOS/Demo/CORTEX_MPU_M33F_NTZ_Nordic_NRF9160_SES/Source/reg_tests.c354
-rw-r--r--FreeRTOS/Demo/CORTEX_MPU_M33F_NTZ_Nordic_NRF9160_SES/Source/reg_tests.h35
-rw-r--r--FreeRTOS/Demo/CORTEX_MPU_M33F_Nordic_NRF9160_SES/FreeRTOSDemo.emProject194
-rw-r--r--FreeRTOS/Demo/CORTEX_MPU_M33F_Nordic_NRF9160_SES/NonSecure/main_ns.c3
-rw-r--r--FreeRTOS/Demo/CORTEX_MPU_M33F_Nordic_NRF9160_SES/NonSecure/reg_tests.c498
-rw-r--r--FreeRTOS/Demo/CORTEX_MPU_M33F_Nordic_NRF9160_SES/NonSecure/reg_tests.h35
8 files changed, 1072 insertions, 132 deletions
diff --git a/FreeRTOS/Demo/CORTEX_MPU_M33F_NTZ_Nordic_NRF9160_SES/FreeRTOSDemo.emProject b/FreeRTOS/Demo/CORTEX_MPU_M33F_NTZ_Nordic_NRF9160_SES/FreeRTOSDemo.emProject
index a8bda3674..0eae156f3 100644
--- a/FreeRTOS/Demo/CORTEX_MPU_M33F_NTZ_Nordic_NRF9160_SES/FreeRTOSDemo.emProject
+++ b/FreeRTOS/Demo/CORTEX_MPU_M33F_NTZ_Nordic_NRF9160_SES/FreeRTOSDemo.emProject
@@ -1,5 +1,10 @@
<!DOCTYPE CrossStudio_Project_File>
<solution Name="FreeRTOSDemo" target="8" version="2">
+ <configuration
+ Name="Debug"
+ c_preprocessor_definitions="DEBUG"
+ gcc_debugging_level="Level 3"
+ gcc_optimization_level="None" />
<project Name="FreeRTOSDemo">
<configuration
LIBRARY_IO_TYPE="RTT"
@@ -24,7 +29,7 @@
build_intermediate_directory="Output/$(Configuration)/Objects/"
build_output_directory="Output/$(Configuration)/"
c_preprocessor_definitions="ARM_MATH_ARMV8MML;NRF9160_XXAA;__NRF_FAMILY;__SUPPORT_RESET_HALT_AFTER_BTL=0;INITIALIZE_USER_SECTIONS;__ARMCC_VERSION"
- c_user_include_directories="$(ProjectDir)/Nordic_Code/CMSIS_5/CMSIS/Core/Include;$(ProjectDir)/Nordic_Code/nRF/Device/Include;$(ProjectDir)/Config;../../Source/include;../../Source/portable/GCC/ARM_CM33_NTZ/non_secure;../Common/ARMv8M/mpu_demo"
+ c_user_include_directories="$(ProjectDir)/Nordic_Code/CMSIS_5/CMSIS/Core/Include;$(ProjectDir)/Nordic_Code/nRF/Device/Include;$(ProjectDir)/Config;../../Source/include;../../Source/portable/GCC/ARM_CM33_NTZ/non_secure;../Common/ARMv8M/mpu_demo;../Common/ARMv8M/reg_tests/GCC/ARM_CM33/non_secure"
debug_register_definition_file="$(ProjectDir)/Nordic_Code/nRF/XML/nrf9160_Registers.xml"
debug_stack_pointer_start="__stack_end__"
debug_start_from_entry_point_symbol="No"
@@ -39,39 +44,21 @@
project_type="Executable"
target_reset_script="Reset();"
target_trace_initialize_script="EnableTrace(&quot;$(TraceInterfaceType)&quot;)" />
- <folder Name="Nordic_Code">
- <folder Name="CMSIS Files">
- <file file_name="Nordic_Code/nRF/Device/Source/system_nrf9160.c">
- <configuration
- Name="Common"
- default_code_section=".init"
- default_const_section=".init_rodata" />
- </file>
- <file file_name="Nordic_Code/nRF/Device/Include/nrf.h" />
- </folder>
- <folder Name="Script Files">
- <file file_name="Nordic_Code/nRF/Scripts/nRF_Target.js">
- <configuration Name="Common" file_type="Reset Script" />
- </file>
- </folder>
- <folder Name="System Files">
- <file file_name="Nordic_Code/nRF/Source/nRF_Startup.s" />
- <file file_name="Nordic_Code/nRF/Source/nrf9160_Vectors.s">
- <configuration Name="Common" file_type="Assembly" />
- </file>
- <file file_name="Nordic_Code/nRF/Source/thumb_crt0.s" />
- </folder>
+ <folder Name="Config">
+ <file file_name="Config/FreeRTOSConfig.h" />
</folder>
- <folder Name="User">
- <configuration Name="Common" filter="c;cpp;cxx;cc;h;s;asm;inc" />
- <file file_name="Source/main.c" />
+ <folder Name="Demos">
+ <file file_name="../Common/ARMv8M/mpu_demo/mpu_demo.c" />
+ <file file_name="../Common/ARMv8M/mpu_demo/mpu_demo.h" />
+ <file file_name="../Common/ARMv8M/reg_tests/GCC/ARM_CM33/non_secure/reg_test_asm.c" />
+ <file file_name="../Common/ARMv8M/reg_tests/GCC/ARM_CM33/non_secure/reg_test_asm.h" />
</folder>
<folder Name="FreeRTOS">
<folder Name="include">
+ <file file_name="../../Source/include/FreeRTOS.h" />
<file file_name="../../Source/include/atomic.h" />
<file file_name="../../Source/include/deprecated_definitions.h" />
<file file_name="../../Source/include/event_groups.h" />
- <file file_name="../../Source/include/FreeRTOS.h" />
<file file_name="../../Source/include/list.h" />
<file file_name="../../Source/include/message_buffer.h" />
<file file_name="../../Source/include/mpu_prototypes.h" />
@@ -92,10 +79,11 @@
</folder>
<folder Name="GCC">
<folder Name="ARM_CM33_NTZ">
+ <file file_name="../../Source/portable/GCC/ARM_CM33_NTZ/non_secure/port.c" />
<file file_name="../../Source/portable/GCC/ARM_CM33_NTZ/non_secure/portasm.c" />
<file file_name="../../Source/portable/GCC/ARM_CM33_NTZ/non_secure/portasm.h" />
- <file file_name="../../Source/portable/GCC/ARM_CM33_NTZ/non_secure/port.c" />
<file file_name="../../Source/portable/GCC/ARM_CM33_NTZ/non_secure/portmacro.h" />
+ <file file_name="../../Source/portable/GCC/ARM_CM33_NTZ/non_secure/portmacrocommon.h" />
</folder>
</folder>
<folder Name="MemMang">
@@ -109,17 +97,34 @@
<file file_name="../../Source/tasks.c" />
<file file_name="../../Source/timers.c" />
</folder>
- <folder Name="Config">
- <file file_name="Config/FreeRTOSConfig.h" />
+ <folder Name="Nordic_Code">
+ <folder Name="CMSIS Files">
+ <file file_name="Nordic_Code/nRF/Device/Include/nrf.h" />
+ <file file_name="Nordic_Code/nRF/Device/Source/system_nrf9160.c">
+ <configuration
+ Name="Common"
+ default_code_section=".init"
+ default_const_section=".init_rodata" />
+ </file>
+ </folder>
+ <folder Name="Script Files">
+ <file file_name="Nordic_Code/nRF/Scripts/nRF_Target.js">
+ <configuration Name="Common" file_type="Reset Script" />
+ </file>
+ </folder>
+ <folder Name="System Files">
+ <file file_name="Nordic_Code/nRF/Source/nRF_Startup.s" />
+ <file file_name="Nordic_Code/nRF/Source/nrf9160_Vectors.s">
+ <configuration Name="Common" file_type="Assembly" />
+ </file>
+ <file file_name="Nordic_Code/nRF/Source/thumb_crt0.s" />
+ </folder>
</folder>
- <folder Name="Demos">
- <file file_name="../Common/ARMv8M/mpu_demo/mpu_demo.c" />
- <file file_name="../Common/ARMv8M/mpu_demo/mpu_demo.h" />
+ <folder Name="User">
+ <configuration Name="Common" filter="c;cpp;cxx;cc;h;s;asm;inc" />
+ <file file_name="Source/main.c" />
+ <file file_name="Source/reg_tests.c" />
+ <file file_name="Source/reg_tests.h" />
</folder>
</project>
- <configuration
- Name="Debug"
- c_preprocessor_definitions="DEBUG"
- gcc_debugging_level="Level 3"
- gcc_optimization_level="None" />
</solution>
diff --git a/FreeRTOS/Demo/CORTEX_MPU_M33F_NTZ_Nordic_NRF9160_SES/Source/main.c b/FreeRTOS/Demo/CORTEX_MPU_M33F_NTZ_Nordic_NRF9160_SES/Source/main.c
index 2398e1a6b..98646f1cf 100644
--- a/FreeRTOS/Demo/CORTEX_MPU_M33F_NTZ_Nordic_NRF9160_SES/Source/main.c
+++ b/FreeRTOS/Demo/CORTEX_MPU_M33F_NTZ_Nordic_NRF9160_SES/Source/main.c
@@ -36,6 +36,7 @@
/* Demo includes. */
#include "mpu_demo.h"
+#include "reg_tests.h"
/*-----------------------------------------------------------*/
/* Initialize the MPU symbols needed by the port code. */
@@ -79,6 +80,9 @@ int main( void )
/* Create tasks for the MPU Demo. */
vStartMPUDemo();
+ /* Create tasks for register tests. */
+ vStartRegTests();
+
/* Start scheduler. */
vTaskStartScheduler();
diff --git a/FreeRTOS/Demo/CORTEX_MPU_M33F_NTZ_Nordic_NRF9160_SES/Source/reg_tests.c b/FreeRTOS/Demo/CORTEX_MPU_M33F_NTZ_Nordic_NRF9160_SES/Source/reg_tests.c
new file mode 100644
index 000000000..be47547c0
--- /dev/null
+++ b/FreeRTOS/Demo/CORTEX_MPU_M33F_NTZ_Nordic_NRF9160_SES/Source/reg_tests.c
@@ -0,0 +1,354 @@
+/*
+ * FreeRTOS V202212.00
+ * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * https://www.FreeRTOS.org
+ * https://github.com/FreeRTOS
+ *
+ */
+
+/* Standard includes. */
+#include <stdio.h>
+
+/* Scheduler includes. */
+#include "FreeRTOS.h"
+#include "task.h"
+
+/* Reg test includes. */
+#include "reg_tests.h"
+#include "reg_test_asm.h"
+
+/*
+ * Functions that implement reg test tasks.
+ */
+static void prvRegTest1_Task( void * pvParameters );
+static void prvRegTest2_Task( void * pvParameters );
+static void prvRegTest3_Task( void * pvParameters );
+static void prvRegTest4_Task( void * pvParameters );
+
+/*
+ * Check task periodically checks that reg tests tasks
+ * are running fine.
+ */
+static void prvCheckTask( void * pvParameters );
+/*-----------------------------------------------------------*/
+
+/*
+ * Priority of the check task.
+ */
+#define CHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
+
+/*
+ * Frequency of check task.
+ */
+#define NO_ERROR_CHECK_TASK_PERIOD ( pdMS_TO_TICKS( 5000UL ) )
+#define ERROR_CHECK_TASK_PERIOD ( pdMS_TO_TICKS( 200UL ) )
+
+/*
+ * Parameters passed to reg test tasks.
+ */
+#define REG_TEST_1_TASK_PARAMETER ( ( void * ) 0x12345678 )
+#define REG_TEST_2_TASK_PARAMETER ( ( void * ) 0x87654321 )
+#define REG_TEST_3_TASK_PARAMETER ( ( void * ) 0x12348765 )
+#define REG_TEST_4_TASK_PARAMETER ( ( void * ) 0x43215678 )
+/*-----------------------------------------------------------*/
+
+/*
+ * The following variables are used to communicate the status of the register
+ * test tasks to the check task. If the variables keep incrementing, then the
+ * register test tasks have not discovered any errors. If a variable stops
+ * incrementing, then an error has been found.
+ */
+volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;
+volatile unsigned long ulRegTest3LoopCounter = 0UL, ulRegTest4LoopCounter = 0UL;
+
+/**
+ * Counter to keep a count of how may times the check task loop has detected
+ * error.
+ */
+volatile unsigned long ulCheckTaskLoops = 0UL;
+/*-----------------------------------------------------------*/
+
+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 xRegTest3TaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) );
+static StackType_t xRegTest4TaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) );
+static StackType_t xCheckTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) );
+
+TaskParameters_t xRegTest1TaskParameters =
+{
+ .pvTaskCode = prvRegTest1_Task,
+ .pcName = "RegTest1",
+ .usStackDepth = configMINIMAL_STACK_SIZE,
+ .pvParameters = REG_TEST_1_TASK_PARAMETER,
+ .uxPriority = tskIDLE_PRIORITY | portPRIVILEGE_BIT,
+ .puxStackBuffer = xRegTest1TaskStack,
+ .xRegions = {
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 }
+ }
+};
+TaskParameters_t xRegTest2TaskParameters =
+{
+ .pvTaskCode = prvRegTest2_Task,
+ .pcName = "RegTest2",
+ .usStackDepth = configMINIMAL_STACK_SIZE,
+ .pvParameters = REG_TEST_2_TASK_PARAMETER,
+ .uxPriority = tskIDLE_PRIORITY | portPRIVILEGE_BIT,
+ .puxStackBuffer = xRegTest2TaskStack,
+ .xRegions = {
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 }
+ }
+};
+TaskParameters_t xRegTest3TaskParameters =
+{
+ .pvTaskCode = prvRegTest3_Task,
+ .pcName = "RegTest3",
+ .usStackDepth = configMINIMAL_STACK_SIZE,
+ .pvParameters = REG_TEST_3_TASK_PARAMETER,
+ .uxPriority = tskIDLE_PRIORITY | portPRIVILEGE_BIT,
+ .puxStackBuffer = xRegTest3TaskStack,
+ .xRegions = {
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 }
+ }
+};
+TaskParameters_t xRegTest4TaskParameters =
+{
+ .pvTaskCode = prvRegTest4_Task,
+ .pcName = "RegTest4",
+ .usStackDepth = configMINIMAL_STACK_SIZE,
+ .pvParameters = REG_TEST_4_TASK_PARAMETER,
+ .uxPriority = tskIDLE_PRIORITY | portPRIVILEGE_BIT,
+ .puxStackBuffer = xRegTest4TaskStack,
+ .xRegions = {
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 }
+ }
+};
+TaskParameters_t xCheckTaskParameters =
+{
+ .pvTaskCode = prvCheckTask,
+ .pcName = "Check",
+ .usStackDepth = configMINIMAL_STACK_SIZE,
+ .pvParameters = NULL,
+ .uxPriority = ( CHECK_TASK_PRIORITY | portPRIVILEGE_BIT ),
+ .puxStackBuffer = xCheckTaskStack,
+ .xRegions = {
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 }
+ }
+};
+
+ xTaskCreateRestricted( &( xRegTest1TaskParameters ), NULL );
+ xTaskCreateRestricted( &( xRegTest2TaskParameters ), NULL );
+ xTaskCreateRestricted( &( xRegTest3TaskParameters ), NULL );
+ xTaskCreateRestricted( &( xRegTest4TaskParameters ), NULL );
+ xTaskCreateRestricted( &( xCheckTaskParameters ), NULL );
+}
+/*-----------------------------------------------------------*/
+
+static void prvRegTest1_Task( void * pvParameters )
+{
+ /* Although the reg tests are written in assembly, its entry
+ * point is written in C for convenience of checking that the
+ * task parameter is being passed in correctly. */
+ if( pvParameters == REG_TEST_1_TASK_PARAMETER )
+ {
+ /* Start the part of the test that is written in assembler. */
+ vRegTest1Asm_NonSecure();
+ }
+
+ /* The following line will only execute if the task parameter
+ * is found to be incorrect. The check task will detect that
+ * the reg test loop counter is not being incremented and flag
+ * an error. */
+ vTaskDelete( NULL );
+}
+/*-----------------------------------------------------------*/
+
+static void prvRegTest2_Task( void * pvParameters )
+{
+ /* Although the reg tests are written in assembly, its entry
+ * point is written in C for convenience of checking that the
+ * task parameter is being passed in correctly. */
+ if( pvParameters == REG_TEST_2_TASK_PARAMETER )
+ {
+ /* Start the part of the test that is written in assembler. */
+ vRegTest2Asm_NonSecure();
+ }
+
+ /* The following line will only execute if the task parameter
+ * is found to be incorrect. The check task will detect that
+ * the reg test loop counter is not being incremented and flag
+ * an error. */
+ vTaskDelete( NULL );
+}
+/*-----------------------------------------------------------*/
+
+static void prvRegTest3_Task( void * pvParameters )
+{
+ /* Although the reg tests are written in assembly, its entry
+ * point is written in C for convenience of checking that the
+ * task parameter is being passed in correctly. */
+ if( pvParameters == REG_TEST_3_TASK_PARAMETER )
+ {
+ /* Start the part of the test that is written in assembler. */
+ vRegTest3Asm_NonSecure();
+ }
+
+ /* The following line will only execute if the task parameter
+ * is found to be incorrect. The check task will detect that
+ * the reg test loop counter is not being incremented and flag
+ * an error. */
+ vTaskDelete( NULL );
+}
+/*-----------------------------------------------------------*/
+
+static void prvRegTest4_Task( void * pvParameters )
+{
+ /* Although the reg tests are written in assembly, its entry
+ * point is written in C for convenience of checking that the
+ * task parameter is being passed in correctly. */
+ if( pvParameters == REG_TEST_4_TASK_PARAMETER )
+ {
+ /* Start the part of the test that is written in assembler. */
+ vRegTest4Asm_NonSecure();
+ }
+
+ /* The following line will only execute if the task parameter
+ * is found to be incorrect. The check task will detect that
+ * the reg test loop counter is not being incremented and flag
+ * an error. */
+ vTaskDelete( NULL );
+}
+/*-----------------------------------------------------------*/
+
+static void prvCheckTask( void * pvParameters )
+{
+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 ulLastRegTest3Value = 0, ulLastRegTest4Value = 0;
+
+ /* Just to stop compiler warnings. */
+ ( void ) pvParameters;
+
+ /* Initialize xLastExecutionTime so the first call to vTaskDelayUntil()
+ * works correctly. */
+ xLastExecutionTime = xTaskGetTickCount();
+
+ /* Cycle for ever, delaying then checking all the other tasks are still
+ * operating without error. The onboard LED is toggled on each iteration.
+ * If an error is detected then the delay period is decreased from
+ * mainNO_ERROR_CHECK_TASK_PERIOD to mainERROR_CHECK_TASK_PERIOD. This has
+ * the effect of increasing the rate at which the onboard LED toggles, and
+ * in so doing gives visual feedback of the system status. */
+ for( ;; )
+ {
+ /* Delay until it is time to execute again. */
+ vTaskDelayUntil( &xLastExecutionTime, xDelayPeriod );
+
+ /* Check that the register test 1 task is still running. */
+ if( ulLastRegTest1Value == ulRegTest1LoopCounter )
+ {
+ ulErrorFound |= 1UL << 0UL;
+ }
+ ulLastRegTest1Value = ulRegTest1LoopCounter;
+
+ /* Check that the register test 2 task is still running. */
+ if( ulLastRegTest2Value == ulRegTest2LoopCounter )
+ {
+ ulErrorFound |= 1UL << 1UL;
+ }
+ ulLastRegTest2Value = ulRegTest2LoopCounter;
+
+ /* Check that the register test 3 task is still running. */
+ if( ulLastRegTest3Value == ulRegTest3LoopCounter )
+ {
+ ulErrorFound |= 1UL << 2UL;
+ }
+ ulLastRegTest3Value = ulRegTest3LoopCounter;
+
+ /* Check that the register test 4 task is still running. */
+ if( ulLastRegTest4Value == ulRegTest4LoopCounter )
+ {
+ ulErrorFound |= 1UL << 3UL;
+ }
+ ulLastRegTest4Value = ulRegTest4LoopCounter;
+
+ if( ulErrorFound != pdFALSE )
+ {
+ /* An error has been detected in one of the tasks. */
+ xDelayPeriod = ERROR_CHECK_TASK_PERIOD;
+
+ printf( "ERROR detected!\r\n" );
+
+ /* Increment error detection count. */
+ ulCheckTaskLoops++;
+ }
+ else
+ {
+ printf( "No errors.\r\n" );
+ }
+ }
+}
+/*-----------------------------------------------------------*/
diff --git a/FreeRTOS/Demo/CORTEX_MPU_M33F_NTZ_Nordic_NRF9160_SES/Source/reg_tests.h b/FreeRTOS/Demo/CORTEX_MPU_M33F_NTZ_Nordic_NRF9160_SES/Source/reg_tests.h
new file mode 100644
index 000000000..0837aad72
--- /dev/null
+++ b/FreeRTOS/Demo/CORTEX_MPU_M33F_NTZ_Nordic_NRF9160_SES/Source/reg_tests.h
@@ -0,0 +1,35 @@
+/*
+ * FreeRTOS V202212.00
+ * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * https://www.FreeRTOS.org
+ * https://github.com/FreeRTOS
+ *
+ */
+
+#ifndef REG_TESTS_H
+#define REG_TESTS_H
+
+/**
+ * @brief Creates all the tasks for reg tests.
+ */
+void vStartRegTests( void );
+
+#endif /* REG_TESTS_H */
diff --git a/FreeRTOS/Demo/CORTEX_MPU_M33F_Nordic_NRF9160_SES/FreeRTOSDemo.emProject b/FreeRTOS/Demo/CORTEX_MPU_M33F_Nordic_NRF9160_SES/FreeRTOSDemo.emProject
index b311d4b23..3185248ac 100644
--- a/FreeRTOS/Demo/CORTEX_MPU_M33F_Nordic_NRF9160_SES/FreeRTOSDemo.emProject
+++ b/FreeRTOS/Demo/CORTEX_MPU_M33F_Nordic_NRF9160_SES/FreeRTOSDemo.emProject
@@ -1,6 +1,11 @@
<!DOCTYPE CrossStudio_Project_File>
<solution Name="FreeRTOSDemo" target="8" version="2">
- <project Name="FreeRTOSDemo_s">
+ <configuration
+ Name="Debug"
+ c_preprocessor_definitions="DEBUG"
+ gcc_debugging_level="Level 3"
+ gcc_optimization_level="None" />
+ <project Name="FreeRTOSDemo_ns">
<configuration
LIBRARY_IO_TYPE="RTT"
Name="Common"
@@ -11,7 +16,6 @@
arm_endian="Little"
arm_fp_abi="Hard"
arm_fpu_type="FPv5-SP-D16"
- arm_linker_cmse_import_library_file_name="$(OutDir)/FreeRTOSDemo_s_cmse.lib"
arm_linker_heap_size="0"
arm_linker_process_stack_size="0"
arm_linker_stack_size="2048"
@@ -24,31 +28,85 @@
arm_v8M_has_cmse="Yes"
build_intermediate_directory="Output/$(ProjectName)/$(Configuration)/Objects/"
build_output_directory="Output/$(ProjectName)/$(Configuration)"
- c_preprocessor_definitions="ARM_MATH_ARMV8MML;NRF9160_XXAA;__NRF_FAMILY;__SUPPORT_RESET_HALT_AFTER_BTL=0;__ARMCC_VERSION"
- c_user_include_directories="$(ProjectDir)/Nordic_Code/CMSIS_5/CMSIS/Core/Include;$(ProjectDir)/Nordic_Code/nRF/Device/Include;$(ProjectDir)/Config;../../Source/portable/GCC/ARM_CM33/secure;../Common/ARMv8M/tz_demo"
+ c_preprocessor_definitions="ARM_MATH_ARMV8MML;NRF9160_XXAA;__NRF_FAMILY;NRF_TRUSTZONE_NONSECURE;__SUPPORT_RESET_HALT_AFTER_BTL=0;INITIALIZE_USER_SECTIONS;__ARMCC_VERSION"
+ c_user_include_directories="$(ProjectDir)/Nordic_Code/CMSIS_5/CMSIS/Core/Include;$(ProjectDir)/Nordic_Code/nRF/Device/Include;$(ProjectDir)/Config;../../Source/include;../../Source/portable/GCC/ARM_CM33/secure;../../Source/portable/GCC/ARM_CM33/non_secure;../Common/ARMv8M/tz_demo;../Common/ARMv8M/mpu_demo;../Common/ARMv8M/reg_tests/GCC/ARM_CM33/secure;../Common/ARMv8M/reg_tests/GCC/ARM_CM33/non_secure"
debug_register_definition_file="$(ProjectDir)/Nordic_Code/nRF/XML/nrf9160_Registers.xml"
debug_stack_pointer_start="__stack_end__"
debug_start_from_entry_point_symbol="No"
debug_target_connection="J-Link"
gcc_entry_point="Reset_Handler"
link_linker_script_file=""
- linker_memory_map_file="$(ProjectDir)/Secure/FreeRTOSDemo_s_MemoryMap.xml"
+ linker_additional_files="$(OutDir)/../../FreeRTOSDemo_s/$(Configuration)/FreeRTOSDemo_s_cmse.lib"
+ linker_memory_map_file="$(ProjectDir)/NonSecure/FreeRTOSDemo_ns_MemoryMap.xml"
linker_output_format="bin"
- linker_section_placement_file="$(ProjectDir)/Secure/FreeRTOSDemo_s_Flash_Placement.xml"
+ linker_section_placement_file="$(ProjectDir)/NonSecure/FreeRTOSDemo_ns_Flash_Placement.xml"
macros="DeviceHeaderFile=$(PackagesDir)/nRF/Device/Include/nrf.h;DeviceLibraryIdentifier=ARMv8MMLlfsp;DeviceSystemFile=$(PackagesDir)/nRF/Device/Source/system_nrf9160.c;DeviceVectorsFile=$(PackagesDir)/nRF/Source/nrf9160_Vectors.s;DeviceFamily=nRF;Target=nRF9160_xxAA"
project_directory=""
project_type="Executable"
target_reset_script="Reset();"
target_trace_initialize_script="EnableTrace(&quot;$(TraceInterfaceType)&quot;)" />
+ <folder Name="Config">
+ <file file_name="Config/FreeRTOSConfig.h" />
+ </folder>
+ <folder Name="Demos">
+ <file file_name="../Common/ARMv8M/mpu_demo/mpu_demo.c" />
+ <file file_name="../Common/ARMv8M/mpu_demo/mpu_demo.h" />
+ <file file_name="../Common/ARMv8M/reg_tests/GCC/ARM_CM33/non_secure/reg_test_asm.c" />
+ <file file_name="../Common/ARMv8M/reg_tests/GCC/ARM_CM33/non_secure/reg_test_asm.h" />
+ <file file_name="../Common/ARMv8M/tz_demo/tz_demo.c" />
+ <file file_name="../Common/ARMv8M/tz_demo/tz_demo.h" />
+ </folder>
+ <folder Name="FreeRTOS">
+ <folder Name="include">
+ <file file_name="../../Source/include/FreeRTOS.h" />
+ <file file_name="../../Source/include/atomic.h" />
+ <file file_name="../../Source/include/deprecated_definitions.h" />
+ <file file_name="../../Source/include/event_groups.h" />
+ <file file_name="../../Source/include/list.h" />
+ <file file_name="../../Source/include/message_buffer.h" />
+ <file file_name="../../Source/include/mpu_prototypes.h" />
+ <file file_name="../../Source/include/mpu_wrappers.h" />
+ <file file_name="../../Source/include/portable.h" />
+ <file file_name="../../Source/include/projdefs.h" />
+ <file file_name="../../Source/include/queue.h" />
+ <file file_name="../../Source/include/semphr.h" />
+ <file file_name="../../Source/include/stack_macros.h" />
+ <file file_name="../../Source/include/stream_buffer.h" />
+ <file file_name="../../Source/include/task.h" />
+ <file file_name="../../Source/include/timers.h" />
+ </folder>
+ <folder Name="portable">
+ <folder Name="Common">
+ <file file_name="../../Source/portable/Common/mpu_wrappers.c" />
+ </folder>
+ <folder Name="GCC">
+ <folder Name="ARM_CM33">
+ <file file_name="../../Source/portable/GCC/ARM_CM33/non_secure/port.c" />
+ <file file_name="../../Source/portable/GCC/ARM_CM33/non_secure/portasm.c" />
+ <file file_name="../../Source/portable/GCC/ARM_CM33/non_secure/portasm.h" />
+ <file file_name="../../Source/portable/GCC/ARM_CM33/non_secure/portmacro.h" />
+ </folder>
+ </folder>
+ <folder Name="MemMang">
+ <file file_name="../../Source/portable/MemMang/heap_4.c" />
+ </folder>
+ </folder>
+ <file file_name="../../Source/event_groups.c" />
+ <file file_name="../../Source/list.c" />
+ <file file_name="../../Source/queue.c" />
+ <file file_name="../../Source/stream_buffer.c" />
+ <file file_name="../../Source/tasks.c" />
+ <file file_name="../../Source/timers.c" />
+ </folder>
<folder Name="Nordic_Code">
<folder Name="CMSIS Files">
+ <file file_name="Nordic_Code/nRF/Device/Include/nrf.h" />
<file file_name="Nordic_Code/nRF/Device/Source/system_nrf9160.c">
<configuration
Name="Common"
default_code_section=".init"
default_const_section=".init_rodata" />
</file>
- <file file_name="Nordic_Code/nRF/Device/Include/nrf.h" />
</folder>
<folder Name="Script Files">
<file file_name="Nordic_Code/nRF/Scripts/nRF_Target.js">
@@ -65,38 +123,12 @@
</folder>
<folder Name="User">
<configuration Name="Common" filter="c;cpp;cxx;cc;h;s;asm;inc" />
- <file file_name="Secure/main_s.c" />
- </folder>
- <folder Name="FreeRTOS">
- <folder Name="SecureContext">
- <file file_name="../../Source/portable/GCC/ARM_CM33/secure/secure_context.c" />
- <file file_name="../../Source/portable/GCC/ARM_CM33/secure/secure_context.h" />
- <file file_name="../../Source/portable/GCC/ARM_CM33/secure/secure_context_port.c" />
- <file file_name="../../Source/portable/GCC/ARM_CM33/secure/secure_port_macros.h" />
- </folder>
- <folder Name="SecureHeap">
- <file file_name="../../Source/portable/GCC/ARM_CM33/secure/secure_heap.c" />
- <file file_name="../../Source/portable/GCC/ARM_CM33/secure/secure_heap.h" />
- </folder>
- <folder Name="SecureInit">
- <file file_name="../../Source/portable/GCC/ARM_CM33/secure/secure_init.c" />
- <file file_name="../../Source/portable/GCC/ARM_CM33/secure/secure_init.h" />
- </folder>
- </folder>
- <folder Name="NSCFunctions">
- <file file_name="../Common/ARMv8M/tz_demo/nsc_functions.c" />
- <file file_name="../Common/ARMv8M/tz_demo/nsc_functions.h" />
- </folder>
- <folder Name="Config">
- <file file_name="Config/FreeRTOSConfig.h" />
+ <file file_name="NonSecure/main_ns.c" />
+ <file file_name="NonSecure/reg_tests.c" />
+ <file file_name="NonSecure/reg_tests.h" />
</folder>
</project>
- <configuration
- Name="Debug"
- c_preprocessor_definitions="DEBUG"
- gcc_debugging_level="Level 3"
- gcc_optimization_level="None" />
- <project Name="FreeRTOSDemo_ns">
+ <project Name="FreeRTOSDemo_s">
<configuration
LIBRARY_IO_TYPE="RTT"
Name="Common"
@@ -107,6 +139,7 @@
arm_endian="Little"
arm_fp_abi="Hard"
arm_fpu_type="FPv5-SP-D16"
+ arm_linker_cmse_import_library_file_name="$(OutDir)/FreeRTOSDemo_s_cmse.lib"
arm_linker_heap_size="0"
arm_linker_process_stack_size="0"
arm_linker_stack_size="2048"
@@ -119,23 +152,47 @@
arm_v8M_has_cmse="Yes"
build_intermediate_directory="Output/$(ProjectName)/$(Configuration)/Objects/"
build_output_directory="Output/$(ProjectName)/$(Configuration)"
- c_preprocessor_definitions="ARM_MATH_ARMV8MML;NRF9160_XXAA;__NRF_FAMILY;NRF_TRUSTZONE_NONSECURE;__SUPPORT_RESET_HALT_AFTER_BTL=0;INITIALIZE_USER_SECTIONS;__ARMCC_VERSION"
- c_user_include_directories="$(ProjectDir)/Nordic_Code/CMSIS_5/CMSIS/Core/Include;$(ProjectDir)/Nordic_Code/nRF/Device/Include;$(ProjectDir)/Config;../../Source/include;../../Source/portable/GCC/ARM_CM33/secure;../../Source/portable/GCC/ARM_CM33/non_secure;../Common/ARMv8M/tz_demo;../Common/ARMv8M/mpu_demo"
+ c_preprocessor_definitions="ARM_MATH_ARMV8MML;NRF9160_XXAA;__NRF_FAMILY;__SUPPORT_RESET_HALT_AFTER_BTL=0;__ARMCC_VERSION"
+ c_user_include_directories="$(ProjectDir)/Nordic_Code/CMSIS_5/CMSIS/Core/Include;$(ProjectDir)/Nordic_Code/nRF/Device/Include;$(ProjectDir)/Config;../../Source/portable/GCC/ARM_CM33/secure;../Common/ARMv8M/tz_demo"
debug_register_definition_file="$(ProjectDir)/Nordic_Code/nRF/XML/nrf9160_Registers.xml"
debug_stack_pointer_start="__stack_end__"
debug_start_from_entry_point_symbol="No"
debug_target_connection="J-Link"
gcc_entry_point="Reset_Handler"
link_linker_script_file=""
- linker_additional_files="$(OutDir)/../../FreeRTOSDemo_s/$(Configuration)/FreeRTOSDemo_s_cmse.lib"
- linker_memory_map_file="$(ProjectDir)/NonSecure/FreeRTOSDemo_ns_MemoryMap.xml"
+ linker_memory_map_file="$(ProjectDir)/Secure/FreeRTOSDemo_s_MemoryMap.xml"
linker_output_format="bin"
- linker_section_placement_file="$(ProjectDir)/NonSecure/FreeRTOSDemo_ns_Flash_Placement.xml"
+ linker_section_placement_file="$(ProjectDir)/Secure/FreeRTOSDemo_s_Flash_Placement.xml"
macros="DeviceHeaderFile=$(PackagesDir)/nRF/Device/Include/nrf.h;DeviceLibraryIdentifier=ARMv8MMLlfsp;DeviceSystemFile=$(PackagesDir)/nRF/Device/Source/system_nrf9160.c;DeviceVectorsFile=$(PackagesDir)/nRF/Source/nrf9160_Vectors.s;DeviceFamily=nRF;Target=nRF9160_xxAA"
project_directory=""
project_type="Executable"
target_reset_script="Reset();"
target_trace_initialize_script="EnableTrace(&quot;$(TraceInterfaceType)&quot;)" />
+ <folder Name="Config">
+ <file file_name="Config/FreeRTOSConfig.h" />
+ </folder>
+ <folder Name="FreeRTOS">
+ <folder Name="SecureContext">
+ <file file_name="../../Source/portable/GCC/ARM_CM33/secure/secure_context.c" />
+ <file file_name="../../Source/portable/GCC/ARM_CM33/secure/secure_context.h" />
+ <file file_name="../../Source/portable/GCC/ARM_CM33/secure/secure_context_port.c" />
+ <file file_name="../../Source/portable/GCC/ARM_CM33/secure/secure_port_macros.h" />
+ </folder>
+ <folder Name="SecureHeap">
+ <file file_name="../../Source/portable/GCC/ARM_CM33/secure/secure_heap.c" />
+ <file file_name="../../Source/portable/GCC/ARM_CM33/secure/secure_heap.h" />
+ </folder>
+ <folder Name="SecureInit">
+ <file file_name="../../Source/portable/GCC/ARM_CM33/secure/secure_init.c" />
+ <file file_name="../../Source/portable/GCC/ARM_CM33/secure/secure_init.h" />
+ </folder>
+ </folder>
+ <folder Name="NSCFunctions">
+ <file file_name="../Common/ARMv8M/tz_demo/nsc_functions.c" />
+ <file file_name="../Common/ARMv8M/tz_demo/nsc_functions.h" />
+ <file file_name="../Common/ARMv8M/reg_tests/GCC/ARM_CM33/secure/secure_reg_test_asm.c" />
+ <file file_name="../Common/ARMv8M/reg_tests/GCC/ARM_CM33/secure/secure_reg_test_asm.h" />
+ </folder>
<folder Name="Nordic_Code">
<folder Name="CMSIS Files">
<file file_name="Nordic_Code/nRF/Device/Include/nrf.h" />
@@ -161,58 +218,7 @@
</folder>
<folder Name="User">
<configuration Name="Common" filter="c;cpp;cxx;cc;h;s;asm;inc" />
- <file file_name="NonSecure/main_ns.c" />
- </folder>
- <folder Name="FreeRTOS">
- <folder Name="include">
- <file file_name="../../Source/include/atomic.h" />
- <file file_name="../../Source/include/deprecated_definitions.h" />
- <file file_name="../../Source/include/event_groups.h" />
- <file file_name="../../Source/include/FreeRTOS.h" />
- <file file_name="../../Source/include/list.h" />
- <file file_name="../../Source/include/message_buffer.h" />
- <file file_name="../../Source/include/mpu_prototypes.h" />
- <file file_name="../../Source/include/mpu_wrappers.h" />
- <file file_name="../../Source/include/portable.h" />
- <file file_name="../../Source/include/projdefs.h" />
- <file file_name="../../Source/include/queue.h" />
- <file file_name="../../Source/include/semphr.h" />
- <file file_name="../../Source/include/stack_macros.h" />
- <file file_name="../../Source/include/stream_buffer.h" />
- <file file_name="../../Source/include/task.h" />
- <file file_name="../../Source/include/timers.h" />
- </folder>
- <folder Name="portable">
- <folder Name="GCC">
- <folder Name="ARM_CM33">
- <file file_name="../../Source/portable/GCC/ARM_CM33/non_secure/portasm.c" />
- <file file_name="../../Source/portable/GCC/ARM_CM33/non_secure/portasm.h" />
- <file file_name="../../Source/portable/GCC/ARM_CM33/non_secure/port.c" />
- <file file_name="../../Source/portable/GCC/ARM_CM33/non_secure/portmacro.h" />
- </folder>
- </folder>
- <folder Name="MemMang">
- <file file_name="../../Source/portable/MemMang/heap_4.c" />
- </folder>
- <folder Name="Common">
- <file file_name="../../Source/portable/Common/mpu_wrappers.c" />
- </folder>
- </folder>
- <file file_name="../../Source/event_groups.c" />
- <file file_name="../../Source/list.c" />
- <file file_name="../../Source/queue.c" />
- <file file_name="../../Source/stream_buffer.c" />
- <file file_name="../../Source/tasks.c" />
- <file file_name="../../Source/timers.c" />
- </folder>
- <folder Name="Demos">
- <file file_name="../Common/ARMv8M/mpu_demo/mpu_demo.c" />
- <file file_name="../Common/ARMv8M/mpu_demo/mpu_demo.h" />
- <file file_name="../Common/ARMv8M/tz_demo/tz_demo.c" />
- <file file_name="../Common/ARMv8M/tz_demo/tz_demo.h" />
- </folder>
- <folder Name="Config">
- <file file_name="Config/FreeRTOSConfig.h" />
+ <file file_name="Secure/main_s.c" />
</folder>
</project>
</solution>
diff --git a/FreeRTOS/Demo/CORTEX_MPU_M33F_Nordic_NRF9160_SES/NonSecure/main_ns.c b/FreeRTOS/Demo/CORTEX_MPU_M33F_Nordic_NRF9160_SES/NonSecure/main_ns.c
index f63971298..3d0ac1c2e 100644
--- a/FreeRTOS/Demo/CORTEX_MPU_M33F_Nordic_NRF9160_SES/NonSecure/main_ns.c
+++ b/FreeRTOS/Demo/CORTEX_MPU_M33F_Nordic_NRF9160_SES/NonSecure/main_ns.c
@@ -37,6 +37,7 @@
/* Demo includes. */
#include "tz_demo.h"
#include "mpu_demo.h"
+#include "reg_tests.h"
/*-----------------------------------------------------------*/
/* Initialize the MPU symbols needed by the port code. */
@@ -106,6 +107,8 @@ static void prvCreateTasks( void )
/* Create tasks for the TZ Demo. */
vStartTZDemo();
+ /* Create tasks for register tests. */
+ vStartRegTests();
}
/*-----------------------------------------------------------*/
diff --git a/FreeRTOS/Demo/CORTEX_MPU_M33F_Nordic_NRF9160_SES/NonSecure/reg_tests.c b/FreeRTOS/Demo/CORTEX_MPU_M33F_Nordic_NRF9160_SES/NonSecure/reg_tests.c
new file mode 100644
index 000000000..2c9fc5ca9
--- /dev/null
+++ b/FreeRTOS/Demo/CORTEX_MPU_M33F_Nordic_NRF9160_SES/NonSecure/reg_tests.c
@@ -0,0 +1,498 @@
+/*
+ * FreeRTOS V202212.00
+ * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * https://www.FreeRTOS.org
+ * https://github.com/FreeRTOS
+ *
+ */
+
+/* Standard includes. */
+#include <stdio.h>
+
+/* Scheduler includes. */
+#include "FreeRTOS.h"
+#include "task.h"
+
+/* Reg test includes. */
+#include "reg_tests.h"
+#include "reg_test_asm.h"
+#include "secure_reg_test_asm.h"
+
+/*
+ * Functions that implement reg test tasks.
+ */
+static void prvRegTest1_Task( void * pvParameters );
+static void prvRegTest2_Task( void * pvParameters );
+static void prvRegTest3_Task( void * pvParameters );
+static void prvRegTest4_Task( void * pvParameters );
+static void prvRegTest_Secure_Task( void * pvParameters );
+static void prvRegTest_NonSecureCallback_Task( void * pvParameters );
+/*
+ * Check task periodically checks that reg tests tasks
+ * are running fine.
+ */
+static void prvCheckTask( void * pvParameters );
+/*-----------------------------------------------------------*/
+
+/*
+ * Priority of the check task.
+ */
+#define CHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
+
+/*
+ * Frequency of check task.
+ */
+#define NO_ERROR_CHECK_TASK_PERIOD ( pdMS_TO_TICKS( 5000UL ) )
+#define ERROR_CHECK_TASK_PERIOD ( pdMS_TO_TICKS( 200UL ) )
+
+/*
+ * Parameters passed to reg test tasks.
+ */
+#define REG_TEST_1_TASK_PARAMETER ( ( void * ) 0x12345678 )
+#define REG_TEST_2_TASK_PARAMETER ( ( void * ) 0x87654321 )
+#define REG_TEST_3_TASK_PARAMETER ( ( void * ) 0x12348765 )
+#define REG_TEST_4_TASK_PARAMETER ( ( void * ) 0x43215678 )
+#define REG_TEST_SECURE_TASK_PARAMETER ( ( void * ) 0x1234ABCD )
+#define REG_TEST_NON_SECURE_CALLBACK_TASK_PARAMETER ( ( void * ) 0xABCD1234 )
+/*-----------------------------------------------------------*/
+
+/*
+ * The following variables are used to communicate the status of the register
+ * test tasks to the check task. If the variables keep incrementing, then the
+ * register test tasks have not discovered any errors. If a variable stops
+ * incrementing, then an error has been found.
+ */
+volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;
+volatile unsigned long ulRegTest3LoopCounter = 0UL, ulRegTest4LoopCounter = 0UL;
+volatile unsigned long ulRegTestSecureLoopCounter = 0UL;
+volatile unsigned long ulRegTestNonSecureCallbackLoopCounter = 0UL;
+
+/**
+ * Counter to keep a count of how may times the check task loop has detected
+ * error.
+ */
+volatile unsigned long ulCheckTaskLoops = 0UL;
+/*-----------------------------------------------------------*/
+
+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 xRegTest3TaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) );
+static StackType_t xRegTest4TaskStack[ 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 ) ) );
+
+TaskParameters_t xRegTest1TaskParameters =
+{
+ .pvTaskCode = prvRegTest1_Task,
+ .pcName = "RegTest1",
+ .usStackDepth = configMINIMAL_STACK_SIZE,
+ .pvParameters = REG_TEST_1_TASK_PARAMETER,
+ .uxPriority = tskIDLE_PRIORITY | portPRIVILEGE_BIT,
+ .puxStackBuffer = xRegTest1TaskStack,
+ .xRegions = {
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 }
+ }
+};
+TaskParameters_t xRegTest2TaskParameters =
+{
+ .pvTaskCode = prvRegTest2_Task,
+ .pcName = "RegTest2",
+ .usStackDepth = configMINIMAL_STACK_SIZE,
+ .pvParameters = REG_TEST_2_TASK_PARAMETER,
+ .uxPriority = tskIDLE_PRIORITY | portPRIVILEGE_BIT,
+ .puxStackBuffer = xRegTest2TaskStack,
+ .xRegions = {
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 }
+ }
+};
+TaskParameters_t xRegTest3TaskParameters =
+{
+ .pvTaskCode = prvRegTest3_Task,
+ .pcName = "RegTest3",
+ .usStackDepth = configMINIMAL_STACK_SIZE,
+ .pvParameters = REG_TEST_3_TASK_PARAMETER,
+ .uxPriority = tskIDLE_PRIORITY | portPRIVILEGE_BIT,
+ .puxStackBuffer = xRegTest3TaskStack,
+ .xRegions = {
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 }
+ }
+};
+TaskParameters_t xRegTest4TaskParameters =
+{
+ .pvTaskCode = prvRegTest4_Task,
+ .pcName = "RegTest4",
+ .usStackDepth = configMINIMAL_STACK_SIZE,
+ .pvParameters = REG_TEST_4_TASK_PARAMETER,
+ .uxPriority = tskIDLE_PRIORITY | portPRIVILEGE_BIT,
+ .puxStackBuffer = xRegTest4TaskStack,
+ .xRegions = {
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 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 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 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 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 }
+ }
+};
+
+TaskParameters_t xCheckTaskParameters =
+{
+ .pvTaskCode = prvCheckTask,
+ .pcName = "Check",
+ .usStackDepth = configMINIMAL_STACK_SIZE,
+ .pvParameters = NULL,
+ .uxPriority = ( CHECK_TASK_PRIORITY | portPRIVILEGE_BIT ),
+ .puxStackBuffer = xCheckTaskStack,
+ .xRegions = {
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 }
+ }
+};
+
+ xTaskCreateRestricted( &( xRegTest1TaskParameters ), NULL );
+ xTaskCreateRestricted( &( xRegTest2TaskParameters ), NULL );
+ xTaskCreateRestricted( &( xRegTest3TaskParameters ), NULL );
+ xTaskCreateRestricted( &( xRegTest4TaskParameters ), NULL );
+ xTaskCreateRestricted( &( xRegTestSecureTaskParameters ), NULL );
+ xTaskCreateRestricted( &( xRegTestNonSecureCallbackTaskParameters ), NULL );
+ xTaskCreateRestricted( &( xCheckTaskParameters ), NULL );
+}
+/*-----------------------------------------------------------*/
+
+static void prvRegTest1_Task( void * pvParameters )
+{
+ /* Although the reg tests are written in assembly, its entry
+ * point is written in C for convenience of checking that the
+ * task parameter is being passed in correctly. */
+ if( pvParameters == REG_TEST_1_TASK_PARAMETER )
+ {
+ /* Start the part of the test that is written in assembler. */
+ vRegTest1Asm_NonSecure();
+ }
+
+ /* The following line will only execute if the task parameter
+ * is found to be incorrect. The check task will detect that
+ * the reg test loop counter is not being incremented and flag
+ * an error. */
+ vTaskDelete( NULL );
+}
+/*-----------------------------------------------------------*/
+
+static void prvRegTest2_Task( void * pvParameters )
+{
+ /* Although the reg tests are written in assembly, its entry
+ * point is written in C for convenience of checking that the
+ * task parameter is being passed in correctly. */
+ if( pvParameters == REG_TEST_2_TASK_PARAMETER )
+ {
+ /* Start the part of the test that is written in assembler. */
+ vRegTest2Asm_NonSecure();
+ }
+
+ /* The following line will only execute if the task parameter
+ * is found to be incorrect. The check task will detect that
+ * the reg test loop counter is not being incremented and flag
+ * an error. */
+ vTaskDelete( NULL );
+}
+/*-----------------------------------------------------------*/
+
+static void prvRegTest3_Task( void * pvParameters )
+{
+ /* Although the reg tests are written in assembly, its entry
+ * point is written in C for convenience of checking that the
+ * task parameter is being passed in correctly. */
+ if( pvParameters == REG_TEST_3_TASK_PARAMETER )
+ {
+ /* Start the part of the test that is written in assembler. */
+ vRegTest3Asm_NonSecure();
+ }
+
+ /* The following line will only execute if the task parameter
+ * is found to be incorrect. The check task will detect that
+ * the reg test loop counter is not being incremented and flag
+ * an error. */
+ vTaskDelete( NULL );
+}
+/*-----------------------------------------------------------*/
+
+static void prvRegTest4_Task( void * pvParameters )
+{
+ /* Although the reg tests are written in assembly, its entry
+ * point is written in C for convenience of checking that the
+ * task parameter is being passed in correctly. */
+ if( pvParameters == REG_TEST_4_TASK_PARAMETER )
+ {
+ /* Start the part of the test that is written in assembler. */
+ vRegTest4Asm_NonSecure();
+ }
+
+ /* The following line will only execute if the task parameter
+ * is found to be incorrect. The check task will detect that
+ * the reg test loop counter is not being incremented and flag
+ * an error. */
+ vTaskDelete( NULL );
+}
+/*-----------------------------------------------------------*/
+
+static void prvRegTest_Secure_Task( void * pvParameters )
+{
+ /* This task is going to call secure side functions. */
+ portALLOCATE_SECURE_CONTEXT( configMINIMAL_SECURE_STACK_SIZE );
+
+ /* Although the reg tests are written in assembly, its entry
+ * point is written in C for convenience of checking that the
+ * task parameter is being passed in correctly. */
+ if( pvParameters == REG_TEST_SECURE_TASK_PARAMETER )
+ {
+ for( ;; )
+ {
+ /* Call the secure side function. This function populates registers
+ * with known values, then forces a context switch while on the
+ * secure side and then verifies that the contents of the registers
+ * are intact. This ensure that the context restoring mechanism
+ * works properly when the interrupted task was in the middle of a
+ * call to a secure side function. */
+ vRegTestAsm_Secure();
+
+ ulRegTestSecureLoopCounter += 1;
+ }
+ }
+
+ /* The following line will only execute if the task parameter
+ * is found to be incorrect. The check task will detect that
+ * the reg test loop counter is not being incremented and flag
+ * an error. */
+ vTaskDelete( NULL );
+}
+/*-----------------------------------------------------------*/
+
+static void prvRegTest_NonSecureCallback_Task( void * pvParameters )
+{
+ /* This task is going to call secure side functions. */
+ portALLOCATE_SECURE_CONTEXT( configMINIMAL_SECURE_STACK_SIZE );
+
+ /* Although the reg tests are written in assembly, its entry
+ * point is written in C for convenience of checking that the
+ * task parameter is being passed in correctly. */
+ if( pvParameters == REG_TEST_NON_SECURE_CALLBACK_TASK_PARAMETER )
+ {
+ for( ;; )
+ {
+ /* Call the secure side function. This function calls the provided
+ * non-secure callback which in-turn populates registers with
+ * known values, then forces a context switch while on the
+ * non-secure side and then verifies that the contents of the
+ * registers are intact. This ensure that the context restoring
+ * mechanism works properly when the interrupted task was in the
+ * middle of a non-secure callback from the secure side. */
+ vRegTest_NonSecureCallback( vRegTestAsm_NonSecureCallback );
+
+ ulRegTestNonSecureCallbackLoopCounter += 1;
+ }
+ }
+
+ /* The following line will only execute if the task parameter
+ * is found to be incorrect. The check task will detect that
+ * the reg test loop counter is not being incremented and flag
+ * an error. */
+ vTaskDelete( NULL );
+}
+/*-----------------------------------------------------------*/
+
+static void prvCheckTask( void * pvParameters )
+{
+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 ulLastRegTest3Value = 0, ulLastRegTest4Value = 0;
+static unsigned long ulLastRegTestSecureValue = 0, ulLastRegTestNonSecureCallbackValue = 0;
+
+ /* Just to stop compiler warnings. */
+ ( void ) pvParameters;
+
+ /* Initialize xLastExecutionTime so the first call to vTaskDelayUntil()
+ * works correctly. */
+ xLastExecutionTime = xTaskGetTickCount();
+
+ /* Cycle for ever, delaying then checking all the other tasks are still
+ * operating without error. The onboard LED is toggled on each iteration.
+ * If an error is detected then the delay period is decreased from
+ * mainNO_ERROR_CHECK_TASK_PERIOD to mainERROR_CHECK_TASK_PERIOD. This has
+ * the effect of increasing the rate at which the onboard LED toggles, and
+ * in so doing gives visual feedback of the system status. */
+ for( ;; )
+ {
+ /* Delay until it is time to execute again. */
+ vTaskDelayUntil( &xLastExecutionTime, xDelayPeriod );
+
+ /* Check that the register test 1 task is still running. */
+ if( ulLastRegTest1Value == ulRegTest1LoopCounter )
+ {
+ ulErrorFound |= 1UL << 0UL;
+ }
+ ulLastRegTest1Value = ulRegTest1LoopCounter;
+
+ /* Check that the register test 2 task is still running. */
+ if( ulLastRegTest2Value == ulRegTest2LoopCounter )
+ {
+ ulErrorFound |= 1UL << 1UL;
+ }
+ ulLastRegTest2Value = ulRegTest2LoopCounter;
+
+ /* Check that the register test 3 task is still running. */
+ if( ulLastRegTest3Value == ulRegTest3LoopCounter )
+ {
+ ulErrorFound |= 1UL << 2UL;
+ }
+ ulLastRegTest3Value = ulRegTest3LoopCounter;
+
+ /* Check that the register test 4 task is still running. */
+ if( ulLastRegTest4Value == ulRegTest4LoopCounter )
+ {
+ ulErrorFound |= 1UL << 3UL;
+ }
+ ulLastRegTest4Value = ulRegTest4LoopCounter;
+
+ /* Check that the register test secure task is still running. */
+ if( ulLastRegTestSecureValue == ulRegTestSecureLoopCounter )
+ {
+ ulErrorFound |= 1UL << 4UL;
+ }
+ ulLastRegTestSecureValue = ulRegTestSecureLoopCounter;
+
+ /* Check that the register test non-secure callback task is
+ * still running. */
+ if( ulLastRegTestNonSecureCallbackValue == ulRegTestNonSecureCallbackLoopCounter )
+ {
+ ulErrorFound |= 1UL << 5UL;
+ }
+ ulLastRegTestNonSecureCallbackValue = ulRegTestNonSecureCallbackLoopCounter;
+
+ if( ulErrorFound != pdFALSE )
+ {
+ /* An error has been detected in one of the tasks. */
+ xDelayPeriod = ERROR_CHECK_TASK_PERIOD;
+
+ printf( "ERROR detected!\r\n" );
+
+ /* Increment error detection count. */
+ ulCheckTaskLoops++;
+ }
+ else
+ {
+ printf( "No errors.\r\n" );
+ }
+ }
+}
+/*-----------------------------------------------------------*/
diff --git a/FreeRTOS/Demo/CORTEX_MPU_M33F_Nordic_NRF9160_SES/NonSecure/reg_tests.h b/FreeRTOS/Demo/CORTEX_MPU_M33F_Nordic_NRF9160_SES/NonSecure/reg_tests.h
new file mode 100644
index 000000000..0837aad72
--- /dev/null
+++ b/FreeRTOS/Demo/CORTEX_MPU_M33F_Nordic_NRF9160_SES/NonSecure/reg_tests.h
@@ -0,0 +1,35 @@
+/*
+ * FreeRTOS V202212.00
+ * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * https://www.FreeRTOS.org
+ * https://github.com/FreeRTOS
+ *
+ */
+
+#ifndef REG_TESTS_H
+#define REG_TESTS_H
+
+/**
+ * @brief Creates all the tasks for reg tests.
+ */
+void vStartRegTests( void );
+
+#endif /* REG_TESTS_H */