]> git.sur5r.net Git - freertos/blob - Demo/WizNET_DEMO_TERN_186/main.c
Update in preparation for the V4.3.1 release.
[freertos] / Demo / WizNET_DEMO_TERN_186 / main.c
1 /*\r
2         FreeRTOS.org V4.3.1 - Copyright (C) 2003-2007 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS.org distribution.\r
5 \r
6         FreeRTOS.org is free software; you can redistribute it and/or modify\r
7         it under the terms of the GNU General Public License as published by\r
8         the Free Software Foundation; either version 2 of the License, or\r
9         (at your option) any later version.\r
10 \r
11         FreeRTOS.org is distributed in the hope that it will be useful,\r
12         but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14         GNU General Public License for more details.\r
15 \r
16         You should have received a copy of the GNU General Public License\r
17         along with FreeRTOS.org; if not, write to the Free Software\r
18         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
19 \r
20         A special exception to the GPL can be applied should you wish to distribute\r
21         a combined work that includes FreeRTOS.org, without being obliged to provide\r
22         the source code for any proprietary components.  See the licensing section\r
23         of http://www.FreeRTOS.org for full details of how and when the exception\r
24         can be applied.\r
25 \r
26         ***************************************************************************\r
27         See http://www.FreeRTOS.org for documentation, latest information, license \r
28         and contact details.  Please ensure to read the configuration and relevant \r
29         port sections of the online documentation.\r
30 \r
31         Also see http://www.SafeRTOS.com for an IEC 61508 compliant version along\r
32         with commercial development and support options.\r
33         ***************************************************************************\r
34 */\r
35 \r
36 /*\r
37  * Creates all the demo application tasks then starts the scheduler.  In \r
38  * addition to the standard demo application tasks main() creates the \r
39  * HTTPServer task, and a "Check" task.  The Check task periodically inspects\r
40  * all the other tasks in the system to see if any errors have been reported.\r
41  * The error status is then displayed on the served WEB page.\r
42  */\r
43 \r
44 /* Tern includes. */\r
45 #include <ae.h>\r
46 #include <embedded.h>\r
47 \r
48 /* FreeRTOS.org includes. */\r
49 #include <FreeRTOS.h>\r
50 #include <task.h>\r
51 \r
52 /* Demo application includes. */\r
53 #include "HTTPTask.h"\r
54 #include "integer.h"\r
55 #include "PollQ.h"\r
56 #include "semtest.h"\r
57 #include "dynamic.h"\r
58 #include "BlockQ.h"\r
59 #include "Death.h"\r
60 #include "serial.h"\r
61 #include "comtest.h"\r
62 \r
63 /* How often should the "check" task execute? */\r
64 #define mainCHECK_DELAY         ( 3000 / portTICK_RATE_MS )\r
65 \r
66 /* Priorities allocated to the various tasks. */\r
67 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
68 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )\r
69 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
70 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
71 #define mainHTTP_TASK_PRIORITY          ( tskIDLE_PRIORITY + 3 )\r
72 #define mainSUICIDE_TASKS_PRIORITY  ( tskIDLE_PRIORITY + 1 )\r
73 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
74 \r
75 /* Used to indicate the error status.  A value of 0 means that an error has not\r
76 been detected in any task.  A non zero value indicates which group of demo \r
77 tasks has reported an error.  See prvCheckTask() for bit definitions. */\r
78 unsigned portSHORT usCheckStatus = 0;\r
79 \r
80 /*-----------------------------------------------------------*/\r
81 \r
82 /*\r
83  * Setup any hardware required by the demo - other than the RTOS tick which\r
84  * is configured when the scheduler is started.\r
85  */\r
86 static void prvSetupHardware( void );\r
87 \r
88 /*\r
89  * Periodically inspect all the other tasks, updating usCheckStatus should an\r
90  * error be discovered in any task.\r
91  */\r
92 static void prvCheckTask( void *pvParameters );\r
93 /*-----------------------------------------------------------*/\r
94 \r
95 void main(void)\r
96 {\r
97         prvSetupHardware();\r
98 \r
99     /* Start the HTTP server task. */\r
100         xTaskCreate( vHTTPTask, "WizNet", configMINIMAL_STACK_SIZE, NULL, mainHTTP_TASK_PRIORITY, NULL );\r
101 \r
102         /* Start the demo/test application tasks.  See the demo application \r
103         section of the FreeRTOS.org WEB site for more information. */\r
104         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
105         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
106         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
107         vStartDynamicPriorityTasks();\r
108         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
109     vStartComTestTasks( mainCOM_TEST_PRIORITY, serCOM2, ser57600 );\r
110 \r
111         /* Start the task that checks the other demo tasks for errors. */\r
112     xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
113 \r
114         /* The suicide tasks must be created last as they monitor the number of\r
115         tasks in the system to ensure there are no more or fewer than expected\r
116         compared to the number that were executing when the task started. */\r
117         vCreateSuicidalTasks( mainSUICIDE_TASKS_PRIORITY );\r
118         \r
119         /* Finally start the scheduler. */\r
120     vTaskStartScheduler();\r
121 \r
122         /* Should not get here! */\r
123         for( ;; );\r
124 }\r
125 /*-----------------------------------------------------------*/\r
126 \r
127 static void prvSetupHardware( void )\r
128 {\r
129         ae_init();\r
130 }\r
131 /*-----------------------------------------------------------*/\r
132 \r
133 static void prvCheckTask( void *pvParameters )\r
134 {\r
135         ( void ) pvParameters;\r
136 \r
137         /* Check all the demo tasks to ensure that they are all still running, and\r
138     that none of them have detected     an error. */\r
139     for( ;; )\r
140     {\r
141                 /* Block until it is time to check again. */\r
142         vTaskDelay( mainCHECK_DELAY );\r
143         \r
144                 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
145                 {\r
146                         usCheckStatus |= 0x01;\r
147                 }\r
148 \r
149                 if( xArePollingQueuesStillRunning() != pdTRUE )\r
150                 {\r
151                         usCheckStatus |= 0x02;\r
152                 }\r
153 \r
154                 if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
155                 {\r
156                         usCheckStatus |= 0x04;\r
157                 }\r
158 \r
159                 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
160                 {\r
161                         usCheckStatus |= 0x08;\r
162                 }\r
163 \r
164                 if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
165                 {\r
166                         usCheckStatus |= 0x10;\r
167                 }\r
168 \r
169         if( xIsCreateTaskStillRunning() != pdTRUE )\r
170         {\r
171                 usCheckStatus |= 0x20;\r
172         }\r
173 \r
174         if( xAreComTestTasksStillRunning() != pdTRUE )\r
175         {\r
176                 usCheckStatus |= 0x40;\r
177         }\r
178         }\r
179 }\r
180 /*-----------------------------------------------------------*/\r
181 \r
182 /* This is included to prevent link errors - allowing the 'full' version of\r
183 the comtest tasks to be used.  It can be ignored. */\r
184 void vPrintDisplayMessage( const portCHAR * const * ppcMessageToSend )\r
185 {\r
186         ( void ) ppcMessageToSend;\r
187 }\r
188 \r
189 \r
190 \r
191 \r
192 \r
193 \r
194 \r
195 \r
196 \r
197 \r
198 \r
199 \r