]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Kintex7_EthernetLite/RTOSDemo/src/lwIP_Demo/main_lwIP.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Demo / MicroBlaze_Kintex7_EthernetLite / RTOSDemo / src / lwIP_Demo / main_lwIP.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  * NOTE 1:  This project provides three demo applications.  A simple blinky\r
31  * style project, a more comprehensive test and demo application, and an\r
32  * lwIP example.  The mainSELECTED_APPLICATION setting in main.c is used to\r
33  * select between the three.  See the notes on using mainSELECTED_APPLICATION\r
34  * in main.c.  This file implements the simply blinky style version.\r
35  *\r
36  * NOTE 2:  This file only contains the source code that is specific to the\r
37  * basic demo.  Generic functions, such FreeRTOS hook functions, and functions\r
38  * required to configure the hardware are defined in main.c.\r
39  ******************************************************************************\r
40  *\r
41  * The lwIP example can be configured to use either a static or dynamic IP\r
42  * address:\r
43  *    + To use a dynamically allocated IP address set LWIP_DHCP to 1 in\r
44  *      lwipopts.h and connect the target to a network that includes a DHCP\r
45  *      server.  The obtained IP address is printed to the UART console.\r
46  *    + To use a static IP address set LWIP_DHCP to 0 in lwipopts.h and set\r
47  *      the static IP address using the configIP_ADDR0 to configIP_ADDR3\r
48  *      constants at the bottom of FreeRTOSConfig.h.  Constants used to define\r
49  *      a netmask are also located at the bottom of FreeRTOSConfig.h.\r
50  *\r
51  * When connected correctly the demo uses the lwIP sockets API to create\r
52  * a FreeRTOS+CLI command console, and the lwIP raw API to create a basic HTTP\r
53  * web server with server side includes that generate dynamic run time web\r
54  * pages.  See http://www.freertos.org/RTOS-Xilinx-Zynq.html for more\r
55  * information.\r
56  *\r
57  * To connect to FreeRTOS+CLI, open a command prompt and enter "telnet <ipaddr>"\r
58  * where <ipaddr> is the IP address of the target.  Once connected type "help"\r
59  * to see a list of registered commands.  Note this example does not implement\r
60  * a real telnet server, it just uses the telnet port number to allow easy\r
61  * connection using telnet tools.\r
62  *\r
63  * To connect to the http server simply type the IP address of the target into\r
64  * the address bar of a web browser.\r
65  *\r
66  */\r
67 \r
68 /* Kernel includes. */\r
69 #include "FreeRTOS.h"\r
70 #include "task.h"\r
71 #include "timers.h"\r
72 \r
73 /* Standard demo includes. */\r
74 #include "partest.h"\r
75 \r
76 /* lwIP includes. */\r
77 #include "lwip/tcpip.h"\r
78 \r
79 /* The rate at which data is sent to the queue.  The 200ms value is converted\r
80 to ticks using the portTICK_PERIOD_MS constant. */\r
81 #define mainTIMER_PERIOD_MS                     ( pdMS_TO_TICKS( 200 ) )\r
82 \r
83 /* The LED toggled by the Rx task. */\r
84 #define mainTIMER_LED                           ( 0 )\r
85 \r
86 /* A block time of zero just means "don't block". */\r
87 #define mainDONT_BLOCK                          ( 0 )\r
88 \r
89 /*-----------------------------------------------------------*/\r
90 \r
91 /*\r
92  * The callback for the timer that just toggles an LED to show the system is\r
93  * running.\r
94  */\r
95 static void prvLEDToggleTimer( TimerHandle_t pxTimer );\r
96 \r
97 /*\r
98  * Defined in lwIPApps.c.\r
99  */\r
100 extern void lwIPAppsInit( void *pvArguments );\r
101 \r
102 /*-----------------------------------------------------------*/\r
103 \r
104 void main_lwIP( void )\r
105 {\r
106 TimerHandle_t xTimer;\r
107 \r
108         /* Init lwIP and start lwIP tasks. */\r
109         tcpip_init( lwIPAppsInit, NULL );\r
110 \r
111         /* A timer is used to toggle an LED just to show the application is\r
112         executing. */\r
113         xTimer = xTimerCreate(  "LED",                                  /* Text name to make debugging easier. */\r
114                                                         mainTIMER_PERIOD_MS,    /* The timer's period. */\r
115                                                         pdTRUE,                                 /* This is an auto reload timer. */\r
116                                                         NULL,                                   /* ID is not used. */\r
117                                                         prvLEDToggleTimer );    /* The callback function. */\r
118 \r
119         /* Start the timer. */\r
120         configASSERT( xTimer );\r
121         xTimerStart( xTimer, mainDONT_BLOCK );\r
122 \r
123         /* Start the tasks and timer running. */\r
124         vTaskStartScheduler();\r
125 \r
126         /* If all is well, the scheduler will now be running, and the following\r
127         line will never be reached.  If the following line does execute, then\r
128         there was insufficient FreeRTOS heap memory available for the Idle and/or\r
129         timer tasks to be created.  See the memory management section on the\r
130         FreeRTOS web site for more details on the FreeRTOS heap\r
131         http://www.freertos.org/a00111.html. */\r
132         for( ;; );\r
133 }\r
134 /*-----------------------------------------------------------*/\r
135 \r
136 static void prvLEDToggleTimer( TimerHandle_t pxTimer )\r
137 {\r
138         /* Prevent compiler warnings. */\r
139         ( void ) pxTimer;\r
140 \r
141         /* Just toggle an LED to show the application is running. */\r
142         vParTestToggleLED( mainTIMER_LED );\r
143 }\r
144 \r
145 /*-----------------------------------------------------------*/\r
146 \r
147 char *pcMainGetTaskStatusMessage( void )\r
148 {\r
149         return "Running lwIP demo";\r
150 }\r
151 /*-----------------------------------------------------------*/\r