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
53 * Instead of the normal single demo application, the PIC18F demo is split
\r
54 * into several smaller programs of which this is the second. This enables the
\r
55 * demo's to be executed on the RAM limited 40 pin devices. The 64 and 80 pin
\r
56 * devices require a more costly development platform and are not so readily
\r
59 * The RTOSDemo2 project is configured for a PIC18F452 device. Main2.c starts
\r
60 * 5 tasks (including the idle task).
\r
62 * The first, second and third tasks do nothing but flash an LED. This gives
\r
63 * visual feedback that everything is executing as expected. One task flashes
\r
64 * an LED every 333ms (i.e. on and off every 333/2 ms), then next every 666ms
\r
65 * and the last every 999ms.
\r
67 * The last task runs at the idle priority. It repeatedly performs a 32bit
\r
68 * calculation and checks it's result against the expected value. This checks
\r
69 * that the temporary storage utilised by the compiler to hold intermediate
\r
70 * results does not get corrupted when the task gets switched in and out.
\r
71 * should the calculation ever provide an incorrect result the final LED is
\r
74 * On entry to main() an 'X' is transmitted. Monitoring the serial port using a
\r
75 * dumb terminal allows for verification that the device is not continuously
\r
76 * being reset (no more than one 'X' should be transmitted).
\r
78 * http://www.FreeRTOS.org contains important information on the use of the
\r
85 + Delay periods are now specified using variables and constants of
\r
86 portTickType rather than unsigned portLONG.
\r
89 /* Scheduler include files. */
\r
90 #include "FreeRTOS.h"
\r
93 /* Demo app include files. */
\r
95 #include "partest.h"
\r
98 /* Priority definitions for the LED tasks. Other tasks just use the idle
\r
100 #define mainLED_FLASH_PRIORITY ( tskIDLE_PRIORITY + ( unsigned portBASE_TYPE ) 1 )
\r
102 /* The LED that is lit when should the calculation fail. */
\r
103 #define mainCHECK_TASK_LED ( ( unsigned portBASE_TYPE ) 3 )
\r
105 /* Constants required for the communications. Only one character is ever
\r
107 #define mainCOMMS_QUEUE_LENGTH ( ( unsigned portBASE_TYPE ) 5 )
\r
108 #define mainNO_BLOCK ( ( portTickType ) 0 )
\r
109 #define mainBAUD_RATE ( ( unsigned portLONG ) 9600 )
\r
112 * The task that performs the 32 bit calculation at the idle priority.
\r
114 static void vCalculationTask( void *pvParameters );
\r
116 /*-----------------------------------------------------------*/
\r
118 /* Creates the tasks, then starts the scheduler. */
\r
121 /* Initialise the required hardware. */
\r
122 vParTestInitialise();
\r
123 vPortInitialiseBlocks();
\r
125 /* Send a character so we have some visible feedback of a reset. */
\r
126 xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH );
\r
127 xSerialPutChar( NULL, 'X', mainNO_BLOCK );
\r
129 /* Start the standard LED flash tasks as defined in demo/common/minimal. */
\r
130 vStartLEDFlashTasks( mainLED_FLASH_PRIORITY );
\r
132 /* Start the check task defined in this file. */
\r
133 xTaskCreate( vCalculationTask, ( const portCHAR * const ) "Check", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
135 /* Start the scheduler. */
\r
136 vTaskStartScheduler();
\r
138 /*-----------------------------------------------------------*/
\r
140 static void vCalculationTask( void *pvParameters )
\r
142 volatile unsigned long ulCalculatedValue; /* Volatile to ensure optimisation is minimal. */
\r
144 /* Continuously perform a calculation. If the calculation result is ever
\r
145 incorrect turn the LED on. */
\r
148 /* A good optimising compiler would just remove all this! */
\r
149 ulCalculatedValue = 1234UL;
\r
150 ulCalculatedValue *= 99UL;
\r
152 if( ulCalculatedValue != 122166UL )
\r
154 vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
\r
157 ulCalculatedValue *= 9876UL;
\r
159 if( ulCalculatedValue != 1206511416UL )
\r
161 vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
\r
164 ulCalculatedValue /= 15UL;
\r
166 if( ulCalculatedValue != 80434094UL )
\r
168 vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
\r
171 ulCalculatedValue += 918273UL;
\r
173 if( ulCalculatedValue != 81352367UL )
\r
175 vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
\r
179 /*-----------------------------------------------------------*/
\r