Add lwip server function

This commit is contained in:
Jeremy Shen
2026-06-17 15:26:10 +08:00
parent d3c9082493
commit 43884afb38
6 changed files with 329 additions and 11 deletions
+104 -11
View File
@@ -61,7 +61,7 @@ void lwip_init();
#if LWIP_IPV6==0
#if LWIP_DHCP==1
extern volatile int dhcp_timoutcntr;
volatile int dhcp_timoutcntr;
err_t dhcp_start(struct netif *netif);
#endif
#endif
@@ -69,13 +69,91 @@ void lwip_init();
static struct netif server_netif;
struct netif *echo_netif;
void print_ip(char *msg, ip_addr_t *ip)
{
print(msg);
xil_printf("%d.%d.%d.%d\n\r", ip4_addr1(ip), ip4_addr2(ip),
ip4_addr3(ip), ip4_addr4(ip));
}
void print_ip_settings(ip_addr_t *ip, ip_addr_t *mask, ip_addr_t *gw)
{
print_ip("Board IP: ", ip);
print_ip("Netmask : ", mask);
print_ip("Gateway : ", gw);
}
int main()
{
int iMainCom = 1;
ip_addr_t ipaddr, netmask, gw;
unsigned char mac_ethernet_address[] = { 0x00, 0x0a, 0x35, 0x00, 0x01, 0x01 };
echo_netif = &server_netif;
init_platform();
#if LWIP_IPV6==0
#if LWIP_DHCP==1
ipaddr.addr = 0;
gw.addr = 0;
netmask.addr = 0;
#else
/* initialize IP addresses to be used */
IP4_ADDR(&ipaddr, 192, 168, 100, 110);
IP4_ADDR(&netmask, 255, 255, 255, 0);
IP4_ADDR(&gw, 192, 168, 100, 1);
#endif
#endif
//LWIP Related Init Start
lwip_init();
if (!xemac_add(echo_netif, &ipaddr, &netmask,
&gw, mac_ethernet_address,
PLATFORM_EMAC_BASEADDR))
{
xil_printf("Error adding N/W interface\n\r");
return -1;
}
netif_set_default(echo_netif);
/* specify that the network if is up */
netif_set_up(echo_netif);
#if (LWIP_DHCP==1)
/* Create a new DHCP client for this interface.
* Note: you must call dhcp_fine_tmr() and dhcp_coarse_tmr() at
* the predefined regular intervals after starting the client.
*/
dhcp_start(echo_netif);
dhcp_timoutcntr = 24;
while(((echo_netif->ip_addr.addr) == 0) && (dhcp_timoutcntr > 0))
xemacif_input(echo_netif);
if (dhcp_timoutcntr <= 0) {
if ((echo_netif->ip_addr.addr) == 0) {
xil_printf("DHCP Timeout\r\n");
xil_printf("Configuring default IP of 192.168.100.110\r\n");
IP4_ADDR(&(echo_netif->ip_addr), 192, 168, 100, 110);
IP4_ADDR(&(echo_netif->netmask), 255, 255, 255, 0);
IP4_ADDR(&(echo_netif->gw), 192, 168, 100, 1);
}
}
ipaddr.addr = echo_netif->ip_addr.addr;
gw.addr = echo_netif->gw.addr;
netmask.addr = echo_netif->netmask.addr;
#endif
print_ip_settings(&ipaddr, &netmask, &gw);
//LWIP Related Init END
xil_printf("=====================\r\n[I] System Init Done!\r\n");
xil_printf("[D] Start EMIO Config\r\n");
EMIO_config();
@@ -95,20 +173,36 @@ int main()
xil_printf("[I] Board Init Complete!\r\n[I] Waiting for Command...\r\n");
/* start the application (web server, rxtest, txtest, etc..) */
start_application();
/* receive and process Instructions */
while (1)
if (iMainCom == 1)
{
int Status = -255;
Status = UART_RecvInstr(recvbuffer);
if (Status < 0)
{
xil_printf("[E] UART Receive ERROR!!! Check PrintOut Ahead\r\n");
print_app_header();
while (1) {
tcp_tmr();
xemacif_input(echo_netif);
transfer_data();
}
else if (Status > 0)
}
else
{
while (1)
{
Command_Parser(recvbuffer,Status); //Here Status should equal to length
int Status = -255;
Status = UART_RecvInstr(recvbuffer);
if (Status < 0)
{
xil_printf("[E] UART Receive ERROR!!! Check PrintOut Ahead\r\n");
}
else if (Status > 0)
{
Command_Parser(recvbuffer,Status); //Here Status should equal to length
}
}
}
/* never reached */
@@ -116,4 +210,3 @@ int main()
return 0;
}