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