2 FreeRTOS V7.5.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
66 * Instead of the normal single demo application, the PIC18F demo is split
\r
67 * into several smaller programs of which this is the second. This enables the
\r
68 * demo's to be executed on the RAM limited 40 pin devices. The 64 and 80 pin
\r
69 * devices require a more costly development platform and are not so readily
\r
72 * The RTOSDemo2 project is configured for a PIC18F452 device. Main2.c starts
\r
73 * 5 tasks (including the idle task).
\r
75 * The first, second and third tasks do nothing but flash an LED. This gives
\r
76 * visual feedback that everything is executing as expected. One task flashes
\r
77 * an LED every 333ms (i.e. on and off every 333/2 ms), then next every 666ms
\r
78 * and the last every 999ms.
\r
80 * The last task runs at the idle priority. It repeatedly performs a 32bit
\r
81 * calculation and checks it's result against the expected value. This checks
\r
82 * that the temporary storage utilised by the compiler to hold intermediate
\r
83 * results does not get corrupted when the task gets switched in and out.
\r
84 * should the calculation ever provide an incorrect result the final LED is
\r
87 * On entry to main() an 'X' is transmitted. Monitoring the serial port using a
\r
88 * dumb terminal allows for verification that the device is not continuously
\r
89 * being reset (no more than one 'X' should be transmitted).
\r
91 * http://www.FreeRTOS.org contains important information on the use of the
\r
98 + Delay periods are now specified using variables and constants of
\r
99 portTickType rather than unsigned long.
\r
102 /* Scheduler include files. */
\r
103 #include "FreeRTOS.h"
\r
106 /* Demo app include files. */
\r
108 #include "partest.h"
\r
109 #include "serial.h"
\r
111 /* Priority definitions for the LED tasks. Other tasks just use the idle
\r
113 #define mainLED_FLASH_PRIORITY ( tskIDLE_PRIORITY + ( unsigned portBASE_TYPE ) 1 )
\r
115 /* The LED that is lit when should the calculation fail. */
\r
116 #define mainCHECK_TASK_LED ( ( unsigned portBASE_TYPE ) 3 )
\r
118 /* Constants required for the communications. Only one character is ever
\r
120 #define mainCOMMS_QUEUE_LENGTH ( ( unsigned portBASE_TYPE ) 5 )
\r
121 #define mainNO_BLOCK ( ( portTickType ) 0 )
\r
122 #define mainBAUD_RATE ( ( unsigned long ) 9600 )
\r
125 * The task that performs the 32 bit calculation at the idle priority.
\r
127 static void vCalculationTask( void *pvParameters );
\r
129 /*-----------------------------------------------------------*/
\r
131 /* Creates the tasks, then starts the scheduler. */
\r
134 /* Initialise the required hardware. */
\r
135 vParTestInitialise();
\r
136 vPortInitialiseBlocks();
\r
138 /* Send a character so we have some visible feedback of a reset. */
\r
139 xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH );
\r
140 xSerialPutChar( NULL, 'X', mainNO_BLOCK );
\r
142 /* Start the standard LED flash tasks as defined in demo/common/minimal. */
\r
143 vStartLEDFlashTasks( mainLED_FLASH_PRIORITY );
\r
145 /* Start the check task defined in this file. */
\r
146 xTaskCreate( vCalculationTask, ( const char * const ) "Check", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
148 /* Start the scheduler. */
\r
149 vTaskStartScheduler();
\r
151 /*-----------------------------------------------------------*/
\r
153 static void vCalculationTask( void *pvParameters )
\r
155 volatile unsigned long ulCalculatedValue; /* Volatile to ensure optimisation is minimal. */
\r
157 /* Continuously perform a calculation. If the calculation result is ever
\r
158 incorrect turn the LED on. */
\r
161 /* A good optimising compiler would just remove all this! */
\r
162 ulCalculatedValue = 1234UL;
\r
163 ulCalculatedValue *= 99UL;
\r
165 if( ulCalculatedValue != 122166UL )
\r
167 vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
\r
170 ulCalculatedValue *= 9876UL;
\r
172 if( ulCalculatedValue != 1206511416UL )
\r
174 vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
\r
177 ulCalculatedValue /= 15UL;
\r
179 if( ulCalculatedValue != 80434094UL )
\r
181 vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
\r
184 ulCalculatedValue += 918273UL;
\r
186 if( ulCalculatedValue != 81352367UL )
\r
188 vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
\r
192 /*-----------------------------------------------------------*/
\r