2 FreeRTOS V4.0.1 - Copyright (C) 2003-2006 Richard Barry.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 See http://www.FreeRTOS.org for documentation, latest information, license
\r
28 and contact details. Please ensure to read the configuration and relevant
\r
29 port sections of the online documentation.
\r
30 ***************************************************************************
\r
40 * Instead of the normal single demo application, the PIC18F demo is split
\r
41 * into several smaller programs of which this is the fifth. This enables the
\r
42 * demo's to be executed on the RAM limited PIC-devices.
\r
44 * The Demo5 project is configured for a PIC18F4620 device. Main.c starts 13
\r
45 * tasks (including the idle task). See the indicated files in the demo/common
\r
46 * directory for more information.
\r
48 * demo/common/minimal/flop.c: Creates 8 tasks
\r
49 * demo/common/minimal/flash.c: Creates 3 tasks
\r
51 * Main.c also creates a check task. This periodically checks that all the
\r
52 * other tasks are still running and have not experienced any unexpected
\r
53 * results. If all the other tasks are executing correctly an LED is flashed
\r
54 * once every mainCHECK_PERIOD milliseconds. If any of the tasks have not
\r
55 * executed, or report an error, the frequency of the LED flash will increase
\r
56 * to mainERROR_FLASH_RATE.
\r
58 * On entry to main an 'X' is transmitted. Monitoring the serial port using a
\r
59 * dumb terminal allows for verification that the device is not continuously
\r
60 * being reset (no more than one 'X' should be transmitted).
\r
62 * http://www.FreeRTOS.org contains important information on the use of the
\r
66 /* Scheduler include files. */
\r
67 #include <FreeRTOS.h>
\r
70 /* Demo app include files. */
\r
73 #include "partest.h"
\r
76 /* The period between executions of the check task before and after an error
\r
77 has been discovered. If an error has been discovered the check task runs
\r
78 more frequently - increasing the LED flash rate. */
\r
79 #define mainNO_ERROR_CHECK_PERIOD ( ( portTickType ) 10000 / portTICK_RATE_MS )
\r
80 #define mainERROR_CHECK_PERIOD ( ( portTickType ) 1000 / portTICK_RATE_MS )
\r
81 #define mainCHECK_TASK_LED ( ( unsigned portCHAR ) 3 )
\r
83 /* Priority definitions for some of the tasks. Other tasks just use the idle
\r
85 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + ( unsigned portCHAR ) 2 )
\r
86 #define mainLED_FLASH_PRIORITY ( tskIDLE_PRIORITY + ( unsigned portCHAR ) 1 )
\r
88 /* Constants required for the communications. Only one character is ever
\r
90 #define mainCOMMS_QUEUE_LENGTH ( ( unsigned portCHAR ) 5 )
\r
91 #define mainNO_BLOCK ( ( portTickType ) 0 )
\r
92 #define mainBAUD_RATE ( ( unsigned portLONG ) 57600 )
\r
95 * The task function for the "Check" task.
\r
97 static portTASK_FUNCTION_PROTO( vErrorChecks, pvParameters );
\r
100 * Checks the unique counts of other tasks to ensure they are still operational.
\r
101 * Returns pdTRUE if an error is detected, otherwise pdFALSE.
\r
103 static portCHAR prvCheckOtherTasksAreStillRunning( void );
\r
105 /*-----------------------------------------------------------*/
\r
107 /* Creates the tasks, then starts the scheduler. */
\r
110 /* Initialise the required hardware. */
\r
111 vParTestInitialise();
\r
113 /* Send a character so we have some visible feedback of a reset. */
\r
114 xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH );
\r
115 xSerialPutChar( NULL, 'X', mainNO_BLOCK );
\r
117 /* Start a few of the standard demo tasks found in the demo\common directory. */
\r
118 vStartMathTasks( tskIDLE_PRIORITY );
\r
119 vStartLEDFlashTasks( mainLED_FLASH_PRIORITY );
\r
121 /* Start the check task defined in this file. */
\r
122 xTaskCreate( vErrorChecks, ( const portCHAR * const ) "Check", portMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
124 /* Start the scheduler. Will never return here. */
\r
125 vTaskStartScheduler();
\r
127 while(1) /* This point should never be reached. */
\r
131 /*-----------------------------------------------------------*/
\r
133 static portTASK_FUNCTION( vErrorChecks, pvParameters )
\r
135 portTickType xLastCheckTime;
\r
136 portTickType xDelayTime = mainNO_ERROR_CHECK_PERIOD;
\r
137 portCHAR cErrorOccurred;
\r
139 /* We need to initialise xLastCheckTime prior to the first call to
\r
140 vTaskDelayUntil(). */
\r
141 xLastCheckTime = xTaskGetTickCount();
\r
143 /* Cycle for ever, delaying then checking all the other tasks are still
\r
144 operating without error. */
\r
147 /* Wait until it is time to check the other tasks again. */
\r
148 vTaskDelayUntil( &xLastCheckTime, xDelayTime );
\r
150 /* Check all the other tasks are running, and running without ever
\r
151 having an error. */
\r
152 cErrorOccurred = prvCheckOtherTasksAreStillRunning();
\r
154 /* If an error was detected increase the frequency of the LED flash. */
\r
155 if( cErrorOccurred == pdTRUE )
\r
157 xDelayTime = mainERROR_CHECK_PERIOD;
\r
160 /* Flash the LED for visual feedback. */
\r
161 vParTestToggleLED( mainCHECK_TASK_LED );
\r
164 /*-----------------------------------------------------------*/
\r
166 static portCHAR prvCheckOtherTasksAreStillRunning( void )
\r
168 portCHAR cErrorHasOccurred = ( portCHAR ) pdFALSE;
\r
170 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
172 cErrorHasOccurred = ( portCHAR ) pdTRUE;
\r
174 return cErrorHasOccurred;
\r
176 /*-----------------------------------------------------------*/
\r