2 FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\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
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
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
25 ***************************************************************************
\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
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
37 ***************************************************************************
\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
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
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
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
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
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
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
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.
\r
79 * In addition a queue is used to demonstrate passing data between
\r
80 * protected/restricted tasks as well as passing data between an interrupt and
\r
81 * a protected/restricted task, and a software timer is used.
\r
84 /* Standard includes. */
\r
87 /* Scheduler includes. */
\r
88 #include "FreeRTOS.h"
\r
93 #include "event_groups.h"
\r
95 /*-----------------------------------------------------------*/
\r
97 /* Misc constants. */
\r
98 #define mainDONT_BLOCK ( 0 )
\r
100 /* Definitions for the messages that can be sent to the check task. */
\r
101 #define mainREG_TEST_1_STILL_EXECUTING ( 0 )
\r
102 #define mainREG_TEST_2_STILL_EXECUTING ( 1 )
\r
103 #define mainPRINT_SYSTEM_STATUS ( 2 )
\r
105 /* GCC specifics. */
\r
106 #define mainALIGN_TO( x ) __attribute__((aligned(x)))
\r
108 /* Hardware register addresses. */
\r
109 #define mainVTOR ( * ( volatile uint32_t * ) 0xE000ED08 )
\r
110 #define mainNVIC_AUX_ACTLR ( * ( volatile uint32_t * ) 0xE000E008 )
\r
111 #define mainEC_INTERRUPT_CONTROL ( * ( volatile uint32_t * ) 0x4000FC18 )
\r
113 /* The period of the timer must be less than the rate at which
\r
114 mainPRINT_SYSTEM_STATUS messages are sent to the check task - otherwise the
\r
115 check task will think the timer has stopped. */
\r
116 #define mainTIMER_PERIOD pdMS_TO_TICKS( 200 )
\r
118 /* The name of the task that is deleted by the Idle task is used in a couple of
\r
119 places, so is #defined. */
\r
120 #define mainTASK_TO_DELETE_NAME "DeleteMe"
\r
122 /*-----------------------------------------------------------*/
\r
123 /* Prototypes for functions that implement tasks. -----------*/
\r
124 /*-----------------------------------------------------------*/
\r
127 * Prototype for the reg test tasks. Amongst other things, these fill the CPU
\r
128 * registers with known values before checking that the registers still contain
\r
129 * the expected values. Each of the two tasks use different values so an error
\r
130 * in the context switch mechanism can be caught. Both reg test tasks execute
\r
131 * at the idle priority so will get preempted regularly. Each task repeatedly
\r
132 * sends a message on a queue so long as it remains functioning correctly. If
\r
133 * an error is detected within the task the task is simply deleted.
\r
135 static void prvRegTest1Task( void *pvParameters );
\r
136 static void prvRegTest2Task( void *pvParameters );
\r
139 * Prototype for the check task. The check task demonstrates various features
\r
140 * of the MPU before entering a loop where it waits for messages to arrive on a
\r
143 * Two types of messages can be processes:
\r
145 * 1) "I'm Alive" messages sent from the reg test tasks, indicating that the
\r
146 * task is still operational.
\r
148 * 2) "Print Status commands" sent periodically by the tick hook function (and
\r
149 * therefore from within an interrupt) which command the check task to write
\r
150 * either pass or fail to the terminal, depending on the status of the reg
\r
153 static void prvCheckTask( void *pvParameters );
\r
156 * Prototype for a task created in User mode using the original vTaskCreate()
\r
157 * API function. The task demonstrates the characteristics of such a task,
\r
158 * before simply deleting itself.
\r
160 static void prvOldStyleUserModeTask( void *pvParameters );
\r
163 * Prototype for a task created in Privileged mode using the original
\r
164 * vTaskCreate() API function. The task demonstrates the characteristics of
\r
165 * such a task, before simply deleting itself.
\r
167 static void prvOldStylePrivilegedModeTask( void *pvParameters );
\r
170 * A task that exercises the API of various RTOS objects before being deleted by
\r
171 * the Idle task. This is done for MPU API code coverage test purposes.
\r
173 static void prvTaskToDelete( void *pvParameters );
\r
176 * Functions called by prvTaskToDelete() to exercise the MPU API.
\r
178 static void prvExerciseEventGroupAPI( void );
\r
179 static void prvExerciseSemaphoreAPI( void );
\r
180 static void prvExerciseTaskNotificationAPI( void );
\r
183 * Just configures any clocks and IO necessary.
\r
185 static void prvSetupHardware( void );
\r
188 * Simply deletes the calling task. The function is provided only because it
\r
189 * is simpler to call from asm code than the normal vTaskDelete() API function.
\r
190 * It has the noinline attribute because it is called from asm code.
\r
192 static void prvDeleteMe( void ) __attribute__((noinline));
\r
195 * Used by both reg test tasks to send messages to the check task. The message
\r
196 * just lets the check task know that the task is still functioning correctly.
\r
197 * If a reg test task detects an error it will delete itself, and in so doing
\r
198 * prevent itself from sending any more 'I'm Alive' messages to the check task.
\r
200 static void prvSendImAlive( QueueHandle_t xHandle, uint32_t ulTaskNumber );
\r
203 * The check task is created with access to three memory regions (plus its
\r
204 * stack). Each memory region is configured with different parameters and
\r
205 * prvTestMemoryRegions() demonstrates what can and cannot be accessed for each
\r
206 * region. prvTestMemoryRegions() also demonstrates a task that was created
\r
207 * as a privileged task settings its own privilege level down to that of a user
\r
210 static void prvTestMemoryRegions( void );
\r
213 * Callback function used with the timer that uses the queue to send messages
\r
214 * to the check task.
\r
216 static void prvTimerCallback( TimerHandle_t xExpiredTimer );
\r
218 /*-----------------------------------------------------------*/
\r
220 /* The handle of the queue used to communicate between tasks and between tasks
\r
221 and interrupts. Note that this is a file scope variable that falls outside of
\r
222 any MPU region. As such other techniques have to be used to allow the tasks
\r
223 to gain access to the queue. See the comments in the tasks themselves for
\r
224 further information. */
\r
225 static QueueHandle_t xFileScopeCheckQueue = NULL;
\r
227 /* Holds the handle of a task that is deleted in the idle task hook - this is
\r
228 done for code coverage test purposes only. */
\r
229 static TaskHandle_t xTaskToDelete = NULL;
\r
231 /* The timer that periodically sends data to the check task on the queue. */
\r
232 static TimerHandle_t xTimer = NULL;
\r
234 /*-----------------------------------------------------------*/
\r
235 /* Data used by the 'check' task. ---------------------------*/
\r
236 /*-----------------------------------------------------------*/
\r
238 /* Define the constants used to allocate the check task stack. Note that the
\r
239 stack size is defined in words, not bytes. */
\r
240 #define mainCHECK_TASK_STACK_SIZE_WORDS 128
\r
241 #define mainCHECK_TASK_STACK_ALIGNMENT ( mainCHECK_TASK_STACK_SIZE_WORDS * sizeof( portSTACK_TYPE ) )
\r
243 /* Declare the stack that will be used by the check task. The kernel will
\r
244 automatically create an MPU region for the stack. The stack alignment must
\r
245 match its size, so if 128 words are reserved for the stack then it must be
\r
246 aligned to ( 128 * 4 ) bytes. */
\r
247 static portSTACK_TYPE xCheckTaskStack[ mainCHECK_TASK_STACK_SIZE_WORDS ] mainALIGN_TO( mainCHECK_TASK_STACK_ALIGNMENT );
\r
249 /* Declare three arrays - an MPU region will be created for each array
\r
250 using the TaskParameters_t structure below. THIS IS JUST TO DEMONSTRATE THE
\r
251 MPU FUNCTIONALITY, the data is not used by the check tasks primary function
\r
252 of monitoring the reg test tasks and printing out status information.
\r
254 Note that the arrays allocate slightly more RAM than is actually assigned to
\r
255 the MPU region. This is to permit writes off the end of the array to be
\r
256 detected even when the arrays are placed in adjacent memory locations (with no
\r
257 gaps between them). The align size must be a power of two. */
\r
258 #define mainREAD_WRITE_ARRAY_SIZE 130
\r
259 #define mainREAD_WRITE_ALIGN_SIZE 128
\r
260 char cReadWriteArray[ mainREAD_WRITE_ARRAY_SIZE ] mainALIGN_TO( mainREAD_WRITE_ALIGN_SIZE );
\r
262 #define mainREAD_ONLY_ARRAY_SIZE 260
\r
263 #define mainREAD_ONLY_ALIGN_SIZE 256
\r
264 char cReadOnlyArray[ mainREAD_ONLY_ARRAY_SIZE ] mainALIGN_TO( mainREAD_ONLY_ALIGN_SIZE );
\r
266 #define mainPRIVILEGED_ONLY_ACCESS_ARRAY_SIZE 130
\r
267 #define mainPRIVILEGED_ONLY_ACCESS_ALIGN_SIZE 128
\r
268 char cPrivilegedOnlyAccessArray[ mainPRIVILEGED_ONLY_ACCESS_ALIGN_SIZE ] mainALIGN_TO( mainPRIVILEGED_ONLY_ACCESS_ALIGN_SIZE );
\r
270 /* Fill in a TaskParameters_t structure to define the check task - this is the
\r
271 structure passed to the xTaskCreateRestricted() function. */
\r
272 static const TaskParameters_t xCheckTaskParameters =
\r
274 prvCheckTask, /* pvTaskCode - the function that implements the task. */
\r
275 "Check", /* pcName */
\r
276 mainCHECK_TASK_STACK_SIZE_WORDS, /* usStackDepth - defined in words, not bytes. */
\r
277 ( void * ) 0x12121212, /* pvParameters - this value is just to test that the parameter is being passed into the task correctly. */
\r
278 ( 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
279 xCheckTaskStack, /* puxStackBuffer - the array to use as the task stack, as declared above. */
\r
281 /* xRegions - In this case the xRegions array is used to create MPU regions
\r
282 for all three of the arrays declared directly above. Each MPU region is
\r
283 created with different parameters. Again, THIS IS JUST TO DEMONSTRATE THE
\r
284 MPU FUNCTIONALITY, the data is not used by the check tasks primary function
\r
285 of monitoring the reg test tasks and printing out status information.*/
\r
287 /* Base address Length Parameters */
\r
288 { cReadWriteArray, mainREAD_WRITE_ALIGN_SIZE, portMPU_REGION_READ_WRITE },
\r
289 { cReadOnlyArray, mainREAD_ONLY_ALIGN_SIZE, portMPU_REGION_READ_ONLY },
\r
290 { cPrivilegedOnlyAccessArray, mainPRIVILEGED_ONLY_ACCESS_ALIGN_SIZE, portMPU_REGION_PRIVILEGED_READ_WRITE }
\r
296 /*-----------------------------------------------------------*/
\r
297 /* Data used by the 'reg test' tasks. -----------------------*/
\r
298 /*-----------------------------------------------------------*/
\r
300 /* Define the constants used to allocate the reg test task stacks. Note that
\r
301 that stack size is defined in words, not bytes. */
\r
302 #define mainREG_TEST_STACK_SIZE_WORDS 128
\r
303 #define mainREG_TEST_STACK_ALIGNMENT ( mainREG_TEST_STACK_SIZE_WORDS * sizeof( portSTACK_TYPE ) )
\r
305 /* Declare the stacks that will be used by the reg test tasks. The kernel will
\r
306 automatically create an MPU region for the stack. The stack alignment must
\r
307 match its size, so if 128 words are reserved for the stack then it must be
\r
308 aligned to ( 128 * 4 ) bytes. */
\r
309 static portSTACK_TYPE xRegTest1Stack[ mainREG_TEST_STACK_SIZE_WORDS ] mainALIGN_TO( mainREG_TEST_STACK_ALIGNMENT );
\r
310 static portSTACK_TYPE xRegTest2Stack[ mainREG_TEST_STACK_SIZE_WORDS ] mainALIGN_TO( mainREG_TEST_STACK_ALIGNMENT );
\r
312 /* Fill in a TaskParameters_t structure per reg test task to define the tasks. */
\r
313 static const TaskParameters_t xRegTest1Parameters =
\r
315 prvRegTest1Task, /* pvTaskCode - the function that implements the task. */
\r
316 "RegTest1", /* pcName */
\r
317 mainREG_TEST_STACK_SIZE_WORDS, /* usStackDepth */
\r
318 ( void * ) 0x12345678, /* pvParameters - this value is just to test that the parameter is being passed into the task correctly. */
\r
319 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
320 xRegTest1Stack, /* puxStackBuffer - the array to use as the task stack, as declared above. */
\r
321 { /* xRegions - this task does not use any non-stack data hence all members are zero. */
\r
322 /* Base address Length Parameters */
\r
323 { 0x00, 0x00, 0x00 },
\r
324 { 0x00, 0x00, 0x00 },
\r
325 { 0x00, 0x00, 0x00 }
\r
328 /*-----------------------------------------------------------*/
\r
330 static TaskParameters_t xRegTest2Parameters =
\r
332 prvRegTest2Task, /* pvTaskCode - the function that implements the task. */
\r
333 "RegTest2", /* pcName */
\r
334 mainREG_TEST_STACK_SIZE_WORDS, /* usStackDepth */
\r
335 ( void * ) NULL, /* pvParameters - this task uses the parameter to pass in a queue handle, but the queue is not created yet. */
\r
336 tskIDLE_PRIORITY, /* uxPriority */
\r
337 xRegTest2Stack, /* puxStackBuffer - the array to use as the task stack, as declared above. */
\r
338 { /* xRegions - this task does not use any non-stack data hence all members are zero. */
\r
339 /* Base address Length Parameters */
\r
340 { 0x00, 0x00, 0x00 },
\r
341 { 0x00, 0x00, 0x00 },
\r
342 { 0x00, 0x00, 0x00 }
\r
346 /*-----------------------------------------------------------*/
\r
348 /*-----------------------------------------------------------*/
\r
349 /* Configures the task that is deleted. ---------------------*/
\r
350 /*-----------------------------------------------------------*/
\r
352 /* Define the constants used to allocate the stack of the task that is
\r
353 deleted. Note that that stack size is defined in words, not bytes. */
\r
354 #define mainDELETE_TASK_STACK_SIZE_WORDS 128
\r
355 #define mainTASK_TO_DELETE_STACK_ALIGNMENT ( mainDELETE_TASK_STACK_SIZE_WORDS * sizeof( portSTACK_TYPE ) )
\r
357 /* Declare the stack that will be used by the task that gets deleted. The
\r
358 kernel will automatically create an MPU region for the stack. The stack
\r
359 alignment must match its size, so if 128 words are reserved for the stack
\r
360 then it must be aligned to ( 128 * 4 ) bytes. */
\r
361 static portSTACK_TYPE xDeleteTaskStack[ mainDELETE_TASK_STACK_SIZE_WORDS ] mainALIGN_TO( mainTASK_TO_DELETE_STACK_ALIGNMENT );
\r
363 static TaskParameters_t xTaskToDeleteParameters =
\r
365 prvTaskToDelete, /* pvTaskCode - the function that implements the task. */
\r
366 mainTASK_TO_DELETE_NAME, /* pcName */
\r
367 mainDELETE_TASK_STACK_SIZE_WORDS, /* usStackDepth */
\r
368 ( void * ) NULL, /* pvParameters - this task uses the parameter to pass in a queue handle, but the queue is not created yet. */
\r
369 tskIDLE_PRIORITY + 1, /* uxPriority */
\r
370 xDeleteTaskStack, /* puxStackBuffer - the array to use as the task stack, as declared above. */
\r
371 { /* xRegions - this task does not use any non-stack data hence all members are zero. */
\r
372 /* Base address Length Parameters */
\r
373 { 0x00, 0x00, 0x00 },
\r
374 { 0x00, 0x00, 0x00 },
\r
375 { 0x00, 0x00, 0x00 }
\r
379 /*-----------------------------------------------------------*/
\r
383 prvSetupHardware();
\r
385 /* Create the queue used to pass "I'm alive" messages to the check task. */
\r
386 xFileScopeCheckQueue = xQueueCreate( 1, sizeof( uint32_t ) );
\r
388 /* One check task uses the task parameter to receive the queue handle.
\r
389 This allows the file scope variable to be accessed from within the task.
\r
390 The pvParameters member of xRegTest2Parameters can only be set after the
\r
391 queue has been created so is set here. */
\r
392 xRegTest2Parameters.pvParameters = xFileScopeCheckQueue;
\r
394 /* Create the three test tasks. Handles to the created tasks are not
\r
395 required, hence the second parameter is NULL. */
\r
396 xTaskCreateRestricted( &xRegTest1Parameters, NULL );
\r
397 xTaskCreateRestricted( &xRegTest2Parameters, NULL );
\r
398 xTaskCreateRestricted( &xCheckTaskParameters, NULL );
\r
400 /* Create a task that does nothing but ensure some of the MPU API functions
\r
401 can be called correctly, then get deleted. This is done for code coverage
\r
402 test purposes only. The task's handle is saved in xTaskToDelete so it can
\r
403 get deleted in the idle task hook. */
\r
404 xTaskCreateRestricted( &xTaskToDeleteParameters, &xTaskToDelete );
\r
406 /* Create the tasks that are created using the original xTaskCreate() API
\r
408 xTaskCreate( prvOldStyleUserModeTask, /* The function that implements the task. */
\r
409 "Task1", /* Text name for the task. */
\r
410 100, /* Stack depth in words. */
\r
411 NULL, /* Task parameters. */
\r
412 3, /* Priority and mode (user in this case). */
\r
416 xTaskCreate( prvOldStylePrivilegedModeTask, /* The function that implements the task. */
\r
417 "Task2", /* Text name for the task. */
\r
418 100, /* Stack depth in words. */
\r
419 NULL, /* Task parameters. */
\r
420 ( 3 | portPRIVILEGE_BIT ), /* Priority and mode. */
\r
424 /* Create and start the software timer. */
\r
425 xTimer = xTimerCreate( "Timer", /* Test name for the timer. */
\r
426 mainTIMER_PERIOD, /* Period of the timer. */
\r
427 pdTRUE, /* The timer will auto-reload itself. */
\r
428 ( void * ) 0, /* The timer's ID is used to count the number of times it expires - initialise this to 0. */
\r
429 prvTimerCallback ); /* The function called when the timer expires. */
\r
430 configASSERT( xTimer );
\r
431 xTimerStart( xTimer, mainDONT_BLOCK );
\r
433 /* Start the scheduler. */
\r
434 vTaskStartScheduler();
\r
436 /* Will only get here if there was insufficient memory to create the idle
\r
441 /*-----------------------------------------------------------*/
\r
443 static void prvCheckTask( void *pvParameters )
\r
445 /* This task is created in privileged mode so can access the file scope
\r
446 queue variable. Take a stack copy of this before the task is set into user
\r
447 mode. Once that task is in user mode the file scope queue variable will no
\r
448 longer be accessible but the stack copy will. */
\r
449 QueueHandle_t xQueue = xFileScopeCheckQueue;
\r
451 uint32_t ulStillAliveCounts[ 2 ] = { 0 };
\r
452 const char *pcStatusMessage = "PASS\r\n";
\r
453 volatile uint32_t ulStatus = pdPASS;
\r
456 /* Just to remove compiler warning. */
\r
457 ( void ) pvParameters;
\r
459 /* Demonstrate how the various memory regions can and can't be accessed.
\r
460 The task privilege level is set down to user mode within this function. */
\r
461 prvTestMemoryRegions();
\r
463 /* Tests are done so lower the privilege status. */
\r
464 portSWITCH_TO_USER_MODE();
\r
466 /* This loop performs the main function of the task, which is blocking
\r
467 on a message queue then processing each message as it arrives. */
\r
470 /* Wait for the next message to arrive. */
\r
471 xQueueReceive( xQueue, &lMessage, portMAX_DELAY );
\r
475 case mainREG_TEST_1_STILL_EXECUTING :
\r
476 /* Message from task 1, so task 1 must still be executing. */
\r
477 ( ulStillAliveCounts[ 0 ] )++;
\r
480 case mainREG_TEST_2_STILL_EXECUTING :
\r
481 /* Message from task 2, so task 2 must still be executing. */
\r
482 ( ulStillAliveCounts[ 1 ] )++;
\r
485 case mainPRINT_SYSTEM_STATUS :
\r
486 /* Message from tick hook, time to print out the system
\r
487 status. If messages has stopped arriving from either reg
\r
488 test task then the status must be set to fail. */
\r
489 if( ( ulStillAliveCounts[ 0 ] == 0 ) || ( ulStillAliveCounts[ 1 ] == 0 ) )
\r
491 /* One or both of the test tasks are no longer sending
\r
492 'still alive' messages. */
\r
493 pcStatusMessage = "FAIL\r\n";
\r
495 /* ulStatus can be viewed (live) in the Keil watch window. */
\r
500 /**** print pcStatusMessage here. ****/
\r
501 ( void ) pcStatusMessage;
\r
503 /* Reset the count of 'still alive' messages. */
\r
504 memset( ulStillAliveCounts, 0x00, sizeof( ulStillAliveCounts ) );
\r
508 /* Something unexpected happened. Delete this task so the
\r
509 error is apparent (no output will be displayed). */
\r
515 /*-----------------------------------------------------------*/
\r
517 static void prvTestMemoryRegions( void )
\r
522 /* The check task (from which this function is called) is created in the
\r
523 Privileged mode. The privileged array can be both read from and written
\r
524 to while this task is privileged. */
\r
525 cPrivilegedOnlyAccessArray[ 0 ] = 'a';
\r
526 if( cPrivilegedOnlyAccessArray[ 0 ] != 'a' )
\r
528 /* Something unexpected happened. Delete this task so the error is
\r
529 apparent (no output will be displayed). */
\r
533 /* Writing off the end of the RAM allocated to this task will *NOT* cause a
\r
534 protection fault because the task is still executing in a privileged mode.
\r
535 Uncomment the following to test. */
\r
536 /*cPrivilegedOnlyAccessArray[ mainPRIVILEGED_ONLY_ACCESS_ALIGN_SIZE ] = 'a';*/
\r
538 /* Now set the task into user mode. */
\r
539 portSWITCH_TO_USER_MODE();
\r
541 /* Accessing the privileged only array will now cause a fault. Uncomment
\r
542 the following line to test. */
\r
543 /*cPrivilegedOnlyAccessArray[ 0 ] = 'a';*/
\r
545 /* The read/write array can still be successfully read and written. */
\r
546 for( x = 0; x < mainREAD_WRITE_ALIGN_SIZE; x++ )
\r
548 cReadWriteArray[ x ] = 'a';
\r
549 if( cReadWriteArray[ x ] != 'a' )
\r
551 /* Something unexpected happened. Delete this task so the error is
\r
552 apparent (no output will be displayed). */
\r
557 /* But attempting to read or write off the end of the RAM allocated to this
\r
558 task will cause a fault. Uncomment either of the following two lines to
\r
560 /* cReadWriteArray[ 0 ] = cReadWriteArray[ -1 ]; */
\r
561 /* cReadWriteArray[ mainREAD_WRITE_ALIGN_SIZE ] = 0x00; */
\r
563 /* The read only array can be successfully read... */
\r
564 for( x = 0; x < mainREAD_ONLY_ALIGN_SIZE; x++ )
\r
566 cTemp = cReadOnlyArray[ x ];
\r
569 /* ...but cannot be written. Uncomment the following line to test. */
\r
570 /* cReadOnlyArray[ 0 ] = 'a'; */
\r
572 /* Writing to the first and last locations in the stack array should not
\r
573 cause a protection fault. Note that doing this will cause the kernel to
\r
574 detect a stack overflow if configCHECK_FOR_STACK_OVERFLOW is greater than
\r
575 1, hence the test is commented out by default. */
\r
576 /* xCheckTaskStack[ 0 ] = 0;
\r
577 xCheckTaskStack[ mainCHECK_TASK_STACK_SIZE_WORDS - 1 ] = 0; */
\r
579 /* Writing off either end of the stack array should cause a protection
\r
580 fault, uncomment either of the following two lines to test. */
\r
581 /* xCheckTaskStack[ -1 ] = 0; */
\r
582 /* xCheckTaskStack[ mainCHECK_TASK_STACK_SIZE_WORDS ] = 0; */
\r
586 /*-----------------------------------------------------------*/
\r
588 static void prvRegTest1Task( void *pvParameters )
\r
590 /* This task is created in privileged mode so can access the file scope
\r
591 queue variable. Take a stack copy of this before the task is set into user
\r
592 mode. Once this task is in user mode the file scope queue variable will no
\r
593 longer be accessible but the stack copy will. */
\r
594 QueueHandle_t xQueue = xFileScopeCheckQueue;
\r
596 /* Now the queue handle has been obtained the task can switch to user
\r
597 mode. This is just one method of passing a handle into a protected
\r
598 task, the other reg test task uses the task parameter instead. */
\r
599 portSWITCH_TO_USER_MODE();
\r
601 /* First check that the parameter value is as expected. */
\r
602 if( pvParameters != ( void * ) 0x12345678 )
\r
604 /* Error detected. Delete the task so it stops communicating with
\r
612 /* This task tests the kernel context switch mechanism by reading and
\r
613 writing directly to registers - which requires the test to be written
\r
614 in assembly code. */
\r
617 " MOV R4, #104 \n" /* Set registers to a known value. R0 to R1 are done in the loop below. */
\r
622 " MOV R10, #110 \n"
\r
623 " MOV R11, #111 \n"
\r
625 " MOV R0, #100 \n" /* Set the scratch registers to known values - done inside the loop as they get clobbered. */
\r
629 " MOV R12, #112 \n"
\r
630 " SVC #1 \n" /* Yield just to increase test coverage. */
\r
631 " CMP R0, #100 \n" /* Check all the registers still contain their expected values. */
\r
632 " BNE prvDeleteMe \n" /* Value was not as expected, delete the task so it stops communicating with the check task. */
\r
634 " BNE prvDeleteMe \n"
\r
636 " BNE prvDeleteMe \n"
\r
638 " BNE prvDeleteMe \n"
\r
640 " BNE prvDeleteMe \n"
\r
642 " BNE prvDeleteMe \n"
\r
644 " BNE prvDeleteMe \n"
\r
646 " BNE prvDeleteMe \n"
\r
648 " BNE prvDeleteMe \n"
\r
649 " CMP R10, #110 \n"
\r
650 " BNE prvDeleteMe \n"
\r
651 " CMP R11, #111 \n"
\r
652 " BNE prvDeleteMe \n"
\r
653 " CMP R12, #112 \n"
\r
654 " BNE prvDeleteMe \n"
\r
655 :::"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r8", "r9", "r10", "r11", "r12"
\r
658 /* Send mainREG_TEST_1_STILL_EXECUTING to the check task to indicate that this
\r
659 task is still functioning. */
\r
660 prvSendImAlive( xQueue, mainREG_TEST_1_STILL_EXECUTING );
\r
662 /* Go back to check all the register values again. */
\r
663 __asm volatile( " B reg1loop " );
\r
666 /*-----------------------------------------------------------*/
\r
668 static void prvRegTest2Task( void *pvParameters )
\r
670 /* The queue handle is passed in as the task parameter. This is one method of
\r
671 passing data into a protected task, the other reg test task uses a different
\r
673 QueueHandle_t xQueue = ( QueueHandle_t ) pvParameters;
\r
677 /* This task tests the kernel context switch mechanism by reading and
\r
678 writing directly to registers - which requires the test to be written
\r
679 in assembly code. */
\r
682 " MOV R4, #4 \n" /* Set registers to a known value. R0 to R1 are done in the loop below. */
\r
685 " MOV R8, #8 \n" /* Frame pointer is omitted as it must not be changed. */
\r
690 " MOV R0, #13 \n" /* Set the scratch registers to known values - done inside the loop as they get clobbered. */
\r
695 " CMP R0, #13 \n" /* Check all the registers still contain their expected values. */
\r
696 " BNE prvDeleteMe \n" /* Value was not as expected, delete the task so it stops communicating with the check task */
\r
698 " BNE prvDeleteMe \n"
\r
700 " BNE prvDeleteMe \n"
\r
702 " BNE prvDeleteMe \n"
\r
704 " BNE prvDeleteMe \n"
\r
706 " BNE prvDeleteMe \n"
\r
708 " BNE prvDeleteMe \n"
\r
710 " BNE prvDeleteMe \n"
\r
712 " BNE prvDeleteMe \n"
\r
714 " BNE prvDeleteMe \n"
\r
716 " BNE prvDeleteMe \n"
\r
718 " BNE prvDeleteMe \n"
\r
719 :::"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r8", "r9", "r10", "r11", "r12"
\r
722 /* Send mainREG_TEST_2_STILL_EXECUTING to the check task to indicate that this
\r
723 task is still functioning. */
\r
724 prvSendImAlive( xQueue, mainREG_TEST_2_STILL_EXECUTING );
\r
726 /* Go back to check all the register values again. */
\r
727 __asm volatile( " B reg2loop " );
\r
730 /*-----------------------------------------------------------*/
\r
732 static void prvExerciseEventGroupAPI( void )
\r
734 EventGroupHandle_t xEventGroup;
\r
736 const EventBits_t xBitsToWaitFor = ( EventBits_t ) 0xff, xBitToClear = ( EventBits_t ) 0x01;
\r
738 /* Exercise some event group functions. */
\r
739 xEventGroup = xEventGroupCreate();
\r
740 configASSERT( xEventGroup );
\r
742 /* No bits should be set. */
\r
743 xBits = xEventGroupWaitBits( xEventGroup, xBitsToWaitFor, pdTRUE, pdFALSE, mainDONT_BLOCK );
\r
744 configASSERT( xBits == ( EventBits_t ) 0 );
\r
746 /* Set bits and read back to ensure the bits were set. */
\r
747 xEventGroupSetBits( xEventGroup, xBitsToWaitFor );
\r
748 xBits = xEventGroupGetBits( xEventGroup );
\r
749 configASSERT( xBits == xBitsToWaitFor );
\r
751 /* Clear a bit and read back again using a different API function. */
\r
752 xEventGroupClearBits( xEventGroup, xBitToClear );
\r
753 xBits = xEventGroupSync( xEventGroup, 0x00, xBitsToWaitFor, mainDONT_BLOCK );
\r
754 configASSERT( xBits == ( xBitsToWaitFor & ~xBitToClear ) );
\r
756 /* Finished with the event group. */
\r
757 vEventGroupDelete( xEventGroup );
\r
759 /*-----------------------------------------------------------*/
\r
761 static void prvExerciseSemaphoreAPI( void )
\r
763 SemaphoreHandle_t xSemaphore;
\r
764 const UBaseType_t uxMaxCount = 5, uxInitialCount = 0;
\r
766 /* Most of the semaphore API is common to the queue API and is already being
\r
767 used. This function uses a few semaphore functions that are unique to the
\r
768 RTOS objects, rather than generic and used by queues also.
\r
770 First create and use a counting semaphore. */
\r
771 xSemaphore = xSemaphoreCreateCounting( uxMaxCount, uxInitialCount );
\r
772 configASSERT( xSemaphore );
\r
774 /* Give the semaphore a couple of times and ensure the count is returned
\r
776 xSemaphoreGive( xSemaphore );
\r
777 xSemaphoreGive( xSemaphore );
\r
778 configASSERT( uxSemaphoreGetCount( xSemaphore ) == 2 );
\r
779 vSemaphoreDelete( xSemaphore );
\r
781 /* Create a recursive mutex, and ensure the mutex holder and count are
\r
782 returned returned correctly. */
\r
783 xSemaphore = xSemaphoreCreateRecursiveMutex();
\r
784 configASSERT( uxSemaphoreGetCount( xSemaphore ) == 1 );
\r
785 configASSERT( xSemaphore );
\r
786 xSemaphoreTakeRecursive( xSemaphore, mainDONT_BLOCK );
\r
787 xSemaphoreTakeRecursive( xSemaphore, mainDONT_BLOCK );
\r
788 configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == xTaskGetCurrentTaskHandle() );
\r
789 configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == xTaskGetHandle( mainTASK_TO_DELETE_NAME ) );
\r
790 xSemaphoreGiveRecursive( xSemaphore );
\r
791 configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 );
\r
792 xSemaphoreGiveRecursive( xSemaphore );
\r
793 configASSERT( uxSemaphoreGetCount( xSemaphore ) == 1 );
\r
794 configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == NULL );
\r
795 vSemaphoreDelete( xSemaphore );
\r
797 /* Create a normal mutex, and sure the mutex holder and count are returned
\r
798 returned correctly. */
\r
799 xSemaphore = xSemaphoreCreateMutex();
\r
800 configASSERT( xSemaphore );
\r
801 xSemaphoreTake( xSemaphore, mainDONT_BLOCK );
\r
802 xSemaphoreTake( xSemaphore, mainDONT_BLOCK );
\r
803 configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 ); /* Not recursive so can only be 1. */
\r
804 configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == xTaskGetCurrentTaskHandle() );
\r
805 xSemaphoreGive( xSemaphore );
\r
806 configASSERT( uxSemaphoreGetCount( xSemaphore ) == 1 );
\r
807 configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == NULL );
\r
808 vSemaphoreDelete( xSemaphore );
\r
810 /*-----------------------------------------------------------*/
\r
812 static void prvExerciseTaskNotificationAPI( void )
\r
814 uint32_t ulNotificationValue;
\r
815 BaseType_t xReturned;
\r
817 /* The task should not yet have a notification pending. */
\r
818 xReturned = xTaskNotifyWait( 0, 0, &ulNotificationValue, mainDONT_BLOCK );
\r
819 configASSERT( xReturned == pdFAIL );
\r
820 configASSERT( ulNotificationValue == 0UL );
\r
822 /* Exercise the 'give' and 'take' versions of the notification API. */
\r
823 xTaskNotifyGive( xTaskGetCurrentTaskHandle() );
\r
824 xTaskNotifyGive( xTaskGetCurrentTaskHandle() );
\r
825 ulNotificationValue = ulTaskNotifyTake( pdTRUE, mainDONT_BLOCK );
\r
826 configASSERT( ulNotificationValue == 2 );
\r
828 /* Exercise the 'notify' and 'clear' API. */
\r
829 ulNotificationValue = 20;
\r
830 xTaskNotify( xTaskGetCurrentTaskHandle(), ulNotificationValue, eSetValueWithOverwrite );
\r
831 ulNotificationValue = 0;
\r
832 xReturned = xTaskNotifyWait( 0, 0, &ulNotificationValue, mainDONT_BLOCK );
\r
833 configASSERT( xReturned == pdPASS );
\r
834 configASSERT( ulNotificationValue == 20 );
\r
835 xTaskNotify( xTaskGetCurrentTaskHandle(), ulNotificationValue, eSetValueWithOverwrite );
\r
836 xReturned = xTaskNotifyStateClear( NULL );
\r
837 configASSERT( xReturned == pdTRUE ); /* First time a notification was pending. */
\r
838 xReturned = xTaskNotifyStateClear( NULL );
\r
839 configASSERT( xReturned == pdFALSE ); /* Second time the notification was already clear. */
\r
841 /*-----------------------------------------------------------*/
\r
843 static void prvTaskToDelete( void *pvParameters )
\r
845 /* Remove compiler warnings about unused parameters. */
\r
846 ( void ) pvParameters;
\r
848 /* Check the enter and exit critical macros are working correctly. If the
\r
849 SVC priority is below configMAX_SYSCALL_INTERRUPT_PRIORITY then this will
\r
851 taskENTER_CRITICAL();
\r
852 taskEXIT_CRITICAL();
\r
854 /* Exercise the API of various RTOS objects. */
\r
855 prvExerciseEventGroupAPI();
\r
856 prvExerciseSemaphoreAPI();
\r
857 prvExerciseTaskNotificationAPI();
\r
859 /* For code coverage test purposes it is deleted by the Idle task. */
\r
860 configASSERT( uxTaskGetStackHighWaterMark( NULL ) > 0 );
\r
861 vTaskSuspend( NULL );
\r
863 /*-----------------------------------------------------------*/
\r
865 void vApplicationIdleHook( void )
\r
867 extern uint32_t __SRAM_segment_end__[];
\r
868 extern uint32_t __privileged_data_start__[];
\r
869 extern uint32_t __privileged_data_end__[];
\r
870 extern uint32_t __FLASH_segment_start__[];
\r
871 extern uint32_t __FLASH_segment_end__[];
\r
872 volatile uint32_t *pul;
\r
873 volatile uint32_t ulReadData;
\r
875 /* The idle task, and therefore this function, run in Supervisor mode and
\r
876 can therefore access all memory. Try reading from corners of flash and
\r
877 RAM to ensure a memory fault does not occur.
\r
879 Start with the edges of the privileged data area. */
\r
880 pul = __privileged_data_start__;
\r
882 pul = __privileged_data_end__ - 1;
\r
885 /* Next the standard SRAM area. */
\r
886 pul = __SRAM_segment_end__ - 1;
\r
889 /* And the standard Flash area - the start of which is marked for
\r
890 privileged access only. */
\r
891 pul = __FLASH_segment_start__;
\r
893 pul = __FLASH_segment_end__ - 1;
\r
896 /* Reading off the end of Flash or SRAM space should cause a fault.
\r
897 Uncomment one of the following two pairs of lines to test. */
\r
899 /* pul = __FLASH_segment_end__ + 4;
\r
900 ulReadData = *pul; */
\r
902 /* pul = __SRAM_segment_end__ + 1;
\r
903 ulReadData = *pul; */
\r
905 /* One task is created purely so it can be deleted - done for code coverage
\r
907 if( xTaskToDelete != NULL )
\r
909 vTaskDelete( xTaskToDelete );
\r
910 xTaskToDelete = NULL;
\r
913 ( void ) ulReadData;
\r
915 /*-----------------------------------------------------------*/
\r
917 static void prvOldStyleUserModeTask( void *pvParameters )
\r
919 extern uint32_t __privileged_data_start__[];
\r
920 extern uint32_t __privileged_data_end__[];
\r
921 extern uint32_t __SRAM_segment_end__[];
\r
922 extern uint32_t __privileged_functions_end__[];
\r
923 extern uint32_t __FLASH_segment_start__[];
\r
924 extern uint32_t __FLASH_segment_end__[];
\r
925 /*const volatile uint32_t *pulStandardPeripheralRegister = ( volatile uint32_t * ) 0x40000000;*/
\r
926 volatile uint32_t *pul;
\r
927 volatile uint32_t ulReadData;
\r
929 /* The following lines are commented out to prevent the unused variable
\r
930 compiler warnings when the tests that use the variable are also commented out. */
\r
931 /*extern uint32_t __privileged_functions_start__[];
\r
932 const volatile uint32_t *pulSystemPeripheralRegister = ( volatile uint32_t * ) 0xe000e014;*/
\r
934 ( void ) pvParameters;
\r
936 /* This task is created in User mode using the original xTaskCreate() API
\r
937 function. It should have access to all Flash and RAM except that marked
\r
938 as Privileged access only. Reading from the start and end of the non-
\r
939 privileged RAM should not cause a problem (the privileged RAM is the first
\r
940 block at the bottom of the RAM memory). */
\r
941 pul = __privileged_data_end__ + 1;
\r
943 pul = __SRAM_segment_end__ - 1;
\r
946 /* Likewise reading from the start and end of the non-privileged Flash
\r
947 should not be a problem (the privileged Flash is the first block at the
\r
948 bottom of the Flash memory). */
\r
949 pul = __privileged_functions_end__ + 1;
\r
951 pul = __FLASH_segment_end__ - 1;
\r
954 /* Standard peripherals are accessible. */
\r
955 /*ulReadData = *pulStandardPeripheralRegister;*/
\r
957 /* System peripherals are not accessible. Uncomment the following line
\r
958 to test. Also uncomment the declaration of pulSystemPeripheralRegister
\r
959 at the top of this function.
\r
960 ulReadData = *pulSystemPeripheralRegister; */
\r
962 /* Reading from anywhere inside the privileged Flash or RAM should cause a
\r
963 fault. This can be tested by uncommenting any of the following pairs of
\r
964 lines. Also uncomment the declaration of __privileged_functions_start__
\r
965 at the top of this function. */
\r
967 /*pul = __privileged_functions_start__;
\r
968 ulReadData = *pul;*/
\r
970 /*pul = __privileged_functions_end__ - 1;
\r
971 ulReadData = *pul;*/
\r
973 /*pul = __privileged_data_start__;
\r
974 ulReadData = *pul;*/
\r
976 /*pul = __privileged_data_end__ - 1;
\r
977 ulReadData = *pul;*/
\r
979 /* Must not just run off the end of a task function, so delete this task.
\r
980 Note that because this task was created using xTaskCreate() the stack was
\r
981 allocated dynamically and I have not included any code to free it again. */
\r
982 vTaskDelete( NULL );
\r
984 ( void ) ulReadData;
\r
986 /*-----------------------------------------------------------*/
\r
988 static void prvOldStylePrivilegedModeTask( void *pvParameters )
\r
990 extern uint32_t __privileged_data_start__[];
\r
991 extern uint32_t __privileged_data_end__[];
\r
992 extern uint32_t __SRAM_segment_end__[];
\r
993 extern uint32_t __privileged_functions_start__[];
\r
994 extern uint32_t __privileged_functions_end__[];
\r
995 extern uint32_t __FLASH_segment_start__[];
\r
996 extern uint32_t __FLASH_segment_end__[];
\r
997 volatile uint32_t *pul;
\r
998 volatile uint32_t ulReadData;
\r
999 const volatile uint32_t *pulSystemPeripheralRegister = ( volatile uint32_t * ) 0xe000e014; /* Systick */
\r
1000 /*const volatile uint32_t *pulStandardPeripheralRegister = ( volatile uint32_t * ) 0x40000000;*/
\r
1002 ( void ) pvParameters;
\r
1004 /* This task is created in Privileged mode using the original xTaskCreate()
\r
1005 API function. It should have access to all Flash and RAM including that
\r
1006 marked as Privileged access only. So reading from the start and end of the
\r
1007 non-privileged RAM should not cause a problem (the privileged RAM is the
\r
1008 first block at the bottom of the RAM memory). */
\r
1009 pul = __privileged_data_end__ + 1;
\r
1010 ulReadData = *pul;
\r
1011 pul = __SRAM_segment_end__ - 1;
\r
1012 ulReadData = *pul;
\r
1014 /* Likewise reading from the start and end of the non-privileged Flash
\r
1015 should not be a problem (the privileged Flash is the first block at the
\r
1016 bottom of the Flash memory). */
\r
1017 pul = __privileged_functions_end__ + 1;
\r
1018 ulReadData = *pul;
\r
1019 pul = __FLASH_segment_end__ - 1;
\r
1020 ulReadData = *pul;
\r
1022 /* Reading from anywhere inside the privileged Flash or RAM should also
\r
1023 not be a problem. */
\r
1024 pul = __privileged_functions_start__;
\r
1025 ulReadData = *pul;
\r
1026 pul = __privileged_functions_end__ - 1;
\r
1027 ulReadData = *pul;
\r
1028 pul = __privileged_data_start__;
\r
1029 ulReadData = *pul;
\r
1030 pul = __privileged_data_end__ - 1;
\r
1031 ulReadData = *pul;
\r
1033 /* Finally, accessing both System and normal peripherals should both be
\r
1035 ulReadData = *pulSystemPeripheralRegister;
\r
1036 /*ulReadData = *pulStandardPeripheralRegister;*/
\r
1038 /* Must not just run off the end of a task function, so delete this task.
\r
1039 Note that because this task was created using xTaskCreate() the stack was
\r
1040 allocated dynamically and I have not included any code to free it again. */
\r
1041 vTaskDelete( NULL );
\r
1043 ( void ) ulReadData;
\r
1045 /*-----------------------------------------------------------*/
\r
1047 static void prvDeleteMe( void )
\r
1049 vTaskDelete( NULL );
\r
1051 /*-----------------------------------------------------------*/
\r
1053 static void prvSendImAlive( QueueHandle_t xHandle, uint32_t ulTaskNumber )
\r
1055 if( xHandle != NULL )
\r
1057 xQueueSend( xHandle, &ulTaskNumber, mainDONT_BLOCK );
\r
1060 /*-----------------------------------------------------------*/
\r
1062 static void prvSetupHardware( void )
\r
1065 /*-----------------------------------------------------------*/
\r
1067 void vApplicationTickHook( void )
\r
1069 static uint32_t ulCallCount;
\r
1070 const uint32_t ulCallsBetweenSends = 5000UL / configTICK_RATE_HZ;
\r
1071 const uint32_t ulMessage = mainPRINT_SYSTEM_STATUS;
\r
1072 portBASE_TYPE xDummy;
\r
1074 /* If configUSE_TICK_HOOK is set to 1 then this function will get called
\r
1075 from each RTOS tick. It is called from the tick interrupt and therefore
\r
1076 will be executing in the privileged state. */
\r
1080 /* Is it time to print out the pass/fail message again? */
\r
1081 if( ulCallCount >= ulCallsBetweenSends )
\r
1085 /* Send a message to the check task to command it to check that all
\r
1086 the tasks are still running then print out the status.
\r
1088 This is running in an ISR so has to use the "FromISR" version of
\r
1089 xQueueSend(). Because it is in an ISR it is running with privileges
\r
1090 so can access xFileScopeCheckQueue directly. */
\r
1091 xQueueSendFromISR( xFileScopeCheckQueue, &ulMessage, &xDummy );
\r
1094 /*-----------------------------------------------------------*/
\r
1096 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
1098 /* If configCHECK_FOR_STACK_OVERFLOW is set to either 1 or 2 then this
\r
1099 function will automatically get called if a task overflows its stack. */
\r
1101 ( void ) pcTaskName;
\r
1104 /*-----------------------------------------------------------*/
\r
1106 void vApplicationMallocFailedHook( void )
\r
1108 /* If configUSE_MALLOC_FAILED_HOOK is set to 1 then this function will
\r
1109 be called automatically if a call to pvPortMalloc() fails. pvPortMalloc()
\r
1110 is called automatically when a task, queue or semaphore is created. */
\r
1113 /*-----------------------------------------------------------*/
\r
1115 void hard_fault_handler( uint32_t * hardfault_args )
\r
1117 volatile uint32_t stacked_r0;
\r
1118 volatile uint32_t stacked_r1;
\r
1119 volatile uint32_t stacked_r2;
\r
1120 volatile uint32_t stacked_r3;
\r
1121 volatile uint32_t stacked_r12;
\r
1122 volatile uint32_t stacked_lr;
\r
1123 volatile uint32_t stacked_pc;
\r
1124 volatile uint32_t stacked_psr;
\r
1126 stacked_r0 = ((uint32_t) hardfault_args[ 0 ]);
\r
1127 stacked_r1 = ((uint32_t) hardfault_args[ 1 ]);
\r
1128 stacked_r2 = ((uint32_t) hardfault_args[ 2 ]);
\r
1129 stacked_r3 = ((uint32_t) hardfault_args[ 3 ]);
\r
1131 stacked_r12 = ((uint32_t) hardfault_args[ 4 ]);
\r
1132 stacked_lr = ((uint32_t) hardfault_args[ 5 ]);
\r
1133 stacked_pc = ((uint32_t) hardfault_args[ 6 ]);
\r
1134 stacked_psr = ((uint32_t) hardfault_args[ 7 ]);
\r
1136 /* Inspect stacked_pc to locate the offending instruction. */
\r
1139 ( void ) stacked_psr;
\r
1140 ( void ) stacked_pc;
\r
1141 ( void ) stacked_lr;
\r
1142 ( void ) stacked_r12;
\r
1143 ( void ) stacked_r0;
\r
1144 ( void ) stacked_r1;
\r
1145 ( void ) stacked_r2;
\r
1146 ( void ) stacked_r3;
\r
1148 /*-----------------------------------------------------------*/
\r
1150 void HardFault_Handler( void ) __attribute__((naked));
\r
1151 void HardFault_Handler( void )
\r
1157 " mrseq r0, msp \n"
\r
1158 " mrsne r0, psp \n"
\r
1159 " ldr r1, [r0, #24] \n"
\r
1160 " ldr r2, handler_address_const \n"
\r
1162 " handler_address_const: .word hard_fault_handler \n"
\r
1165 /*-----------------------------------------------------------*/
\r
1167 void MemManage_Handler( void ) __attribute__((naked));
\r
1168 void MemManage_Handler( void )
\r
1174 " mrseq r0, msp \n"
\r
1175 " mrsne r0, psp \n"
\r
1176 " ldr r1, [r0, #24] \n"
\r
1177 " ldr r2, handler2_address_const \n"
\r
1179 " handler2_address_const: .word hard_fault_handler \n"
\r
1182 /*-----------------------------------------------------------*/
\r
1184 static void prvTimerCallback( TaskHandle_t xExpiredTimer )
\r
1188 /* The count of the number of times this timer has expired is saved in the
\r
1189 timer's ID. Obtain the current count. */
\r
1190 ulCount = ( uint32_t ) pvTimerGetTimerID( xTimer );
\r
1192 /* Increment the count, and save it back into the timer's ID. */
\r
1194 vTimerSetTimerID( xTimer, ( void * ) ulCount );
\r
1196 /*-----------------------------------------------------------*/
\r
1198 /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an
\r
1199 implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
\r
1200 used by the Idle task. */
\r
1201 void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
\r
1203 /* If the buffers to be provided to the Idle task are declared inside this
\r
1204 function then they must be declared static - otherwise they will be allocated on
\r
1205 the stack and so not exists after this function exits. */
\r
1206 static StaticTask_t xIdleTaskTCB;
\r
1207 static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];
\r
1209 /* Pass out a pointer to the StaticTask_t structure in which the Idle task's
\r
1210 state will be stored. */
\r
1211 *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
\r
1213 /* Pass out the array that will be used as the Idle task's stack. */
\r
1214 *ppxIdleTaskStackBuffer = uxIdleTaskStack;
\r
1216 /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
\r
1217 Note that, as the array is necessarily of type StackType_t,
\r
1218 configMINIMAL_STACK_SIZE is specified in words, not bytes. */
\r
1219 *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
\r
1221 /*-----------------------------------------------------------*/
\r
1223 /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
\r
1224 application must provide an implementation of vApplicationGetTimerTaskMemory()
\r
1225 to provide the memory that is used by the Timer service task. */
\r
1226 void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )
\r
1228 /* If the buffers to be provided to the Timer task are declared inside this
\r
1229 function then they must be declared static - otherwise they will be allocated on
\r
1230 the stack and so not exists after this function exits. */
\r
1231 static StaticTask_t xTimerTaskTCB;
\r
1232 static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];
\r
1234 /* Pass out a pointer to the StaticTask_t structure in which the Timer
\r
1235 task's state will be stored. */
\r
1236 *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
\r
1238 /* Pass out the array that will be used as the Timer task's stack. */
\r
1239 *ppxTimerTaskStackBuffer = uxTimerTaskStack;
\r
1241 /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
\r
1242 Note that, as the array is necessarily of type StackType_t,
\r
1243 configMINIMAL_STACK_SIZE is specified in words, not bytes. */
\r
1244 *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
\r