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