]> git.sur5r.net Git - freertos/blob - Demo/PIC18_WizC/Demo2/main.c
Remove unnecessary use of portLONG, portCHAR and portSHORT.
[freertos] / Demo / PIC18_WizC / Demo2 / 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 second.  This enables the \r
58  * demo's to be executed on the RAM limited PIC-devices.\r
59  *\r
60  * The Demo2 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/PollQ.c:         Creates 2 tasks\r
66  * demo/common/minimal/semtest.c:       Creates 4 tasks\r
67  * demo/common/minimal/flash.c:         Creates 3 tasks\r
68  *\r
69  * Main.c also creates a check task.  This periodically checks that all the \r
70  * other tasks are still running and have not experienced any unexpected \r
71  * results.  If all the other tasks are executing correctly an LED is flashed \r
72  * once every mainCHECK_PERIOD milliseconds.  If any of the tasks have not \r
73  * executed, or report an error, the frequency of the LED flash will increase \r
74  * to mainERROR_FLASH_RATE.\r
75  *\r
76  * On entry to main an 'X' is transmitted.  Monitoring the serial port using a\r
77  * dumb terminal allows for verification that the device is not continuously \r
78  * being reset (no more than one 'X' should be transmitted).\r
79  *\r
80  * http://www.FreeRTOS.org contains important information on the use of the \r
81  * wizC PIC18F port.\r
82  */\r
83 \r
84 /* Scheduler include files. */\r
85 #include <FreeRTOS.h>\r
86 #include <task.h>\r
87 \r
88 /* Demo app include files. */\r
89 #include "integer.h"\r
90 #include "PollQ.h"\r
91 #include "semtest.h"\r
92 #include "flash.h"\r
93 #include "partest.h"\r
94 #include "serial.h"\r
95 \r
96 /* The period between executions of the check task before and after an error\r
97 has been discovered.  If an error has been discovered the check task runs\r
98 more frequently - increasing the LED flash rate. */\r
99 #define mainNO_ERROR_CHECK_PERIOD       ( ( portTickType ) 10000 / portTICK_RATE_MS )\r
100 #define mainERROR_CHECK_PERIOD          ( ( portTickType )  1000 / portTICK_RATE_MS )\r
101 #define mainCHECK_TASK_LED                      ( ( unsigned char ) 3 )\r
102 \r
103 /* Priority definitions for some of the tasks.  Other tasks just use the idle\r
104 priority. */\r
105 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + ( unsigned char ) 3 )\r
106 #define mainLED_FLASH_PRIORITY  ( tskIDLE_PRIORITY + ( unsigned char ) 2 )\r
107 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + ( unsigned char ) 1 )\r
108 #define mainSEM_TEST_PRIORITY   ( tskIDLE_PRIORITY + ( unsigned char ) 1 )\r
109 #define mainINTEGER_PRIORITY    ( tskIDLE_PRIORITY + ( unsigned char ) 0 )\r
110 \r
111 /* Constants required for the communications.  Only one character is ever \r
112 transmitted. */\r
113 #define mainCOMMS_QUEUE_LENGTH          ( ( unsigned char ) 5 )\r
114 #define mainNO_BLOCK                            ( ( portTickType ) 0 )\r
115 #define mainBAUD_RATE                           ( ( unsigned long ) 57600 )\r
116 \r
117 /*\r
118  * The task function for the "Check" task.\r
119  */\r
120 static portTASK_FUNCTION_PROTO( vErrorChecks, pvParameters );\r
121 \r
122 /*\r
123  * Checks the unique counts of other tasks to ensure they are still operational.\r
124  * Returns pdTRUE if an error is detected, otherwise pdFALSE.\r
125  */\r
126 static char prvCheckOtherTasksAreStillRunning( void );\r
127 \r
128 /*-----------------------------------------------------------*/\r
129 \r
130 /* Creates the tasks, then starts the scheduler. */\r
131 void main( void )\r
132 {\r
133         /* Initialise the required hardware. */\r
134         vParTestInitialise();\r
135 \r
136         /* Send a character so we have some visible feedback of a reset. */\r
137         xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH );\r
138         xSerialPutChar( NULL, 'X', mainNO_BLOCK );\r
139 \r
140         /* Start a few of the standard demo tasks found in the demo\common directory. */\r
141         vStartIntegerMathTasks( mainINTEGER_PRIORITY);\r
142         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
143         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
144         vStartLEDFlashTasks( mainLED_FLASH_PRIORITY );\r
145 \r
146         /* Start the check task defined in this file. */\r
147         xTaskCreate( vErrorChecks, ( const char * const ) "Check", portMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
148 \r
149         /* Start the scheduler.  Will never return here. */\r
150         vTaskStartScheduler();\r
151 \r
152         while(1)        /* This point should never be reached. */\r
153         {\r
154         }\r
155 }\r
156 /*-----------------------------------------------------------*/\r
157 \r
158 static portTASK_FUNCTION( vErrorChecks, pvParameters )\r
159 {\r
160 portTickType xLastCheckTime;\r
161 portTickType xDelayTime = mainNO_ERROR_CHECK_PERIOD;\r
162 char cErrorOccurred;\r
163 \r
164         /* We need to initialise xLastCheckTime prior to the first call to \r
165         vTaskDelayUntil(). */\r
166         xLastCheckTime = xTaskGetTickCount();\r
167         \r
168         /* Cycle for ever, delaying then checking all the other tasks are still\r
169         operating without error. */\r
170         for( ;; )\r
171         {\r
172                 /* Wait until it is time to check the other tasks again. */\r
173                 vTaskDelayUntil( &xLastCheckTime, xDelayTime );\r
174                 \r
175                 /* Check all the other tasks are running, and running without ever\r
176                 having an error. */\r
177                 cErrorOccurred = prvCheckOtherTasksAreStillRunning();\r
178 \r
179                 /* If an error was detected increase the frequency of the LED flash. */\r
180                 if( cErrorOccurred == pdTRUE )\r
181                 {\r
182                         xDelayTime = mainERROR_CHECK_PERIOD;\r
183                 }\r
184 \r
185                 /* Flash the LED for visual feedback. */\r
186                 vParTestToggleLED( mainCHECK_TASK_LED );\r
187         }\r
188 }\r
189 /*-----------------------------------------------------------*/\r
190 \r
191 static char prvCheckOtherTasksAreStillRunning( void )\r
192 {\r
193         char cErrorHasOccurred = ( char ) pdFALSE;\r
194 \r
195         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
196         {\r
197                 cErrorHasOccurred = ( char ) pdTRUE;\r
198         }\r
199 \r
200         if( xArePollingQueuesStillRunning() != pdTRUE )\r
201         {\r
202                 cErrorHasOccurred = ( char ) pdTRUE;\r
203         }\r
204 \r
205         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
206         {\r
207                 cErrorHasOccurred = ( char ) pdTRUE;\r
208         }\r
209 \r
210         return cErrorHasOccurred;\r
211 }\r
212 /*-----------------------------------------------------------*/\r
213 \r
214 \r