]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_MPU_M33F_Simulator_Keil_GCC/NonSecure/main_ns.c
Fix Build and Links failure in MPU projects. Minor cosmetic changes in some V8M files.
[freertos] / FreeRTOS / Demo / CORTEX_MPU_M33F_Simulator_Keil_GCC / 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 includes. */\r
29 #include "FreeRTOS.h"\r
30 #include "task.h"\r
31 \r
32 /* Demo includes. */\r
33 #include "tz_demo.h"\r
34 #include "mpu_demo.h"\r
35 \r
36 /* Externs needed by the MPU setup code. These must match the memory map as\r
37  * specified in Scatter-Loading description file (FreeRTOSDemo_ns.sct). */\r
38 /* Privileged flash. */\r
39 const uint32_t * __privileged_functions_start__         = ( uint32_t * ) ( 0x00200000 );\r
40 const uint32_t * __privileged_functions_end__           = ( uint32_t * ) ( 0x00208000 - 0x1 );  /* Last address in privileged Flash region. */\r
41 \r
42 /* Flash containing system calls. */\r
43 const uint32_t * __syscalls_flash_start__                       = ( uint32_t * ) ( 0x00208000 );\r
44 const uint32_t * __syscalls_flash_end__                         = ( uint32_t * ) ( 0x00209000 - 0x1 );  /* Last address in Flash region containing system calls. */\r
45 \r
46 /* Unprivileged flash. Note that the section containing\r
47  * system calls is unprivilged so that unprivleged tasks\r
48  * can make system calls. */\r
49 const uint32_t * __unprivileged_flash_start__           = ( uint32_t * ) ( 0x00209000 );\r
50 const uint32_t * __unprivileged_flash_end__                     = ( uint32_t * ) ( 0x00400000 - 0x1 );  /* Last address in un-privileged Flash region. */\r
51 \r
52 /* 512 bytes (0x200) of RAM starting at 0x30008000 is\r
53  * priviledged access only. This contains kernel data. */\r
54 const uint32_t * __privileged_sram_start__                      = ( uint32_t * ) ( 0x20200000 );\r
55 const uint32_t * __privileged_sram_end__                        = ( uint32_t * ) ( 0x20201000 - 0x1 ); /* Last address in privileged RAM. */\r
56 ;\r
57 /* Unprivileged RAM. */\r
58 const uint32_t * __unprivileged_sram_start__            = ( uint32_t * ) ( 0x20201000 );\r
59 const uint32_t * __unprivileged_sram_end__                      = ( uint32_t * ) ( 0x20220000 - 0x1 ); /* Last address in un-privileged RAM. */\r
60 /*-----------------------------------------------------------*/\r
61 \r
62 /**\r
63  * @brief Create all demo tasks.\r
64  */\r
65 static void prvCreateTasks( void );\r
66 /*-----------------------------------------------------------*/\r
67 \r
68 /*\r
69  *      Instructions to Build and Run:\r
70  *       - The Keil multi-project workspace FreeRTOSDemo.uvmpw contains projects for\r
71  *         both the secure project, and non secure project.\r
72  *       - Set the FreeRTOSDemo_s project as Active - Right click on\r
73  *         "Project: FreeRTOSDemo_s" and select "Set as Active Project".\r
74  *       - Build the FreeRTOSDemo_s project using "Project --> Build" or by pressing\r
75  *         "F7".\r
76  *       - Set the FreeRTOSDemo_ns project as Active - Right click on\r
77  *         "Project: FreeRTOSDemo_ns" and select "Set as Active Project".\r
78  *       - Build the FreeRTOSDemo_ns project using "Project --> Build" or by\r
79  *         pressing "F7".\r
80  *       - Start Debug Session using "Debug -> Start/Stop Debug Session" or by\r
81  *         pressing "Ctrl+F5".\r
82  */\r
83 \r
84 /* Non-Secure main. */\r
85 int main( void )\r
86 {\r
87         /* Create tasks. */\r
88         prvCreateTasks();\r
89 \r
90         /* Start scheduler. */\r
91         vTaskStartScheduler();\r
92 \r
93         /* Should not reach here as the scheduler is already started. */\r
94         for( ; ; )\r
95         {\r
96         }\r
97 }\r
98 /*-----------------------------------------------------------*/\r
99 \r
100 static void prvCreateTasks( void )\r
101 {\r
102         /* Create tasks for the MPU Demo. */\r
103         vStartMPUDemo();\r
104 \r
105         /* Create tasks for the TZ Demo. */\r
106         vStartTZDemo();\r
107 \r
108 }\r
109 /*-----------------------------------------------------------*/\r
110 \r
111 /* Stack overflow hook. */\r
112 void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName )\r
113 {\r
114         /* Force an assert. */\r
115         configASSERT( pcTaskName == 0 );\r
116 }\r
117 /*-----------------------------------------------------------*/\r
118 \r
119 /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an\r
120  * implementation of vApplicationGetIdleTaskMemory() to provide the memory that\r
121  * is used by the Idle task. */\r
122 void vApplicationGetIdleTaskMemory(     StaticTask_t ** ppxIdleTaskTCBBuffer,\r
123                                                                         StackType_t ** ppxIdleTaskStackBuffer,\r
124                                                                         uint32_t * pulIdleTaskStackSize )\r
125 {\r
126         /* If the buffers to be provided to the Idle task are declared inside this\r
127          * function then they must be declared static - otherwise they will be\r
128          * allocated on the stack and so not exists after this function exits. */\r
129         static StaticTask_t xIdleTaskTCB;\r
130         static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__((aligned(32)));\r
131 \r
132         /* Pass out a pointer to the StaticTask_t structure in which the Idle\r
133          * task's state will be stored. */\r
134         *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;\r
135 \r
136         /* Pass out the array that will be used as the Idle task's stack. */\r
137         *ppxIdleTaskStackBuffer = uxIdleTaskStack;\r
138 \r
139         /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.\r
140          * Note that, as the array is necessarily of type StackType_t,\r
141          * configMINIMAL_STACK_SIZE is specified in words, not bytes. */\r
142         *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;\r
143 }\r
144 /*-----------------------------------------------------------*/\r
145 \r
146 /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the\r
147  * application must provide an implementation of vApplicationGetTimerTaskMemory()\r
148  * to provide the memory that is used by the Timer service task. */\r
149 void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,\r
150                                                                          StackType_t ** ppxTimerTaskStackBuffer,\r
151                                                                          uint32_t * pulTimerTaskStackSize )\r
152 {\r
153         /* If the buffers to be provided to the Timer task are declared inside this\r
154          * function then they must be declared static - otherwise they will be\r
155          * allocated on the stack and so not exists after this function exits. */\r
156         static StaticTask_t xTimerTaskTCB;\r
157         static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ] __attribute__((aligned(32)));\r
158 \r
159         /* Pass out a pointer to the StaticTask_t structure in which the Timer\r
160          * task's state will be stored. */\r
161         *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;\r
162 \r
163         /* Pass out the array that will be used as the Timer task's stack. */\r
164         *ppxTimerTaskStackBuffer = uxTimerTaskStack;\r
165 \r
166         /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.\r
167          * Note that, as the array is necessarily of type StackType_t,\r
168          * configTIMER_TASK_STACK_DEPTH is specified in words, not bytes. */\r
169         *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;\r
170 }\r
171 /*-----------------------------------------------------------*/\r
172 \r
173 /**\r
174  * @brief The mem fault handler implementation calls a function called\r
175  * vHandleMemoryFault.\r
176  */\r
177 void MemManage_Handler( void )\r
178 {\r
179         __asm volatile\r
180         (\r
181                 " tst lr, #4                                                                            \n"\r
182                 " ite eq                                                                                        \n"\r
183                 " mrseq r0, msp                                                                         \n"\r
184                 " mrsne r0, psp                                                                         \n"\r
185                 " ldr r1, handler_address_const                                         \n"\r
186                 " bx r1                                                                                         \n"\r
187                 "                                                                                                       \n"\r
188                 " handler_address_const: .word vHandleMemoryFault       \n"\r
189         );\r
190 }\r
191 /*-----------------------------------------------------------*/\r