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