2 FreeRTOS V6.0.4 - Copyright (C) 2010 Real Time Engineers Ltd.
\r
4 ***************************************************************************
\r
8 * + New to FreeRTOS, *
\r
9 * + Wanting to learn FreeRTOS or multitasking in general quickly *
\r
10 * + Looking for basic training, *
\r
11 * + Wanting to improve your FreeRTOS skills and productivity *
\r
13 * then take a look at the FreeRTOS eBook *
\r
15 * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
\r
16 * http://www.FreeRTOS.org/Documentation *
\r
18 * A pdf reference manual is also available. Both are usually delivered *
\r
19 * to your inbox within 20 minutes to two hours when purchased between 8am *
\r
20 * and 8pm GMT (although please allow up to 24 hours in case of *
\r
21 * exceptional circumstances). Thank you for your support! *
\r
23 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 ***NOTE*** The exception to the GPL is included to allow you to distribute
\r
31 a combined work that includes FreeRTOS without being obliged to provide the
\r
32 source code for proprietary components outside of the FreeRTOS kernel.
\r
33 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
34 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
35 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
55 * Instead of the normal single demo application, the PIC18F demo is split
\r
56 * into several smaller programs of which this is the first. This enables the
\r
57 * demo's to be executed on the RAM limited 40 pin devices. The 64 and 80 pin
\r
58 * devices require a more costly development platform and are not so readily
\r
61 * The RTOSDemo1 project is configured for a PIC18F452 device. Main1.c starts 5
\r
62 * tasks (including the idle task).
\r
64 * The first task runs at the idle priority. It repeatedly performs a 32bit
\r
65 * calculation and checks it's result against the expected value. This checks
\r
66 * that the temporary storage utilised by the compiler to hold intermediate
\r
67 * results does not get corrupted when the task gets switched in and out. See
\r
68 * demo/common/minimal/integer.c for more information.
\r
70 * The second and third tasks pass an incrementing value between each other on
\r
71 * a message queue. See demo/common/minimal/PollQ.c for more information.
\r
73 * Main1.c also creates a check task. This periodically checks that all the
\r
74 * other tasks are still running and have not experienced any unexpected
\r
75 * results. If all the other tasks are executing correctly an LED is flashed
\r
76 * once every mainCHECK_PERIOD milliseconds. If any of the tasks have not
\r
77 * executed, or report and error, the frequency of the LED flash will increase
\r
78 * to mainERROR_FLASH_RATE.
\r
80 * On entry to main an 'X' is transmitted. Monitoring the serial port using a
\r
81 * dumb terminal allows for verification that the device is not continuously
\r
82 * being reset (no more than one 'X' should be transmitted).
\r
84 * http://www.FreeRTOS.org contains important information on the use of the
\r
91 + Delay periods are now specified using variables and constants of
\r
92 portTickType rather than unsigned long.
\r
95 /* Scheduler include files. */
\r
96 #include "FreeRTOS.h"
\r
99 /* Demo app include files. */
\r
101 #include "integer.h"
\r
102 #include "partest.h"
\r
103 #include "serial.h"
\r
105 /* The period between executions of the check task before and after an error
\r
106 has been discovered. If an error has been discovered the check task runs
\r
107 more frequently - increasing the LED flash rate. */
\r
108 #define mainNO_ERROR_CHECK_PERIOD ( ( portTickType ) 1000 / portTICK_RATE_MS )
\r
109 #define mainERROR_CHECK_PERIOD ( ( portTickType ) 100 / portTICK_RATE_MS )
\r
111 /* Priority definitions for some of the tasks. Other tasks just use the idle
\r
113 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
114 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
116 /* The LED that is flashed by the check task. */
\r
117 #define mainCHECK_TASK_LED ( 0 )
\r
119 /* Constants required for the communications. Only one character is ever
\r
121 #define mainCOMMS_QUEUE_LENGTH ( 5 )
\r
122 #define mainNO_BLOCK ( ( portTickType ) 0 )
\r
123 #define mainBAUD_RATE ( ( unsigned long ) 9600 )
\r
126 * The task function for the "Check" task.
\r
128 static void vErrorChecks( void *pvParameters );
\r
131 * Checks the unique counts of other tasks to ensure they are still operational.
\r
132 * Returns pdTRUE if an error is detected, otherwise pdFALSE.
\r
134 static portBASE_TYPE prvCheckOtherTasksAreStillRunning( void );
\r
136 /*-----------------------------------------------------------*/
\r
138 /* Creates the tasks, then starts the scheduler. */
\r
141 /* Initialise the required hardware. */
\r
142 vParTestInitialise();
\r
143 vPortInitialiseBlocks();
\r
145 /* Send a character so we have some visible feedback of a reset. */
\r
146 xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH );
\r
147 xSerialPutChar( NULL, 'X', mainNO_BLOCK );
\r
149 /* Start the standard demo tasks found in the demo\common directory. */
\r
150 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
151 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
153 /* Start the check task defined in this file. */
\r
154 xTaskCreate( vErrorChecks, ( const char * const ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
156 /* Start the scheduler. Will never return here. */
\r
157 vTaskStartScheduler();
\r
159 /*-----------------------------------------------------------*/
\r
161 static void vErrorChecks( void *pvParameters )
\r
163 portTickType xDelayTime = mainNO_ERROR_CHECK_PERIOD;
\r
164 portBASE_TYPE xErrorOccurred;
\r
166 /* Cycle for ever, delaying then checking all the other tasks are still
\r
167 operating without error. */
\r
170 /* Wait until it is time to check the other tasks. */
\r
171 vTaskDelay( xDelayTime );
\r
173 /* Check all the other tasks are running, and running without ever
\r
174 having an error. */
\r
175 xErrorOccurred = prvCheckOtherTasksAreStillRunning();
\r
177 /* If an error was detected increase the frequency of the LED flash. */
\r
178 if( xErrorOccurred == pdTRUE )
\r
180 xDelayTime = mainERROR_CHECK_PERIOD;
\r
183 /* Flash the LED for visual feedback. */
\r
184 vParTestToggleLED( mainCHECK_TASK_LED );
\r
187 /*-----------------------------------------------------------*/
\r
189 static portBASE_TYPE prvCheckOtherTasksAreStillRunning( void )
\r
191 portBASE_TYPE xErrorHasOccurred = pdFALSE;
\r
193 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
195 xErrorHasOccurred = pdTRUE;
\r
198 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
200 xErrorHasOccurred = pdTRUE;
\r
203 return xErrorHasOccurred;
\r
205 /*-----------------------------------------------------------*/
\r