]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/PIC18_WizC/Demo6/main.c
Update version number to 9.0.0rc2.
[freertos] / FreeRTOS / Demo / PIC18_WizC / Demo6 / main.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 Changes from V3.0.0\r
72 \r
73 Changes from V3.0.1\r
74 */\r
75 \r
76 /*\r
77  * Instead of the normal single demo application, the PIC18F demo is split\r
78  * into several smaller programs of which this is the sixth.  This enables the\r
79  * demo's to be executed on the RAM limited PIC-devices.\r
80  *\r
81  * The Demo6 project is configured for a PIC18F4620 device.  Main.c starts 4\r
82  * tasks (including the idle task). See the indicated files in the demo/common\r
83  * directory for more information.\r
84  *\r
85  * demo/common/minimal/comtest.c:       Creates 2 tasks\r
86  * ATTENTION: Comtest needs a loopback-connector on the serial port.\r
87  *\r
88  * Main.c also creates a check task.  This periodically checks that all the\r
89  * other tasks are still running and have not experienced any unexpected\r
90  * results.  If all the other tasks are executing correctly an LED is flashed\r
91  * once every mainCHECK_PERIOD milliseconds.  If any of the tasks have not\r
92  * executed, or report an error, the frequency of the LED flash will increase\r
93  * to mainERROR_FLASH_RATE.\r
94  *\r
95  * http://www.FreeRTOS.org contains important information on the use of the\r
96  * wizC PIC18F port.\r
97  */\r
98 \r
99 /* Scheduler include files. */\r
100 #include <FreeRTOS.h>\r
101 #include <task.h>\r
102 \r
103 /* Demo app include files. */\r
104 #include "partest.h"\r
105 #include "serial.h"\r
106 #include "comtest.h"\r
107 \r
108 /* The period between executions of the check task before and after an error\r
109 has been discovered.  If an error has been discovered the check task runs\r
110 more frequently - increasing the LED flash rate. */\r
111 #define mainNO_ERROR_CHECK_PERIOD       ( ( TickType_t ) 10000 / portTICK_PERIOD_MS )\r
112 #define mainERROR_CHECK_PERIOD          ( ( TickType_t )  1000 / portTICK_PERIOD_MS )\r
113 #define mainCHECK_TASK_LED                      ( ( unsigned char ) 3 )\r
114 \r
115 /* Priority definitions for some of the tasks.  Other tasks just use the idle\r
116 priority. */\r
117 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + ( unsigned char ) 2 )\r
118 #define mainCOMM_TEST_PRIORITY  ( tskIDLE_PRIORITY + ( unsigned char ) 1 )\r
119 \r
120 /* The LED that is toggled whenever a character is transmitted.\r
121 mainCOMM_TX_RX_LED + 1 will be toggled every time a character is received. */\r
122 #define mainCOMM_TX_RX_LED              ( ( unsigned char ) 0 )\r
123 \r
124 /* Constants required for the communications. */\r
125 #define mainBAUD_RATE                   ( ( unsigned long ) 57600 )\r
126 \r
127 /*\r
128  * The task function for the "Check" task.\r
129  */\r
130 static portTASK_FUNCTION_PROTO( vErrorChecks, pvParameters );\r
131 \r
132 /*\r
133  * Checks the unique counts of other tasks to ensure they are still operational.\r
134  * Returns pdTRUE if an error is detected, otherwise pdFALSE.\r
135  */\r
136 static char prvCheckOtherTasksAreStillRunning( void );\r
137 \r
138 /*-----------------------------------------------------------*/\r
139 \r
140 /* Creates the tasks, then starts the scheduler. */\r
141 void main( void )\r
142 {\r
143         /* Initialise the required hardware. */\r
144         vParTestInitialise();\r
145 \r
146         /* Start a few of the standard demo tasks found in the demo\common directory. */\r
147         vAltStartComTestTasks( mainCOMM_TEST_PRIORITY, mainBAUD_RATE, mainCOMM_TX_RX_LED );\r
148 \r
149         /* Start the check task defined in this file. */\r
150         xTaskCreate( vErrorChecks, "Check", portMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
151 \r
152         /* Start the scheduler.  Will never return here. */\r
153         vTaskStartScheduler();\r
154 \r
155         while(1)        /* This point should never be reached. */\r
156         {\r
157         }\r
158 }\r
159 /*-----------------------------------------------------------*/\r
160 \r
161 static portTASK_FUNCTION( vErrorChecks, pvParameters )\r
162 {\r
163 TickType_t xLastCheckTime;\r
164 TickType_t xDelayTime = mainNO_ERROR_CHECK_PERIOD;\r
165 char cErrorOccurred;\r
166 \r
167         /* We need to initialise xLastCheckTime prior to the first call to\r
168         vTaskDelayUntil(). */\r
169         xLastCheckTime = xTaskGetTickCount();\r
170 \r
171         /* Cycle for ever, delaying then checking all the other tasks are still\r
172         operating without error. */\r
173         for( ;; )\r
174         {\r
175                 /* Wait until it is time to check the other tasks again. */\r
176                 vTaskDelayUntil( &xLastCheckTime, xDelayTime );\r
177 \r
178                 /* Check all the other tasks are running, and running without ever\r
179                 having an error. */\r
180                 cErrorOccurred = prvCheckOtherTasksAreStillRunning();\r
181 \r
182                 /* If an error was detected increase the frequency of the LED flash. */\r
183                 if( cErrorOccurred == pdTRUE )\r
184                 {\r
185                         xDelayTime = mainERROR_CHECK_PERIOD;\r
186                 }\r
187 \r
188                 /* Flash the LED for visual feedback. */\r
189                 vParTestToggleLED( mainCHECK_TASK_LED );\r
190         }\r
191 }\r
192 /*-----------------------------------------------------------*/\r
193 \r
194 static char prvCheckOtherTasksAreStillRunning( void )\r
195 {\r
196         char cErrorHasOccurred = ( char ) pdFALSE;\r
197 \r
198         if( xAreComTestTasksStillRunning() != pdTRUE )\r
199         {\r
200                 cErrorHasOccurred = ( char ) pdTRUE;\r
201         }\r
202 \r
203         return cErrorHasOccurred;\r
204 }\r
205 /*-----------------------------------------------------------*/\r
206 \r
207 \r