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