]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/WizNET_DEMO_TERN_186/main.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Demo / WizNET_DEMO_TERN_186 / main.c
1 /*\r
2  * FreeRTOS Kernel V10.0.0\r
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software. If you wish to use our Amazon\r
14  * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
15  *\r
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 \r
29 /*\r
30  * Creates all the demo application tasks then starts the scheduler.  In \r
31  * addition to the standard demo application tasks main() creates the \r
32  * HTTPServer task, and a "Check" task.  The Check task periodically inspects\r
33  * all the other tasks in the system to see if any errors have been reported.\r
34  * The error status is then displayed on the served WEB page.\r
35  */\r
36 \r
37 /* Tern includes. */\r
38 #include <ae.h>\r
39 #include <embedded.h>\r
40 \r
41 /* FreeRTOS.org includes. */\r
42 #include <FreeRTOS.h>\r
43 #include <task.h>\r
44 \r
45 /* Demo application includes. */\r
46 #include "HTTPTask.h"\r
47 #include "integer.h"\r
48 #include "PollQ.h"\r
49 #include "semtest.h"\r
50 #include "dynamic.h"\r
51 #include "BlockQ.h"\r
52 #include "death.h"\r
53 #include "serial.h"\r
54 #include "comtest.h"\r
55 \r
56 /* How often should the "check" task execute? */\r
57 #define mainCHECK_DELAY         ( 3000 / portTICK_PERIOD_MS )\r
58 \r
59 /* Priorities allocated to the various tasks. */\r
60 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
61 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )\r
62 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
63 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
64 #define mainHTTP_TASK_PRIORITY          ( tskIDLE_PRIORITY + 3 )\r
65 #define mainSUICIDE_TASKS_PRIORITY  ( tskIDLE_PRIORITY + 1 )\r
66 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
67 \r
68 /* Used to indicate the error status.  A value of 0 means that an error has not\r
69 been detected in any task.  A non zero value indicates which group of demo \r
70 tasks has reported an error.  See prvCheckTask() for bit definitions. */\r
71 unsigned short usCheckStatus = 0;\r
72 \r
73 /*-----------------------------------------------------------*/\r
74 \r
75 /*\r
76  * Setup any hardware required by the demo - other than the RTOS tick which\r
77  * is configured when the scheduler is started.\r
78  */\r
79 static void prvSetupHardware( void );\r
80 \r
81 /*\r
82  * Periodically inspect all the other tasks, updating usCheckStatus should an\r
83  * error be discovered in any task.\r
84  */\r
85 static void prvCheckTask( void *pvParameters );\r
86 /*-----------------------------------------------------------*/\r
87 \r
88 void main(void)\r
89 {\r
90         prvSetupHardware();\r
91 \r
92     /* Start the HTTP server task. */\r
93         xTaskCreate( vHTTPTask, "WizNet", configMINIMAL_STACK_SIZE, NULL, mainHTTP_TASK_PRIORITY, NULL );\r
94 \r
95         /* Start the demo/test application tasks.  See the demo application \r
96         section of the FreeRTOS.org WEB site for more information. */\r
97         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
98         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
99         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
100         vStartDynamicPriorityTasks();\r
101         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
102     vStartComTestTasks( mainCOM_TEST_PRIORITY, serCOM2, ser57600 );\r
103 \r
104         /* Start the task that checks the other demo tasks for errors. */\r
105     xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
106 \r
107         /* The suicide tasks must be created last as they monitor the number of\r
108         tasks in the system to ensure there are no more or fewer than expected\r
109         compared to the number that were executing when the task started. */\r
110         vCreateSuicidalTasks( mainSUICIDE_TASKS_PRIORITY );\r
111         \r
112         /* Finally start the scheduler. */\r
113     vTaskStartScheduler();\r
114 \r
115         /* Should not get here! */\r
116         for( ;; );\r
117 }\r
118 /*-----------------------------------------------------------*/\r
119 \r
120 static void prvSetupHardware( void )\r
121 {\r
122         ae_init();\r
123 }\r
124 /*-----------------------------------------------------------*/\r
125 \r
126 static void prvCheckTask( void *pvParameters )\r
127 {\r
128         ( void ) pvParameters;\r
129 \r
130         /* Check all the demo tasks to ensure that they are all still running, and\r
131     that none of them have detected     an error. */\r
132     for( ;; )\r
133     {\r
134                 /* Block until it is time to check again. */\r
135         vTaskDelay( mainCHECK_DELAY );\r
136         \r
137                 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
138                 {\r
139                         usCheckStatus |= 0x01;\r
140                 }\r
141 \r
142                 if( xArePollingQueuesStillRunning() != pdTRUE )\r
143                 {\r
144                         usCheckStatus |= 0x02;\r
145                 }\r
146 \r
147                 if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
148                 {\r
149                         usCheckStatus |= 0x04;\r
150                 }\r
151 \r
152                 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
153                 {\r
154                         usCheckStatus |= 0x08;\r
155                 }\r
156 \r
157                 if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
158                 {\r
159                         usCheckStatus |= 0x10;\r
160                 }\r
161 \r
162         if( xIsCreateTaskStillRunning() != pdTRUE )\r
163         {\r
164                 usCheckStatus |= 0x20;\r
165         }\r
166 \r
167         if( xAreComTestTasksStillRunning() != pdTRUE )\r
168         {\r
169                 usCheckStatus |= 0x40;\r
170         }\r
171         }\r
172 }\r
173 /*-----------------------------------------------------------*/\r
174 \r
175 /* This is included to prevent link errors - allowing the 'full' version of\r
176 the comtest tasks to be used.  It can be ignored. */\r
177 void vPrintDisplayMessage( const char * const * ppcMessageToSend )\r
178 {\r
179         ( void ) ppcMessageToSend;\r
180 }\r
181 \r
182 \r
183 \r
184 \r
185 \r
186 \r
187 \r
188 \r
189 \r
190 \r
191 \r
192 \r