]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/WizNET_DEMO_TERN_186/main.c
Prepare for V7.2.0 release.
[freertos] / FreeRTOS / Demo / WizNET_DEMO_TERN_186 / main.c
1 /*\r
2     FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd.\r
3         \r
4 \r
5     ***************************************************************************\r
6      *                                                                       *\r
7      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
8      *    Complete, revised, and edited pdf reference manuals are also       *\r
9      *    available.                                                         *\r
10      *                                                                       *\r
11      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
12      *    ensuring you get running as quickly as possible and with an        *\r
13      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
14      *    the FreeRTOS project to continue with its mission of providing     *\r
15      *    professional grade, cross platform, de facto standard solutions    *\r
16      *    for microcontrollers - completely free of charge!                  *\r
17      *                                                                       *\r
18      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
19      *                                                                       *\r
20      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
21      *                                                                       *\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 modification to the GPL is included to allow you to\r
31     distribute a combined work that includes FreeRTOS without being obliged to\r
32     provide the source code for proprietary components outside of the FreeRTOS\r
33     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
34     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
35     or 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     ***************************************************************************\r
45      *                                                                       *\r
46      *    Having a problem?  Start by reading the FAQ "My application does   *\r
47      *    not run, what could be wrong?                                      *\r
48      *                                                                       *\r
49      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
50      *                                                                       *\r
51     ***************************************************************************\r
52 \r
53     \r
54     http://www.FreeRTOS.org - Documentation, training, latest information, \r
55     license and contact details.\r
56     \r
57     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
58     including FreeRTOS+Trace - an indispensable productivity tool.\r
59 \r
60     Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell \r
61     the code with commercial support, indemnification, and middleware, under \r
62     the OpenRTOS brand: http://www.OpenRTOS.com.  High Integrity Systems also\r
63     provide a safety engineered and independently SIL3 certified version under \r
64     the SafeRTOS brand: http://www.SafeRTOS.com.\r
65 */\r
66 \r
67 /*\r
68  * Creates all the demo application tasks then starts the scheduler.  In \r
69  * addition to the standard demo application tasks main() creates the \r
70  * HTTPServer task, and a "Check" task.  The Check task periodically inspects\r
71  * all the other tasks in the system to see if any errors have been reported.\r
72  * The error status is then displayed on the served WEB page.\r
73  */\r
74 \r
75 /* Tern includes. */\r
76 #include <ae.h>\r
77 #include <embedded.h>\r
78 \r
79 /* FreeRTOS.org includes. */\r
80 #include <FreeRTOS.h>\r
81 #include <task.h>\r
82 \r
83 /* Demo application includes. */\r
84 #include "HTTPTask.h"\r
85 #include "integer.h"\r
86 #include "PollQ.h"\r
87 #include "semtest.h"\r
88 #include "dynamic.h"\r
89 #include "BlockQ.h"\r
90 #include "death.h"\r
91 #include "serial.h"\r
92 #include "comtest.h"\r
93 \r
94 /* How often should the "check" task execute? */\r
95 #define mainCHECK_DELAY         ( 3000 / portTICK_RATE_MS )\r
96 \r
97 /* Priorities allocated to the various tasks. */\r
98 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
99 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )\r
100 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
101 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
102 #define mainHTTP_TASK_PRIORITY          ( tskIDLE_PRIORITY + 3 )\r
103 #define mainSUICIDE_TASKS_PRIORITY  ( tskIDLE_PRIORITY + 1 )\r
104 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
105 \r
106 /* Used to indicate the error status.  A value of 0 means that an error has not\r
107 been detected in any task.  A non zero value indicates which group of demo \r
108 tasks has reported an error.  See prvCheckTask() for bit definitions. */\r
109 unsigned short usCheckStatus = 0;\r
110 \r
111 /*-----------------------------------------------------------*/\r
112 \r
113 /*\r
114  * Setup any hardware required by the demo - other than the RTOS tick which\r
115  * is configured when the scheduler is started.\r
116  */\r
117 static void prvSetupHardware( void );\r
118 \r
119 /*\r
120  * Periodically inspect all the other tasks, updating usCheckStatus should an\r
121  * error be discovered in any task.\r
122  */\r
123 static void prvCheckTask( void *pvParameters );\r
124 /*-----------------------------------------------------------*/\r
125 \r
126 void main(void)\r
127 {\r
128         prvSetupHardware();\r
129 \r
130     /* Start the HTTP server task. */\r
131         xTaskCreate( vHTTPTask, "WizNet", configMINIMAL_STACK_SIZE, NULL, mainHTTP_TASK_PRIORITY, NULL );\r
132 \r
133         /* Start the demo/test application tasks.  See the demo application \r
134         section of the FreeRTOS.org WEB site for more information. */\r
135         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
136         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
137         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
138         vStartDynamicPriorityTasks();\r
139         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
140     vStartComTestTasks( mainCOM_TEST_PRIORITY, serCOM2, ser57600 );\r
141 \r
142         /* Start the task that checks the other demo tasks for errors. */\r
143     xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
144 \r
145         /* The suicide tasks must be created last as they monitor the number of\r
146         tasks in the system to ensure there are no more or fewer than expected\r
147         compared to the number that were executing when the task started. */\r
148         vCreateSuicidalTasks( mainSUICIDE_TASKS_PRIORITY );\r
149         \r
150         /* Finally start the scheduler. */\r
151     vTaskStartScheduler();\r
152 \r
153         /* Should not get here! */\r
154         for( ;; );\r
155 }\r
156 /*-----------------------------------------------------------*/\r
157 \r
158 static void prvSetupHardware( void )\r
159 {\r
160         ae_init();\r
161 }\r
162 /*-----------------------------------------------------------*/\r
163 \r
164 static void prvCheckTask( void *pvParameters )\r
165 {\r
166         ( void ) pvParameters;\r
167 \r
168         /* Check all the demo tasks to ensure that they are all still running, and\r
169     that none of them have detected     an error. */\r
170     for( ;; )\r
171     {\r
172                 /* Block until it is time to check again. */\r
173         vTaskDelay( mainCHECK_DELAY );\r
174         \r
175                 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
176                 {\r
177                         usCheckStatus |= 0x01;\r
178                 }\r
179 \r
180                 if( xArePollingQueuesStillRunning() != pdTRUE )\r
181                 {\r
182                         usCheckStatus |= 0x02;\r
183                 }\r
184 \r
185                 if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
186                 {\r
187                         usCheckStatus |= 0x04;\r
188                 }\r
189 \r
190                 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
191                 {\r
192                         usCheckStatus |= 0x08;\r
193                 }\r
194 \r
195                 if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
196                 {\r
197                         usCheckStatus |= 0x10;\r
198                 }\r
199 \r
200         if( xIsCreateTaskStillRunning() != pdTRUE )\r
201         {\r
202                 usCheckStatus |= 0x20;\r
203         }\r
204 \r
205         if( xAreComTestTasksStillRunning() != pdTRUE )\r
206         {\r
207                 usCheckStatus |= 0x40;\r
208         }\r
209         }\r
210 }\r
211 /*-----------------------------------------------------------*/\r
212 \r
213 /* This is included to prevent link errors - allowing the 'full' version of\r
214 the comtest tasks to be used.  It can be ignored. */\r
215 void vPrintDisplayMessage( const char * const * ppcMessageToSend )\r
216 {\r
217         ( void ) ppcMessageToSend;\r
218 }\r
219 \r
220 \r
221 \r
222 \r
223 \r
224 \r
225 \r
226 \r
227 \r
228 \r
229 \r
230 \r