2 FreeRTOS V6.0.4 - Copyright (C) 2010 Real Time Engineers Ltd.
\r
4 ***************************************************************************
\r
8 * + New to FreeRTOS, *
\r
9 * + Wanting to learn FreeRTOS or multitasking in general quickly *
\r
10 * + Looking for basic training, *
\r
11 * + Wanting to improve your FreeRTOS skills and productivity *
\r
13 * then take a look at the FreeRTOS eBook *
\r
15 * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
\r
16 * http://www.FreeRTOS.org/Documentation *
\r
18 * A pdf reference manual is also available. Both are usually delivered *
\r
19 * to your inbox within 20 minutes to two hours when purchased between 8am *
\r
20 * and 8pm GMT (although please allow up to 24 hours in case of *
\r
21 * exceptional circumstances). Thank you for your support! *
\r
23 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 ***NOTE*** The exception to the GPL is included to allow you to distribute
\r
31 a combined work that includes FreeRTOS without being obliged to provide the
\r
32 source code for proprietary components outside of the FreeRTOS kernel.
\r
33 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
34 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
35 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
55 * Instead of the normal single demo application, the PIC18F demo is split
\r
56 * into several smaller programs of which this is the second. This enables the
\r
57 * demo's to be executed on the RAM limited 40 pin devices. The 64 and 80 pin
\r
58 * devices require a more costly development platform and are not so readily
\r
61 * The RTOSDemo2 project is configured for a PIC18F452 device. Main2.c starts
\r
62 * 5 tasks (including the idle task).
\r
64 * The first, second and third tasks do nothing but flash an LED. This gives
\r
65 * visual feedback that everything is executing as expected. One task flashes
\r
66 * an LED every 333ms (i.e. on and off every 333/2 ms), then next every 666ms
\r
67 * and the last every 999ms.
\r
69 * The last task runs at the idle priority. It repeatedly performs a 32bit
\r
70 * calculation and checks it's result against the expected value. This checks
\r
71 * that the temporary storage utilised by the compiler to hold intermediate
\r
72 * results does not get corrupted when the task gets switched in and out.
\r
73 * should the calculation ever provide an incorrect result the final LED is
\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
87 + Delay periods are now specified using variables and constants of
\r
88 portTickType rather than unsigned long.
\r
91 /* Scheduler include files. */
\r
92 #include "FreeRTOS.h"
\r
95 /* Demo app include files. */
\r
97 #include "partest.h"
\r
100 /* Priority definitions for the LED tasks. Other tasks just use the idle
\r
102 #define mainLED_FLASH_PRIORITY ( tskIDLE_PRIORITY + ( unsigned portBASE_TYPE ) 1 )
\r
104 /* The LED that is lit when should the calculation fail. */
\r
105 #define mainCHECK_TASK_LED ( ( unsigned portBASE_TYPE ) 3 )
\r
107 /* Constants required for the communications. Only one character is ever
\r
109 #define mainCOMMS_QUEUE_LENGTH ( ( unsigned portBASE_TYPE ) 5 )
\r
110 #define mainNO_BLOCK ( ( portTickType ) 0 )
\r
111 #define mainBAUD_RATE ( ( unsigned long ) 9600 )
\r
114 * The task that performs the 32 bit calculation at the idle priority.
\r
116 static void vCalculationTask( void *pvParameters );
\r
118 /*-----------------------------------------------------------*/
\r
120 /* Creates the tasks, then starts the scheduler. */
\r
123 /* Initialise the required hardware. */
\r
124 vParTestInitialise();
\r
125 vPortInitialiseBlocks();
\r
127 /* Send a character so we have some visible feedback of a reset. */
\r
128 xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH );
\r
129 xSerialPutChar( NULL, 'X', mainNO_BLOCK );
\r
131 /* Start the standard LED flash tasks as defined in demo/common/minimal. */
\r
132 vStartLEDFlashTasks( mainLED_FLASH_PRIORITY );
\r
134 /* Start the check task defined in this file. */
\r
135 xTaskCreate( vCalculationTask, ( const char * const ) "Check", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
137 /* Start the scheduler. */
\r
138 vTaskStartScheduler();
\r
140 /*-----------------------------------------------------------*/
\r
142 static void vCalculationTask( void *pvParameters )
\r
144 volatile unsigned long ulCalculatedValue; /* Volatile to ensure optimisation is minimal. */
\r
146 /* Continuously perform a calculation. If the calculation result is ever
\r
147 incorrect turn the LED on. */
\r
150 /* A good optimising compiler would just remove all this! */
\r
151 ulCalculatedValue = 1234UL;
\r
152 ulCalculatedValue *= 99UL;
\r
154 if( ulCalculatedValue != 122166UL )
\r
156 vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
\r
159 ulCalculatedValue *= 9876UL;
\r
161 if( ulCalculatedValue != 1206511416UL )
\r
163 vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
\r
166 ulCalculatedValue /= 15UL;
\r
168 if( ulCalculatedValue != 80434094UL )
\r
170 vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
\r
173 ulCalculatedValue += 918273UL;
\r
175 if( ulCalculatedValue != 81352367UL )
\r
177 vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
\r
181 /*-----------------------------------------------------------*/
\r