2 FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
7 the terms of the GNU General Public License (version 2) as published by the
\r
8 Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS without being obliged to provide the
\r
11 source code for proprietary components outside of the FreeRTOS kernel.
\r
12 Alternative commercial license and support terms are also available upon
\r
13 request. See the licensing section of http://www.FreeRTOS.org for full
\r
16 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
21 You should have received a copy of the GNU General Public License along
\r
22 with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
\r
23 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
26 ***************************************************************************
\r
28 * The FreeRTOS eBook and reference manual are available to purchase for a *
\r
29 * small fee. Help yourself get started quickly while also helping the *
\r
30 * FreeRTOS project! See http://www.FreeRTOS.org/Documentation for details *
\r
32 ***************************************************************************
\r
36 Please ensure to read the configuration and relevant port sections of the
\r
37 online documentation.
\r
39 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
42 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
45 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
46 licensing and training services.
\r
56 * Instead of the normal single demo application, the PIC18F demo is split
\r
57 * into several smaller programs of which this is the second. This enables the
\r
58 * demo's to be executed on the RAM limited PIC-devices.
\r
60 * The Demo2 project is configured for a PIC18F4620 device. Main.c starts 12
\r
61 * tasks (including the idle task). See the indicated files in the demo/common
\r
62 * directory for more information.
\r
64 * demo/common/minimal/integer.c: Creates 1 task
\r
65 * demo/common/minimal/PollQ.c: Creates 2 tasks
\r
66 * demo/common/minimal/semtest.c: Creates 4 tasks
\r
67 * demo/common/minimal/flash.c: Creates 3 tasks
\r
69 * Main.c also creates a check task. This periodically checks that all the
\r
70 * other tasks are still running and have not experienced any unexpected
\r
71 * results. If all the other tasks are executing correctly an LED is flashed
\r
72 * once every mainCHECK_PERIOD milliseconds. If any of the tasks have not
\r
73 * executed, or report an error, the frequency of the LED flash will increase
\r
74 * to mainERROR_FLASH_RATE.
\r
76 * On entry to main an 'X' is transmitted. Monitoring the serial port using a
\r
77 * dumb terminal allows for verification that the device is not continuously
\r
78 * being reset (no more than one 'X' should be transmitted).
\r
80 * http://www.FreeRTOS.org contains important information on the use of the
\r
84 /* Scheduler include files. */
\r
85 #include <FreeRTOS.h>
\r
88 /* Demo app include files. */
\r
89 #include "integer.h"
\r
91 #include "semtest.h"
\r
93 #include "partest.h"
\r
96 /* The period between executions of the check task before and after an error
\r
97 has been discovered. If an error has been discovered the check task runs
\r
98 more frequently - increasing the LED flash rate. */
\r
99 #define mainNO_ERROR_CHECK_PERIOD ( ( portTickType ) 10000 / portTICK_RATE_MS )
\r
100 #define mainERROR_CHECK_PERIOD ( ( portTickType ) 1000 / portTICK_RATE_MS )
\r
101 #define mainCHECK_TASK_LED ( ( unsigned char ) 3 )
\r
103 /* Priority definitions for some of the tasks. Other tasks just use the idle
\r
105 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + ( unsigned char ) 3 )
\r
106 #define mainLED_FLASH_PRIORITY ( tskIDLE_PRIORITY + ( unsigned char ) 2 )
\r
107 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + ( unsigned char ) 1 )
\r
108 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + ( unsigned char ) 1 )
\r
109 #define mainINTEGER_PRIORITY ( tskIDLE_PRIORITY + ( unsigned char ) 0 )
\r
111 /* Constants required for the communications. Only one character is ever
\r
113 #define mainCOMMS_QUEUE_LENGTH ( ( unsigned char ) 5 )
\r
114 #define mainNO_BLOCK ( ( portTickType ) 0 )
\r
115 #define mainBAUD_RATE ( ( unsigned long ) 57600 )
\r
118 * The task function for the "Check" task.
\r
120 static portTASK_FUNCTION_PROTO( vErrorChecks, pvParameters );
\r
123 * Checks the unique counts of other tasks to ensure they are still operational.
\r
124 * Returns pdTRUE if an error is detected, otherwise pdFALSE.
\r
126 static char prvCheckOtherTasksAreStillRunning( void );
\r
128 /*-----------------------------------------------------------*/
\r
130 /* Creates the tasks, then starts the scheduler. */
\r
133 /* Initialise the required hardware. */
\r
134 vParTestInitialise();
\r
136 /* Send a character so we have some visible feedback of a reset. */
\r
137 xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH );
\r
138 xSerialPutChar( NULL, 'X', mainNO_BLOCK );
\r
140 /* Start a few of the standard demo tasks found in the demo\common directory. */
\r
141 vStartIntegerMathTasks( mainINTEGER_PRIORITY);
\r
142 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
143 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
144 vStartLEDFlashTasks( mainLED_FLASH_PRIORITY );
\r
146 /* Start the check task defined in this file. */
\r
147 xTaskCreate( vErrorChecks, ( const char * const ) "Check", portMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
149 /* Start the scheduler. Will never return here. */
\r
150 vTaskStartScheduler();
\r
152 while(1) /* This point should never be reached. */
\r
156 /*-----------------------------------------------------------*/
\r
158 static portTASK_FUNCTION( vErrorChecks, pvParameters )
\r
160 portTickType xLastCheckTime;
\r
161 portTickType xDelayTime = mainNO_ERROR_CHECK_PERIOD;
\r
162 char cErrorOccurred;
\r
164 /* We need to initialise xLastCheckTime prior to the first call to
\r
165 vTaskDelayUntil(). */
\r
166 xLastCheckTime = xTaskGetTickCount();
\r
168 /* Cycle for ever, delaying then checking all the other tasks are still
\r
169 operating without error. */
\r
172 /* Wait until it is time to check the other tasks again. */
\r
173 vTaskDelayUntil( &xLastCheckTime, xDelayTime );
\r
175 /* Check all the other tasks are running, and running without ever
\r
176 having an error. */
\r
177 cErrorOccurred = prvCheckOtherTasksAreStillRunning();
\r
179 /* If an error was detected increase the frequency of the LED flash. */
\r
180 if( cErrorOccurred == pdTRUE )
\r
182 xDelayTime = mainERROR_CHECK_PERIOD;
\r
185 /* Flash the LED for visual feedback. */
\r
186 vParTestToggleLED( mainCHECK_TASK_LED );
\r
189 /*-----------------------------------------------------------*/
\r
191 static char prvCheckOtherTasksAreStillRunning( void )
\r
193 char cErrorHasOccurred = ( char ) pdFALSE;
\r
195 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
197 cErrorHasOccurred = ( char ) pdTRUE;
\r
200 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
202 cErrorHasOccurred = ( char ) pdTRUE;
\r
205 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
207 cErrorHasOccurred = ( char ) pdTRUE;
\r
210 return cErrorHasOccurred;
\r
212 /*-----------------------------------------------------------*/
\r