netconf.c

来自「LWIP在STM32裸机上的移植」· C语言 代码 · 共 108 行

C
108
字号
/**
  ******************************************************************************
  * @file    netconf.c
  * @author  MCD Application Team
  * @version V1.0.0
  * @date    11/20/2009
  * @brief   Network connection configuration
  *****************************************************************************/
#include "server.h"
#include "lwip/memp.h"
#include "lwip/tcp.h"
#include "lwip/udp.h"
#include "lwip/dhcp.h"
#include "netif/etharp.h"
#include "ethernetif.h"
#include "netconf.h"
#include "stm32_eth.h"
#include <stdio.h>

extern u8 IPAddress[12];

struct netif netif;

__IO uint32_t TCPTimer = 0;
__IO uint32_t ARPTimer = 0;


void LwIP_Init(void)
{
  	struct ip_addr ipaddr;
  	struct ip_addr netmask;
  	struct ip_addr gw;
  
  	uint8_t macaddress[6]={0x00,0x1a,0x92,0x4b,0xbb,0x23};
  
  	mem_init();			//Initializes the dynamic memory heap defined by MEM_SIZE.
  
  	memp_init();		//Initializes the memory pools defined by MEMP_NUM_x.
	

//	IP4_ADDR(&ipaddr, 10, 10, 0, 10);		//TCP客户端IP地址
//	IP4_ADDR(&netmask, 255, 0, 0, 0);		//子网掩码
//	IP4_ADDR(&gw, 10, 10, 0, 96);			//网关

	IP4_ADDR(&ipaddr, IPAddress[0], IPAddress[1], IPAddress[2], IPAddress[3]);
	IP4_ADDR(&netmask,IPAddress[4], IPAddress[5], IPAddress[6], IPAddress[7]);
	IP4_ADDR(&gw,     IPAddress[8], IPAddress[9], IPAddress[10],IPAddress[11]);

  	Set_MAC_Address(macaddress);

    /* - netif_add(struct netif *netif, struct ip_addr *ipaddr,
              struct ip_addr *netmask, struct ip_addr *gw,
              void *state, err_t (* init)(struct netif *netif),
              err_t (* input)(struct pbuf *p, struct netif *netif))
      
    Adds your network interface to the netif_list. Allocate a struct
    netif and pass a pointer to this structure as the first argument.
    Give pointers to cleared ip_addr structures when using DHCP,
    or fill them with sane numbers otherwise. The state pointer may be NULL.
  
    The init function pointer must point to a initialization function for
    your ethernet netif interface. The following code illustrates it's use.*/  
  	netif_add(&netif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &ethernet_input);
	
	/* Registers the default network interface. */
  	netif_set_default(&netif);

	/* When the netif is fully configured this function must be called.*/
  	netif_set_up(&netif);
}

/**
  * @brief  Called when a frame is received
  * @param  None
  */
void LwIP_Pkt_Handle(void)
{
  	/* Read a received packet from the Ethernet buffers 
                and send it to the lwIP for handling */
  	ethernetif_input(&netif);
}

/**
  * @brief  LwIP periodic tasks
  * @param  localtime : the current LocalTime value
  * @retval None
  */
void LwIP_Periodic_Handle(__IO uint32_t localtime)
{
	/* TCP periodic process every 250 ms */
  	if ((localtime - TCPTimer) >= TCP_TMR_INTERVAL)		
  	{
    	TCPTimer =  localtime;
//		printf("TCPTimer = %d\n",TCPTimer);

    	tcp_tmr();
  	}

	/* ARP periodic process every 5s */ 
  	if ((localtime - ARPTimer) >= ARP_TMR_INTERVAL)
  	{
    	ARPTimer =  localtime;
//		printf("ARPTimer = %d\n",ARPTimer);

    	etharp_tmr();
  	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?