]> git.sur5r.net Git - freertos/blob - Demo/WizNET_DEMO_TERN_186/main.c
Update to V5.0.2
[freertos] / Demo / WizNET_DEMO_TERN_186 / main.c
1 /*\r
2         FreeRTOS.org V5.0.2 - Copyright (C) 2003-2008 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     ***************************************************************************\r
28     *                                                                         *\r
29     * SAVE TIME AND MONEY!  We can port FreeRTOS.org to your own hardware,    *\r
30     * and even write all or part of your application on your behalf.          *\r
31     * See http://www.OpenRTOS.com for details of the services we provide to   *\r
32     * expedite your project.                                                  *\r
33     *                                                                         *\r
34     ***************************************************************************\r
35     ***************************************************************************\r
36 \r
37         Please ensure to read the configuration and relevant port sections of the\r
38         online documentation.\r
39 \r
40         http://www.FreeRTOS.org - Documentation, latest information, license and \r
41         contact details.\r
42 \r
43         http://www.SafeRTOS.com - A version that is certified for use in safety \r
44         critical systems.\r
45 \r
46         http://www.OpenRTOS.com - Commercial support, development, porting, \r
47         licensing and training services.\r
48 */\r
49 \r
50 /*\r
51  * Creates all the demo application tasks then starts the scheduler.  In \r
52  * addition to the standard demo application tasks main() creates the \r
53  * HTTPServer task, and a "Check" task.  The Check task periodically inspects\r
54  * all the other tasks in the system to see if any errors have been reported.\r
55  * The error status is then displayed on the served WEB page.\r
56  */\r
57 \r
58 /* Tern includes. */\r
59 #include <ae.h>\r
60 #include <embedded.h>\r
61 \r
62 /* FreeRTOS.org includes. */\r
63 #include <FreeRTOS.h>\r
64 #include <task.h>\r
65 \r
66 /* Demo application includes. */\r
67 #include "HTTPTask.h"\r
68 #include "integer.h"\r
69 #include "PollQ.h"\r
70 #include "semtest.h"\r
71 #include "dynamic.h"\r
72 #include "BlockQ.h"\r
73 #include "death.h"\r
74 #include "serial.h"\r
75 #include "comtest.h"\r
76 \r
77 /* How often should the "check" task execute? */\r
78 #define mainCHECK_DELAY         ( 3000 / portTICK_RATE_MS )\r
79 \r
80 /* Priorities allocated to the various tasks. */\r
81 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
82 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )\r
83 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
84 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
85 #define mainHTTP_TASK_PRIORITY          ( tskIDLE_PRIORITY + 3 )\r
86 #define mainSUICIDE_TASKS_PRIORITY  ( tskIDLE_PRIORITY + 1 )\r
87 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
88 \r
89 /* Used to indicate the error status.  A value of 0 means that an error has not\r
90 been detected in any task.  A non zero value indicates which group of demo \r
91 tasks has reported an error.  See prvCheckTask() for bit definitions. */\r
92 unsigned portSHORT usCheckStatus = 0;\r
93 \r
94 /*-----------------------------------------------------------*/\r
95 \r
96 /*\r
97  * Setup any hardware required by the demo - other than the RTOS tick which\r
98  * is configured when the scheduler is started.\r
99  */\r
100 static void prvSetupHardware( void );\r
101 \r
102 /*\r
103  * Periodically inspect all the other tasks, updating usCheckStatus should an\r
104  * error be discovered in any task.\r
105  */\r
106 static void prvCheckTask( void *pvParameters );\r
107 /*-----------------------------------------------------------*/\r
108 \r
109 void main(void)\r
110 {\r
111         prvSetupHardware();\r
112 \r
113     /* Start the HTTP server task. */\r
114         xTaskCreate( vHTTPTask, "WizNet", configMINIMAL_STACK_SIZE, NULL, mainHTTP_TASK_PRIORITY, NULL );\r
115 \r
116         /* Start the demo/test application tasks.  See the demo application \r
117         section of the FreeRTOS.org WEB site for more information. */\r
118         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
119         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
120         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
121         vStartDynamicPriorityTasks();\r
122         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
123     vStartComTestTasks( mainCOM_TEST_PRIORITY, serCOM2, ser57600 );\r
124 \r
125         /* Start the task that checks the other demo tasks for errors. */\r
126     xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
127 \r
128         /* The suicide tasks must be created last as they monitor the number of\r
129         tasks in the system to ensure there are no more or fewer than expected\r
130         compared to the number that were executing when the task started. */\r
131         vCreateSuicidalTasks( mainSUICIDE_TASKS_PRIORITY );\r
132         \r
133         /* Finally start the scheduler. */\r
134     vTaskStartScheduler();\r
135 \r
136         /* Should not get here! */\r
137         for( ;; );\r
138 }\r
139 /*-----------------------------------------------------------*/\r
140 \r
141 static void prvSetupHardware( void )\r
142 {\r
143         ae_init();\r
144 }\r
145 /*-----------------------------------------------------------*/\r
146 \r
147 static void prvCheckTask( void *pvParameters )\r
148 {\r
149         ( void ) pvParameters;\r
150 \r
151         /* Check all the demo tasks to ensure that they are all still running, and\r
152     that none of them have detected     an error. */\r
153     for( ;; )\r
154     {\r
155                 /* Block until it is time to check again. */\r
156         vTaskDelay( mainCHECK_DELAY );\r
157         \r
158                 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
159                 {\r
160                         usCheckStatus |= 0x01;\r
161                 }\r
162 \r
163                 if( xArePollingQueuesStillRunning() != pdTRUE )\r
164                 {\r
165                         usCheckStatus |= 0x02;\r
166                 }\r
167 \r
168                 if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
169                 {\r
170                         usCheckStatus |= 0x04;\r
171                 }\r
172 \r
173                 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
174                 {\r
175                         usCheckStatus |= 0x08;\r
176                 }\r
177 \r
178                 if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
179                 {\r
180                         usCheckStatus |= 0x10;\r
181                 }\r
182 \r
183         if( xIsCreateTaskStillRunning() != pdTRUE )\r
184         {\r
185                 usCheckStatus |= 0x20;\r
186         }\r
187 \r
188         if( xAreComTestTasksStillRunning() != pdTRUE )\r
189         {\r
190                 usCheckStatus |= 0x40;\r
191         }\r
192         }\r
193 }\r
194 /*-----------------------------------------------------------*/\r
195 \r
196 /* This is included to prevent link errors - allowing the 'full' version of\r
197 the comtest tasks to be used.  It can be ignored. */\r
198 void vPrintDisplayMessage( const portCHAR * const * ppcMessageToSend )\r
199 {\r
200         ( void ) ppcMessageToSend;\r
201 }\r
202 \r
203 \r
204 \r
205 \r
206 \r
207 \r
208 \r
209 \r
210 \r
211 \r
212 \r
213 \r