2 * FreeRTOS Kernel V10.1.1
\r
3 * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
30 * This file demonstrates the use of FreeRTOS-MPU. It creates tasks in both
\r
31 * User mode and Privileged mode, and using both the xTaskCreate() and
\r
32 * xTaskCreateRestricted() API functions. The purpose of each created task is
\r
33 * documented in the comments above the task function prototype (in this file),
\r
34 * with the task behaviour demonstrated and documented within the task function
\r
37 * In addition a queue is used to demonstrate passing data between
\r
38 * protected/restricted tasks as well as passing data between an interrupt and
\r
39 * a protected/restricted task. A software timer is also used.
\r
42 /* Standard includes. */
\r
45 /* Scheduler includes. */
\r
46 #include "FreeRTOS.h"
\r
51 #include "event_groups.h"
\r
52 #include "stream_buffer.h"
\r
54 /*-----------------------------------------------------------*/
\r
56 /* Misc constants. */
\r
57 #define mainDONT_BLOCK ( 0 )
\r
59 /* GCC specifics. */
\r
60 #define mainALIGN_TO( x ) __attribute__((aligned(x)))
\r
62 /* Hardware register addresses. */
\r
63 #define mainVTOR ( * ( volatile uint32_t * ) 0xE000ED08 )
\r
65 /* The period of the timer must be less than the rate at which
\r
66 configPRINT_SYSTEM_STATUS messages are sent to the check task - otherwise the
\r
67 check task will think the timer has stopped. */
\r
68 #define mainTIMER_PERIOD pdMS_TO_TICKS( 200 )
\r
70 /* The name of the task that is deleted by the Idle task is used in a couple of
\r
71 places, so is #defined. */
\r
72 #define mainTASK_TO_DELETE_NAME "DeleteMe"
\r
74 /*-----------------------------------------------------------*/
\r
75 /* Prototypes for functions that implement tasks. -----------*/
\r
76 /*-----------------------------------------------------------*/
\r
79 * NOTE: The filling and checking of the registers in the following two tasks
\r
80 * is only actually performed when the GCC compiler is used. Use of the
\r
81 * queue to communicate with the check task is done with all compilers.
\r
83 * Prototype for the first two register test tasks, which execute in User mode.
\r
84 * Amongst other things, these fill the CPU registers (other than the FPU
\r
85 * registers) with known values before checking that the registers still contain
\r
86 * the expected values. Each of the two tasks use different values so an error
\r
87 * in the context switch mechanism can be caught. Both tasks execute at the
\r
88 * idle priority so will get preempted regularly. Each task repeatedly sends a
\r
89 * message on a queue to a 'check' task so the check task knows the register
\r
90 * check task is still executing and has not detected any errors. If an error
\r
91 * is detected within the task the task is simply deleted so it no longer sends
\r
94 * For demonstration and test purposes, both tasks obtain access to the queue
\r
95 * handle in different ways; vRegTest1Implementation() is created in Privileged
\r
96 * mode and copies the queue handle to its local stack before setting itself to
\r
97 * User mode, and vRegTest2Implementation() receives the task handle using its
\r
100 extern void vRegTest1Implementation( void *pvParameters );
\r
101 extern void vRegTest2Implementation( void *pvParameters );
\r
104 * The second two register test tasks are similar to the first two, but do test
\r
105 * the floating point registers, execute in Privileged mode, and signal their
\r
106 * execution status to the 'check' task by incrementing a loop counter on each
\r
107 * iteration instead of sending a message on a queue. The loop counters use a
\r
108 * memory region to which the User mode 'check' task has read access.
\r
110 * The functions ending 'Implementation' are called by the register check tasks.
\r
112 static void prvRegTest3Task( void *pvParameters );
\r
113 extern void vRegTest3Implementation( void );
\r
114 static void prvRegTest4Task( void *pvParameters );
\r
115 extern void vRegTest4Implementation( void );
\r
118 * Prototype for the check task. The check task demonstrates various features
\r
119 * of the MPU before entering a loop where it waits for messages to arrive on a
\r
122 * Two types of messages can be processes:
\r
124 * 1) "I'm Alive" messages sent from the first two register test tasks and a
\r
125 * software timer callback, as described above.
\r
127 * 2) "Print Status commands" sent periodically by the tick hook function (and
\r
128 * therefore from within an interrupt) which commands the check task to write
\r
129 * either pass or fail to the terminal, depending on the status of the reg
\r
130 * test tasks (no write is performed in the simulator!).
\r
132 static void prvCheckTask( void *pvParameters );
\r
135 * Prototype for a task created in User mode using the original vTaskCreate()
\r
136 * API function. The task demonstrates the characteristics of such a task,
\r
137 * before simply deleting itself.
\r
139 static void prvOldStyleUserModeTask( void *pvParameters );
\r
142 * Prototype for a task created in Privileged mode using the original
\r
143 * vTaskCreate() API function. The task demonstrates the characteristics of
\r
144 * such a task, before simply deleting itself.
\r
146 static void prvOldStylePrivilegedModeTask( void *pvParameters );
\r
149 * A task that exercises the API of various RTOS objects before being deleted by
\r
150 * the Idle task. This is done for MPU API code coverage test purposes.
\r
152 static void prvTaskToDelete( void *pvParameters );
\r
155 * Functions called by prvTaskToDelete() to exercise the MPU API.
\r
157 static void prvExerciseEventGroupAPI( void );
\r
158 static void prvExerciseSemaphoreAPI( void );
\r
159 static void prvExerciseTaskNotificationAPI( void );
\r
160 static void prvExerciseStreamBufferAPI( void );
\r
161 static void prvExerciseTimerAPI( void );
\r
164 * Just configures any clocks and IO necessary.
\r
166 static void prvSetupHardware( void );
\r
169 * Simply deletes the calling task. The function is provided only because it
\r
170 * is simpler to call from asm code than the normal vTaskDelete() API function.
\r
171 * It has the noinline attribute because it is called from asm code.
\r
173 void vMainDeleteMe( void ) __attribute__((noinline));
\r
176 * Used by the first two reg test tasks and a software timer callback function
\r
177 * to send messages to the check task. The message just lets the check task
\r
178 * know that the tasks and timer are still functioning correctly. If a reg test
\r
179 * task detects an error it will delete itself, and in so doing prevent itself
\r
180 * from sending any more 'I'm Alive' messages to the check task.
\r
182 void vMainSendImAlive( QueueHandle_t xHandle, uint32_t ulTaskNumber );
\r
185 * The check task is created with access to three memory regions (plus its
\r
186 * stack). Each memory region is configured with different parameters and
\r
187 * prvTestMemoryRegions() demonstrates what can and cannot be accessed for each
\r
188 * region. prvTestMemoryRegions() also demonstrates a task that was created
\r
189 * as a privileged task settings its own privilege level down to that of a user
\r
192 static void prvTestMemoryRegions( void );
\r
195 * Callback function used with the timer that uses the queue to send messages
\r
196 * to the check task.
\r
198 static void prvTimerCallback( TimerHandle_t xExpiredTimer );
\r
201 * The callback function and a function that is pended used when exercising the
\r
204 static void prvPendedFunctionCall( void *pvParameter1, uint32_t ulParameter2 );
\r
205 static void prvTestTimerCallback( TimerHandle_t xTimer );
\r
207 /*-----------------------------------------------------------*/
\r
209 /* The handle of the queue used to communicate between tasks and between tasks
\r
210 and interrupts. Note that this is a global scope variable that falls outside of
\r
211 any MPU region. As such other techniques have to be used to allow the tasks
\r
212 to gain access to the queue. See the comments in the tasks themselves for
\r
213 further information. */
\r
214 QueueHandle_t xGlobalScopeCheckQueue = NULL;
\r
216 /* Holds the handle of a task that is deleted in the idle task hook - this is
\r
217 done for code coverage test purposes only. */
\r
218 static TaskHandle_t xTaskToDelete = NULL;
\r
220 /* The timer that periodically sends data to the check task on the queue. */
\r
221 static TimerHandle_t xTimer = NULL;
\r
223 /* Just used to check start up code for initialised an uninitialised data. */
\r
224 volatile uint32_t ul1 = 0x123, ul2 = 0;
\r
226 #if defined ( __GNUC__ )
\r
227 /* Memory map read directl from linker variables. */
\r
228 extern uint32_t __FLASH_segment_start__[];
\r
229 extern uint32_t __FLASH_segment_end__[];
\r
230 extern uint32_t __SRAM_segment_start__[];
\r
231 extern uint32_t __SRAM_segment_end__[];
\r
232 extern uint32_t __privileged_functions_start__[];
\r
233 extern uint32_t __privileged_functions_end__[];
\r
234 extern uint32_t __privileged_data_start__[];
\r
235 extern uint32_t __privileged_data_end__[];
\r
236 extern uint32_t __privileged_functions_actual_end__[];
\r
237 extern uint32_t __privileged_data_actual_end__[];
\r
239 /* Must be set manually to match memory map. */
\r
240 const uint32_t * __FLASH_segment_start__ = ( uint32_t * ) 0x00UL;
\r
241 const uint32_t * __FLASH_segment_end__ = ( uint32_t * ) 0x00080000UL;
\r
242 const uint32_t * __SRAM_segment_start__ = ( uint32_t * ) 0x20000000UL;
\r
243 const uint32_t * __SRAM_segment_end__ = ( uint32_t * ) 0x20008000UL;
\r
244 const uint32_t * __privileged_functions_start__ = ( uint32_t * ) 0x00UL;
\r
245 const uint32_t * __privileged_functions_end__ = ( uint32_t * ) 0x8000UL;
\r
246 const uint32_t * __privileged_data_start__ = ( uint32_t * ) 0x20000000UL;
\r
247 const uint32_t * __privileged_data_end__ = ( uint32_t * ) 0x20000200UL;
\r
249 /*-----------------------------------------------------------*/
\r
250 /* Data used by the 'check' task. ---------------------------*/
\r
251 /*-----------------------------------------------------------*/
\r
253 /* Define the constants used to allocate the check task stack. Note that the
\r
254 stack size is defined in words, not bytes. */
\r
255 #define mainCHECK_TASK_STACK_SIZE_WORDS 128
\r
256 #define mainCHECK_TASK_STACK_ALIGNMENT ( mainCHECK_TASK_STACK_SIZE_WORDS * sizeof( portSTACK_TYPE ) )
\r
258 /* Declare the stack that will be used by the check task. The kernel will
\r
259 automatically create an MPU region for the stack. The stack alignment must
\r
260 match its size, so if 128 words are reserved for the stack then it must be
\r
261 aligned to ( 128 * 4 ) bytes. */
\r
262 static portSTACK_TYPE xCheckTaskStack[ mainCHECK_TASK_STACK_SIZE_WORDS ] mainALIGN_TO( mainCHECK_TASK_STACK_ALIGNMENT );
\r
264 /* Declare three arrays - an MPU region will be created for each array
\r
265 using the TaskParameters_t structure below. THIS IS JUST TO DEMONSTRATE THE
\r
266 MPU FUNCTIONALITY, the data is not used by the check tasks primary function
\r
267 of monitoring the reg test tasks and printing out status information.
\r
269 Note that the arrays allocate slightly more RAM than is actually assigned to
\r
270 the MPU region. This is to permit writes off the end of the array to be
\r
271 detected even when the arrays are placed in adjacent memory locations (with no
\r
272 gaps between them). The align size must be a power of two. */
\r
273 #define mainREAD_WRITE_ARRAY_SIZE 130
\r
274 #define mainREAD_WRITE_ALIGN_SIZE 128
\r
275 char cReadWriteArray[ mainREAD_WRITE_ARRAY_SIZE ] mainALIGN_TO( mainREAD_WRITE_ALIGN_SIZE );
\r
277 #define mainREAD_ONLY_ARRAY_SIZE 260
\r
278 #define mainREAD_ONLY_ALIGN_SIZE 256
\r
279 char cReadOnlyArray[ mainREAD_ONLY_ARRAY_SIZE ] mainALIGN_TO( mainREAD_ONLY_ALIGN_SIZE );
\r
281 #define mainPRIVILEGED_ONLY_ACCESS_ARRAY_SIZE 130
\r
282 #define mainPRIVILEGED_ONLY_ACCESS_ALIGN_SIZE 128
\r
283 char cPrivilegedOnlyAccessArray[ mainPRIVILEGED_ONLY_ACCESS_ALIGN_SIZE ] mainALIGN_TO( mainPRIVILEGED_ONLY_ACCESS_ALIGN_SIZE );
\r
285 /* The following two variables are used to communicate the status of the second
\r
286 two register check tasks (tasks 3 and 4) to the check task. If the variables
\r
287 keep incrementing, then the register check tasks have not discovered any errors.
\r
288 If a variable stops incrementing, then an error has been found. The variables
\r
289 overlay the array that the check task has access to so they can be read by the
\r
290 check task without causing a memory fault. The check task has the highest
\r
291 priority so will have finished with the array before the register test tasks
\r
292 start to access it. */
\r
293 volatile uint32_t *pulRegTest3LoopCounter = ( uint32_t * ) &( cReadWriteArray[ 0 ] ), *pulRegTest4LoopCounter = ( uint32_t * ) &( cReadWriteArray[ 4 ] );
\r
295 /* Fill in a TaskParameters_t structure to define the check task - this is the
\r
296 structure passed to the xTaskCreateRestricted() function. */
\r
297 static const TaskParameters_t xCheckTaskParameters =
\r
299 prvCheckTask, /* pvTaskCode - the function that implements the task. */
\r
300 "Check", /* pcName */
\r
301 mainCHECK_TASK_STACK_SIZE_WORDS, /* usStackDepth - defined in words, not bytes. */
\r
302 ( void * ) 0x12121212, /* pvParameters - this value is just to test that the parameter is being passed into the task correctly. */
\r
303 ( 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
304 xCheckTaskStack, /* puxStackBuffer - the array to use as the task stack, as declared above. */
\r
306 /* xRegions - In this case the xRegions array is used to create MPU regions
\r
307 for all three of the arrays declared directly above. Each MPU region is
\r
308 created with different parameters. Again, THIS IS JUST TO DEMONSTRATE THE
\r
309 MPU FUNCTIONALITY, the data is not used by the check tasks primary function
\r
310 of monitoring the reg test tasks and printing out status information.*/
\r
312 /* Base address Length Parameters */
\r
313 { cReadWriteArray, mainREAD_WRITE_ALIGN_SIZE, portMPU_REGION_READ_WRITE },
\r
314 { cReadOnlyArray, mainREAD_ONLY_ALIGN_SIZE, portMPU_REGION_READ_ONLY },
\r
315 { cPrivilegedOnlyAccessArray, mainPRIVILEGED_ONLY_ACCESS_ALIGN_SIZE, portMPU_REGION_PRIVILEGED_READ_WRITE }
\r
321 /*-----------------------------------------------------------*/
\r
322 /* Data used by the 'reg test' tasks. -----------------------*/
\r
323 /*-----------------------------------------------------------*/
\r
325 /* Define the constants used to allocate the reg test task stacks. Note that
\r
326 that stack size is defined in words, not bytes. */
\r
327 #define mainREG_TEST_STACK_SIZE_WORDS 128
\r
328 #define mainREG_TEST_STACK_ALIGNMENT ( mainREG_TEST_STACK_SIZE_WORDS * sizeof( portSTACK_TYPE ) )
\r
330 /* Declare the stacks that will be used by the reg test tasks. The kernel will
\r
331 automatically create an MPU region for the stack. The stack alignment must
\r
332 match its size, so if 128 words are reserved for the stack then it must be
\r
333 aligned to ( 128 * 4 ) bytes. */
\r
334 static portSTACK_TYPE xRegTest1Stack[ mainREG_TEST_STACK_SIZE_WORDS ] mainALIGN_TO( mainREG_TEST_STACK_ALIGNMENT );
\r
335 static portSTACK_TYPE xRegTest2Stack[ mainREG_TEST_STACK_SIZE_WORDS ] mainALIGN_TO( mainREG_TEST_STACK_ALIGNMENT );
\r
337 /* Fill in a TaskParameters_t structure per reg test task to define the tasks. */
\r
338 static const TaskParameters_t xRegTest1Parameters =
\r
340 vRegTest1Implementation, /* pvTaskCode - the function that implements the task. */
\r
341 "RegTest1", /* pcName */
\r
342 mainREG_TEST_STACK_SIZE_WORDS, /* usStackDepth */
\r
343 ( void * ) configREG_TEST_TASK_1_PARAMETER, /* pvParameters - this value is just to test that the parameter is being passed into the task correctly. */
\r
344 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
345 xRegTest1Stack, /* puxStackBuffer - the array to use as the task stack, as declared above. */
\r
346 { /* xRegions - this task does not use any non-stack data hence all members are zero. */
\r
347 /* Base address Length Parameters */
\r
348 { 0x00, 0x00, 0x00 },
\r
349 { 0x00, 0x00, 0x00 },
\r
350 { 0x00, 0x00, 0x00 }
\r
353 /*-----------------------------------------------------------*/
\r
355 static TaskParameters_t xRegTest2Parameters =
\r
357 vRegTest2Implementation, /* pvTaskCode - the function that implements the task. */
\r
358 "RegTest2", /* pcName */
\r
359 mainREG_TEST_STACK_SIZE_WORDS, /* usStackDepth */
\r
360 ( void * ) NULL, /* pvParameters - this task uses the parameter to pass in a queue handle, but the queue is not created yet. */
\r
361 tskIDLE_PRIORITY, /* uxPriority */
\r
362 xRegTest2Stack, /* puxStackBuffer - the array to use as the task stack, as declared above. */
\r
363 { /* xRegions - this task does not use any non-stack data hence all members are zero. */
\r
364 /* Base address Length Parameters */
\r
365 { 0x00, 0x00, 0x00 },
\r
366 { 0x00, 0x00, 0x00 },
\r
367 { 0x00, 0x00, 0x00 }
\r
371 /*-----------------------------------------------------------*/
\r
372 /* Configures the task that is deleted. ---------------------*/
\r
373 /*-----------------------------------------------------------*/
\r
375 /* Define the constants used to allocate the stack of the task that is
\r
376 deleted. Note that that stack size is defined in words, not bytes. */
\r
377 #define mainDELETE_TASK_STACK_SIZE_WORDS 128
\r
378 #define mainTASK_TO_DELETE_STACK_ALIGNMENT ( mainDELETE_TASK_STACK_SIZE_WORDS * sizeof( portSTACK_TYPE ) )
\r
380 /* Declare the stack that will be used by the task that gets deleted. The
\r
381 kernel will automatically create an MPU region for the stack. The stack
\r
382 alignment must match its size, so if 128 words are reserved for the stack
\r
383 then it must be aligned to ( 128 * 4 ) bytes. */
\r
384 static portSTACK_TYPE xDeleteTaskStack[ mainDELETE_TASK_STACK_SIZE_WORDS ] mainALIGN_TO( mainTASK_TO_DELETE_STACK_ALIGNMENT );
\r
386 static TaskParameters_t xTaskToDeleteParameters =
\r
388 prvTaskToDelete, /* pvTaskCode - the function that implements the task. */
\r
389 mainTASK_TO_DELETE_NAME, /* pcName */
\r
390 mainDELETE_TASK_STACK_SIZE_WORDS, /* usStackDepth */
\r
391 ( void * ) NULL, /* pvParameters - this task uses the parameter to pass in a queue handle, but the queue is not created yet. */
\r
392 tskIDLE_PRIORITY + 1, /* uxPriority */
\r
393 xDeleteTaskStack, /* puxStackBuffer - the array to use as the task stack, as declared above. */
\r
394 { /* xRegions - this task does not use any non-stack data hence all members are zero. */
\r
395 /* Base address Length Parameters */
\r
396 { 0x00, 0x00, 0x00 },
\r
397 { 0x00, 0x00, 0x00 },
\r
398 { 0x00, 0x00, 0x00 }
\r
402 /*-----------------------------------------------------------*/
\r
406 /* Used to check linker configuration. */
\r
407 configASSERT( ul1 == 0x123 );
\r
408 configASSERT( ul2 == 0 );
\r
409 prvSetupHardware();
\r
411 /* Create the queue used to pass "I'm alive" messages to the check task. */
\r
412 xGlobalScopeCheckQueue = xQueueCreate( 1, sizeof( uint32_t ) );
\r
414 /* One check task uses the task parameter to receive the queue handle.
\r
415 This allows the file scope variable to be accessed from within the task.
\r
416 The pvParameters member of xRegTest2Parameters can only be set after the
\r
417 queue has been created so is set here. */
\r
418 xRegTest2Parameters.pvParameters = xGlobalScopeCheckQueue;
\r
420 /* Create three test tasks. Handles to the created tasks are not required,
\r
421 hence the second parameter is NULL. */
\r
422 xTaskCreateRestricted( &xRegTest1Parameters, NULL );
\r
423 xTaskCreateRestricted( &xRegTest2Parameters, NULL );
\r
424 xTaskCreateRestricted( &xCheckTaskParameters, NULL );
\r
426 /* Create a task that does nothing but ensure some of the MPU API functions
\r
427 can be called correctly, then get deleted. This is done for code coverage
\r
428 test purposes only. The task's handle is saved in xTaskToDelete so it can
\r
429 get deleted in the idle task hook. */
\r
430 xTaskCreateRestricted( &xTaskToDeleteParameters, &xTaskToDelete );
\r
432 /* Create the tasks that are created using the original xTaskCreate() API
\r
434 xTaskCreate( prvOldStyleUserModeTask, /* The function that implements the task. */
\r
435 "Task1", /* Text name for the task. */
\r
436 100, /* Stack depth in words. */
\r
437 NULL, /* Task parameters. */
\r
438 3, /* Priority and mode (user in this case). */
\r
442 xTaskCreate( prvOldStylePrivilegedModeTask, /* The function that implements the task. */
\r
443 "Task2", /* Text name for the task. */
\r
444 100, /* Stack depth in words. */
\r
445 NULL, /* Task parameters. */
\r
446 ( 3 | portPRIVILEGE_BIT ), /* Priority and mode. */
\r
450 /* Create the third and fourth register check tasks, as described at the top
\r
452 xTaskCreate( prvRegTest3Task, "Reg3", configMINIMAL_STACK_SIZE, configREG_TEST_TASK_3_PARAMETER, tskIDLE_PRIORITY, NULL );
\r
453 xTaskCreate( prvRegTest4Task, "Reg4", configMINIMAL_STACK_SIZE, configREG_TEST_TASK_4_PARAMETER, tskIDLE_PRIORITY, NULL );
\r
455 /* Create and start the software timer. */
\r
456 xTimer = xTimerCreate( "Timer", /* Test name for the timer. */
\r
457 mainTIMER_PERIOD, /* Period of the timer. */
\r
458 pdTRUE, /* The timer will auto-reload itself. */
\r
459 ( void * ) 0, /* The timer's ID is used to count the number of times it expires - initialise this to 0. */
\r
460 prvTimerCallback ); /* The function called when the timer expires. */
\r
461 configASSERT( xTimer );
\r
462 xTimerStart( xTimer, mainDONT_BLOCK );
\r
464 /* Start the scheduler. */
\r
465 vTaskStartScheduler();
\r
467 /* Will only get here if there was insufficient memory to create the idle
\r
471 /*-----------------------------------------------------------*/
\r
473 static void prvCheckTask( void *pvParameters )
\r
475 /* This task is created in privileged mode so can access the file scope
\r
476 queue variable. Take a stack copy of this before the task is set into user
\r
477 mode. Once that task is in user mode the file scope queue variable will no
\r
478 longer be accessible but the stack copy will. */
\r
479 QueueHandle_t xQueue = xGlobalScopeCheckQueue;
\r
481 uint32_t ulStillAliveCounts[ 3 ] = { 0 };
\r
482 const char *pcStatusMessage = "PASS\r\n";
\r
483 uint32_t ulLastRegTest3CountValue = 0, ulLastRegTest4Value = 0;
\r
485 /* The register test tasks that also test the floating point registers increment
\r
486 a counter on each iteration of their loop. The counters are inside the array
\r
487 that this task has access to. */
\r
488 volatile uint32_t *pulOverlaidCounter3 = ( uint32_t * ) &( cReadWriteArray[ 0 ] ), *pulOverlaidCounter4 = ( uint32_t * ) &( cReadWriteArray[ 4 ] );
\r
490 /* ulCycleCount is incremented on each cycle of the check task. It can be
\r
491 viewed updating in the Keil watch window as the simulator does not print to
\r
493 volatile uint32_t ulCycleCount = 0;
\r
495 /* Just to remove compiler warning. */
\r
496 ( void ) pvParameters;
\r
498 /* Demonstrate how the various memory regions can and can't be accessed.
\r
499 The task privilege level is set down to user mode within this function. */
\r
500 prvTestMemoryRegions();
\r
502 /* Clear overlaid reg test counters before entering the loop below. */
\r
503 *pulOverlaidCounter3 = 0UL;
\r
504 *pulOverlaidCounter4 = 0UL;
\r
506 /* This loop performs the main function of the task, which is blocking
\r
507 on a message queue then processing each message as it arrives. */
\r
510 /* Wait for the next message to arrive. */
\r
511 xQueueReceive( xQueue, &lMessage, portMAX_DELAY );
\r
515 case configREG_TEST_1_STILL_EXECUTING :
\r
516 case configREG_TEST_2_STILL_EXECUTING :
\r
517 case configTIMER_STILL_EXECUTING :
\r
518 /* Message from the first or second register check task, or
\r
519 the timer callback function. Increment the count of the
\r
520 number of times the message source has sent the message as
\r
521 the message source must still be executed. */
\r
522 ( ulStillAliveCounts[ lMessage ] )++;
\r
525 case configPRINT_SYSTEM_STATUS :
\r
526 /* Message from tick hook, time to print out the system
\r
527 status. If messages have stopped arriving from either of
\r
528 the first two reg test task or the timer callback then the
\r
529 status must be set to fail. */
\r
530 if( ( ulStillAliveCounts[ 0 ] == 0 ) || ( ulStillAliveCounts[ 1 ] == 0 ) || ( ulStillAliveCounts[ 2 ] == 0 ) )
\r
532 /* One or both of the test tasks are no longer sending
\r
533 'still alive' messages. */
\r
534 pcStatusMessage = "FAIL\r\n";
\r
538 /* Reset the count of 'still alive' messages. */
\r
539 memset( ( void * ) ulStillAliveCounts, 0x00, sizeof( ulStillAliveCounts ) );
\r
542 /* Check that the register test 3 task is still incrementing
\r
543 its counter, and therefore still running. */
\r
544 if( ulLastRegTest3CountValue == *pulOverlaidCounter3 )
\r
546 pcStatusMessage = "FAIL\r\n";
\r
548 ulLastRegTest3CountValue = *pulOverlaidCounter3;
\r
550 /* Check that the register test 4 task is still incrementing
\r
551 its counter, and therefore still running. */
\r
552 if( ulLastRegTest4Value == *pulOverlaidCounter4 )
\r
554 pcStatusMessage = "FAIL\r\n";
\r
556 ulLastRegTest4Value = *pulOverlaidCounter4;
\r
558 /**** Print pcStatusMessage here. ****/
\r
559 ( void ) pcStatusMessage;
\r
561 /* The cycle count can be viewed updating in the Keil watch
\r
562 window if ITM printf is not being used. */
\r
567 /* Something unexpected happened. Delete this task so the
\r
568 error is apparent (no output will be displayed). */
\r
574 /*-----------------------------------------------------------*/
\r
576 static void prvTestMemoryRegions( void )
\r
581 /* The check task (from which this function is called) is created in the
\r
582 Privileged mode. The privileged array can be both read from and written
\r
583 to while this task is privileged. */
\r
584 cPrivilegedOnlyAccessArray[ 0 ] = 'a';
\r
585 if( cPrivilegedOnlyAccessArray[ 0 ] != 'a' )
\r
587 /* Something unexpected happened. Delete this task so the error is
\r
588 apparent (no output will be displayed). */
\r
592 /* Writing off the end of the RAM allocated to this task will *NOT* cause a
\r
593 protection fault because the task is still executing in a privileged mode.
\r
594 Uncomment the following to test. */
\r
595 /*cPrivilegedOnlyAccessArray[ mainPRIVILEGED_ONLY_ACCESS_ALIGN_SIZE ] = 'a';*/
\r
597 /* Now set the task into user mode. */
\r
598 portSWITCH_TO_USER_MODE();
\r
600 /* Accessing the privileged only array will now cause a fault. Uncomment
\r
601 the following line to test. */
\r
602 /*cPrivilegedOnlyAccessArray[ 0 ] = 'a';*/
\r
604 /* The read/write array can still be successfully read and written. */
\r
605 for( x = 0; x < mainREAD_WRITE_ALIGN_SIZE; x++ )
\r
607 cReadWriteArray[ x ] = 'a';
\r
608 if( cReadWriteArray[ x ] != 'a' )
\r
610 /* Something unexpected happened. Delete this task so the error is
\r
611 apparent (no output will be displayed). */
\r
616 /* But attempting to read or write off the end of the RAM allocated to this
\r
617 task will cause a fault. Uncomment either of the following two lines to
\r
619 /* cReadWriteArray[ 0 ] = cReadWriteArray[ -1 ]; */
\r
620 /* cReadWriteArray[ mainREAD_WRITE_ALIGN_SIZE ] = 0x00; */
\r
622 /* The read only array can be successfully read... */
\r
623 for( x = 0; x < mainREAD_ONLY_ALIGN_SIZE; x++ )
\r
625 cTemp = cReadOnlyArray[ x ];
\r
628 /* ...but cannot be written. Uncomment the following line to test. */
\r
629 /* cReadOnlyArray[ 0 ] = 'a'; */
\r
631 /* Writing to the first and last locations in the stack array should not
\r
632 cause a protection fault. Note that doing this will cause the kernel to
\r
633 detect a stack overflow if configCHECK_FOR_STACK_OVERFLOW is greater than
\r
634 1, hence the test is commented out by default. */
\r
635 /* xCheckTaskStack[ 0 ] = 0;
\r
636 xCheckTaskStack[ mainCHECK_TASK_STACK_SIZE_WORDS - 1 ] = 0; */
\r
638 /* Writing off either end of the stack array should cause a protection
\r
639 fault, uncomment either of the following two lines to test. */
\r
640 /* xCheckTaskStack[ -1 ] = 0; */
\r
641 /* xCheckTaskStack[ mainCHECK_TASK_STACK_SIZE_WORDS ] = 0; */
\r
645 /*-----------------------------------------------------------*/
\r
647 static void prvExerciseEventGroupAPI( void )
\r
649 EventGroupHandle_t xEventGroup;
\r
651 const EventBits_t xBitsToWaitFor = ( EventBits_t ) 0xff, xBitToClear = ( EventBits_t ) 0x01;
\r
653 /* Exercise some event group functions. */
\r
654 xEventGroup = xEventGroupCreate();
\r
655 configASSERT( xEventGroup );
\r
657 /* No bits should be set. */
\r
658 xBits = xEventGroupWaitBits( xEventGroup, xBitsToWaitFor, pdTRUE, pdFALSE, mainDONT_BLOCK );
\r
659 configASSERT( xBits == ( EventBits_t ) 0 );
\r
661 /* Set bits and read back to ensure the bits were set. */
\r
662 xEventGroupSetBits( xEventGroup, xBitsToWaitFor );
\r
663 xBits = xEventGroupGetBits( xEventGroup );
\r
664 configASSERT( xBits == xBitsToWaitFor );
\r
666 /* Clear a bit and read back again using a different API function. */
\r
667 xEventGroupClearBits( xEventGroup, xBitToClear );
\r
668 xBits = xEventGroupSync( xEventGroup, 0x00, xBitsToWaitFor, mainDONT_BLOCK );
\r
669 configASSERT( xBits == ( xBitsToWaitFor & ~xBitToClear ) );
\r
671 /* Finished with the event group. */
\r
672 vEventGroupDelete( xEventGroup );
\r
674 /*-----------------------------------------------------------*/
\r
676 static void prvExerciseSemaphoreAPI( void )
\r
678 SemaphoreHandle_t xSemaphore;
\r
679 const UBaseType_t uxMaxCount = 5, uxInitialCount = 0;
\r
681 /* Most of the semaphore API is common to the queue API and is already being
\r
682 used. This function uses a few semaphore functions that are unique to the
\r
683 RTOS objects, rather than generic and used by queues also.
\r
685 First create and use a counting semaphore. */
\r
686 xSemaphore = xSemaphoreCreateCounting( uxMaxCount, uxInitialCount );
\r
687 configASSERT( xSemaphore );
\r
689 /* Give the semaphore a couple of times and ensure the count is returned
\r
691 xSemaphoreGive( xSemaphore );
\r
692 xSemaphoreGive( xSemaphore );
\r
693 configASSERT( uxSemaphoreGetCount( xSemaphore ) == 2 );
\r
694 vSemaphoreDelete( xSemaphore );
\r
696 /* Create a recursive mutex, and ensure the mutex holder and count are
\r
697 returned returned correctly. */
\r
698 xSemaphore = xSemaphoreCreateRecursiveMutex();
\r
699 configASSERT( uxSemaphoreGetCount( xSemaphore ) == 1 );
\r
700 configASSERT( xSemaphore );
\r
701 xSemaphoreTakeRecursive( xSemaphore, mainDONT_BLOCK );
\r
702 xSemaphoreTakeRecursive( xSemaphore, mainDONT_BLOCK );
\r
703 configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == xTaskGetCurrentTaskHandle() );
\r
704 configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == xTaskGetHandle( mainTASK_TO_DELETE_NAME ) );
\r
705 xSemaphoreGiveRecursive( xSemaphore );
\r
706 configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 );
\r
707 xSemaphoreGiveRecursive( xSemaphore );
\r
708 configASSERT( uxSemaphoreGetCount( xSemaphore ) == 1 );
\r
709 configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == NULL );
\r
710 vSemaphoreDelete( xSemaphore );
\r
712 /* Create a normal mutex, and sure the mutex holder and count are returned
\r
713 returned correctly. */
\r
714 xSemaphore = xSemaphoreCreateMutex();
\r
715 configASSERT( xSemaphore );
\r
716 xSemaphoreTake( xSemaphore, mainDONT_BLOCK );
\r
717 xSemaphoreTake( xSemaphore, mainDONT_BLOCK );
\r
718 configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 ); /* Not recursive so can only be 1. */
\r
719 configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == xTaskGetCurrentTaskHandle() );
\r
720 xSemaphoreGive( xSemaphore );
\r
721 configASSERT( uxSemaphoreGetCount( xSemaphore ) == 1 );
\r
722 configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == NULL );
\r
723 vSemaphoreDelete( xSemaphore );
\r
725 /*-----------------------------------------------------------*/
\r
727 static void prvExerciseTaskNotificationAPI( void )
\r
729 uint32_t ulNotificationValue;
\r
730 BaseType_t xReturned;
\r
732 /* The task should not yet have a notification pending. */
\r
733 xReturned = xTaskNotifyWait( 0, 0, &ulNotificationValue, mainDONT_BLOCK );
\r
734 configASSERT( xReturned == pdFAIL );
\r
735 configASSERT( ulNotificationValue == 0UL );
\r
737 /* Exercise the 'give' and 'take' versions of the notification API. */
\r
738 xTaskNotifyGive( xTaskGetCurrentTaskHandle() );
\r
739 xTaskNotifyGive( xTaskGetCurrentTaskHandle() );
\r
740 ulNotificationValue = ulTaskNotifyTake( pdTRUE, mainDONT_BLOCK );
\r
741 configASSERT( ulNotificationValue == 2 );
\r
743 /* Exercise the 'notify' and 'clear' API. */
\r
744 ulNotificationValue = 20;
\r
745 xTaskNotify( xTaskGetCurrentTaskHandle(), ulNotificationValue, eSetValueWithOverwrite );
\r
746 ulNotificationValue = 0;
\r
747 xReturned = xTaskNotifyWait( 0, 0, &ulNotificationValue, mainDONT_BLOCK );
\r
748 configASSERT( xReturned == pdPASS );
\r
749 configASSERT( ulNotificationValue == 20 );
\r
750 xTaskNotify( xTaskGetCurrentTaskHandle(), ulNotificationValue, eSetValueWithOverwrite );
\r
751 xReturned = xTaskNotifyStateClear( NULL );
\r
752 configASSERT( xReturned == pdTRUE ); /* First time a notification was pending. */
\r
753 xReturned = xTaskNotifyStateClear( NULL );
\r
754 configASSERT( xReturned == pdFALSE ); /* Second time the notification was already clear. */
\r
756 /*-----------------------------------------------------------*/
\r
758 static void prvTaskToDelete( void *pvParameters )
\r
760 /* Remove compiler warnings about unused parameters. */
\r
761 ( void ) pvParameters;
\r
763 /* Check the enter and exit critical macros are working correctly. If the
\r
764 SVC priority is below configMAX_SYSCALL_INTERRUPT_PRIORITY then this will
\r
766 taskENTER_CRITICAL();
\r
767 taskEXIT_CRITICAL();
\r
769 /* Exercise the API of various RTOS objects. */
\r
770 prvExerciseEventGroupAPI();
\r
771 prvExerciseSemaphoreAPI();
\r
772 prvExerciseTaskNotificationAPI();
\r
773 prvExerciseStreamBufferAPI();
\r
774 prvExerciseTimerAPI();
\r
776 /* For code coverage test purposes it is deleted by the Idle task. */
\r
777 configASSERT( uxTaskGetStackHighWaterMark( NULL ) > 0 );
\r
778 configASSERT( uxTaskGetStackHighWaterMark2( NULL ) > 0 );
\r
779 vTaskSuspend( NULL );
\r
781 /*-----------------------------------------------------------*/
\r
783 static void prvPendedFunctionCall( void *pvParameter1, uint32_t ulParameter2 )
\r
785 uint32_t *pulCounter = ( uint32_t * ) pvParameter1;
\r
787 /* Increment the paramater to show the pended function has executed. */
\r
790 /*-----------------------------------------------------------*/
\r
792 static void prvTestTimerCallback( TimerHandle_t xTimer )
\r
794 uint32_t ulTimerID;
\r
796 /* Increment the timer's ID to show the callback has executed. */
\r
797 ulTimerID = ( uint32_t ) pvTimerGetTimerID( xTimer );
\r
799 vTimerSetTimerID( xTimer, ( void * ) ulTimerID );
\r
801 /*-----------------------------------------------------------*/
\r
803 static void prvExerciseTimerAPI( void )
\r
805 TimerHandle_t xTimer;
\r
806 const char * const pcTimerName = "TestTimer";
\r
807 const TickType_t x10ms = pdMS_TO_TICKS( 3 );
\r
808 uint32_t ulValueForTesting = 0;
\r
810 xTimer = xTimerCreate( pcTimerName,
\r
812 pdFALSE, /* Created as a one shot timer. */
\r
814 prvTestTimerCallback );
\r
815 configASSERT( xTimer );
\r
816 configASSERT( xTimerIsTimerActive( xTimer ) == pdFALSE );
\r
817 configASSERT( xTimerGetTimerDaemonTaskHandle() != NULL );
\r
818 configASSERT( strcmp( pcTimerName, pcTimerGetName( xTimer ) ) == 0 );
\r
819 configASSERT( xTimerGetPeriod( xTimer ) == x10ms );
\r
820 configASSERT( xTimerGetExpiryTime( xTimer ) == 0 ); /* The timer has been created only. */
\r
822 /* Pend a function then wait for it to execute. All it does is increment
\r
824 xTimerPendFunctionCall( prvPendedFunctionCall, &ulValueForTesting, 0, 0 );
\r
825 vTaskDelay( x10ms );
\r
826 configASSERT( ulValueForTesting == 1 );
\r
828 /* Timer was created as a one shot timer. Its callback just increments the
\r
829 timer's ID - so set the ID to 0, let the timer run for a number of timeout
\r
830 periods, then check the timer has only executed once. */
\r
831 vTimerSetTimerID( xTimer, ( void * ) 0 );
\r
832 xTimerStart( xTimer, 0 );
\r
833 vTaskDelay( 3UL * x10ms );
\r
834 configASSERT( ( ( uint32_t ) ( pvTimerGetTimerID( xTimer ) ) ) == 1UL );
\r
836 /* Now change the timer to be an autoreload timer and check it executes
\r
837 the expected number of times. */
\r
838 vTimerSetReloadMode( xTimer, pdTRUE );
\r
839 xTimerStart( xTimer, 0 );
\r
840 vTaskDelay( 3UL * x10ms );
\r
841 configASSERT( ( uint32_t ) ( pvTimerGetTimerID( xTimer ) ) > 3UL );
\r
842 configASSERT( xTimerStop( xTimer, 0 ) != pdFAIL );
\r
844 /* Clean up at the end. */
\r
845 xTimerDelete( xTimer, portMAX_DELAY );
\r
847 /*-----------------------------------------------------------*/
\r
849 static void prvExerciseStreamBufferAPI( void )
\r
851 uint8_t ucBuffer[ 10 ];
\r
852 BaseType_t x, xRead;
\r
854 StreamBufferHandle_t xStreamBuffer;
\r
856 /* Just makes API calls to ensure the MPU versions are used. */
\r
858 xStreamBuffer = xStreamBufferCreate( sizeof( ucBuffer ) , 1 );
\r
859 configASSERT( xStreamBuffer );
\r
861 for( x = 0; x < ( sizeof( ucBuffer ) * 2 ); x++ )
\r
863 /* Write and check the value is written, then read and check the value
\r
864 read is expected. */
\r
865 xReturned = xStreamBufferSend( xStreamBuffer,
\r
869 configASSERT( xReturned == sizeof( x ) );
\r
871 xReturned = xStreamBufferReceive( xStreamBuffer,
\r
875 configASSERT( xReturned == sizeof( xRead ) );
\r
876 configASSERT( xRead == x );
\r
877 configASSERT( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
\r
878 configASSERT( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );
\r
879 configASSERT( xStreamBufferSpacesAvailable( xStreamBuffer ) == sizeof( ucBuffer ) );
\r
880 configASSERT( xStreamBufferBytesAvailable( xStreamBuffer ) == 0 );
\r
883 /* Call the functions that have not been exercised yet before finishing by
\r
884 deleting the stream buffer. */
\r
885 configASSERT( xStreamBufferSetTriggerLevel( xStreamBuffer, 0 ) == pdTRUE );
\r
886 configASSERT( xStreamBufferReset( xStreamBuffer ) == pdPASS );
\r
887 vStreamBufferDelete( xStreamBuffer );
\r
889 /*-----------------------------------------------------------*/
\r
891 void vApplicationIdleHook( void )
\r
893 volatile const uint32_t *pul;
\r
894 volatile uint32_t ulReadData;
\r
896 /* The idle task, and therefore this function, run in Supervisor mode and
\r
897 can therefore access all memory. Try reading from corners of flash and
\r
898 RAM to ensure a memory fault does not occur.
\r
900 Start with the edges of the privileged data area. */
\r
901 pul = __privileged_data_start__;
\r
903 pul = __privileged_data_end__ - 1;
\r
906 /* Next the standard SRAM area. */
\r
907 pul = __SRAM_segment_end__ - 1;
\r
910 /* And the standard Flash area - the start of which is marked for
\r
911 privileged access only. */
\r
912 pul = __FLASH_segment_start__;
\r
914 pul = __FLASH_segment_end__ - 1;
\r
917 /* Reading off the end of Flash or SRAM space should cause a fault.
\r
918 Uncomment one of the following two pairs of lines to test. */
\r
920 /* pul = __FLASH_segment_end__ + 4;
\r
921 ulReadData = *pul; */
\r
923 /* pul = __SRAM_segment_end__ + 1;
\r
924 ulReadData = *pul; */
\r
926 /* One task is created purely so it can be deleted - done for code coverage
\r
928 if( xTaskToDelete != NULL )
\r
930 if( eTaskGetState( xTaskToDelete ) == eSuspended )
\r
932 /* The task has finished its tests and can be deleted. */
\r
933 vTaskDelete( xTaskToDelete );
\r
934 xTaskToDelete = NULL;
\r
938 ( void ) ulReadData;
\r
940 /*-----------------------------------------------------------*/
\r
942 static void prvOldStyleUserModeTask( void *pvParameters )
\r
944 /*const volatile uint32_t *pulStandardPeripheralRegister = ( volatile uint32_t * ) 0x40000000;*/
\r
945 volatile const uint32_t *pul;
\r
946 volatile uint32_t ulReadData;
\r
948 /* The following lines are commented out to prevent the unused variable
\r
949 compiler warnings when the tests that use the variable are also commented out. */
\r
950 /* extern uint32_t __privileged_functions_start__[]; */
\r
951 /* const volatile uint32_t *pulSystemPeripheralRegister = ( volatile uint32_t * ) 0xe000e014; */
\r
953 ( void ) pvParameters;
\r
955 /* This task is created in User mode using the original xTaskCreate() API
\r
956 function. It should have access to all Flash and RAM except that marked
\r
957 as Privileged access only. Reading from the start and end of the non-
\r
958 privileged RAM should not cause a problem (the privileged RAM is the first
\r
959 block at the bottom of the RAM memory). */
\r
960 pul = __privileged_data_end__ + 1;
\r
962 pul = __SRAM_segment_end__ - 1;
\r
965 /* Likewise reading from the start and end of the non-privileged Flash
\r
966 should not be a problem (the privileged Flash is the first block at the
\r
967 bottom of the Flash memory). */
\r
968 pul = __privileged_functions_end__ + 1;
\r
970 pul = __FLASH_segment_end__ - 1;
\r
973 /* Standard peripherals are accessible. */
\r
974 /*ulReadData = *pulStandardPeripheralRegister;*/
\r
976 /* System peripherals are not accessible. Uncomment the following line
\r
977 to test. Also uncomment the declaration of pulSystemPeripheralRegister
\r
978 at the top of this function.
\r
979 ulReadData = *pulSystemPeripheralRegister; */
\r
981 /* Reading from anywhere inside the privileged Flash or RAM should cause a
\r
982 fault. This can be tested by uncommenting any of the following pairs of
\r
983 lines. Also uncomment the declaration of __privileged_functions_start__
\r
984 at the top of this function. */
\r
986 /*pul = __privileged_functions_start__;
\r
987 ulReadData = *pul;*/
\r
989 /*pul = __privileged_functions_end__ - 1;
\r
990 ulReadData = *pul;*/
\r
992 /*pul = __privileged_data_start__;
\r
993 ulReadData = *pul;*/
\r
995 /*pul = __privileged_data_end__ - 1;
\r
996 ulReadData = *pul;*/
\r
998 /* Must not just run off the end of a task function, so delete this task.
\r
999 Note that because this task was created using xTaskCreate() the stack was
\r
1000 allocated dynamically and I have not included any code to free it again. */
\r
1001 vTaskDelete( NULL );
\r
1003 ( void ) ulReadData;
\r
1005 /*-----------------------------------------------------------*/
\r
1007 static void prvOldStylePrivilegedModeTask( void *pvParameters )
\r
1009 volatile const uint32_t *pul;
\r
1010 volatile uint32_t ulReadData;
\r
1011 const volatile uint32_t *pulSystemPeripheralRegister = ( volatile uint32_t * ) 0xe000e014; /* Systick */
\r
1012 /*const volatile uint32_t *pulStandardPeripheralRegister = ( volatile uint32_t * ) 0x40000000;*/
\r
1014 ( void ) pvParameters;
\r
1016 /* This task is created in Privileged mode using the original xTaskCreate()
\r
1017 API function. It should have access to all Flash and RAM including that
\r
1018 marked as Privileged access only. So reading from the start and end of the
\r
1019 non-privileged RAM should not cause a problem (the privileged RAM is the
\r
1020 first block at the bottom of the RAM memory). */
\r
1021 pul = __privileged_data_end__ + 1;
\r
1022 ulReadData = *pul;
\r
1023 pul = __SRAM_segment_end__ - 1;
\r
1024 ulReadData = *pul;
\r
1026 /* Likewise reading from the start and end of the non-privileged Flash
\r
1027 should not be a problem (the privileged Flash is the first block at the
\r
1028 bottom of the Flash memory). */
\r
1029 pul = __privileged_functions_end__ + 1;
\r
1030 ulReadData = *pul;
\r
1031 pul = __FLASH_segment_end__ - 1;
\r
1032 ulReadData = *pul;
\r
1034 /* Reading from anywhere inside the privileged Flash or RAM should also
\r
1035 not be a problem. */
\r
1036 pul = __privileged_functions_start__;
\r
1037 ulReadData = *pul;
\r
1038 pul = __privileged_functions_end__ - 1;
\r
1039 ulReadData = *pul;
\r
1040 pul = __privileged_data_start__;
\r
1041 ulReadData = *pul;
\r
1042 pul = __privileged_data_end__ - 1;
\r
1043 ulReadData = *pul;
\r
1045 /* Finally, accessing both System and normal peripherals should both be
\r
1047 ulReadData = *pulSystemPeripheralRegister;
\r
1048 /*ulReadData = *pulStandardPeripheralRegister;*/
\r
1050 /* Must not just run off the end of a task function, so delete this task.
\r
1051 Note that because this task was created using xTaskCreate() the stack was
\r
1052 allocated dynamically and I have not included any code to free it again. */
\r
1053 vTaskDelete( NULL );
\r
1055 ( void ) ulReadData;
\r
1057 /*-----------------------------------------------------------*/
\r
1059 void vMainDeleteMe( void )
\r
1061 vTaskDelete( NULL );
\r
1063 /*-----------------------------------------------------------*/
\r
1065 void vMainSendImAlive( QueueHandle_t xHandle, uint32_t ulTaskNumber )
\r
1067 if( xHandle != NULL )
\r
1069 xQueueSend( xHandle, &ulTaskNumber, mainDONT_BLOCK );
\r
1072 /*-----------------------------------------------------------*/
\r
1074 static void prvSetupHardware( void )
\r
1077 /*-----------------------------------------------------------*/
\r
1079 void vApplicationTickHook( void )
\r
1081 static uint32_t ulCallCount = 0;
\r
1082 const uint32_t ulCallsBetweenSends = pdMS_TO_TICKS( 1000 );
\r
1083 const uint32_t ulMessage = configPRINT_SYSTEM_STATUS;
\r
1084 portBASE_TYPE xDummy;
\r
1086 /* If configUSE_TICK_HOOK is set to 1 then this function will get called
\r
1087 from each RTOS tick. It is called from the tick interrupt and therefore
\r
1088 will be executing in the privileged state. */
\r
1092 /* Is it time to print out the pass/fail message again? */
\r
1093 if( ulCallCount >= ulCallsBetweenSends )
\r
1097 /* Send a message to the check task to command it to check that all
\r
1098 the tasks are still running then print out the status.
\r
1100 This is running in an ISR so has to use the "FromISR" version of
\r
1101 xQueueSend(). Because it is in an ISR it is running with privileges
\r
1102 so can access xGlobalScopeCheckQueue directly. */
\r
1103 xQueueSendFromISR( xGlobalScopeCheckQueue, &ulMessage, &xDummy );
\r
1106 /*-----------------------------------------------------------*/
\r
1108 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
1110 /* If configCHECK_FOR_STACK_OVERFLOW is set to either 1 or 2 then this
\r
1111 function will automatically get called if a task overflows its stack. */
\r
1113 ( void ) pcTaskName;
\r
1116 /*-----------------------------------------------------------*/
\r
1118 void vApplicationMallocFailedHook( void )
\r
1120 /* If configUSE_MALLOC_FAILED_HOOK is set to 1 then this function will
\r
1121 be called automatically if a call to pvPortMalloc() fails. pvPortMalloc()
\r
1122 is called automatically when a task, queue or semaphore is created. */
\r
1125 /*-----------------------------------------------------------*/
\r
1127 static void prvTimerCallback( TimerHandle_t xExpiredTimer )
\r
1131 /* The count of the number of times this timer has expired is saved in the
\r
1132 timer's ID. Obtain the current count. */
\r
1133 ulCount = ( uint32_t ) pvTimerGetTimerID( xTimer );
\r
1135 /* Increment the count, and save it back into the timer's ID. */
\r
1137 vTimerSetTimerID( xTimer, ( void * ) ulCount );
\r
1139 /* Let the check task know the timer is still running. */
\r
1140 vMainSendImAlive( xGlobalScopeCheckQueue, configTIMER_STILL_EXECUTING );
\r
1142 /*-----------------------------------------------------------*/
\r
1144 /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an
\r
1145 implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
\r
1146 used by the Idle task. */
\r
1147 void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
\r
1149 /* If the buffers to be provided to the Idle task are declared inside this
\r
1150 function then they must be declared static - otherwise they will be allocated on
\r
1151 the stack and so not exists after this function exits. */
\r
1152 static StaticTask_t xIdleTaskTCB;
\r
1153 static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];
\r
1155 /* Pass out a pointer to the StaticTask_t structure in which the Idle task's
\r
1156 state will be stored. */
\r
1157 *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
\r
1159 /* Pass out the array that will be used as the Idle task's stack. */
\r
1160 *ppxIdleTaskStackBuffer = uxIdleTaskStack;
\r
1162 /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
\r
1163 Note that, as the array is necessarily of type StackType_t,
\r
1164 configMINIMAL_STACK_SIZE is specified in words, not bytes. */
\r
1165 *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
\r
1167 /*-----------------------------------------------------------*/
\r
1169 /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
\r
1170 application must provide an implementation of vApplicationGetTimerTaskMemory()
\r
1171 to provide the memory that is used by the Timer service task. */
\r
1172 void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )
\r
1174 /* If the buffers to be provided to the Timer task are declared inside this
\r
1175 function then they must be declared static - otherwise they will be allocated on
\r
1176 the stack and so not exists after this function exits. */
\r
1177 static StaticTask_t xTimerTaskTCB;
\r
1178 static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];
\r
1180 /* Pass out a pointer to the StaticTask_t structure in which the Timer
\r
1181 task's state will be stored. */
\r
1182 *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
\r
1184 /* Pass out the array that will be used as the Timer task's stack. */
\r
1185 *ppxTimerTaskStackBuffer = uxTimerTaskStack;
\r
1187 /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
\r
1188 Note that, as the array is necessarily of type StackType_t,
\r
1189 configMINIMAL_STACK_SIZE is specified in words, not bytes. */
\r
1190 *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
\r
1192 /*-----------------------------------------------------------*/
\r
1194 static void prvRegTest3Task( void *pvParameters )
\r
1196 /* Although the regtest task is written in assembler, its entry point is
\r
1197 written in C for convenience of checking the task parameter is being passed
\r
1199 if( pvParameters == configREG_TEST_TASK_3_PARAMETER )
\r
1201 /* Start the part of the test that is written in assembler. */
\r
1202 vRegTest3Implementation();
\r
1205 /* The following line will only execute if the task parameter is found to
\r
1206 be incorrect. The check task will detect that the regtest loop counter is
\r
1207 not being incremented and flag an error. */
\r
1208 vTaskDelete( NULL );
\r
1210 /*-----------------------------------------------------------*/
\r
1212 static void prvRegTest4Task( void *pvParameters )
\r
1214 /* Although the regtest task is written in assembler, its entry point is
\r
1215 written in C for convenience of checking the task parameter is being passed
\r
1217 if( pvParameters == configREG_TEST_TASK_4_PARAMETER )
\r
1219 /* Start the part of the test that is written in assembler. */
\r
1220 vRegTest4Implementation();
\r
1223 /* The following line will only execute if the task parameter is found to
\r
1224 be incorrect. The check task will detect that the regtest loop counter is
\r
1225 not being incremented and flag an error. */
\r
1226 vTaskDelete( NULL );
\r
1228 /*-----------------------------------------------------------*/
\r