blob: cafdcc37cf5eea6edb40f09167ba65ac41d64ee0 [file] [log] [blame]
Richard Barryb6df57c2006-05-02 09:39:15 +00001/*
Richard Barrye262d952010-02-25 13:41:09 +00002 FreeRTOS V6.0.3 - Copyright (C) 2010 Real Time Engineers Ltd.
Richard Barryb6df57c2006-05-02 09:39:15 +00003
Richard Barry26bf0da2009-10-13 11:05:41 +00004 ***************************************************************************
5 * *
6 * If you are: *
7 * *
8 * + New to FreeRTOS, *
9 * + Wanting to learn FreeRTOS or multitasking in general quickly *
10 * + Looking for basic training, *
11 * + Wanting to improve your FreeRTOS skills and productivity *
12 * *
13 * then take a look at the FreeRTOS eBook *
14 * *
15 * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
16 * http://www.FreeRTOS.org/Documentation *
17 * *
18 * A pdf reference manual is also available. Both are usually delivered *
19 * to your inbox within 20 minutes to two hours when purchased between 8am *
20 * and 8pm GMT (although please allow up to 24 hours in case of *
21 * exceptional circumstances). Thank you for your support! *
22 * *
23 ***************************************************************************
24
Richard Barry9468e362009-10-05 11:10:48 +000025 This file is part of the FreeRTOS distribution.
Richard Barryb6df57c2006-05-02 09:39:15 +000026
Richard Barry26bf0da2009-10-13 11:05:41 +000027 FreeRTOS is free software; you can redistribute it and/or modify it under
Richard Barry9468e362009-10-05 11:10:48 +000028 the terms of the GNU General Public License (version 2) as published by the
Richard Barry26bf0da2009-10-13 11:05:41 +000029 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
30 ***NOTE*** The exception to the GPL is included to allow you to distribute
31 a combined work that includes FreeRTOS without being obliged to provide the
Richard Barry9468e362009-10-05 11:10:48 +000032 source code for proprietary components outside of the FreeRTOS kernel.
Richard Barry26bf0da2009-10-13 11:05:41 +000033 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
Richard Barry9468e362009-10-05 11:10:48 +000034 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
Richard Barry26bf0da2009-10-13 11:05:41 +000036 more details. You should have received a copy of the GNU General Public
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
39 by writing to Richard Barry, contact details for whom are available on the
40 FreeRTOS WEB site.
Richard Barry2f40ad72009-03-14 19:20:12 +000041
Richard Barry9468e362009-10-05 11:10:48 +000042 1 tab == 4 spaces!
Richard Barry0a6d59a2007-04-01 20:47:49 +000043
Richard Barry9468e362009-10-05 11:10:48 +000044 http://www.FreeRTOS.org - Documentation, latest information, license and
45 contact details.
Richard Barryc86dcf72008-02-03 19:45:58 +000046
Richard Barry9468e362009-10-05 11:10:48 +000047 http://www.SafeRTOS.com - A version that is certified for use in safety
48 critical systems.
Richard Barryc86dcf72008-02-03 19:45:58 +000049
Richard Barry9468e362009-10-05 11:10:48 +000050 http://www.OpenRTOS.com - Commercial support, development, porting,
51 licensing and training services.
Richard Barryb6df57c2006-05-02 09:39:15 +000052*/
53
54/*
55 * Instead of the normal single demo application, the PIC18F demo is split
56 * into several smaller programs of which this is the second. This enables the
57 * demo's to be executed on the RAM limited 40 pin devices. The 64 and 80 pin
58 * devices require a more costly development platform and are not so readily
59 * available.
60 *
61 * The RTOSDemo2 project is configured for a PIC18F452 device. Main2.c starts
62 * 5 tasks (including the idle task).
63 *
64 * The first, second and third tasks do nothing but flash an LED. This gives
65 * visual feedback that everything is executing as expected. One task flashes
66 * an LED every 333ms (i.e. on and off every 333/2 ms), then next every 666ms
67 * and the last every 999ms.
68 *
69 * The last task runs at the idle priority. It repeatedly performs a 32bit
70 * calculation and checks it's result against the expected value. This checks
71 * that the temporary storage utilised by the compiler to hold intermediate
72 * results does not get corrupted when the task gets switched in and out.
73 * should the calculation ever provide an incorrect result the final LED is
74 * turned on.
75 *
76 * On entry to main() an 'X' is transmitted. Monitoring the serial port using a
77 * dumb terminal allows for verification that the device is not continuously
78 * being reset (no more than one 'X' should be transmitted).
79 *
80 * http://www.FreeRTOS.org contains important information on the use of the
81 * PIC18F port.
82 */
83
84/*
85Changes from V2.0.0
86
87 + Delay periods are now specified using variables and constants of
Richard Barry9468e362009-10-05 11:10:48 +000088 portTickType rather than unsigned long.
Richard Barryb6df57c2006-05-02 09:39:15 +000089*/
90
91/* Scheduler include files. */
92#include "FreeRTOS.h"
93#include "task.h"
94
95/* Demo app include files. */
96#include "flash.h"
97#include "partest.h"
98#include "serial.h"
99
100/* Priority definitions for the LED tasks. Other tasks just use the idle
101priority. */
102#define mainLED_FLASH_PRIORITY ( tskIDLE_PRIORITY + ( unsigned portBASE_TYPE ) 1 )
103
104/* The LED that is lit when should the calculation fail. */
105#define mainCHECK_TASK_LED ( ( unsigned portBASE_TYPE ) 3 )
106
107/* Constants required for the communications. Only one character is ever
108transmitted. */
109#define mainCOMMS_QUEUE_LENGTH ( ( unsigned portBASE_TYPE ) 5 )
110#define mainNO_BLOCK ( ( portTickType ) 0 )
Richard Barry9468e362009-10-05 11:10:48 +0000111#define mainBAUD_RATE ( ( unsigned long ) 9600 )
Richard Barryb6df57c2006-05-02 09:39:15 +0000112
113/*
114 * The task that performs the 32 bit calculation at the idle priority.
115 */
116static void vCalculationTask( void *pvParameters );
117
118/*-----------------------------------------------------------*/
119
120/* Creates the tasks, then starts the scheduler. */
121void main( void )
122{
123 /* Initialise the required hardware. */
124 vParTestInitialise();
125 vPortInitialiseBlocks();
126
127 /* Send a character so we have some visible feedback of a reset. */
128 xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH );
129 xSerialPutChar( NULL, 'X', mainNO_BLOCK );
130
131 /* Start the standard LED flash tasks as defined in demo/common/minimal. */
132 vStartLEDFlashTasks( mainLED_FLASH_PRIORITY );
133
134 /* Start the check task defined in this file. */
Richard Barry9468e362009-10-05 11:10:48 +0000135 xTaskCreate( vCalculationTask, ( const char * const ) "Check", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
Richard Barryb6df57c2006-05-02 09:39:15 +0000136
137 /* Start the scheduler. */
138 vTaskStartScheduler();
139}
140/*-----------------------------------------------------------*/
141
142static void vCalculationTask( void *pvParameters )
143{
144volatile unsigned long ulCalculatedValue; /* Volatile to ensure optimisation is minimal. */
145
146 /* Continuously perform a calculation. If the calculation result is ever
147 incorrect turn the LED on. */
148 for( ;; )
149 {
150 /* A good optimising compiler would just remove all this! */
151 ulCalculatedValue = 1234UL;
152 ulCalculatedValue *= 99UL;
153
154 if( ulCalculatedValue != 122166UL )
155 {
156 vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
157 }
158
159 ulCalculatedValue *= 9876UL;
160
161 if( ulCalculatedValue != 1206511416UL )
162 {
163 vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
164 }
165
166 ulCalculatedValue /= 15UL;
167
168 if( ulCalculatedValue != 80434094UL )
169 {
170 vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
171 }
172
173 ulCalculatedValue += 918273UL;
174
175 if( ulCalculatedValue != 81352367UL )
176 {
177 vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
178 }
179 }
180}
181/*-----------------------------------------------------------*/
182