]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_MPU_LM3Sxxxx_Rowley/main.c
Add configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS mechanism to allow the...
[freertos] / FreeRTOS / Demo / CORTEX_MPU_LM3Sxxxx_Rowley / main.c
1 /*\r
2     FreeRTOS V7.4.2 - Copyright (C) 2013 Real Time Engineers Ltd.\r
3 \r
4     FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME.  PLEASE VISIT\r
5     http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
10      *    Complete, revised, and edited pdf reference manuals are also       *\r
11      *    available.                                                         *\r
12      *                                                                       *\r
13      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
14      *    ensuring you get running as quickly as possible and with an        *\r
15      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
16      *    the FreeRTOS project to continue with its mission of providing     *\r
17      *    professional grade, cross platform, de facto standard solutions    *\r
18      *    for microcontrollers - completely free of charge!                  *\r
19      *                                                                       *\r
20      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
21      *                                                                       *\r
22      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
23      *                                                                       *\r
24     ***************************************************************************\r
25 \r
26 \r
27     This file is part of the FreeRTOS distribution.\r
28 \r
29     FreeRTOS is free software; you can redistribute it and/or modify it under\r
30     the terms of the GNU General Public License (version 2) as published by the\r
31     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
32 \r
33     >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to\r
34     distribute a combined work that includes FreeRTOS without being obliged to\r
35     provide the source code for proprietary components outside of the FreeRTOS\r
36     kernel.\r
37 \r
38     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
39     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
40     FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more\r
41     details. You should have received a copy of the GNU General Public License\r
42     and the FreeRTOS license exception along with FreeRTOS; if not it can be\r
43     viewed here: http://www.freertos.org/a00114.html and also obtained by\r
44     writing to Real Time Engineers Ltd., contact details for whom are available\r
45     on the FreeRTOS WEB site.\r
46 \r
47     1 tab == 4 spaces!\r
48 \r
49     ***************************************************************************\r
50      *                                                                       *\r
51      *    Having a problem?  Start by reading the FAQ "My application does   *\r
52      *    not run, what could be wrong?"                                     *\r
53      *                                                                       *\r
54      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
55      *                                                                       *\r
56     ***************************************************************************\r
57 \r
58 \r
59     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
60     license and Real Time Engineers Ltd. contact details.\r
61 \r
62     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
63     including FreeRTOS+Trace - an indispensable productivity tool, and our new\r
64     fully thread aware and reentrant UDP/IP stack.\r
65 \r
66     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
67     Integrity Systems, who sell the code with commercial support,\r
68     indemnification and middleware, under the OpenRTOS brand.\r
69 \r
70     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
71     engineered and independently SIL3 certified version for use in safety and\r
72     mission critical applications that require provable dependability.\r
73 */\r
74 \r
75 \r
76 /*\r
77  * This file demonstrates the use of FreeRTOS-MPU.  It creates tasks in both\r
78  * User mode and Privileged mode, and using both the original xTaskCreate() and\r
79  * the new xTaskCreateRestricted() API functions.  The purpose of each created\r
80  * task is documented in the comments above the task function prototype (in\r
81  * this file), with the task behaviour demonstrated and documented within the\r
82  * task function itself.  In addition a queue is used to demonstrate passing\r
83  * data between protected/restricted tasks as well as passing data between an\r
84  * interrupt and a protected/restricted task.\r
85  */\r
86 \r
87 \r
88 \r
89 /* Standard includes. */\r
90 #include <string.h>\r
91 #include <__cross_studio_io.h>\r
92 \r
93 /* Scheduler includes. */\r
94 #include "FreeRTOS.h"\r
95 #include "task.h"\r
96 #include "queue.h"\r
97 #include "semphr.h"\r
98 \r
99 /* Hardware library includes. */\r
100 #include "hw_types.h"\r
101 #include "hw_sysctl.h"\r
102 #include "sysctl.h"\r
103 \r
104 /*-----------------------------------------------------------*/\r
105 \r
106 /* Misc constants. */\r
107 #define mainDONT_BLOCK                                  ( 0 )\r
108 \r
109 /* Definitions for the messages that can be sent to the check task. */\r
110 #define mainREG_TEST_1_STILL_EXECUTING  ( 0 )\r
111 #define mainREG_TEST_2_STILL_EXECUTING  ( 1 )\r
112 #define mainPRINT_SYSTEM_STATUS                 ( 2 )\r
113 \r
114 /* GCC specifics. */\r
115 #define mainALIGN_TO( x )                               __attribute__((aligned(x)))\r
116 \r
117 \r
118 /*-----------------------------------------------------------*/\r
119 /* Prototypes for functions that implement tasks. -----------*/\r
120 /*-----------------------------------------------------------*/\r
121 \r
122 /*\r
123  * Prototype for the reg test tasks.  Amongst other things, these fill the CPU\r
124  * registers with known values before checking that the registers still contain\r
125  * the expected values.  Each of the two tasks use different values so an error\r
126  * in the context switch mechanism can be caught.  Both reg test tasks execute\r
127  * at the idle priority so will get preempted regularly.  Each task repeatedly\r
128  * sends a message on a queue so long as it remains functioning correctly.  If\r
129  * an error is detected within the task the task is simply deleted.\r
130  */\r
131 static void prvRegTest1Task( void *pvParameters );\r
132 static void prvRegTest2Task( void *pvParameters );\r
133 \r
134 /*\r
135  * Prototype for the check task.  The check task demonstrates various features\r
136  * of the MPU before entering a loop where it waits for messages to arrive on a\r
137  * queue.\r
138  *\r
139  * Two types of messages can be processes:\r
140  *\r
141  * 1) "I'm Alive" messages sent from the reg test tasks, indicating that the\r
142  *    task is still operational.\r
143  *\r
144  * 2) "Print Status commands" sent periodically by the tick hook function (and\r
145  *    therefore from within an interrupt) which command the check task to write\r
146  *    either pass or fail to the terminal, depending on the status of the reg\r
147  *    test tasks.\r
148  */\r
149 static void prvCheckTask( void *pvParameters );\r
150 \r
151 /*\r
152  * Prototype for a task created in User mode using the original vTaskCreate()\r
153  * API function.  The task demonstrates the characteristics of such a task,\r
154  * before simply deleting itself.\r
155  */\r
156 static void prvOldStyleUserModeTask( void *pvParameters );\r
157 \r
158 /*\r
159  * Prototype for a task created in Privileged mode using the original\r
160  * vTaskCreate() API function.  The task demonstrates the characteristics of\r
161  * such a task, before simply deleting itself.\r
162  */\r
163 static void prvOldStylePrivilegedModeTask( void *pvParameters );\r
164 \r
165 \r
166 /*-----------------------------------------------------------*/\r
167 /* Prototypes for other misc functions.  --------------------*/\r
168 /*-----------------------------------------------------------*/\r
169 \r
170 /*\r
171  * Just configures any clocks and IO necessary.\r
172  */\r
173 static void prvSetupHardware( void );\r
174 \r
175 /*\r
176  * Simply deletes the calling task.  The function is provided only because it\r
177  * is simpler to call from asm code than the normal vTaskDelete() API function.\r
178  * It has the noinline attribute because it is called from asm code.\r
179  */\r
180 static void prvDeleteMe( void ) __attribute__((noinline));\r
181 \r
182 /*\r
183  * Used by both reg test tasks to send messages to the check task.  The message\r
184  * just lets the check task know that the task is still functioning correctly.\r
185  * If a reg test task detects an error it will delete itself, and in so doing\r
186  * prevent itself from sending any more 'I'm Alive' messages to the check task.\r
187  */\r
188 static void prvSendImAlive( xQueueHandle xHandle, unsigned long ulTaskNumber );\r
189 \r
190 /*\r
191  * The check task is created with access to three memory regions (plus its\r
192  * stack).  Each memory region is configured with different parameters and\r
193  * prvTestMemoryRegions() demonstrates what can and cannot be accessed for each\r
194  * region.  prvTestMemoryRegions() also demonstrates a task that was created\r
195  * as a privileged task settings its own privilege level down to that of a user\r
196  * task.\r
197  */\r
198 static void prvTestMemoryRegions( void );\r
199 \r
200 /*-----------------------------------------------------------*/\r
201 \r
202 /* The handle of the queue used to communicate between tasks and between tasks\r
203 and interrupts.  Note that this is a file scope variable that falls outside of\r
204 any MPU region.  As such other techniques have to be used to allow the tasks\r
205 to gain access to the queue.  See the comments in the tasks themselves for\r
206 further information. */\r
207 static xQueueHandle xFileScopeCheckQueue = NULL;\r
208 \r
209 \r
210 /*-----------------------------------------------------------*/\r
211 /* Data used by the 'check' task. ---------------------------*/\r
212 /*-----------------------------------------------------------*/\r
213 \r
214 /* Define the constants used to allocate the check task stack.  Note that the\r
215 stack size is defined in words, not bytes. */\r
216 #define mainCHECK_TASK_STACK_SIZE_WORDS 128\r
217 #define mainCHECK_TASK_STACK_ALIGNMENT ( mainCHECK_TASK_STACK_SIZE_WORDS * sizeof( portSTACK_TYPE ) )\r
218 \r
219 /* Declare the stack that will be used by the check task.  The kernel will\r
220  automatically create an MPU region for the stack.  The stack alignment must\r
221  match its size, so if 128 words are reserved for the stack then it must be\r
222  aligned to ( 128 * 4 ) bytes. */\r
223 static portSTACK_TYPE xCheckTaskStack[ mainCHECK_TASK_STACK_SIZE_WORDS ] mainALIGN_TO( mainCHECK_TASK_STACK_ALIGNMENT );\r
224 \r
225 /* Declare three arrays - an MPU region will be created for each array\r
226 using the xTaskParameters structure below.  THIS IS JUST TO DEMONSTRATE THE\r
227 MPU FUNCTIONALITY, the data is not used by the check tasks primary function\r
228 of monitoring the reg test tasks and printing out status information.\r
229 \r
230 Note that the arrays allocate slightly more RAM than is actually assigned to\r
231 the MPU region.  This is to permit writes off the end of the array to be\r
232 detected even when the arrays are placed in adjacent memory locations (with no\r
233 gaps between them).  The align size must be a power of two. */\r
234 #define mainREAD_WRITE_ARRAY_SIZE 130\r
235 #define mainREAD_WRITE_ALIGN_SIZE 128\r
236 char cReadWriteArray[ mainREAD_WRITE_ARRAY_SIZE ] mainALIGN_TO( mainREAD_WRITE_ALIGN_SIZE );\r
237 \r
238 #define mainREAD_ONLY_ARRAY_SIZE 260\r
239 #define mainREAD_ONLY_ALIGN_SIZE 256\r
240 char cReadOnlyArray[ mainREAD_ONLY_ARRAY_SIZE ] mainALIGN_TO( mainREAD_ONLY_ALIGN_SIZE );\r
241 \r
242 #define mainPRIVILEGED_ONLY_ACCESS_ARRAY_SIZE 130\r
243 #define mainPRIVILEGED_ONLY_ACCESS_ALIGN_SIZE 128\r
244 char cPrivilegedOnlyAccessArray[ mainPRIVILEGED_ONLY_ACCESS_ALIGN_SIZE ] mainALIGN_TO( mainPRIVILEGED_ONLY_ACCESS_ALIGN_SIZE );\r
245 \r
246 /* Fill in a xTaskParameters structure to define the check task - this is the\r
247 structure passed to the xTaskCreateRestricted() function. */\r
248 static const xTaskParameters xCheckTaskParameters =\r
249 {\r
250         prvCheckTask,                                                           /* pvTaskCode - the function that implements the task. */\r
251         ( signed char * ) "Check",                                      /* pcName                       */\r
252         mainCHECK_TASK_STACK_SIZE_WORDS,                        /* usStackDepth - defined in words, not bytes. */\r
253         ( void * ) 0x12121212,                                          /* pvParameters - this value is just to test that the parameter is being passed into the task correctly. */\r
254         ( tskIDLE_PRIORITY + 1 ) | portPRIVILEGE_BIT,/* uxPriority - this is the highest priority task in the system.  The task is created in privileged mode to demonstrate accessing the privileged only data. */\r
255         xCheckTaskStack,                                                        /* puxStackBuffer - the array to use as the task stack, as declared above. */\r
256 \r
257         /* xRegions - In this case the xRegions array is used to create MPU regions\r
258         for all three of the arrays declared directly above.  Each MPU region is\r
259         created with different parameters.  Again, THIS IS JUST TO DEMONSTRATE THE\r
260         MPU FUNCTIONALITY, the data is not used by the check tasks primary function\r
261         of monitoring the reg test tasks and printing out status information.*/\r
262         {\r
263                 /* Base address                                 Length                                                                  Parameters */\r
264         { cReadWriteArray,                              mainREAD_WRITE_ALIGN_SIZE,                              portMPU_REGION_READ_WRITE },\r
265         { cReadOnlyArray,                               mainREAD_ONLY_ALIGN_SIZE,                               portMPU_REGION_READ_ONLY },\r
266         { cPrivilegedOnlyAccessArray,   mainPRIVILEGED_ONLY_ACCESS_ALIGN_SIZE,  portMPU_REGION_PRIVILEGED_READ_WRITE }\r
267         }\r
268 };\r
269 \r
270 \r
271 \r
272 /*-----------------------------------------------------------*/\r
273 /* Data used by the 'reg test' tasks. -----------------------*/\r
274 /*-----------------------------------------------------------*/\r
275 \r
276 /* Define the constants used to allocate the reg test task stacks.  Note that\r
277 that stack size is defined in words, not bytes. */\r
278 #define mainREG_TEST_STACK_SIZE_WORDS   128\r
279 #define mainREG_TEST_STACK_ALIGNMENT    ( mainREG_TEST_STACK_SIZE_WORDS * sizeof( portSTACK_TYPE ) )\r
280 \r
281 /* Declare the stacks that will be used by the reg test tasks.  The kernel will\r
282 automatically create an MPU region for the stack.  The stack alignment must\r
283 match its size, so if 128 words are reserved for the stack then it must be\r
284 aligned to ( 128 * 4 ) bytes. */\r
285 static portSTACK_TYPE xRegTest1Stack[ mainREG_TEST_STACK_SIZE_WORDS ] mainALIGN_TO( mainREG_TEST_STACK_ALIGNMENT );\r
286 static portSTACK_TYPE xRegTest2Stack[ mainREG_TEST_STACK_SIZE_WORDS ] mainALIGN_TO( mainREG_TEST_STACK_ALIGNMENT );\r
287 \r
288 /* Fill in a xTaskParameters structure per reg test task to define the tasks. */\r
289 static const xTaskParameters xRegTest1Parameters =\r
290 {\r
291         prvRegTest1Task,                                                /* pvTaskCode - the function that implements the task. */\r
292         ( signed char * ) "RegTest1",                   /* pcName                       */\r
293         mainREG_TEST_STACK_SIZE_WORDS,                  /* usStackDepth         */\r
294         ( void * ) 0x12345678,                                  /* pvParameters - this value is just to test that the parameter is being passed into the task correctly. */\r
295         tskIDLE_PRIORITY | portPRIVILEGE_BIT,   /* uxPriority - note that this task is created with privileges to demonstrate one method of passing a queue handle into the task. */\r
296         xRegTest1Stack,                                                 /* puxStackBuffer - the array to use as the task stack, as declared above. */\r
297         {                                                                               /* xRegions - this task does not use any non-stack data hence all members are zero. */\r
298                 /* Base address         Length          Parameters */\r
299         { 0x00,                         0x00,                   0x00 },\r
300         { 0x00,                         0x00,                   0x00 },\r
301         { 0x00,                         0x00,                   0x00 }\r
302         }\r
303 };\r
304 /*-----------------------------------------------------------*/\r
305 \r
306 static xTaskParameters xRegTest2Parameters =\r
307 {\r
308         prvRegTest2Task,                                /* pvTaskCode - the function that implements the task. */\r
309         ( signed char * ) "RegTest2",   /* pcName                       */\r
310         mainREG_TEST_STACK_SIZE_WORDS,  /* usStackDepth         */\r
311         ( void * ) NULL,                                /* pvParameters - this task uses the parameter to pass in a queue handle, but the queue is not created yet. */\r
312         tskIDLE_PRIORITY,                               /* uxPriority           */\r
313         xRegTest2Stack,                                 /* puxStackBuffer - the array to use as the task stack, as declared above. */\r
314         {                                                               /* xRegions - this task does not use any non-stack data hence all members are zero. */\r
315                 /* Base address         Length          Parameters */\r
316         { 0x00,                         0x00,                   0x00 },\r
317         { 0x00,                         0x00,                   0x00 },\r
318         { 0x00,                         0x00,                   0x00 }\r
319         }\r
320 };\r
321 \r
322 /*-----------------------------------------------------------*/\r
323 \r
324 int main( void )\r
325 {\r
326         prvSetupHardware();\r
327 \r
328         /* Create the queue used to pass "I'm alive" messages to the check task. */\r
329         xFileScopeCheckQueue = xQueueCreate( 1, sizeof( unsigned long ) );\r
330 \r
331         /* One check task uses the task parameter to receive the queue handle.\r
332         This allows the file scope variable to be accessed from within the task.\r
333         The pvParameters member of xRegTest2Parameters can only be set after the\r
334         queue has been created so is set here. */\r
335         xRegTest2Parameters.pvParameters = xFileScopeCheckQueue;\r
336 \r
337         /* Create the three test tasks.  Handles to the created tasks are not\r
338         required, hence the second parameter is NULL. */\r
339         xTaskCreateRestricted( &xRegTest1Parameters, NULL );\r
340     xTaskCreateRestricted( &xRegTest2Parameters, NULL );\r
341         xTaskCreateRestricted( &xCheckTaskParameters, NULL );\r
342 \r
343         /* Create the tasks that are created using the original xTaskCreate() API\r
344         function. */\r
345         xTaskCreate(    prvOldStyleUserModeTask,        /* The function that implements the task. */\r
346                                         ( signed char * ) "Task1",      /* Text name for the task. */\r
347                                         100,                                            /* Stack depth in words. */\r
348                                         NULL,                                           /* Task parameters. */\r
349                                         3,                                                      /* Priority and mode (user in this case). */\r
350                                         NULL                                            /* Handle. */\r
351                                 );\r
352 \r
353         xTaskCreate(    prvOldStylePrivilegedModeTask,  /* The function that implements the task. */\r
354                                         ( signed char * ) "Task2",              /* Text name for the task. */\r
355                                         100,                                                    /* Stack depth in words. */\r
356                                         NULL,                                                   /* Task parameters. */\r
357                                         ( 3 | portPRIVILEGE_BIT ),              /* Priority and mode. */\r
358                                         NULL                                                    /* Handle. */\r
359                                 );\r
360 \r
361         /* Start the scheduler. */\r
362         vTaskStartScheduler();\r
363 \r
364         /* Will only get here if there was insufficient memory to create the idle\r
365         task. */\r
366         for( ;; );\r
367         return 0;\r
368 }\r
369 /*-----------------------------------------------------------*/\r
370 \r
371 static void prvCheckTask( void *pvParameters )\r
372 {\r
373 /* This task is created in privileged mode so can access the file scope\r
374 queue variable.  Take a stack copy of this before the task is set into user\r
375 mode.  Once that task is in user mode the file scope queue variable will no\r
376 longer be accessible but the stack copy will. */\r
377 xQueueHandle xQueue = xFileScopeCheckQueue;\r
378 long lMessage;\r
379 unsigned long ulStillAliveCounts[ 2 ] = { 0 };\r
380 const char *pcStatusMessage = "PASS\r\n";\r
381 \r
382 /* The debug_printf() function uses RAM that is outside of the control of the\r
383 application writer.  Therefore the application_defined_privileged_functions.h\r
384 header file is used to provide a version that executes with privileges. */\r
385 extern int MPU_debug_printf( const char *pcMessage );\r
386 \r
387         /* Just to remove compiler warning. */\r
388         ( void ) pvParameters;\r
389 \r
390         /* Demonstrate how the various memory regions can and can't be accessed.\r
391         The task privilege level is set down to user mode within this function. */\r
392         prvTestMemoryRegions();\r
393 \r
394         /* Tests are done so lower the privilege status. */\r
395         portSWITCH_TO_USER_MODE();\r
396 \r
397         /* This loop performs the main function of the task, which is blocking\r
398         on a message queue then processing each message as it arrives. */\r
399         for( ;; )\r
400         {\r
401                 /* Wait for the next message to arrive. */\r
402                 xQueueReceive( xQueue, &lMessage, portMAX_DELAY );\r
403 \r
404                 switch( lMessage )\r
405                 {\r
406                         case mainREG_TEST_1_STILL_EXECUTING     :\r
407                                         /* Message from task 1, so task 1 must still be executing. */\r
408                                         ( ulStillAliveCounts[ 0 ] )++;\r
409                                         break;\r
410 \r
411                         case mainREG_TEST_2_STILL_EXECUTING     :\r
412                                         /* Message from task 2, so task 2 must still be executing. */\r
413                                         ( ulStillAliveCounts[ 1 ] )++;\r
414                                         break;\r
415 \r
416                         case mainPRINT_SYSTEM_STATUS            :\r
417                                         /* Message from tick hook, time to print out the system\r
418                                         status.  If messages has stopped arriving from either reg\r
419                                         test task then the status must be set to fail. */\r
420                                         if( ( ulStillAliveCounts[ 0 ] == 0 ) || ( ulStillAliveCounts[ 1 ] == 0 )  )\r
421                                         {\r
422                                                 /* One or both of the test tasks are no longer sending\r
423                                                 'still alive' messages. */\r
424                                                 pcStatusMessage = "FAIL\r\n";\r
425                                         }\r
426 \r
427                                         /* Print a pass/fail message to the terminal.  This will be\r
428                                         visible in the CrossWorks IDE. */\r
429                                         MPU_debug_printf( pcStatusMessage );\r
430 \r
431                                         /* Reset the count of 'still alive' messages. */\r
432                                         memset( ulStillAliveCounts, 0x00, sizeof( ulStillAliveCounts ) );\r
433                                         break;\r
434 \r
435                 default :\r
436                                         /* Something unexpected happened.  Delete this task so the\r
437                                         error is apparent (no output will be displayed). */\r
438                                         prvDeleteMe();\r
439                                         break;\r
440                 }\r
441         }\r
442 }\r
443 /*-----------------------------------------------------------*/\r
444 \r
445 static void prvTestMemoryRegions( void )\r
446 {\r
447 long l;\r
448 char cTemp;\r
449 \r
450         /* The check task (from which this function is called) is created in the\r
451         Privileged mode.  The privileged array can be both read from and written\r
452         to while this task is privileged. */\r
453         cPrivilegedOnlyAccessArray[ 0 ] = 'a';\r
454         if( cPrivilegedOnlyAccessArray[ 0 ] != 'a' )\r
455         {\r
456                 /* Something unexpected happened.  Delete this task so the error is\r
457                 apparent (no output will be displayed). */\r
458                 prvDeleteMe();\r
459         }\r
460 \r
461         /* Writing off the end of the RAM allocated to this task will *NOT* cause a\r
462         protection fault because the task is still executing in a privileged mode.\r
463         Uncomment the following to test. */\r
464         /*cPrivilegedOnlyAccessArray[ mainPRIVILEGED_ONLY_ACCESS_ALIGN_SIZE ] = 'a';*/\r
465 \r
466         /* Now set the task into user mode. */\r
467         portSWITCH_TO_USER_MODE();\r
468 \r
469         /* Accessing the privileged only array will now cause a fault.  Uncomment\r
470         the following line to test. */\r
471         /*cPrivilegedOnlyAccessArray[ 0 ] = 'a';*/\r
472 \r
473         /* The read/write array can still be successfully read and written. */\r
474         for( l = 0; l < mainREAD_WRITE_ALIGN_SIZE; l++ )\r
475         {\r
476                 cReadWriteArray[ l ] = 'a';\r
477                 if( cReadWriteArray[ l ] != 'a' )\r
478                 {\r
479                         /* Something unexpected happened.  Delete this task so the error is\r
480                         apparent (no output will be displayed). */\r
481                         prvDeleteMe();\r
482                 }\r
483         }\r
484 \r
485         /* But attempting to read or write off the end of the RAM allocated to this\r
486         task will cause a fault.  Uncomment either of the following two lines to\r
487         test. */\r
488         /* cReadWriteArray[ 0 ] = cReadWriteArray[ -1 ]; */\r
489         /* cReadWriteArray[ mainREAD_WRITE_ALIGN_SIZE ] = 0x00; */\r
490 \r
491         /* The read only array can be successfully read... */\r
492         for( l = 0; l < mainREAD_ONLY_ALIGN_SIZE; l++ )\r
493         {\r
494                 cTemp = cReadOnlyArray[ l ];\r
495         }\r
496 \r
497         /* ...but cannot be written.  Uncomment the following line to test. */\r
498         /* cReadOnlyArray[ 0 ] = 'a'; */\r
499 \r
500         /* Writing to the first and last locations in the stack array should not\r
501         cause a protection fault.  Note that doing this will cause the kernel to\r
502         detect a stack overflow if configCHECK_FOR_STACK_OVERFLOW is greater than\r
503         1. */\r
504     xCheckTaskStack[ 0 ] = 0;\r
505     xCheckTaskStack[ mainCHECK_TASK_STACK_SIZE_WORDS - 1 ] = 0;\r
506 \r
507         /* Writing off either end of the stack array should cause a protection\r
508         fault, uncomment either of the following two lines to test. */\r
509         /* xCheckTaskStack[ -1 ] = 0; */\r
510     /* xCheckTaskStack[ mainCHECK_TASK_STACK_SIZE_WORDS ] = 0; */\r
511 \r
512         ( void ) cTemp;\r
513 }\r
514 /*-----------------------------------------------------------*/\r
515 \r
516 static void prvRegTest1Task( void *pvParameters )\r
517 {\r
518 /* This task is created in privileged mode so can access the file scope\r
519 queue variable.  Take a stack copy of this before the task is set into user\r
520 mode.  Once this task is in user mode the file scope queue variable will no\r
521 longer be accessible but the stack copy will. */\r
522 xQueueHandle xQueue = xFileScopeCheckQueue;\r
523 \r
524         /* Now the queue handle has been obtained the task can switch to user\r
525         mode.  This is just one method of passing a handle into a protected\r
526         task, the other reg test task uses the task parameter instead. */\r
527     portSWITCH_TO_USER_MODE();\r
528 \r
529         /* First check that the parameter value is as expected. */\r
530         if( pvParameters != ( void * ) 0x12345678 )\r
531         {\r
532                 /* Error detected.  Delete the task so it stops communicating with\r
533                 the check task. */\r
534                 prvDeleteMe();\r
535         }\r
536 \r
537 \r
538         for( ;; )\r
539         {\r
540                 /* This task tests the kernel context switch mechanism by reading and\r
541                 writing directly to registers - which requires the test to be written\r
542                 in assembly code. */\r
543                 __asm volatile\r
544                 (\r
545                         "               MOV     R4, #104                        \n" /* Set registers to a known value.  R0 to R1 are done in the loop below. */\r
546                         "               MOV     R5, #105                        \n"\r
547                         "               MOV     R6, #106                        \n"\r
548                         "               MOV     R8, #108                        \n"\r
549                         "               MOV     R9, #109                        \n"\r
550                         "               MOV     R10, #110                       \n"\r
551                         "               MOV     R11, #111                       \n"\r
552                         "reg1loop:                                              \n"\r
553                         "               MOV     R0, #100                        \n" /* Set the scratch registers to known values - done inside the loop as they get clobbered. */\r
554                         "               MOV     R1, #101                        \n"\r
555                         "               MOV     R2, #102                        \n"\r
556                         "               MOV R3, #103                    \n"\r
557                         "               MOV     R12, #112                       \n"\r
558                         "               SVC #1                                  \n" /* Yield just to increase test coverage. */\r
559                         "               CMP     R0, #100                        \n" /* Check all the registers still contain their expected values. */\r
560                         "               BNE     prvDeleteMe                     \n" /* Value was not as expected, delete the task so it stops communicating with the check task. */\r
561                         "               CMP     R1, #101                        \n"\r
562                         "               BNE     prvDeleteMe                     \n"\r
563                         "               CMP     R2, #102                        \n"\r
564                         "               BNE     prvDeleteMe                     \n"\r
565                         "               CMP R3, #103                    \n"\r
566                         "               BNE     prvDeleteMe                     \n"\r
567                         "               CMP     R4, #104                        \n"\r
568                         "               BNE     prvDeleteMe                     \n"\r
569                         "               CMP     R5, #105                        \n"\r
570                         "               BNE     prvDeleteMe                     \n"\r
571                         "               CMP     R6, #106                        \n"\r
572                         "               BNE     prvDeleteMe                     \n"\r
573                         "               CMP     R8, #108                        \n"\r
574                         "               BNE     prvDeleteMe                     \n"\r
575                         "               CMP     R9, #109                        \n"\r
576                         "               BNE     prvDeleteMe                     \n"\r
577                         "               CMP     R10, #110                       \n"\r
578                         "               BNE     prvDeleteMe                     \n"\r
579                         "               CMP     R11, #111                       \n"\r
580                         "               BNE     prvDeleteMe                     \n"\r
581                         "               CMP     R12, #112                       \n"\r
582                         "               BNE     prvDeleteMe                     \n"\r
583                         :::"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r8", "r9", "r10", "r11", "r12"\r
584                 );\r
585 \r
586                 /* Send mainREG_TEST_1_STILL_EXECUTING to the check task to indicate that this\r
587                 task is still functioning. */\r
588                 prvSendImAlive( xQueue, mainREG_TEST_1_STILL_EXECUTING );\r
589 \r
590                 /* Go back to check all the register values again. */\r
591                 __asm volatile( "               B reg1loop      " );\r
592         }\r
593 }\r
594 /*-----------------------------------------------------------*/\r
595 \r
596 static void prvRegTest2Task( void *pvParameters )\r
597 {\r
598 /* The queue handle is passed in as the task parameter.  This is one method of\r
599 passing data into a protected task, the other reg test task uses a different\r
600 method. */\r
601 xQueueHandle xQueue = ( xQueueHandle ) pvParameters;\r
602 \r
603         for( ;; )\r
604         {\r
605                 /* This task tests the kernel context switch mechanism by reading and\r
606                 writing directly to registers - which requires the test to be written\r
607                 in assembly code. */\r
608                 __asm volatile\r
609                 (\r
610                         "               MOV     R4, #4                          \n" /* Set registers to a known value.  R0 to R1 are done in the loop below. */\r
611                         "               MOV     R5, #5                          \n"\r
612                         "               MOV     R6, #6                          \n"\r
613                         "               MOV     R8, #8                          \n" /* Frame pointer is omitted as it must not be changed. */\r
614                         "               MOV     R9, #9                          \n"\r
615                         "               MOV     R10, 10                         \n"\r
616                         "               MOV     R11, #11                        \n"\r
617                         "reg2loop:                                              \n"\r
618                         "               MOV     R0, #13                         \n" /* Set the scratch registers to known values - done inside the loop as they get clobbered. */\r
619                         "               MOV     R1, #1                          \n"\r
620                         "               MOV     R2, #2                          \n"\r
621                         "               MOV R3, #3                              \n"\r
622                         "               MOV     R12, #12                        \n"\r
623                         "               CMP     R0, #13                         \n" /* Check all the registers still contain their expected values. */\r
624                         "               BNE     prvDeleteMe                     \n" /* Value was not as expected, delete the task so it stops communicating with the check task */\r
625                         "               CMP     R1, #1                          \n"\r
626                         "               BNE     prvDeleteMe                     \n"\r
627                         "               CMP     R2, #2                          \n"\r
628                         "               BNE     prvDeleteMe                     \n"\r
629                         "               CMP R3, #3                              \n"\r
630                         "               BNE     prvDeleteMe                     \n"\r
631                         "               CMP     R4, #4                          \n"\r
632                         "               BNE     prvDeleteMe                     \n"\r
633                         "               CMP     R5, #5                          \n"\r
634                         "               BNE     prvDeleteMe                     \n"\r
635                         "               CMP     R6, #6                          \n"\r
636                         "               BNE     prvDeleteMe                     \n"\r
637                         "               CMP     R8, #8                          \n"\r
638                         "               BNE     prvDeleteMe                     \n"\r
639                         "               CMP     R9, #9                          \n"\r
640                         "               BNE     prvDeleteMe                     \n"\r
641                         "               CMP     R10, #10                        \n"\r
642                         "               BNE     prvDeleteMe                     \n"\r
643                         "               CMP     R11, #11                        \n"\r
644                         "               BNE     prvDeleteMe                     \n"\r
645                         "               CMP     R12, #12                        \n"\r
646                         "               BNE     prvDeleteMe                     \n"\r
647             :::"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r8", "r9", "r10", "r11", "r12"\r
648                 );\r
649 \r
650                 /* Send mainREG_TEST_2_STILL_EXECUTING to the check task to indicate that this\r
651                 task is still functioning. */\r
652                 prvSendImAlive( xQueue, mainREG_TEST_2_STILL_EXECUTING );\r
653 \r
654                 /* Go back to check all the register values again. */\r
655                 __asm volatile( "               B reg2loop      " );\r
656         }\r
657 }\r
658 /*-----------------------------------------------------------*/\r
659 \r
660 void vApplicationIdleHook( void )\r
661 {\r
662 extern unsigned long __SRAM_segment_end__[];\r
663 extern unsigned long __privileged_data_start__[];\r
664 extern unsigned long __privileged_data_end__[];\r
665 extern unsigned long __FLASH_segment_start__[];\r
666 extern unsigned long __FLASH_segment_end__[];\r
667 volatile unsigned long *pul;\r
668 volatile unsigned long ulReadData;\r
669 \r
670         /* The idle task, and therefore this function, run in Supervisor mode and\r
671         can therefore access all memory.  Try reading from corners of flash and\r
672         RAM to ensure a memory fault does not occur.\r
673 \r
674         Start with the edges of the privileged data area. */\r
675         pul = __privileged_data_start__;\r
676         ulReadData = *pul;\r
677         pul = __privileged_data_end__ - 1;\r
678         ulReadData = *pul;\r
679 \r
680         /* Next the standard SRAM area. */\r
681         pul = __SRAM_segment_end__ - 1;\r
682         ulReadData = *pul;\r
683 \r
684         /* And the standard Flash area - the start of which is marked for\r
685         privileged access only. */\r
686         pul = __FLASH_segment_start__;\r
687         ulReadData = *pul;\r
688         pul = __FLASH_segment_end__ - 1;\r
689         ulReadData = *pul;\r
690 \r
691         /* Reading off the end of Flash or SRAM space should cause a fault.\r
692         Uncomment one of the following two pairs of lines to test. */\r
693 \r
694         /* pul = __FLASH_segment_end__ + 4;\r
695         ulReadData = *pul; */\r
696 \r
697         /* pul = __SRAM_segment_end__ + 1;\r
698         ulReadData = *pul; */\r
699 \r
700         ( void ) ulReadData;\r
701 }\r
702 /*-----------------------------------------------------------*/\r
703 \r
704 static void prvOldStyleUserModeTask( void *pvParameters )\r
705 {\r
706 extern unsigned long __privileged_data_start__[];\r
707 extern unsigned long __privileged_data_end__[];\r
708 extern unsigned long __SRAM_segment_end__[];\r
709 extern unsigned long __privileged_functions_end__[];\r
710 extern unsigned long __FLASH_segment_start__[];\r
711 extern unsigned long __FLASH_segment_end__[];\r
712 const volatile unsigned long *pulStandardPeripheralRegister = ( volatile unsigned long * ) 0x400FC0C4; /* PCONP */\r
713 volatile unsigned long *pul;\r
714 volatile unsigned long ulReadData;\r
715 \r
716 /* The following lines are commented out to prevent the unused variable\r
717 compiler warnings when the tests that use the variable are also commented out.\r
718 extern unsigned long __privileged_functions_start__[];\r
719 const volatile unsigned long *pulSystemPeripheralRegister = ( volatile unsigned long * ) 0xe000e014; */\r
720 \r
721         ( void ) pvParameters;\r
722 \r
723         /* This task is created in User mode using the original xTaskCreate() API\r
724         function.  It should have access to all Flash and RAM except that marked\r
725         as Privileged access only.  Reading from the start and end of the non-\r
726         privileged RAM should not cause a problem (the privileged RAM is the first\r
727         block at the bottom of the RAM memory). */\r
728         pul = __privileged_data_end__ + 1;\r
729         ulReadData = *pul;\r
730         pul = __SRAM_segment_end__ - 1;\r
731         ulReadData = *pul;\r
732 \r
733         /* Likewise reading from the start and end of the non-privileged Flash\r
734         should not be a problem (the privileged Flash is the first block at the\r
735         bottom of the Flash memory). */\r
736         pul = __privileged_functions_end__ + 1;\r
737         ulReadData = *pul;\r
738         pul = __FLASH_segment_end__ - 1;\r
739         ulReadData = *pul;\r
740 \r
741         /* Standard peripherals are accessible. */\r
742         ulReadData = *pulStandardPeripheralRegister;\r
743 \r
744         /* System peripherals are not accessible.  Uncomment the following line\r
745         to test.  Also uncomment the declaration of pulSystemPeripheralRegister\r
746         at the top of this function. */\r
747     /* ulReadData = *pulSystemPeripheralRegister; */\r
748 \r
749         /* Reading from anywhere inside the privileged Flash or RAM should cause a\r
750         fault.  This can be tested by uncommenting any of the following pairs of\r
751         lines.  Also uncomment the declaration of __privileged_functions_start__\r
752         at the top of this function. */\r
753 \r
754         /* pul = __privileged_functions_start__;\r
755         ulReadData = *pul; */\r
756 \r
757         /* pul = __privileged_functions_end__ - 1;\r
758         ulReadData = *pul; */\r
759 \r
760         /* pul = __privileged_data_start__;\r
761         ulReadData = *pul; */\r
762 \r
763         /* pul = __privileged_data_end__ - 1;\r
764         ulReadData = *pul; */\r
765 \r
766         /* Must not just run off the end of a task function, so delete this task.\r
767         Note that because this task was created using xTaskCreate() the stack was\r
768         allocated dynamically and I have not included any code to free it again. */\r
769         vTaskDelete( NULL );\r
770 \r
771         ( void ) ulReadData;\r
772 }\r
773 /*-----------------------------------------------------------*/\r
774 \r
775 static void prvOldStylePrivilegedModeTask( void *pvParameters )\r
776 {\r
777 extern unsigned long __privileged_data_start__[];\r
778 extern unsigned long __privileged_data_end__[];\r
779 extern unsigned long __SRAM_segment_end__[];\r
780 extern unsigned long __privileged_functions_start__[];\r
781 extern unsigned long __privileged_functions_end__[];\r
782 extern unsigned long __FLASH_segment_start__[];\r
783 extern unsigned long __FLASH_segment_end__[];\r
784 volatile unsigned long *pul;\r
785 volatile unsigned long ulReadData;\r
786 const volatile unsigned long *pulSystemPeripheralRegister = ( volatile unsigned long * ) 0xe000e014; /* Systick */\r
787 const volatile unsigned long *pulStandardPeripheralRegister = ( volatile unsigned long * ) 0x400FC0C4; /* PCONP */\r
788 \r
789         ( void ) pvParameters;\r
790 \r
791         /* This task is created in Privileged mode using the original xTaskCreate()\r
792         API     function.  It should have access to all Flash and RAM including that\r
793         marked as Privileged access only.  So reading from the start and end of the\r
794         non-privileged RAM should not cause a problem (the privileged RAM is the\r
795         first block at the bottom of the RAM memory). */\r
796         pul = __privileged_data_end__ + 1;\r
797         ulReadData = *pul;\r
798         pul = __SRAM_segment_end__ - 1;\r
799         ulReadData = *pul;\r
800 \r
801         /* Likewise reading from the start and end of the non-privileged Flash\r
802         should not be a problem (the privileged Flash is the first block at the\r
803         bottom of the Flash memory). */\r
804         pul = __privileged_functions_end__ + 1;\r
805         ulReadData = *pul;\r
806         pul = __FLASH_segment_end__ - 1;\r
807         ulReadData = *pul;\r
808 \r
809         /* Reading from anywhere inside the privileged Flash or RAM should also\r
810         not be a problem. */\r
811         pul = __privileged_functions_start__;\r
812         ulReadData = *pul;\r
813         pul = __privileged_functions_end__ - 1;\r
814         ulReadData = *pul;\r
815         pul = __privileged_data_start__;\r
816         ulReadData = *pul;\r
817         pul = __privileged_data_end__ - 1;\r
818         ulReadData = *pul;\r
819 \r
820         /* Finally, accessing both System and normal peripherals should both be\r
821         possible. */\r
822     ulReadData = *pulSystemPeripheralRegister;\r
823         ulReadData = *pulStandardPeripheralRegister;\r
824 \r
825         /* Must not just run off the end of a task function, so delete this task.\r
826         Note that because this task was created using xTaskCreate() the stack was\r
827         allocated dynamically and I have not included any code to free it again. */\r
828         vTaskDelete( NULL );\r
829 \r
830         ( void ) ulReadData;\r
831 }\r
832 /*-----------------------------------------------------------*/\r
833 \r
834 static void prvDeleteMe( void )\r
835 {\r
836         vTaskDelete( NULL );\r
837 }\r
838 /*-----------------------------------------------------------*/\r
839 \r
840 static void prvSendImAlive( xQueueHandle xHandle, unsigned long ulTaskNumber )\r
841 {\r
842         if( xHandle != NULL )\r
843         {\r
844                 xQueueSend( xHandle, &ulTaskNumber, mainDONT_BLOCK );\r
845         }\r
846 }\r
847 /*-----------------------------------------------------------*/\r
848 \r
849 static void prvSetupHardware( void )\r
850 {\r
851         /* If running on Rev A2 silicon, turn the LDO voltage up to 2.75V.  This is\r
852         a workaround to allow the PLL to operate reliably. */\r
853         if( DEVICE_IS_REVA2 )\r
854         {\r
855                 SysCtlLDOSet( SYSCTL_LDO_2_75V );\r
856         }\r
857 \r
858         /* Set the clocking to run from the PLL at 50 MHz */\r
859         SysCtlClockSet( SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ );\r
860 }\r
861 /*-----------------------------------------------------------*/\r
862 \r
863 void vApplicationTickHook( void )\r
864 {\r
865 static unsigned long ulCallCount;\r
866 const unsigned long ulCallsBetweenSends = 5000 / portTICK_RATE_MS;\r
867 const unsigned long ulMessage = mainPRINT_SYSTEM_STATUS;\r
868 portBASE_TYPE xDummy;\r
869 \r
870         /* If configUSE_TICK_HOOK is set to 1 then this function will get called\r
871         from each RTOS tick.  It is called from the tick interrupt and therefore\r
872         will be executing in the privileged state. */\r
873 \r
874         ulCallCount++;\r
875 \r
876         /* Is it time to print out the pass/fail message again? */\r
877         if( ulCallCount >= ulCallsBetweenSends )\r
878         {\r
879                 ulCallCount = 0;\r
880 \r
881                 /* Send a message to the check task to command it to check that all\r
882                 the tasks are still running then print out the status.\r
883 \r
884                 This is running in an ISR so has to use the "FromISR" version of\r
885                 xQueueSend().  Because it is in an ISR it is running with privileges\r
886                 so can access xFileScopeCheckQueue directly. */\r
887                 xQueueSendFromISR( xFileScopeCheckQueue, &ulMessage, &xDummy );\r
888         }\r
889 }\r
890 /*-----------------------------------------------------------*/\r
891 \r
892 void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )\r
893 {\r
894         /* If configCHECK_FOR_STACK_OVERFLOW is set to either 1 or 2 then this\r
895         function will automatically get called if a task overflows its stack. */\r
896         ( void ) pxTask;\r
897         ( void ) pcTaskName;\r
898         for( ;; );\r
899 }\r
900 /*-----------------------------------------------------------*/\r
901 \r
902 void vApplicationMallocFailedHook( void )\r
903 {\r
904         /* If configUSE_MALLOC_FAILED_HOOK is set to 1 then this function will\r
905         be called automatically if a call to pvPortMalloc() fails.  pvPortMalloc()\r
906         is called automatically when a task, queue or semaphore is created. */\r
907         for( ;; );\r
908 }\r
909 /*-----------------------------------------------------------*/\r
910 \r
911 /* Just to keep the linker happy. */\r
912 void __error__( char *pcFilename, unsigned long ulLine )\r
913 {\r
914         ( void ) pcFilename;\r
915         ( void ) ulLine;\r
916         for( ;; );\r
917 }\r
918 /*-----------------------------------------------------------*/\r
919 \r
920 /* Just to keep the linker happy. */\r
921 int uipprintf( const char *fmt, ... )\r
922 {\r
923         ( void ) fmt;\r
924         return( 0 );\r
925 }\r
926 /*-----------------------------------------------------------*/\r
927 \r
928 void hard_fault_handler(unsigned int * hardfault_args)\r
929 {\r
930 volatile unsigned int stacked_r0;\r
931 volatile unsigned int stacked_r1;\r
932 volatile unsigned int stacked_r2;\r
933 volatile unsigned int stacked_r3;\r
934 volatile unsigned int stacked_r12;\r
935 volatile unsigned int stacked_lr;\r
936 volatile unsigned int stacked_pc;\r
937 volatile unsigned int stacked_psr;\r
938 \r
939         stacked_r0 = ((unsigned long) hardfault_args[0]);\r
940         stacked_r1 = ((unsigned long) hardfault_args[1]);\r
941         stacked_r2 = ((unsigned long) hardfault_args[2]);\r
942         stacked_r3 = ((unsigned long) hardfault_args[3]);\r
943 \r
944         stacked_r12 = ((unsigned long) hardfault_args[4]);\r
945         stacked_lr = ((unsigned long) hardfault_args[5]);\r
946         stacked_pc = ((unsigned long) hardfault_args[6]);\r
947         stacked_psr = ((unsigned long) hardfault_args[7]);\r
948 \r
949         /* Inspect stacked_pc to locate the offending instruction. */\r
950         for( ;; );\r
951 \r
952         ( void ) stacked_psr;\r
953         ( void ) stacked_pc;\r
954         ( void ) stacked_lr;\r
955         ( void ) stacked_r12;\r
956     ( void ) stacked_r0;\r
957     ( void ) stacked_r1;\r
958     ( void ) stacked_r2;\r
959     ( void ) stacked_r3;\r
960 }\r
961 /*-----------------------------------------------------------*/\r
962 \r
963 void Fault_ISR( void ) __attribute__((naked));\r
964 void Fault_ISR( void )\r
965 {\r
966         __asm volatile\r
967         (\r
968                 " tst lr, #4                                                                            \n"\r
969                 " ite eq                                                                                        \n"\r
970                 " mrseq r0, msp                                                                         \n"\r
971                 " mrsne r0, psp                                                                         \n"\r
972                 " ldr r1, [r0, #24]                                                                     \n"\r
973                 " ldr r2, handler_address_const                                         \n"\r
974                 " bx r2                                                                                         \n"\r
975                 " handler_address_const: .word hard_fault_handler       \n"\r
976         );\r
977 }\r
978 /*-----------------------------------------------------------*/\r
979 \r
980 void MPU_Fault_ISR( void ) __attribute__((naked));\r
981 void MPU_Fault_ISR( void )\r
982 {\r
983         __asm volatile\r
984         (\r
985                 " tst lr, #4                                                                            \n"\r
986                 " ite eq                                                                                        \n"\r
987                 " mrseq r0, msp                                                                         \n"\r
988                 " mrsne r0, psp                                                                         \n"\r
989                 " ldr r1, [r0, #24]                                                                     \n"\r
990                 " ldr r2, handler_address_const                                         \n"\r
991                 " bx r2                                                                                         \n"\r
992                 " handler2_address_const: .word hard_fault_handler      \n"\r
993         );\r
994 }\r
995 /*-----------------------------------------------------------*/