2 FreeRTOS.org V5.2.0 - Copyright (C) 2003-2009 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 it
\r
7 under the terms of the GNU General Public License (version 2) as published
\r
8 by the Free Software Foundation and modified by the FreeRTOS exception.
\r
10 FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT
\r
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
15 You should have received a copy of the GNU General Public License along
\r
16 with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59
\r
17 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
19 A special exception to the GPL is included to allow you to distribute a
\r
20 combined work that includes FreeRTOS.org without being obliged to provide
\r
21 the source code for any proprietary components. See the licensing section
\r
22 of http://www.FreeRTOS.org for full details.
\r
25 ***************************************************************************
\r
27 * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *
\r
29 * This is a concise, step by step, 'hands on' guide that describes both *
\r
30 * general multitasking concepts and FreeRTOS specifics. It presents and *
\r
31 * explains numerous examples that are written using the FreeRTOS API. *
\r
32 * Full source code for all the examples is provided in an accompanying *
\r
35 ***************************************************************************
\r
39 Please ensure to read the configuration and relevant port sections of the
\r
40 online documentation.
\r
42 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
45 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
48 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
49 licensing and training services.
\r
59 * Instead of the normal single demo application, the PIC18F demo is split
\r
60 * into several smaller programs of which this is the second. This enables the
\r
61 * demo's to be executed on the RAM limited PIC-devices.
\r
63 * The Demo2 project is configured for a PIC18F4620 device. Main.c starts 12
\r
64 * tasks (including the idle task). See the indicated files in the demo/common
\r
65 * directory for more information.
\r
67 * demo/common/minimal/integer.c: Creates 1 task
\r
68 * demo/common/minimal/PollQ.c: Creates 2 tasks
\r
69 * demo/common/minimal/semtest.c: Creates 4 tasks
\r
70 * demo/common/minimal/flash.c: Creates 3 tasks
\r
72 * Main.c also creates a check task. This periodically checks that all the
\r
73 * other tasks are still running and have not experienced any unexpected
\r
74 * results. If all the other tasks are executing correctly an LED is flashed
\r
75 * once every mainCHECK_PERIOD milliseconds. If any of the tasks have not
\r
76 * executed, or report an error, the frequency of the LED flash will increase
\r
77 * to mainERROR_FLASH_RATE.
\r
79 * On entry to main an 'X' is transmitted. Monitoring the serial port using a
\r
80 * dumb terminal allows for verification that the device is not continuously
\r
81 * being reset (no more than one 'X' should be transmitted).
\r
83 * http://www.FreeRTOS.org contains important information on the use of the
\r
87 /* Scheduler include files. */
\r
88 #include <FreeRTOS.h>
\r
91 /* Demo app include files. */
\r
92 #include "integer.h"
\r
94 #include "semtest.h"
\r
96 #include "partest.h"
\r
99 /* The period between executions of the check task before and after an error
\r
100 has been discovered. If an error has been discovered the check task runs
\r
101 more frequently - increasing the LED flash rate. */
\r
102 #define mainNO_ERROR_CHECK_PERIOD ( ( portTickType ) 10000 / portTICK_RATE_MS )
\r
103 #define mainERROR_CHECK_PERIOD ( ( portTickType ) 1000 / portTICK_RATE_MS )
\r
104 #define mainCHECK_TASK_LED ( ( unsigned portCHAR ) 3 )
\r
106 /* Priority definitions for some of the tasks. Other tasks just use the idle
\r
108 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + ( unsigned portCHAR ) 3 )
\r
109 #define mainLED_FLASH_PRIORITY ( tskIDLE_PRIORITY + ( unsigned portCHAR ) 2 )
\r
110 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + ( unsigned portCHAR ) 1 )
\r
111 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + ( unsigned portCHAR ) 1 )
\r
112 #define mainINTEGER_PRIORITY ( tskIDLE_PRIORITY + ( unsigned portCHAR ) 0 )
\r
114 /* Constants required for the communications. Only one character is ever
\r
116 #define mainCOMMS_QUEUE_LENGTH ( ( unsigned portCHAR ) 5 )
\r
117 #define mainNO_BLOCK ( ( portTickType ) 0 )
\r
118 #define mainBAUD_RATE ( ( unsigned portLONG ) 57600 )
\r
121 * The task function for the "Check" task.
\r
123 static portTASK_FUNCTION_PROTO( vErrorChecks, pvParameters );
\r
126 * Checks the unique counts of other tasks to ensure they are still operational.
\r
127 * Returns pdTRUE if an error is detected, otherwise pdFALSE.
\r
129 static portCHAR prvCheckOtherTasksAreStillRunning( void );
\r
131 /*-----------------------------------------------------------*/
\r
133 /* Creates the tasks, then starts the scheduler. */
\r
136 /* Initialise the required hardware. */
\r
137 vParTestInitialise();
\r
139 /* Send a character so we have some visible feedback of a reset. */
\r
140 xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH );
\r
141 xSerialPutChar( NULL, 'X', mainNO_BLOCK );
\r
143 /* Start a few of the standard demo tasks found in the demo\common directory. */
\r
144 vStartIntegerMathTasks( mainINTEGER_PRIORITY);
\r
145 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
146 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
147 vStartLEDFlashTasks( mainLED_FLASH_PRIORITY );
\r
149 /* Start the check task defined in this file. */
\r
150 xTaskCreate( vErrorChecks, ( const portCHAR * const ) "Check", portMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
152 /* Start the scheduler. Will never return here. */
\r
153 vTaskStartScheduler();
\r
155 while(1) /* This point should never be reached. */
\r
159 /*-----------------------------------------------------------*/
\r
161 static portTASK_FUNCTION( vErrorChecks, pvParameters )
\r
163 portTickType xLastCheckTime;
\r
164 portTickType xDelayTime = mainNO_ERROR_CHECK_PERIOD;
\r
165 portCHAR cErrorOccurred;
\r
167 /* We need to initialise xLastCheckTime prior to the first call to
\r
168 vTaskDelayUntil(). */
\r
169 xLastCheckTime = xTaskGetTickCount();
\r
171 /* Cycle for ever, delaying then checking all the other tasks are still
\r
172 operating without error. */
\r
175 /* Wait until it is time to check the other tasks again. */
\r
176 vTaskDelayUntil( &xLastCheckTime, xDelayTime );
\r
178 /* Check all the other tasks are running, and running without ever
\r
179 having an error. */
\r
180 cErrorOccurred = prvCheckOtherTasksAreStillRunning();
\r
182 /* If an error was detected increase the frequency of the LED flash. */
\r
183 if( cErrorOccurred == pdTRUE )
\r
185 xDelayTime = mainERROR_CHECK_PERIOD;
\r
188 /* Flash the LED for visual feedback. */
\r
189 vParTestToggleLED( mainCHECK_TASK_LED );
\r
192 /*-----------------------------------------------------------*/
\r
194 static portCHAR prvCheckOtherTasksAreStillRunning( void )
\r
196 portCHAR cErrorHasOccurred = ( portCHAR ) pdFALSE;
\r
198 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
200 cErrorHasOccurred = ( portCHAR ) pdTRUE;
\r
203 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
205 cErrorHasOccurred = ( portCHAR ) pdTRUE;
\r
208 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
210 cErrorHasOccurred = ( portCHAR ) pdTRUE;
\r
213 return cErrorHasOccurred;
\r
215 /*-----------------------------------------------------------*/
\r