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