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
29 * Instead of the normal single demo application, the PIC18F demo is split
\r
30 * into several smaller programs of which this is the first. This enables the
\r
31 * demo's to be executed on the RAM limited 40 pin devices. The 64 and 80 pin
\r
32 * devices require a more costly development platform and are not so readily
\r
35 * The RTOSDemo1 project is configured for a PIC18F452 device. Main1.c starts 5
\r
36 * tasks (including the idle task).
\r
38 * The first task runs at the idle priority. It repeatedly performs a 32bit
\r
39 * calculation and checks it's result against the expected value. This checks
\r
40 * that the temporary storage utilised by the compiler to hold intermediate
\r
41 * results does not get corrupted when the task gets switched in and out. See
\r
42 * demo/common/minimal/integer.c for more information.
\r
44 * The second and third tasks pass an incrementing value between each other on
\r
45 * a message queue. See demo/common/minimal/PollQ.c for more information.
\r
47 * Main1.c also creates a check task. This periodically checks that all the
\r
48 * other tasks are still running and have not experienced any unexpected
\r
49 * results. If all the other tasks are executing correctly an LED is flashed
\r
50 * once every mainCHECK_PERIOD milliseconds. If any of the tasks have not
\r
51 * executed, or report and error, the frequency of the LED flash will increase
\r
52 * to mainERROR_FLASH_RATE.
\r
54 * On entry to main an 'X' is transmitted. Monitoring the serial port using a
\r
55 * dumb terminal allows for verification that the device is not continuously
\r
56 * being reset (no more than one 'X' should be transmitted).
\r
58 * http://www.FreeRTOS.org contains important information on the use of the
\r
65 + Delay periods are now specified using variables and constants of
\r
66 TickType_t rather than unsigned long.
\r
69 /* Scheduler include files. */
\r
70 #include "FreeRTOS.h"
\r
73 /* Demo app include files. */
\r
75 #include "integer.h"
\r
76 #include "partest.h"
\r
79 /* The period between executions of the check task before and after an error
\r
80 has been discovered. If an error has been discovered the check task runs
\r
81 more frequently - increasing the LED flash rate. */
\r
82 #define mainNO_ERROR_CHECK_PERIOD ( ( TickType_t ) 1000 / portTICK_PERIOD_MS )
\r
83 #define mainERROR_CHECK_PERIOD ( ( TickType_t ) 100 / portTICK_PERIOD_MS )
\r
85 /* Priority definitions for some of the tasks. Other tasks just use the idle
\r
87 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
88 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
90 /* The LED that is flashed by the check task. */
\r
91 #define mainCHECK_TASK_LED ( 0 )
\r
93 /* Constants required for the communications. Only one character is ever
\r
95 #define mainCOMMS_QUEUE_LENGTH ( 5 )
\r
96 #define mainNO_BLOCK ( ( TickType_t ) 0 )
\r
97 #define mainBAUD_RATE ( ( unsigned long ) 9600 )
\r
100 * The task function for the "Check" task.
\r
102 static void vErrorChecks( void *pvParameters );
\r
105 * Checks the unique counts of other tasks to ensure they are still operational.
\r
106 * Returns pdTRUE if an error is detected, otherwise pdFALSE.
\r
108 static portBASE_TYPE prvCheckOtherTasksAreStillRunning( void );
\r
110 /*-----------------------------------------------------------*/
\r
112 /* Creates the tasks, then starts the scheduler. */
\r
115 /* Initialise the required hardware. */
\r
116 vParTestInitialise();
\r
117 vPortInitialiseBlocks();
\r
119 /* Send a character so we have some visible feedback of a reset. */
\r
120 xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH );
\r
121 xSerialPutChar( NULL, 'X', mainNO_BLOCK );
\r
123 /* Start the standard demo tasks found in the demo\common directory. */
\r
124 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
125 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
127 /* Start the check task defined in this file. */
\r
128 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
130 /* Start the scheduler. Will never return here. */
\r
131 vTaskStartScheduler();
\r
133 /*-----------------------------------------------------------*/
\r
135 static void vErrorChecks( void *pvParameters )
\r
137 TickType_t xDelayTime = mainNO_ERROR_CHECK_PERIOD;
\r
138 portBASE_TYPE xErrorOccurred;
\r
140 /* Cycle for ever, delaying then checking all the other tasks are still
\r
141 operating without error. */
\r
144 /* Wait until it is time to check the other tasks. */
\r
145 vTaskDelay( xDelayTime );
\r
147 /* Check all the other tasks are running, and running without ever
\r
148 having an error. */
\r
149 xErrorOccurred = prvCheckOtherTasksAreStillRunning();
\r
151 /* If an error was detected increase the frequency of the LED flash. */
\r
152 if( xErrorOccurred == pdTRUE )
\r
154 xDelayTime = mainERROR_CHECK_PERIOD;
\r
157 /* Flash the LED for visual feedback. */
\r
158 vParTestToggleLED( mainCHECK_TASK_LED );
\r
161 /*-----------------------------------------------------------*/
\r
163 static portBASE_TYPE prvCheckOtherTasksAreStillRunning( void )
\r
165 portBASE_TYPE xErrorHasOccurred = pdFALSE;
\r
167 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
169 xErrorHasOccurred = pdTRUE;
\r
172 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
174 xErrorHasOccurred = pdTRUE;
\r
177 return xErrorHasOccurred;
\r
179 /*-----------------------------------------------------------*/
\r