]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/PIC18_MPLAB/main2.c
Update version number to 9.0.0rc2.
[freertos] / FreeRTOS / Demo / PIC18_MPLAB / main2.c
1 /*\r
2     FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\r
12 \r
13     ***************************************************************************\r
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
16     >>!   obliged to provide the source code for proprietary components     !<<\r
17     >>!   outside of the FreeRTOS kernel.                                   !<<\r
18     ***************************************************************************\r
19 \r
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
23     link: http://www.freertos.org/a00114.html\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    FreeRTOS provides completely free yet professionally developed,    *\r
28      *    robust, strictly quality controlled, supported, and cross          *\r
29      *    platform software that is more than just the market leader, it     *\r
30      *    is the industry's de facto standard.                               *\r
31      *                                                                       *\r
32      *    Help yourself get started quickly while simultaneously helping     *\r
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
34      *    tutorial book, reference manual, or both:                          *\r
35      *    http://www.FreeRTOS.org/Documentation                              *\r
36      *                                                                       *\r
37     ***************************************************************************\r
38 \r
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
40     the FAQ page "My application does not run, what could be wrong?".  Have you\r
41     defined configASSERT()?\r
42 \r
43     http://www.FreeRTOS.org/support - In return for receiving this top quality\r
44     embedded software for free we request you assist our global community by\r
45     participating in the support forum.\r
46 \r
47     http://www.FreeRTOS.org/training - Investing in training allows your team to\r
48     be as productive as possible as early as possible.  Now you can receive\r
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
50     Ltd, and the world's leading authority on the world's leading RTOS.\r
51 \r
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
55 \r
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
58 \r
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
61     licenses offer ticketed support, indemnification and commercial middleware.\r
62 \r
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
64     engineered and independently SIL3 certified version for use in safety and\r
65     mission critical applications that require provable dependability.\r
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 /*\r
71  * Instead of the normal single demo application, the PIC18F demo is split\r
72  * into several smaller programs of which this is the second.  This enables the\r
73  * demo's to be executed on the RAM limited 40 pin devices.  The 64 and 80 pin\r
74  * devices require a more costly development platform and are not so readily\r
75  * available.\r
76  *\r
77  * The RTOSDemo2 project is configured for a PIC18F452 device.  Main2.c starts\r
78  * 5 tasks (including the idle task).\r
79  *\r
80  * The first, second and third tasks do nothing but flash an LED.  This gives\r
81  * visual feedback that everything is executing as expected.  One task flashes\r
82  * an LED every 333ms (i.e. on and off every 333/2 ms), then next every 666ms\r
83  * and the last every 999ms.\r
84  *\r
85  * The last task runs at the idle priority.  It repeatedly performs a 32bit\r
86  * calculation and checks it's result against the expected value.  This checks\r
87  * that the temporary storage utilised by the compiler to hold intermediate\r
88  * results does not get corrupted when the task gets switched in and out.\r
89  * should the calculation ever provide an incorrect result the final LED is\r
90  * turned on.\r
91  *\r
92  * On entry to main() an 'X' is transmitted.  Monitoring the serial port using a\r
93  * dumb terminal allows for verification that the device is not continuously\r
94  * being reset (no more than one 'X' should be transmitted).\r
95  *\r
96  * http://www.FreeRTOS.org contains important information on the use of the\r
97  * PIC18F port.\r
98  */\r
99 \r
100 /*\r
101 Changes from V2.0.0\r
102 \r
103         + Delay periods are now specified using variables and constants of\r
104           TickType_t rather than unsigned long.\r
105 */\r
106 \r
107 /* Scheduler include files. */\r
108 #include "FreeRTOS.h"\r
109 #include "task.h"\r
110 \r
111 /* Demo app include files. */\r
112 #include "flash.h"\r
113 #include "partest.h"\r
114 #include "serial.h"\r
115 \r
116 /* Priority definitions for the LED tasks.  Other tasks just use the idle\r
117 priority. */\r
118 #define mainLED_FLASH_PRIORITY                  ( tskIDLE_PRIORITY + ( unsigned portBASE_TYPE ) 1 )\r
119 \r
120 /* The LED that is lit when should the calculation fail. */\r
121 #define mainCHECK_TASK_LED                              ( ( unsigned portBASE_TYPE ) 3 )\r
122 \r
123 /* Constants required for the communications.  Only one character is ever\r
124 transmitted. */\r
125 #define mainCOMMS_QUEUE_LENGTH                  ( ( unsigned portBASE_TYPE ) 5 )\r
126 #define mainNO_BLOCK                                    ( ( TickType_t ) 0 )\r
127 #define mainBAUD_RATE                                   ( ( unsigned long ) 9600 )\r
128 \r
129 /*\r
130  * The task that performs the 32 bit calculation at the idle priority.\r
131  */\r
132 static void vCalculationTask( void *pvParameters );\r
133 \r
134 /*-----------------------------------------------------------*/\r
135 \r
136 /* Creates the tasks, then starts the scheduler. */\r
137 void main( void )\r
138 {\r
139         /* Initialise the required hardware. */\r
140         vParTestInitialise();\r
141         vPortInitialiseBlocks();\r
142 \r
143         /* Send a character so we have some visible feedback of a reset. */\r
144         xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH );\r
145         xSerialPutChar( NULL, 'X', mainNO_BLOCK );\r
146 \r
147         /* Start the standard LED flash tasks as defined in demo/common/minimal. */\r
148         vStartLEDFlashTasks( mainLED_FLASH_PRIORITY );\r
149 \r
150         /* Start the check task defined in this file. */\r
151         xTaskCreate( vCalculationTask, "Check", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
152 \r
153         /* Start the scheduler. */\r
154         vTaskStartScheduler();\r
155 }\r
156 /*-----------------------------------------------------------*/\r
157 \r
158 static void vCalculationTask( void *pvParameters )\r
159 {\r
160 volatile unsigned long ulCalculatedValue; /* Volatile to ensure optimisation is minimal. */\r
161 \r
162         /* Continuously perform a calculation.  If the calculation result is ever\r
163         incorrect turn the LED on. */\r
164         for( ;; )\r
165         {\r
166                 /* A good optimising compiler would just remove all this! */\r
167                 ulCalculatedValue = 1234UL;\r
168                 ulCalculatedValue *= 99UL;\r
169 \r
170                 if( ulCalculatedValue != 122166UL )\r
171                 {\r
172                         vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );\r
173                 }\r
174 \r
175                 ulCalculatedValue *= 9876UL;\r
176 \r
177                 if( ulCalculatedValue != 1206511416UL )\r
178                 {\r
179                         vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );\r
180                 }\r
181 \r
182                 ulCalculatedValue /= 15UL;\r
183 \r
184                 if( ulCalculatedValue != 80434094UL )\r
185                 {\r
186                         vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );\r
187                 }\r
188 \r
189                 ulCalculatedValue += 918273UL;\r
190 \r
191                 if( ulCalculatedValue != 81352367UL )\r
192                 {\r
193                         vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );\r
194                 }\r
195         }\r
196 }\r
197 /*-----------------------------------------------------------*/\r
198 \r