]> git.sur5r.net Git - freertos/blob - Demo/WizNET_DEMO_TERN_186/main.c
Change to the file headers only.
[freertos] / Demo / WizNET_DEMO_TERN_186 / main.c
1 /*\r
2     FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.\r
3 \r
4     ***************************************************************************\r
5     *                                                                         *\r
6     * If you are:                                                             *\r
7     *                                                                         *\r
8     *    + New to FreeRTOS,                                                   *\r
9     *    + Wanting to learn FreeRTOS or multitasking in general quickly       *\r
10     *    + Looking for basic training,                                        *\r
11     *    + Wanting to improve your FreeRTOS skills and productivity           *\r
12     *                                                                         *\r
13     * then take a look at the FreeRTOS eBook                                  *\r
14     *                                                                         *\r
15     *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *\r
16     *                  http://www.FreeRTOS.org/Documentation                  *\r
17     *                                                                         *\r
18     * A pdf reference manual is also available.  Both are usually delivered   *\r
19     * to your inbox within 20 minutes to two hours when purchased between 8am *\r
20     * and 8pm GMT (although please allow up to 24 hours in case of            *\r
21     * exceptional circumstances).  Thank you for your support!                *\r
22     *                                                                         *\r
23     ***************************************************************************\r
24 \r
25     This file is part of the FreeRTOS distribution.\r
26 \r
27     FreeRTOS is free software; you can redistribute it and/or modify it under\r
28     the terms of the GNU General Public License (version 2) as published by the\r
29     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
30     ***NOTE*** The exception to the GPL is included to allow you to distribute\r
31     a combined work that includes FreeRTOS without being obliged to provide the\r
32     source code for proprietary components outside of the FreeRTOS kernel.\r
33     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT\r
34     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
35     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
36     more details. You should have received a copy of the GNU General Public \r
37     License and the FreeRTOS license exception along with FreeRTOS; if not it \r
38     can be viewed here: http://www.freertos.org/a00114.html and also obtained \r
39     by writing to Richard Barry, contact details for whom are available on the\r
40     FreeRTOS WEB site.\r
41 \r
42     1 tab == 4 spaces!\r
43 \r
44     http://www.FreeRTOS.org - Documentation, latest information, license and\r
45     contact details.\r
46 \r
47     http://www.SafeRTOS.com - A version that is certified for use in safety\r
48     critical systems.\r
49 \r
50     http://www.OpenRTOS.com - Commercial support, development, porting,\r
51     licensing and training services.\r
52 */\r
53 \r
54 /*\r
55  * Creates all the demo application tasks then starts the scheduler.  In \r
56  * addition to the standard demo application tasks main() creates the \r
57  * HTTPServer task, and a "Check" task.  The Check task periodically inspects\r
58  * all the other tasks in the system to see if any errors have been reported.\r
59  * The error status is then displayed on the served WEB page.\r
60  */\r
61 \r
62 /* Tern includes. */\r
63 #include <ae.h>\r
64 #include <embedded.h>\r
65 \r
66 /* FreeRTOS.org includes. */\r
67 #include <FreeRTOS.h>\r
68 #include <task.h>\r
69 \r
70 /* Demo application includes. */\r
71 #include "HTTPTask.h"\r
72 #include "integer.h"\r
73 #include "PollQ.h"\r
74 #include "semtest.h"\r
75 #include "dynamic.h"\r
76 #include "BlockQ.h"\r
77 #include "death.h"\r
78 #include "serial.h"\r
79 #include "comtest.h"\r
80 \r
81 /* How often should the "check" task execute? */\r
82 #define mainCHECK_DELAY         ( 3000 / portTICK_RATE_MS )\r
83 \r
84 /* Priorities allocated to the various tasks. */\r
85 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
86 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )\r
87 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
88 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
89 #define mainHTTP_TASK_PRIORITY          ( tskIDLE_PRIORITY + 3 )\r
90 #define mainSUICIDE_TASKS_PRIORITY  ( tskIDLE_PRIORITY + 1 )\r
91 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
92 \r
93 /* Used to indicate the error status.  A value of 0 means that an error has not\r
94 been detected in any task.  A non zero value indicates which group of demo \r
95 tasks has reported an error.  See prvCheckTask() for bit definitions. */\r
96 unsigned short usCheckStatus = 0;\r
97 \r
98 /*-----------------------------------------------------------*/\r
99 \r
100 /*\r
101  * Setup any hardware required by the demo - other than the RTOS tick which\r
102  * is configured when the scheduler is started.\r
103  */\r
104 static void prvSetupHardware( void );\r
105 \r
106 /*\r
107  * Periodically inspect all the other tasks, updating usCheckStatus should an\r
108  * error be discovered in any task.\r
109  */\r
110 static void prvCheckTask( void *pvParameters );\r
111 /*-----------------------------------------------------------*/\r
112 \r
113 void main(void)\r
114 {\r
115         prvSetupHardware();\r
116 \r
117     /* Start the HTTP server task. */\r
118         xTaskCreate( vHTTPTask, "WizNet", configMINIMAL_STACK_SIZE, NULL, mainHTTP_TASK_PRIORITY, NULL );\r
119 \r
120         /* Start the demo/test application tasks.  See the demo application \r
121         section of the FreeRTOS.org WEB site for more information. */\r
122         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
123         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
124         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
125         vStartDynamicPriorityTasks();\r
126         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
127     vStartComTestTasks( mainCOM_TEST_PRIORITY, serCOM2, ser57600 );\r
128 \r
129         /* Start the task that checks the other demo tasks for errors. */\r
130     xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
131 \r
132         /* The suicide tasks must be created last as they monitor the number of\r
133         tasks in the system to ensure there are no more or fewer than expected\r
134         compared to the number that were executing when the task started. */\r
135         vCreateSuicidalTasks( mainSUICIDE_TASKS_PRIORITY );\r
136         \r
137         /* Finally start the scheduler. */\r
138     vTaskStartScheduler();\r
139 \r
140         /* Should not get here! */\r
141         for( ;; );\r
142 }\r
143 /*-----------------------------------------------------------*/\r
144 \r
145 static void prvSetupHardware( void )\r
146 {\r
147         ae_init();\r
148 }\r
149 /*-----------------------------------------------------------*/\r
150 \r
151 static void prvCheckTask( void *pvParameters )\r
152 {\r
153         ( void ) pvParameters;\r
154 \r
155         /* Check all the demo tasks to ensure that they are all still running, and\r
156     that none of them have detected     an error. */\r
157     for( ;; )\r
158     {\r
159                 /* Block until it is time to check again. */\r
160         vTaskDelay( mainCHECK_DELAY );\r
161         \r
162                 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
163                 {\r
164                         usCheckStatus |= 0x01;\r
165                 }\r
166 \r
167                 if( xArePollingQueuesStillRunning() != pdTRUE )\r
168                 {\r
169                         usCheckStatus |= 0x02;\r
170                 }\r
171 \r
172                 if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
173                 {\r
174                         usCheckStatus |= 0x04;\r
175                 }\r
176 \r
177                 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
178                 {\r
179                         usCheckStatus |= 0x08;\r
180                 }\r
181 \r
182                 if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
183                 {\r
184                         usCheckStatus |= 0x10;\r
185                 }\r
186 \r
187         if( xIsCreateTaskStillRunning() != pdTRUE )\r
188         {\r
189                 usCheckStatus |= 0x20;\r
190         }\r
191 \r
192         if( xAreComTestTasksStillRunning() != pdTRUE )\r
193         {\r
194                 usCheckStatus |= 0x40;\r
195         }\r
196         }\r
197 }\r
198 /*-----------------------------------------------------------*/\r
199 \r
200 /* This is included to prevent link errors - allowing the 'full' version of\r
201 the comtest tasks to be used.  It can be ignored. */\r
202 void vPrintDisplayMessage( const char * const * ppcMessageToSend )\r
203 {\r
204         ( void ) ppcMessageToSend;\r
205 }\r
206 \r
207 \r
208 \r
209 \r
210 \r
211 \r
212 \r
213 \r
214 \r
215 \r
216 \r
217 \r