2 FreeRTOS.org V4.7.1 - Copyright (C) 2003-2008 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org 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.org 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.org; 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.org, 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
28 Please ensure to read the configuration and relevant port sections of the
\r
29 online documentation.
\r
31 +++ http://www.FreeRTOS.org +++
\r
32 Documentation, latest information, license and contact details.
\r
34 +++ http://www.SafeRTOS.com +++
\r
35 A version that is certified for use in safety critical systems.
\r
37 +++ http://www.OpenRTOS.com +++
\r
38 Commercial support, development, porting, licensing and training services.
\r
40 ***************************************************************************
\r
50 * Instead of the normal single demo application, the PIC18F demo is split
\r
51 * into several smaller programs of which this is the sixth. This enables the
\r
52 * demo's to be executed on the RAM limited PIC-devices.
\r
54 * The Demo6 project is configured for a PIC18F4620 device. Main.c starts 4
\r
55 * tasks (including the idle task). See the indicated files in the demo/common
\r
56 * directory for more information.
\r
58 * demo/common/minimal/comtest.c: Creates 2 tasks
\r
59 * ATTENTION: Comtest needs a loopback-connector on the serial port.
\r
61 * Main.c also creates a check task. This periodically checks that all the
\r
62 * other tasks are still running and have not experienced any unexpected
\r
63 * results. If all the other tasks are executing correctly an LED is flashed
\r
64 * once every mainCHECK_PERIOD milliseconds. If any of the tasks have not
\r
65 * executed, or report an error, the frequency of the LED flash will increase
\r
66 * to mainERROR_FLASH_RATE.
\r
68 * http://www.FreeRTOS.org contains important information on the use of the
\r
72 /* Scheduler include files. */
\r
73 #include <FreeRTOS.h>
\r
76 /* Demo app include files. */
\r
77 #include "partest.h"
\r
79 #include "comtest.h"
\r
81 /* The period between executions of the check task before and after an error
\r
82 has been discovered. If an error has been discovered the check task runs
\r
83 more frequently - increasing the LED flash rate. */
\r
84 #define mainNO_ERROR_CHECK_PERIOD ( ( portTickType ) 10000 / portTICK_RATE_MS )
\r
85 #define mainERROR_CHECK_PERIOD ( ( portTickType ) 1000 / portTICK_RATE_MS )
\r
86 #define mainCHECK_TASK_LED ( ( unsigned portCHAR ) 3 )
\r
88 /* Priority definitions for some of the tasks. Other tasks just use the idle
\r
90 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + ( unsigned portCHAR ) 2 )
\r
91 #define mainCOMM_TEST_PRIORITY ( tskIDLE_PRIORITY + ( unsigned portCHAR ) 1 )
\r
93 /* The LED that is toggled whenever a character is transmitted.
\r
94 mainCOMM_TX_RX_LED + 1 will be toggled every time a character is received. */
\r
95 #define mainCOMM_TX_RX_LED ( ( unsigned portCHAR ) 0 )
\r
97 /* Constants required for the communications. */
\r
98 #define mainBAUD_RATE ( ( unsigned portLONG ) 57600 )
\r
101 * The task function for the "Check" task.
\r
103 static portTASK_FUNCTION_PROTO( vErrorChecks, pvParameters );
\r
106 * Checks the unique counts of other tasks to ensure they are still operational.
\r
107 * Returns pdTRUE if an error is detected, otherwise pdFALSE.
\r
109 static portCHAR prvCheckOtherTasksAreStillRunning( void );
\r
111 /*-----------------------------------------------------------*/
\r
113 /* Creates the tasks, then starts the scheduler. */
\r
116 /* Initialise the required hardware. */
\r
117 vParTestInitialise();
\r
119 /* Start a few of the standard demo tasks found in the demo\common directory. */
\r
120 vAltStartComTestTasks( mainCOMM_TEST_PRIORITY, mainBAUD_RATE, mainCOMM_TX_RX_LED );
\r
122 /* Start the check task defined in this file. */
\r
123 xTaskCreate( vErrorChecks, ( const portCHAR * const ) "Check", portMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
125 /* Start the scheduler. Will never return here. */
\r
126 vTaskStartScheduler();
\r
128 while(1) /* This point should never be reached. */
\r
132 /*-----------------------------------------------------------*/
\r
134 static portTASK_FUNCTION( vErrorChecks, pvParameters )
\r
136 portTickType xLastCheckTime;
\r
137 portTickType xDelayTime = mainNO_ERROR_CHECK_PERIOD;
\r
138 portCHAR cErrorOccurred;
\r
140 /* We need to initialise xLastCheckTime prior to the first call to
\r
141 vTaskDelayUntil(). */
\r
142 xLastCheckTime = xTaskGetTickCount();
\r
144 /* Cycle for ever, delaying then checking all the other tasks are still
\r
145 operating without error. */
\r
148 /* Wait until it is time to check the other tasks again. */
\r
149 vTaskDelayUntil( &xLastCheckTime, xDelayTime );
\r
151 /* Check all the other tasks are running, and running without ever
\r
152 having an error. */
\r
153 cErrorOccurred = prvCheckOtherTasksAreStillRunning();
\r
155 /* If an error was detected increase the frequency of the LED flash. */
\r
156 if( cErrorOccurred == pdTRUE )
\r
158 xDelayTime = mainERROR_CHECK_PERIOD;
\r
161 /* Flash the LED for visual feedback. */
\r
162 vParTestToggleLED( mainCHECK_TASK_LED );
\r
165 /*-----------------------------------------------------------*/
\r
167 static portCHAR prvCheckOtherTasksAreStillRunning( void )
\r
169 portCHAR cErrorHasOccurred = ( portCHAR ) pdFALSE;
\r
171 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
173 cErrorHasOccurred = ( portCHAR ) pdTRUE;
\r
176 return cErrorHasOccurred;
\r
178 /*-----------------------------------------------------------*/
\r