2 FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
32 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
33 distribute a combined work that includes FreeRTOS without being obliged to
\r
34 provide the source code for proprietary components outside of the FreeRTOS
\r
35 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
36 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
37 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
38 more details. You should have received a copy of the GNU General Public
\r
39 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
40 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
41 by writing to Richard Barry, contact details for whom are available on the
\r
46 ***************************************************************************
\r
48 * Having a problem? Start by reading the FAQ "My application does *
\r
49 * not run, what could be wrong?" *
\r
51 * http://www.FreeRTOS.org/FAQHelp.html *
\r
53 ***************************************************************************
\r
56 http://www.FreeRTOS.org - Documentation, training, latest versions, license
\r
57 and contact details.
\r
59 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
60 including FreeRTOS+Trace - an indispensable productivity tool.
\r
62 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
63 the code with commercial support, indemnification, and middleware, under
\r
64 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
65 provide a safety engineered and independently SIL3 certified version under
\r
66 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
70 * Instead of the normal single demo application, the PIC18F demo is split
\r
71 * into several smaller programs of which this is the second. This enables the
\r
72 * demo's to be executed on the RAM limited 40 pin devices. The 64 and 80 pin
\r
73 * devices require a more costly development platform and are not so readily
\r
76 * The RTOSDemo2 project is configured for a PIC18F452 device. Main2.c starts
\r
77 * 5 tasks (including the idle task).
\r
79 * The first, second and third tasks do nothing but flash an LED. This gives
\r
80 * visual feedback that everything is executing as expected. One task flashes
\r
81 * an LED every 333ms (i.e. on and off every 333/2 ms), then next every 666ms
\r
82 * and the last every 999ms.
\r
84 * The last task runs at the idle priority. It repeatedly performs a 32bit
\r
85 * calculation and checks it's result against the expected value. This checks
\r
86 * that the temporary storage utilised by the compiler to hold intermediate
\r
87 * results does not get corrupted when the task gets switched in and out.
\r
88 * should the calculation ever provide an incorrect result the final LED is
\r
91 * On entry to main() an 'X' is transmitted. Monitoring the serial port using a
\r
92 * dumb terminal allows for verification that the device is not continuously
\r
93 * being reset (no more than one 'X' should be transmitted).
\r
95 * http://www.FreeRTOS.org contains important information on the use of the
\r
100 Changes from V2.0.0
\r
102 + Delay periods are now specified using variables and constants of
\r
103 portTickType rather than unsigned long.
\r
106 /* Scheduler include files. */
\r
107 #include "FreeRTOS.h"
\r
110 /* Demo app include files. */
\r
112 #include "partest.h"
\r
113 #include "serial.h"
\r
115 /* Priority definitions for the LED tasks. Other tasks just use the idle
\r
117 #define mainLED_FLASH_PRIORITY ( tskIDLE_PRIORITY + ( unsigned portBASE_TYPE ) 1 )
\r
119 /* The LED that is lit when should the calculation fail. */
\r
120 #define mainCHECK_TASK_LED ( ( unsigned portBASE_TYPE ) 3 )
\r
122 /* Constants required for the communications. Only one character is ever
\r
124 #define mainCOMMS_QUEUE_LENGTH ( ( unsigned portBASE_TYPE ) 5 )
\r
125 #define mainNO_BLOCK ( ( portTickType ) 0 )
\r
126 #define mainBAUD_RATE ( ( unsigned long ) 9600 )
\r
129 * The task that performs the 32 bit calculation at the idle priority.
\r
131 static void vCalculationTask( void *pvParameters );
\r
133 /*-----------------------------------------------------------*/
\r
135 /* Creates the tasks, then starts the scheduler. */
\r
138 /* Initialise the required hardware. */
\r
139 vParTestInitialise();
\r
140 vPortInitialiseBlocks();
\r
142 /* Send a character so we have some visible feedback of a reset. */
\r
143 xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH );
\r
144 xSerialPutChar( NULL, 'X', mainNO_BLOCK );
\r
146 /* Start the standard LED flash tasks as defined in demo/common/minimal. */
\r
147 vStartLEDFlashTasks( mainLED_FLASH_PRIORITY );
\r
149 /* Start the check task defined in this file. */
\r
150 xTaskCreate( vCalculationTask, ( const char * const ) "Check", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
152 /* Start the scheduler. */
\r
153 vTaskStartScheduler();
\r
155 /*-----------------------------------------------------------*/
\r
157 static void vCalculationTask( void *pvParameters )
\r
159 volatile unsigned long ulCalculatedValue; /* Volatile to ensure optimisation is minimal. */
\r
161 /* Continuously perform a calculation. If the calculation result is ever
\r
162 incorrect turn the LED on. */
\r
165 /* A good optimising compiler would just remove all this! */
\r
166 ulCalculatedValue = 1234UL;
\r
167 ulCalculatedValue *= 99UL;
\r
169 if( ulCalculatedValue != 122166UL )
\r
171 vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
\r
174 ulCalculatedValue *= 9876UL;
\r
176 if( ulCalculatedValue != 1206511416UL )
\r
178 vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
\r
181 ulCalculatedValue /= 15UL;
\r
183 if( ulCalculatedValue != 80434094UL )
\r
185 vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
\r
188 ulCalculatedValue += 918273UL;
\r
190 if( ulCalculatedValue != 81352367UL )
\r
192 vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
\r
196 /*-----------------------------------------------------------*/
\r