]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/PIC18_MPLAB/main2.c
Prepare for V7.3.0 release.
[freertos] / FreeRTOS / Demo / PIC18_MPLAB / main2.c
1 /*\r
2     FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd.\r
3 \r
4     FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME.  PLEASE VISIT \r
5     http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
10      *    Complete, revised, and edited pdf reference manuals are also       *\r
11      *    available.                                                         *\r
12      *                                                                       *\r
13      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
14      *    ensuring you get running as quickly as possible and with an        *\r
15      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
16      *    the FreeRTOS project to continue with its mission of providing     *\r
17      *    professional grade, cross platform, de facto standard solutions    *\r
18      *    for microcontrollers - completely free of charge!                  *\r
19      *                                                                       *\r
20      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
21      *                                                                       *\r
22      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
23      *                                                                       *\r
24     ***************************************************************************\r
25 \r
26 \r
27     This file is part of the FreeRTOS distribution.\r
28 \r
29     FreeRTOS is free software; you can redistribute it and/or modify it under\r
30     the terms of the GNU General Public License (version 2) as published by the\r
31     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
32     >>>NOTE<<< The modification to the GPL is included to allow you to\r
33     distribute a combined work that includes FreeRTOS without being obliged to\r
34     provide the source code for proprietary components outside of the FreeRTOS\r
35     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
36     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
37     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
38     more details. You should have received a copy of the GNU General Public\r
39     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
40     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
41     by writing to Richard Barry, contact details for whom are available on the\r
42     FreeRTOS WEB site.\r
43 \r
44     1 tab == 4 spaces!\r
45     \r
46     ***************************************************************************\r
47      *                                                                       *\r
48      *    Having a problem?  Start by reading the FAQ "My application does   *\r
49      *    not run, what could be wrong?"                                     *\r
50      *                                                                       *\r
51      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
52      *                                                                       *\r
53     ***************************************************************************\r
54 \r
55     \r
56     http://www.FreeRTOS.org - Documentation, training, latest versions, license \r
57     and contact details.  \r
58     \r
59     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
60     including FreeRTOS+Trace - an indispensable productivity tool.\r
61 \r
62     Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell \r
63     the code with commercial support, indemnification, and middleware, under \r
64     the OpenRTOS brand: http://www.OpenRTOS.com.  High Integrity Systems also\r
65     provide a safety engineered and independently SIL3 certified version under \r
66     the SafeRTOS brand: http://www.SafeRTOS.com.\r
67 */\r
68 \r
69 /*\r
70  * Instead of the normal single demo application, the PIC18F demo is split \r
71  * into several smaller programs of which this is the second.  This enables the \r
72  * demo's to be executed on the RAM limited 40 pin devices.  The 64 and 80 pin \r
73  * devices require a more costly development platform and are not so readily \r
74  * available.\r
75  *\r
76  * The RTOSDemo2 project is configured for a PIC18F452 device.  Main2.c starts  \r
77  * 5 tasks (including the idle task).\r
78  * \r
79  * The first, second and third tasks do nothing but flash an LED.  This gives\r
80  * visual feedback that everything is executing as expected.  One task flashes\r
81  * an LED every 333ms (i.e. on and off every 333/2 ms), then next every 666ms\r
82  * and the last every 999ms.\r
83  *\r
84  * The last task runs at the idle priority.  It repeatedly performs a 32bit \r
85  * calculation and checks it's result against the expected value.  This checks \r
86  * that the temporary storage utilised by the compiler to hold intermediate \r
87  * results does not get corrupted when the task gets switched in and out.\r
88  * should the calculation ever provide an incorrect result the final LED is\r
89  * turned on.\r
90  *\r
91  * On entry to main() an 'X' is transmitted.  Monitoring the serial port using a\r
92  * dumb terminal allows for verification that the device is not continuously \r
93  * being reset (no more than one 'X' should be transmitted).\r
94  *\r
95  * http://www.FreeRTOS.org contains important information on the use of the \r
96  * PIC18F port.\r
97  */\r
98 \r
99 /*\r
100 Changes from V2.0.0\r
101 \r
102         + Delay periods are now specified using variables and constants of\r
103           portTickType rather than unsigned long.\r
104 */\r
105 \r
106 /* Scheduler include files. */\r
107 #include "FreeRTOS.h"\r
108 #include "task.h"\r
109 \r
110 /* Demo app include files. */\r
111 #include "flash.h"\r
112 #include "partest.h"\r
113 #include "serial.h"\r
114 \r
115 /* Priority definitions for the LED tasks.  Other tasks just use the idle\r
116 priority. */\r
117 #define mainLED_FLASH_PRIORITY                  ( tskIDLE_PRIORITY + ( unsigned portBASE_TYPE ) 1 )\r
118 \r
119 /* The LED that is lit when should the calculation fail. */\r
120 #define mainCHECK_TASK_LED                              ( ( unsigned portBASE_TYPE ) 3 )\r
121 \r
122 /* Constants required for the communications.  Only one character is ever \r
123 transmitted. */\r
124 #define mainCOMMS_QUEUE_LENGTH                  ( ( unsigned portBASE_TYPE ) 5 )\r
125 #define mainNO_BLOCK                                    ( ( portTickType ) 0 )\r
126 #define mainBAUD_RATE                                   ( ( unsigned long ) 9600 )\r
127 \r
128 /*\r
129  * The task that performs the 32 bit calculation at the idle priority.\r
130  */\r
131 static void vCalculationTask( void *pvParameters );\r
132 \r
133 /*-----------------------------------------------------------*/\r
134 \r
135 /* Creates the tasks, then starts the scheduler. */\r
136 void main( void )\r
137 {\r
138         /* Initialise the required hardware. */\r
139         vParTestInitialise();\r
140         vPortInitialiseBlocks();\r
141 \r
142         /* Send a character so we have some visible feedback of a reset. */\r
143         xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH );\r
144         xSerialPutChar( NULL, 'X', mainNO_BLOCK );\r
145 \r
146         /* Start the standard LED flash tasks as defined in demo/common/minimal. */\r
147         vStartLEDFlashTasks( mainLED_FLASH_PRIORITY );\r
148 \r
149         /* Start the check task defined in this file. */\r
150         xTaskCreate( vCalculationTask, ( const char * const ) "Check", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
151 \r
152         /* Start the scheduler. */\r
153         vTaskStartScheduler();\r
154 }\r
155 /*-----------------------------------------------------------*/\r
156 \r
157 static void vCalculationTask( void *pvParameters )\r
158 {\r
159 volatile unsigned long ulCalculatedValue; /* Volatile to ensure optimisation is minimal. */\r
160 \r
161         /* Continuously perform a calculation.  If the calculation result is ever\r
162         incorrect turn the LED on. */\r
163         for( ;; )\r
164         {\r
165                 /* A good optimising compiler would just remove all this! */\r
166                 ulCalculatedValue = 1234UL;\r
167                 ulCalculatedValue *= 99UL;\r
168 \r
169                 if( ulCalculatedValue != 122166UL )\r
170                 {\r
171                         vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );\r
172                 }\r
173 \r
174                 ulCalculatedValue *= 9876UL;\r
175 \r
176                 if( ulCalculatedValue != 1206511416UL )\r
177                 {\r
178                         vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );\r
179                 }\r
180 \r
181                 ulCalculatedValue /= 15UL;\r
182 \r
183                 if( ulCalculatedValue != 80434094UL )\r
184                 {\r
185                         vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );\r
186                 }\r
187 \r
188                 ulCalculatedValue += 918273UL;\r
189 \r
190                 if( ulCalculatedValue != 81352367UL )\r
191                 {\r
192                         vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );\r
193                 }\r
194         }\r
195 }\r
196 /*-----------------------------------------------------------*/\r
197 \r