]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/PIC18_MPLAB/main1.c
Update version number to 9.0.0rc2.
[freertos] / FreeRTOS / Demo / PIC18_MPLAB / main1.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 first.  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 RTOSDemo1 project is configured for a PIC18F452 device.  Main1.c starts 5\r
78  * tasks (including the idle task).\r
79  *\r
80  * The first task runs at the idle priority.  It repeatedly performs a 32bit\r
81  * calculation and checks it's result against the expected value.  This checks\r
82  * that the temporary storage utilised by the compiler to hold intermediate\r
83  * results does not get corrupted when the task gets switched in and out.  See\r
84  * demo/common/minimal/integer.c for more information.\r
85  *\r
86  * The second and third tasks pass an incrementing value between each other on\r
87  * a message queue.  See demo/common/minimal/PollQ.c for more information.\r
88  *\r
89  * Main1.c also creates a check task.  This periodically checks that all the\r
90  * other tasks are still running and have not experienced any unexpected\r
91  * results.  If all the other tasks are executing correctly an LED is flashed\r
92  * once every mainCHECK_PERIOD milliseconds.  If any of the tasks have not\r
93  * executed, or report and error, the frequency of the LED flash will increase\r
94  * to mainERROR_FLASH_RATE.\r
95  *\r
96  * On entry to main an 'X' is transmitted.  Monitoring the serial port using a\r
97  * dumb terminal allows for verification that the device is not continuously\r
98  * being reset (no more than one 'X' should be transmitted).\r
99  *\r
100  * http://www.FreeRTOS.org contains important information on the use of the\r
101  * PIC18F port.\r
102  */\r
103 \r
104 /*\r
105 Changes from V2.0.0\r
106 \r
107         + Delay periods are now specified using variables and constants of\r
108           TickType_t rather than unsigned long.\r
109 */\r
110 \r
111 /* Scheduler include files. */\r
112 #include "FreeRTOS.h"\r
113 #include "task.h"\r
114 \r
115 /* Demo app include files. */\r
116 #include "PollQ.h"\r
117 #include "integer.h"\r
118 #include "partest.h"\r
119 #include "serial.h"\r
120 \r
121 /* The period between executions of the check task before and after an error\r
122 has been discovered.  If an error has been discovered the check task runs\r
123 more frequently - increasing the LED flash rate. */\r
124 #define mainNO_ERROR_CHECK_PERIOD               ( ( TickType_t ) 1000 / portTICK_PERIOD_MS )\r
125 #define mainERROR_CHECK_PERIOD                  ( ( TickType_t ) 100 / portTICK_PERIOD_MS )\r
126 \r
127 /* Priority definitions for some of the tasks.  Other tasks just use the idle\r
128 priority. */\r
129 #define mainQUEUE_POLL_PRIORITY                 ( tskIDLE_PRIORITY + 2 )\r
130 #define mainCHECK_TASK_PRIORITY                 ( tskIDLE_PRIORITY + 3 )\r
131 \r
132 /* The LED that is flashed by the check task. */\r
133 #define mainCHECK_TASK_LED                              ( 0 )\r
134 \r
135 /* Constants required for the communications.  Only one character is ever\r
136 transmitted. */\r
137 #define mainCOMMS_QUEUE_LENGTH                  ( 5 )\r
138 #define mainNO_BLOCK                                    ( ( TickType_t ) 0 )\r
139 #define mainBAUD_RATE                                   ( ( unsigned long ) 9600 )\r
140 \r
141 /*\r
142  * The task function for the "Check" task.\r
143  */\r
144 static void vErrorChecks( void *pvParameters );\r
145 \r
146 /*\r
147  * Checks the unique counts of other tasks to ensure they are still operational.\r
148  * Returns pdTRUE if an error is detected, otherwise pdFALSE.\r
149  */\r
150 static portBASE_TYPE prvCheckOtherTasksAreStillRunning( void );\r
151 \r
152 /*-----------------------------------------------------------*/\r
153 \r
154 /* Creates the tasks, then starts the scheduler. */\r
155 void main( void )\r
156 {\r
157         /* Initialise the required hardware. */\r
158         vParTestInitialise();\r
159         vPortInitialiseBlocks();\r
160 \r
161         /* Send a character so we have some visible feedback of a reset. */\r
162         xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH );\r
163         xSerialPutChar( NULL, 'X', mainNO_BLOCK );\r
164 \r
165         /* Start the standard demo tasks found in the demo\common directory. */\r
166         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
167         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
168 \r
169         /* Start the check task defined in this file. */\r
170         xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
171 \r
172         /* Start the scheduler.  Will never return here. */\r
173         vTaskStartScheduler();\r
174 }\r
175 /*-----------------------------------------------------------*/\r
176 \r
177 static void vErrorChecks( void *pvParameters )\r
178 {\r
179 TickType_t xDelayTime = mainNO_ERROR_CHECK_PERIOD;\r
180 portBASE_TYPE xErrorOccurred;\r
181 \r
182         /* Cycle for ever, delaying then checking all the other tasks are still\r
183         operating without error. */\r
184         for( ;; )\r
185         {\r
186                 /* Wait until it is time to check the other tasks. */\r
187                 vTaskDelay( xDelayTime );\r
188 \r
189                 /* Check all the other tasks are running, and running without ever\r
190                 having an error. */\r
191                 xErrorOccurred = prvCheckOtherTasksAreStillRunning();\r
192 \r
193                 /* If an error was detected increase the frequency of the LED flash. */\r
194                 if( xErrorOccurred == pdTRUE )\r
195                 {\r
196                         xDelayTime = mainERROR_CHECK_PERIOD;\r
197                 }\r
198 \r
199                 /* Flash the LED for visual feedback. */\r
200                 vParTestToggleLED( mainCHECK_TASK_LED );\r
201         }\r
202 }\r
203 /*-----------------------------------------------------------*/\r
204 \r
205 static portBASE_TYPE prvCheckOtherTasksAreStillRunning( void )\r
206 {\r
207 portBASE_TYPE xErrorHasOccurred = pdFALSE;\r
208 \r
209         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
210         {\r
211                 xErrorHasOccurred = pdTRUE;\r
212         }\r
213 \r
214         if( xArePollingQueuesStillRunning() != pdTRUE )\r
215         {\r
216                 xErrorHasOccurred = pdTRUE;\r
217         }\r
218 \r
219         return xErrorHasOccurred;\r
220 }\r
221 /*-----------------------------------------------------------*/\r
222 \r
223 \r