]> git.sur5r.net Git - freertos/blob - Demo/PIC18_MPLAB/main2.c
Ensure LPC1768 demos are correct prior to V5.4.0 release.
[freertos] / Demo / PIC18_MPLAB / main2.c
1 /*\r
2         FreeRTOS V5.4.0 - Copyright (C) 2003-2009 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS distribution.\r
5 \r
6         FreeRTOS is free software; you can redistribute it and/or modify it     under \r
7         the terms of the GNU General Public License (version 2) as published by the \r
8         Free Software Foundation and modified by the FreeRTOS exception.\r
9         **NOTE** The exception to the GPL is included to allow you to distribute a\r
10         combined work that includes FreeRTOS without being obliged to provide the \r
11         source code for proprietary components outside of the FreeRTOS kernel.  \r
12         Alternative commercial license and support terms are also available upon \r
13         request.  See the licensing section of http://www.FreeRTOS.org for full \r
14         license details.\r
15 \r
16         FreeRTOS is distributed in the hope that it will be useful,     but WITHOUT\r
17         ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
18         FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
19         more details.\r
20 \r
21         You should have received a copy of the GNU General Public License along\r
22         with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59\r
23         Temple Place, Suite 330, Boston, MA  02111-1307  USA.\r
24 \r
25 \r
26         ***************************************************************************\r
27         *                                                                         *\r
28         * Looking for a quick start?  Then check out the FreeRTOS eBook!          *\r
29         * See http://www.FreeRTOS.org/Documentation for details                   *\r
30         *                                                                         *\r
31         ***************************************************************************\r
32 \r
33         1 tab == 4 spaces!\r
34 \r
35         Please ensure to read the configuration and relevant port sections of the\r
36         online documentation.\r
37 \r
38         http://www.FreeRTOS.org - Documentation, latest information, license and\r
39         contact details.\r
40 \r
41         http://www.SafeRTOS.com - A version that is certified for use in safety\r
42         critical systems.\r
43 \r
44         http://www.OpenRTOS.com - Commercial support, development, porting,\r
45         licensing and training services.\r
46 */\r
47 \r
48 /*\r
49  * Instead of the normal single demo application, the PIC18F demo is split \r
50  * into several smaller programs of which this is the second.  This enables the \r
51  * demo's to be executed on the RAM limited 40 pin devices.  The 64 and 80 pin \r
52  * devices require a more costly development platform and are not so readily \r
53  * available.\r
54  *\r
55  * The RTOSDemo2 project is configured for a PIC18F452 device.  Main2.c starts  \r
56  * 5 tasks (including the idle task).\r
57  * \r
58  * The first, second and third tasks do nothing but flash an LED.  This gives\r
59  * visual feedback that everything is executing as expected.  One task flashes\r
60  * an LED every 333ms (i.e. on and off every 333/2 ms), then next every 666ms\r
61  * and the last every 999ms.\r
62  *\r
63  * The last task runs at the idle priority.  It repeatedly performs a 32bit \r
64  * calculation and checks it's result against the expected value.  This checks \r
65  * that the temporary storage utilised by the compiler to hold intermediate \r
66  * results does not get corrupted when the task gets switched in and out.\r
67  * should the calculation ever provide an incorrect result the final LED is\r
68  * turned on.\r
69  *\r
70  * On entry to main() an 'X' is transmitted.  Monitoring the serial port using a\r
71  * dumb terminal allows for verification that the device is not continuously \r
72  * being reset (no more than one 'X' should be transmitted).\r
73  *\r
74  * http://www.FreeRTOS.org contains important information on the use of the \r
75  * PIC18F port.\r
76  */\r
77 \r
78 /*\r
79 Changes from V2.0.0\r
80 \r
81         + Delay periods are now specified using variables and constants of\r
82           portTickType rather than unsigned portLONG.\r
83 */\r
84 \r
85 /* Scheduler include files. */\r
86 #include "FreeRTOS.h"\r
87 #include "task.h"\r
88 \r
89 /* Demo app include files. */\r
90 #include "flash.h"\r
91 #include "partest.h"\r
92 #include "serial.h"\r
93 \r
94 /* Priority definitions for the LED tasks.  Other tasks just use the idle\r
95 priority. */\r
96 #define mainLED_FLASH_PRIORITY                  ( tskIDLE_PRIORITY + ( unsigned portBASE_TYPE ) 1 )\r
97 \r
98 /* The LED that is lit when should the calculation fail. */\r
99 #define mainCHECK_TASK_LED                              ( ( unsigned portBASE_TYPE ) 3 )\r
100 \r
101 /* Constants required for the communications.  Only one character is ever \r
102 transmitted. */\r
103 #define mainCOMMS_QUEUE_LENGTH                  ( ( unsigned portBASE_TYPE ) 5 )\r
104 #define mainNO_BLOCK                                    ( ( portTickType ) 0 )\r
105 #define mainBAUD_RATE                                   ( ( unsigned portLONG ) 9600 )\r
106 \r
107 /*\r
108  * The task that performs the 32 bit calculation at the idle priority.\r
109  */\r
110 static void vCalculationTask( void *pvParameters );\r
111 \r
112 /*-----------------------------------------------------------*/\r
113 \r
114 /* Creates the tasks, then starts the scheduler. */\r
115 void main( void )\r
116 {\r
117         /* Initialise the required hardware. */\r
118         vParTestInitialise();\r
119         vPortInitialiseBlocks();\r
120 \r
121         /* Send a character so we have some visible feedback of a reset. */\r
122         xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH );\r
123         xSerialPutChar( NULL, 'X', mainNO_BLOCK );\r
124 \r
125         /* Start the standard LED flash tasks as defined in demo/common/minimal. */\r
126         vStartLEDFlashTasks( mainLED_FLASH_PRIORITY );\r
127 \r
128         /* Start the check task defined in this file. */\r
129         xTaskCreate( vCalculationTask, ( const portCHAR * const ) "Check", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
130 \r
131         /* Start the scheduler. */\r
132         vTaskStartScheduler();\r
133 }\r
134 /*-----------------------------------------------------------*/\r
135 \r
136 static void vCalculationTask( void *pvParameters )\r
137 {\r
138 volatile unsigned long ulCalculatedValue; /* Volatile to ensure optimisation is minimal. */\r
139 \r
140         /* Continuously perform a calculation.  If the calculation result is ever\r
141         incorrect turn the LED on. */\r
142         for( ;; )\r
143         {\r
144                 /* A good optimising compiler would just remove all this! */\r
145                 ulCalculatedValue = 1234UL;\r
146                 ulCalculatedValue *= 99UL;\r
147 \r
148                 if( ulCalculatedValue != 122166UL )\r
149                 {\r
150                         vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );\r
151                 }\r
152 \r
153                 ulCalculatedValue *= 9876UL;\r
154 \r
155                 if( ulCalculatedValue != 1206511416UL )\r
156                 {\r
157                         vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );\r
158                 }\r
159 \r
160                 ulCalculatedValue /= 15UL;\r
161 \r
162                 if( ulCalculatedValue != 80434094UL )\r
163                 {\r
164                         vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );\r
165                 }\r
166 \r
167                 ulCalculatedValue += 918273UL;\r
168 \r
169                 if( ulCalculatedValue != 81352367UL )\r
170                 {\r
171                         vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );\r
172                 }\r
173         }\r
174 }\r
175 /*-----------------------------------------------------------*/\r
176 \r