]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_MPU_M33F_NXP_LPC55S69_MCUXpresso/Projects/MCUXpresso/NonSecure/main_ns.c
Ensure that fault handlers are declared naked.
[freertos] / FreeRTOS / Demo / CORTEX_MPU_M33F_NXP_LPC55S69_MCUXpresso / Projects / MCUXpresso / NonSecure / main_ns.c
1 /*\r
2  * FreeRTOS Kernel V10.2.0\r
3  * Copyright (C) 2019 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /* FreeRTOS include. */\r
29 #include "FreeRTOS.h"\r
30 #include "task.h"\r
31 \r
32 /* Device includes. */\r
33 #include "fsl_device_registers.h"\r
34 #include "fsl_debug_console.h"\r
35 #include "pin_mux.h"\r
36 #include "board.h"\r
37 #include "clock_config.h"\r
38 \r
39 /* Demo includes. */\r
40 #include "tz_demo.h"\r
41 #include "mpu_demo.h"\r
42 /*-----------------------------------------------------------*/\r
43 \r
44 /**\r
45  * @brief Create all demo tasks.\r
46  */\r
47 static void prvCreateTasks( void );\r
48 \r
49 /**\r
50  * @brief Application-specific implementation of the SystemInit() weak\r
51  * function.\r
52  */\r
53 void SystemInit( void );\r
54 \r
55 /**\r
56  * @brief The mem fault handler.\r
57  *\r
58  * It calls a function called vHandleMemoryFault.\r
59  */\r
60 void MemManage_Handler( void ) __attribute__ ( ( naked ) );\r
61 /*-----------------------------------------------------------*/\r
62 \r
63 static void prvCreateTasks( void )\r
64 {\r
65         /* Create tasks for the MPU Demo. */\r
66         vStartMPUDemo();\r
67 \r
68         /* Create tasks for the TZ Demo. */\r
69         vStartTZDemo();\r
70 \r
71 }\r
72 /*-----------------------------------------------------------*/\r
73 \r
74 void SystemInit( void )\r
75 {\r
76         /* Nothing needs to be initialized for Non-Secure project. */\r
77 }\r
78 /*-----------------------------------------------------------*/\r
79 \r
80 /* Stack overflow hook. */\r
81 void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName )\r
82 {\r
83         /* Force an assert. */\r
84         configASSERT( pcTaskName == 0 );\r
85 }\r
86 /*-----------------------------------------------------------*/\r
87 \r
88 /* Non-Secure main. */\r
89 int main( void )\r
90 {\r
91         /* Create tasks. */\r
92         prvCreateTasks();\r
93 \r
94         /* Start scheduler. */\r
95         vTaskStartScheduler();\r
96 \r
97         /* Should not reach here as the scheduler is already started. */\r
98         for( ; ; )\r
99         {\r
100         }\r
101 }\r
102 /*-----------------------------------------------------------*/\r
103 \r
104 /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an\r
105  * implementation of vApplicationGetIdleTaskMemory() to provide the memory that\r
106  * is used by the Idle task. */\r
107 void vApplicationGetIdleTaskMemory(     StaticTask_t ** ppxIdleTaskTCBBuffer,\r
108                                                                         StackType_t ** ppxIdleTaskStackBuffer,\r
109                                                                         uint32_t * pulIdleTaskStackSize )\r
110 {\r
111         /* If the buffers to be provided to the Idle task are declared inside this\r
112          * function then they must be declared static - otherwise they will be\r
113          * allocated on the stack and so not exists after this function exits. */\r
114         static StaticTask_t xIdleTaskTCB;\r
115         static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) );\r
116 \r
117         /* Pass out a pointer to the StaticTask_t structure in which the Idle\r
118          * task's state will be stored. */\r
119         *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;\r
120 \r
121         /* Pass out the array that will be used as the Idle task's stack. */\r
122         *ppxIdleTaskStackBuffer = uxIdleTaskStack;\r
123 \r
124         /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.\r
125          * Note that, as the array is necessarily of type StackType_t,\r
126          * configMINIMAL_STACK_SIZE is specified in words, not bytes. */\r
127         *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;\r
128 }\r
129 /*-----------------------------------------------------------*/\r
130 \r
131 /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the\r
132  * application must provide an implementation of vApplicationGetTimerTaskMemory()\r
133  * to provide the memory that is used by the Timer service task. */\r
134 void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,\r
135                                                                          StackType_t ** ppxTimerTaskStackBuffer,\r
136                                                                          uint32_t * pulTimerTaskStackSize )\r
137 {\r
138         /* If the buffers to be provided to the Timer task are declared inside this\r
139          * function then they must be declared static - otherwise they will be\r
140          * allocated on the stack and so not exists after this function exits. */\r
141         static StaticTask_t xTimerTaskTCB;\r
142         static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ] __attribute__( ( aligned( 32 ) ) );\r
143 \r
144         /* Pass out a pointer to the StaticTask_t structure in which the Timer\r
145          * task's state will be stored. */\r
146         *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;\r
147 \r
148         /* Pass out the array that will be used as the Timer task's stack. */\r
149         *ppxTimerTaskStackBuffer = uxTimerTaskStack;\r
150 \r
151         /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.\r
152          * Note that, as the array is necessarily of type StackType_t,\r
153          * configTIMER_TASK_STACK_DEPTH is specified in words, not bytes. */\r
154         *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;\r
155 }\r
156 /*-----------------------------------------------------------*/\r
157 \r
158 void MemManage_Handler( void )\r
159 {\r
160         __asm volatile\r
161         (\r
162                 " tst lr, #4                                                                            \n"\r
163                 " ite eq                                                                                        \n"\r
164                 " mrseq r0, msp                                                                         \n"\r
165                 " mrsne r0, psp                                                                         \n"\r
166                 " ldr r1, handler_address_const                                         \n"\r
167                 " bx r1                                                                                         \n"\r
168                 "                                                                                                       \n"\r
169                 " handler_address_const: .word vHandleMemoryFault       \n"\r
170         );\r
171 }\r
172 /*-----------------------------------------------------------*/\r