]> git.sur5r.net Git - freertos/blob - Demo/PIC18_MPLAB/main2.c
Update to V4.3.0 as described in http://www.FreeRTOS.org/History.txt
[freertos] / Demo / PIC18_MPLAB / main2.c
1 /*\r
2         FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 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         See http://www.FreeRTOS.org for documentation, latest information, license \r
28         and contact details.  Please ensure to read the configuration and relevant \r
29         port sections of the online documentation.\r
30 \r
31         Also see http://www.SafeRTOS.com for an IEC 61508 compliant version along\r
32         with commercial development and support options.\r
33         ***************************************************************************\r
34 */\r
35 \r
36 /*\r
37  * Instead of the normal single demo application, the PIC18F demo is split \r
38  * into several smaller programs of which this is the second.  This enables the \r
39  * demo's to be executed on the RAM limited 40 pin devices.  The 64 and 80 pin \r
40  * devices require a more costly development platform and are not so readily \r
41  * available.\r
42  *\r
43  * The RTOSDemo2 project is configured for a PIC18F452 device.  Main2.c starts  \r
44  * 5 tasks (including the idle task).\r
45  * \r
46  * The first, second and third tasks do nothing but flash an LED.  This gives\r
47  * visual feedback that everything is executing as expected.  One task flashes\r
48  * an LED every 333ms (i.e. on and off every 333/2 ms), then next every 666ms\r
49  * and the last every 999ms.\r
50  *\r
51  * The last task runs at the idle priority.  It repeatedly performs a 32bit \r
52  * calculation and checks it's result against the expected value.  This checks \r
53  * that the temporary storage utilised by the compiler to hold intermediate \r
54  * results does not get corrupted when the task gets switched in and out.\r
55  * should the calculation ever provide an incorrect result the final LED is\r
56  * turned on.\r
57  *\r
58  * On entry to main() an 'X' is transmitted.  Monitoring the serial port using a\r
59  * dumb terminal allows for verification that the device is not continuously \r
60  * being reset (no more than one 'X' should be transmitted).\r
61  *\r
62  * http://www.FreeRTOS.org contains important information on the use of the \r
63  * PIC18F port.\r
64  */\r
65 \r
66 /*\r
67 Changes from V2.0.0\r
68 \r
69         + Delay periods are now specified using variables and constants of\r
70           portTickType rather than unsigned portLONG.\r
71 */\r
72 \r
73 /* Scheduler include files. */\r
74 #include "FreeRTOS.h"\r
75 #include "task.h"\r
76 \r
77 /* Demo app include files. */\r
78 #include "flash.h"\r
79 #include "partest.h"\r
80 #include "serial.h"\r
81 \r
82 /* Priority definitions for the LED tasks.  Other tasks just use the idle\r
83 priority. */\r
84 #define mainLED_FLASH_PRIORITY                  ( tskIDLE_PRIORITY + ( unsigned portBASE_TYPE ) 1 )\r
85 \r
86 /* The LED that is lit when should the calculation fail. */\r
87 #define mainCHECK_TASK_LED                              ( ( unsigned portBASE_TYPE ) 3 )\r
88 \r
89 /* Constants required for the communications.  Only one character is ever \r
90 transmitted. */\r
91 #define mainCOMMS_QUEUE_LENGTH                  ( ( unsigned portBASE_TYPE ) 5 )\r
92 #define mainNO_BLOCK                                    ( ( portTickType ) 0 )\r
93 #define mainBAUD_RATE                                   ( ( unsigned portLONG ) 9600 )\r
94 \r
95 /*\r
96  * The task that performs the 32 bit calculation at the idle priority.\r
97  */\r
98 static void vCalculationTask( void *pvParameters );\r
99 \r
100 /*-----------------------------------------------------------*/\r
101 \r
102 /* Creates the tasks, then starts the scheduler. */\r
103 void main( void )\r
104 {\r
105         /* Initialise the required hardware. */\r
106         vParTestInitialise();\r
107         vPortInitialiseBlocks();\r
108 \r
109         /* Send a character so we have some visible feedback of a reset. */\r
110         xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH );\r
111         xSerialPutChar( NULL, 'X', mainNO_BLOCK );\r
112 \r
113         /* Start the standard LED flash tasks as defined in demo/common/minimal. */\r
114         vStartLEDFlashTasks( mainLED_FLASH_PRIORITY );\r
115 \r
116         /* Start the check task defined in this file. */\r
117         xTaskCreate( vCalculationTask, ( const portCHAR * const ) "Check", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
118 \r
119         /* Start the scheduler. */\r
120         vTaskStartScheduler();\r
121 }\r
122 /*-----------------------------------------------------------*/\r
123 \r
124 static void vCalculationTask( void *pvParameters )\r
125 {\r
126 volatile unsigned long ulCalculatedValue; /* Volatile to ensure optimisation is minimal. */\r
127 \r
128         /* Continuously perform a calculation.  If the calculation result is ever\r
129         incorrect turn the LED on. */\r
130         for( ;; )\r
131         {\r
132                 /* A good optimising compiler would just remove all this! */\r
133                 ulCalculatedValue = 1234UL;\r
134                 ulCalculatedValue *= 99UL;\r
135 \r
136                 if( ulCalculatedValue != 122166UL )\r
137                 {\r
138                         vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );\r
139                 }\r
140 \r
141                 ulCalculatedValue *= 9876UL;\r
142 \r
143                 if( ulCalculatedValue != 1206511416UL )\r
144                 {\r
145                         vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );\r
146                 }\r
147 \r
148                 ulCalculatedValue /= 15UL;\r
149 \r
150                 if( ulCalculatedValue != 80434094UL )\r
151                 {\r
152                         vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );\r
153                 }\r
154 \r
155                 ulCalculatedValue += 918273UL;\r
156 \r
157                 if( ulCalculatedValue != 81352367UL )\r
158                 {\r
159                         vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );\r
160                 }\r
161         }\r
162 }\r
163 /*-----------------------------------------------------------*/\r
164 \r