]> git.sur5r.net Git - freertos/blob - Demo/PIC18_WizC/Demo3/main.c
Remove unnecessary use of portLONG, portCHAR and portSHORT.
[freertos] / Demo / PIC18_WizC / Demo3 / main.c
1 /*\r
2     FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.\r
3 \r
4     This file is part of the FreeRTOS distribution.\r
5 \r
6     FreeRTOS is free software; you can redistribute it and/or modify it    under\r
7     the terms of the GNU General Public License (version 2) as published by the\r
8     Free Software Foundation and modified by the FreeRTOS exception.\r
9     **NOTE** The exception to the GPL is included to allow you to distribute a\r
10     combined work that includes FreeRTOS without being obliged to provide the\r
11     source code for proprietary components outside of the FreeRTOS kernel.\r
12     Alternative commercial license and support terms are also available upon\r
13     request.  See the licensing section of http://www.FreeRTOS.org for full\r
14     license details.\r
15 \r
16     FreeRTOS is distributed in the hope that it will be useful,    but WITHOUT\r
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
19     more details.\r
20 \r
21     You should have received a copy of the GNU General Public License along\r
22     with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59\r
23     Temple Place, Suite 330, Boston, MA  02111-1307  USA.\r
24 \r
25 \r
26     ***************************************************************************\r
27     *                                                                         *\r
28     * The FreeRTOS eBook and reference manual are available to purchase for a *\r
29     * small fee. Help yourself get started quickly while also helping the     *\r
30     * FreeRTOS project! See http://www.FreeRTOS.org/Documentation for details *\r
31     *                                                                         *\r
32     ***************************************************************************\r
33 \r
34     1 tab == 4 spaces!\r
35 \r
36     Please ensure to read the configuration and relevant port sections of the\r
37     online documentation.\r
38 \r
39     http://www.FreeRTOS.org - Documentation, latest information, license and\r
40     contact details.\r
41 \r
42     http://www.SafeRTOS.com - A version that is certified for use in safety\r
43     critical systems.\r
44 \r
45     http://www.OpenRTOS.com - Commercial support, development, porting,\r
46     licensing and training services.\r
47 */\r
48 \r
49 /*\r
50 Changes from V3.0.0\r
51 \r
52 Changes from V3.0.1\r
53 */\r
54 \r
55 /*\r
56  * Instead of the normal single demo application, the PIC18F demo is split \r
57  * into several smaller programs of which this is the third.  This enables the \r
58  * demo's to be executed on the RAM limited PIC-devices.\r
59  *\r
60  * The Demo3 project is configured for a PIC18F4620 device.  Main.c starts 12 \r
61  * tasks (including the idle task). See the indicated files in the demo/common\r
62  * directory for more information.\r
63  *\r
64  * demo/common/minimal/integer.c:       Creates 1 task\r
65  * demo/common/minimal/BlockQ.c:        Creates 6 tasks\r
66  * demo/common/minimal/flash.c:         Creates 3 tasks\r
67  *\r
68  * Main.c also creates a check task.  This periodically checks that all the \r
69  * other tasks are still running and have not experienced any unexpected \r
70  * results.  If all the other tasks are executing correctly an LED is flashed \r
71  * once every mainCHECK_PERIOD milliseconds.  If any of the tasks have not \r
72  * executed, or report an error, the frequency of the LED flash will increase \r
73  * to mainERROR_FLASH_RATE.\r
74  *\r
75  * On entry to main an 'X' is transmitted.  Monitoring the serial port using a\r
76  * dumb terminal allows for verification that the device is not continuously \r
77  * being reset (no more than one 'X' should be transmitted).\r
78  *\r
79  * http://www.FreeRTOS.org contains important information on the use of the \r
80  * wizC PIC18F port.\r
81  */\r
82 \r
83 /* Scheduler include files. */\r
84 #include <FreeRTOS.h>\r
85 #include <task.h>\r
86 \r
87 /* Demo app include files. */\r
88 #include "integer.h"\r
89 #include "BlockQ.h"\r
90 #include "flash.h"\r
91 #include "partest.h"\r
92 #include "serial.h"\r
93 \r
94 /* The period between executions of the check task before and after an error\r
95 has been discovered.  If an error has been discovered the check task runs\r
96 more frequently - increasing the LED flash rate. */\r
97 #define mainNO_ERROR_CHECK_PERIOD               ( ( portTickType ) 10000 / portTICK_RATE_MS )\r
98 #define mainERROR_CHECK_PERIOD                  ( ( portTickType )  1000 / portTICK_RATE_MS )\r
99 #define mainCHECK_TASK_LED                              ( ( unsigned char ) 3 )\r
100 \r
101 /* Priority definitions for some of the tasks.  Other tasks just use the idle\r
102 priority. */\r
103 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + ( unsigned char ) 3 )\r
104 #define mainLED_FLASH_PRIORITY  ( tskIDLE_PRIORITY + ( unsigned char ) 2 )\r
105 #define mainBLOCK_Q_PRIORITY    ( tskIDLE_PRIORITY + ( unsigned char ) 1 )\r
106 #define mainINTEGER_PRIORITY    ( tskIDLE_PRIORITY + ( unsigned char ) 0 )\r
107 \r
108 /* Constants required for the communications.  Only one character is ever \r
109 transmitted. */\r
110 #define mainCOMMS_QUEUE_LENGTH                  ( ( unsigned char ) 5 )\r
111 #define mainNO_BLOCK                                    ( ( portTickType ) 0 )\r
112 #define mainBAUD_RATE                                   ( ( unsigned long ) 57600 )\r
113 \r
114 /*\r
115  * The task function for the "Check" task.\r
116  */\r
117 static portTASK_FUNCTION_PROTO( vErrorChecks, pvParameters );\r
118 \r
119 /*\r
120  * Checks the unique counts of other tasks to ensure they are still operational.\r
121  * Returns pdTRUE if an error is detected, otherwise pdFALSE.\r
122  */\r
123 static char prvCheckOtherTasksAreStillRunning( void );\r
124 \r
125 /*-----------------------------------------------------------*/\r
126 \r
127 /* Creates the tasks, then starts the scheduler. */\r
128 void main( void )\r
129 {\r
130         /* Initialise the required hardware. */\r
131         vParTestInitialise();\r
132 \r
133         /* Send a character so we have some visible feedback of a reset. */\r
134         xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH );\r
135         xSerialPutChar( NULL, 'X', mainNO_BLOCK );\r
136 \r
137         /* Start the standard demo tasks found in the demo\common directory. */\r
138         vStartIntegerMathTasks( mainINTEGER_PRIORITY);\r
139         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
140         vStartLEDFlashTasks( mainLED_FLASH_PRIORITY );\r
141 \r
142         /* Start the check task defined in this file. */\r
143         xTaskCreate( vErrorChecks, ( const char * const ) "Check", portMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
144 \r
145         /* Start the scheduler.  Will never return here. */\r
146         vTaskStartScheduler( );\r
147 \r
148         while(1)        /* This point should never be reached. */\r
149         {\r
150         }\r
151 }\r
152 /*-----------------------------------------------------------*/\r
153 \r
154 static portTASK_FUNCTION( vErrorChecks, pvParameters )\r
155 {\r
156         portTickType xLastCheckTime;\r
157         portTickType xDelayTime = mainNO_ERROR_CHECK_PERIOD;\r
158         char cErrorOccurred;\r
159 \r
160         /* We need to initialise xLastCheckTime prior to the first call to \r
161         vTaskDelayUntil(). */\r
162         xLastCheckTime = xTaskGetTickCount();\r
163         \r
164         /* Cycle for ever, delaying then checking all the other tasks are still\r
165         operating without error. */\r
166         for( ;; )\r
167         {\r
168                 /* Wait until it is time to check the other tasks again. */\r
169                 vTaskDelayUntil( &xLastCheckTime, xDelayTime );\r
170 \r
171                 /* Check all the other tasks are running, and running without ever\r
172                 having an error. */\r
173                 cErrorOccurred = prvCheckOtherTasksAreStillRunning();\r
174 \r
175                 /* If an error was detected increase the frequency of the LED flash. */\r
176                 if( cErrorOccurred == pdTRUE )\r
177                 {\r
178                         xDelayTime = mainERROR_CHECK_PERIOD;\r
179                 }\r
180 \r
181                 /* Flash the LED for visual feedback. */\r
182                 vParTestToggleLED( mainCHECK_TASK_LED );\r
183         }\r
184 }\r
185 \r
186 /*-----------------------------------------------------------*/\r
187 \r
188 static char prvCheckOtherTasksAreStillRunning( void )\r
189 {\r
190         char cErrorHasOccurred = ( char ) pdFALSE;\r
191 \r
192         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
193         {\r
194                 cErrorHasOccurred = ( char ) pdTRUE;\r
195         }\r
196 \r
197         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
198         {\r
199                 cErrorHasOccurred = ( char ) pdTRUE;\r
200         }\r
201 \r
202         return cErrorHasOccurred;\r
203 }\r
204 /*-----------------------------------------------------------*/\r
205 \r
206 \r