| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
webserver.c
Go to the documentation of this file.
1 /*
2 * @brief LWIP standalone http server example
3 *
4 * @note
5 * Copyright(C) NXP Semiconductors, 2012
6 * All rights reserved.
7 *
8 * @par
9 * Software that is described herein is for illustrative purposes only
10 * which provides customers with programming information regarding the
11 * LPC products. This software is supplied "AS IS" without any warranties of
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
13 * all warranties, express or implied, including all implied warranties of
14 * merchantability, fitness for a particular purpose and non-infringement of
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
16 * or liability for the use of the software, conveys no license or rights under any
17 * patent, copyright, mask work right, or any other intellectual property rights in
18 * or to any products. NXP Semiconductors reserves the right to make changes
19 * in the software without notification. NXP Semiconductors also makes no
20 * representation or warranty that such application will be suitable for the
21 * specified use without further testing or modification.
22 *
23 * @par
24 * Permission to use, copy, modify, and distribute this software and its
25 * documentation is hereby granted, under NXP Semiconductors' and its
26 * licensor's relevant copyrights in the software, without fee, provided that it
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
28 * copyright, permission, and disclaimer notice must appear in all copies of
29 * this code.
30 */
31
32 #include "lwip/init.h"
33 #include "lwip/opt.h"
34 #include "lwip/sys.h"
35 #include "lwip/memp.h"
36 #include "lwip/tcpip.h"
37 #include "lwip/ip_addr.h"
38 #include "lwip/netif.h"
39 #include "lwip/timers.h"
40 #include "netif/etharp.h"
41
42 #if LWIP_DHCP
43 #include "lwip/dhcp.h"
44 #endif
45
46 #include "board.h"
47 #include "lpc_phy.h"
48 #include "arch\lpc17xx_40xx_emac.h"
49 #include "arch\lpc_arch.h"
50 #include "echo.h"
51 #include "httpd.h"
52
93 /*****************************************************************************
94 * Private types/enumerations/variables
95 ****************************************************************************/
96
97 /* NETIF data */
98 static struct netif lpc_netif;
99
100 /*****************************************************************************
101 * Public types/enumerations/variables
102 ****************************************************************************/
103
104 /*****************************************************************************
105 * Private functions
106 ****************************************************************************/
107
108 /* Sets up system hardware */
109 static void prvSetupHardware(void)
110 {
111 /* LED0 is used for the link status, on = PHY cable detected */
112 Board_Init();
113
114 /* Initial LED state is off to show an unconnected cable state */
115 Board_LED_Set(0, false);
116 Board_LED_Set(1, false);
117 /* Setup a 1mS sysTick for the primary time base */
118 SysTick_Enable(1);
119
120 }
121
122 /*****************************************************************************
123 * Public functions
124 ****************************************************************************/
125
130 int main(void)
131 {
132 extern int fs_init(void);
133 uint32_t physts;
134 ip_addr_t ipaddr, netmask, gw;
135 static int prt_ip = 0;
136
137 prvSetupHardware();
138
139 #ifndef BOARD_HITEX_EVA_18504350
140 /* Initialize the file system */
141 fs_init();
142 #endif
143
144 /* Initialize LWIP */
145 lwip_init();
146
147 LWIP_DEBUGF(LWIP_DBG_ON, ("Starting LWIP TCP echo server...\n"));
148
149 /* Static IP assignment */
150 #if LWIP_DHCP
151 IP4_ADDR(&gw, 0, 0, 0, 0);
152 IP4_ADDR(&ipaddr, 0, 0, 0, 0);
153 IP4_ADDR(&netmask, 0, 0, 0, 0);
154 #else
155 IP4_ADDR(&gw, 10, 1, 10, 1);
156 IP4_ADDR(&ipaddr, 10, 1, 10, 234);
157 IP4_ADDR(&netmask, 255, 255, 255, 0);
158 APP_PRINT_IP(&ipaddr);
159 #endif
160
161 /* Add netif interface for lpc17xx_8x */
162 netif_add(&lpc_netif, &ipaddr, &netmask, &gw, NULL, lpc_enetif_init,
163 ethernet_input);
164 netif_set_default(&lpc_netif);
165 netif_set_up(&lpc_netif);
166
167 #if LWIP_DHCP
168 dhcp_start(&lpc_netif);
169 #endif
170
171 /* Initialize and start application */
172 echo_init();
173
174 /* Initialize and start application */
175 httpd_init();
176
177 /* This could be done in the sysTick ISR, but may stay in IRQ context
178 too long, so do this stuff with a background loop. */
179 while (1) {
180 /* Handle packets as part of this loop, not in the IRQ handler */
181 lpc_enetif_input(&lpc_netif);
182
183 /* lpc_rx_queue will re-qeueu receive buffers. This normally occurs
184 automatically, but in systems were memory is constrained, pbufs
185 may not always be able to get allocated, so this function can be
186 optionally enabled to re-queue receive buffers. */
187 #if 0
188 while (lpc_rx_queue(&lpc_netif)) {}
189 #endif
190
191 /* Free TX buffers that are done sending */
192 lpc_tx_reclaim(&lpc_netif);
193
194 /* LWIP timers - ARP, DHCP, TCP, etc. */
195 sys_check_timeouts();
196
197 /* Call the PHY status update state machine once in a while
198 to keep the link status up-to-date */
199 physts = lpcPHYStsPoll();
200
201 /* Only check for connection state when the PHY status has changed */
202 if (physts & PHY_LINK_CHANGED) {
203 if (physts & PHY_LINK_CONNECTED) {
204 Board_LED_Set(0, true);
205 prt_ip = 0;
206
207 /* Set interface speed and duplex */
208 if (physts & PHY_LINK_SPEED100) {
209 Chip_ENET_SetSpeed(LPC_ETHERNET, TRUE);
210 NETIF_INIT_SNMP(&lpc_netif, snmp_ifType_ethernet_csmacd, 100000000);
211 }
212 else {
213 Chip_ENET_SetSpeed(LPC_ETHERNET, FALSE);
214 NETIF_INIT_SNMP(&lpc_netif, snmp_ifType_ethernet_csmacd, 10000000);
215 }
216 if (physts & PHY_LINK_FULLDUPLX) {
217 Chip_ENET_SetDuplex(LPC_ETHERNET, TRUE);
218 }
219 else {
220 Chip_ENET_SetDuplex(LPC_ETHERNET, FALSE);
221 }
222
223 netif_set_link_up(&lpc_netif);
224 }
225 else {
226 Board_LED_Set(0, false);
227 Board_LED_Set(1, false);
228 netif_set_link_down(&lpc_netif);
229 }
230
231 DEBUGOUT("Link connect status: %d\r\n", ((physts & PHY_LINK_CONNECTED) != 0));
232 }
233
234 /* Print IP address info */
235 if (!prt_ip) {
236 if (lpc_netif.ip_addr.addr) {
237 static char tmp_buff[16];
238 DEBUGOUT("IP_ADDR : %s\r\n", ipaddr_ntoa_r((const ip_addr_t *) &lpc_netif.ip_addr, tmp_buff, 16));
239 DEBUGOUT("NET_MASK : %s\r\n", ipaddr_ntoa_r((const ip_addr_t *) &lpc_netif.netmask, tmp_buff, 16));
240 DEBUGOUT("GATEWAY_IP : %s\r\n", ipaddr_ntoa_r((const ip_addr_t *) &lpc_netif.gw, tmp_buff, 16));
241 prt_ip = 1;
242 Board_LED_Set(1, true);
243 }
244 }
245 }
246
247 /* Never returns, for warning only */
248 return 0;
249 }
250