2 * FreeRTOS Kernel V10.0.1
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * http://www.FreeRTOS.org
23 * http://aws.amazon.com/freertos
29 * Instead of the normal single demo application, the PIC18F demo is split
30 * into several smaller programs of which this is the first. This enables the
31 * demo's to be executed on the RAM limited 40 pin devices. The 64 and 80 pin
32 * devices require a more costly development platform and are not so readily
35 * The RTOSDemo1 project is configured for a PIC18F452 device. Main1.c starts 5
36 * tasks (including the idle task).
38 * The first task runs at the idle priority. It repeatedly performs a 32bit
39 * calculation and checks it's result against the expected value. This checks
40 * that the temporary storage utilised by the compiler to hold intermediate
41 * results does not get corrupted when the task gets switched in and out. See
42 * demo/common/minimal/integer.c for more information.
44 * The second and third tasks pass an incrementing value between each other on
45 * a message queue. See demo/common/minimal/PollQ.c for more information.
47 * Main1.c also creates a check task. This periodically checks that all the
48 * other tasks are still running and have not experienced any unexpected
49 * results. If all the other tasks are executing correctly an LED is flashed
50 * once every mainCHECK_PERIOD milliseconds. If any of the tasks have not
51 * executed, or report and error, the frequency of the LED flash will increase
52 * to mainERROR_FLASH_RATE.
54 * On entry to main an 'X' is transmitted. Monitoring the serial port using a
55 * dumb terminal allows for verification that the device is not continuously
56 * being reset (no more than one 'X' should be transmitted).
58 * http://www.FreeRTOS.org contains important information on the use of the
65 + Delay periods are now specified using variables and constants of
66 TickType_t rather than unsigned long.
69 /* Scheduler include files. */
73 /* Demo app include files. */
79 /* The period between executions of the check task before and after an error
80 has been discovered. If an error has been discovered the check task runs
81 more frequently - increasing the LED flash rate. */
82 #define mainNO_ERROR_CHECK_PERIOD ( ( TickType_t ) 1000 / portTICK_PERIOD_MS )
83 #define mainERROR_CHECK_PERIOD ( ( TickType_t ) 100 / portTICK_PERIOD_MS )
85 /* Priority definitions for some of the tasks. Other tasks just use the idle
87 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
88 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
90 /* The LED that is flashed by the check task. */
91 #define mainCHECK_TASK_LED ( 0 )
93 /* Constants required for the communications. Only one character is ever
95 #define mainCOMMS_QUEUE_LENGTH ( 5 )
96 #define mainNO_BLOCK ( ( TickType_t ) 0 )
97 #define mainBAUD_RATE ( ( unsigned long ) 9600 )
100 * The task function for the "Check" task.
102 static void vErrorChecks( void *pvParameters );
105 * Checks the unique counts of other tasks to ensure they are still operational.
106 * Returns pdTRUE if an error is detected, otherwise pdFALSE.
108 static portBASE_TYPE prvCheckOtherTasksAreStillRunning( void );
110 /*-----------------------------------------------------------*/
112 /* Creates the tasks, then starts the scheduler. */
115 /* Initialise the required hardware. */
116 vParTestInitialise();
117 vPortInitialiseBlocks();
119 /* Send a character so we have some visible feedback of a reset. */
120 xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH );
121 xSerialPutChar( NULL, 'X', mainNO_BLOCK );
123 /* Start the standard demo tasks found in the demo\common directory. */
124 vStartIntegerMathTasks( tskIDLE_PRIORITY );
125 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
127 /* Start the check task defined in this file. */
128 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
130 /* Start the scheduler. Will never return here. */
131 vTaskStartScheduler();
133 /*-----------------------------------------------------------*/
135 static void vErrorChecks( void *pvParameters )
137 TickType_t xDelayTime = mainNO_ERROR_CHECK_PERIOD;
138 portBASE_TYPE xErrorOccurred;
140 /* Cycle for ever, delaying then checking all the other tasks are still
141 operating without error. */
144 /* Wait until it is time to check the other tasks. */
145 vTaskDelay( xDelayTime );
147 /* Check all the other tasks are running, and running without ever
149 xErrorOccurred = prvCheckOtherTasksAreStillRunning();
151 /* If an error was detected increase the frequency of the LED flash. */
152 if( xErrorOccurred == pdTRUE )
154 xDelayTime = mainERROR_CHECK_PERIOD;
157 /* Flash the LED for visual feedback. */
158 vParTestToggleLED( mainCHECK_TASK_LED );
161 /*-----------------------------------------------------------*/
163 static portBASE_TYPE prvCheckOtherTasksAreStillRunning( void )
165 portBASE_TYPE xErrorHasOccurred = pdFALSE;
167 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
169 xErrorHasOccurred = pdTRUE;
172 if( xArePollingQueuesStillRunning() != pdTRUE )
174 xErrorHasOccurred = pdTRUE;
177 return xErrorHasOccurred;
179 /*-----------------------------------------------------------*/