⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lwiplib.c

📁 lm3s下lwip的udp
💻 C
📖 第 1 页 / 共 2 页
字号:
//*****************************************************************************
//
// lwiplib.c - lwIP TCP/IP Library Abstraction Layer.
//
// Copyright (c) 2008-2009 Luminary Micro, Inc.  All rights reserved.
// Software License Agreement
// 
// Luminary Micro, Inc. (LMI) is supplying this software for use solely and
// exclusively on LMI's microcontroller products.
// 
// The software is owned by LMI and/or its suppliers, and is protected under
// applicable copyright laws.  All rights are reserved.  You may not combine
// this software with "viral" open-source software in order to form a larger
// program.  Any use in violation of the foregoing restrictions may subject
// the user to criminal sanctions under applicable laws, as well as to civil
// liability for the breach of the terms and conditions of this license.
// 
// THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
// LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
// CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
// 
// This is part of revision 4905 of the Stellaris Firmware Development Package.
//
//*****************************************************************************

//*****************************************************************************
//
// Ensure that the lwIP Compile Time Options are included first.
//
//*****************************************************************************
#include "lwiplib.h"

//*****************************************************************************
//
// Include lwIP high-level API code.
//
//*****************************************************************************
#include "lwip-1.3.0/src/api/api_lib.c"
#include "lwip-1.3.0/src/api/api_msg.c"
#include "lwip-1.3.0/src/api/err.c"
#include "lwip-1.3.0/src/api/netbuf.c"
#include "lwip-1.3.0/src/api/netdb.c"
#include "lwip-1.3.0/src/api/netifapi.c"
#include "lwip-1.3.0/src/api/sockets.c"
#include "lwip-1.3.0/src/api/tcpip.c"

//*****************************************************************************
//
// Include the core lwIP TCP/IP stack code.
//
//*****************************************************************************
#include "lwip-1.3.0/src/core/dhcp.c"
#include "lwip-1.3.0/src/core/dns.c"
#include "lwip-1.3.0/src/core/init.c"
#include "lwip-1.3.0/src/core/mem.c"
#include "lwip-1.3.0/src/core/memp.c"
#include "lwip-1.3.0/src/core/netif.c"
#include "lwip-1.3.0/src/core/pbuf.c"
#include "lwip-1.3.0/src/core/raw.c"
#include "lwip-1.3.0/src/core/stats.c"
#include "lwip-1.3.0/src/core/sys.c"
#include "lwip-1.3.0/src/core/tcp.c"
#include "lwip-1.3.0/src/core/tcp_in.c"
#include "lwip-1.3.0/src/core/tcp_out.c"
#include "lwip-1.3.0/src/core/udp.c"

//*****************************************************************************
//
// Include the IPV4 code.
//
//*****************************************************************************
#include "lwip-1.3.0/src/core/ipv4/autoip.c"
#include "lwip-1.3.0/src/core/ipv4/icmp.c"
#include "lwip-1.3.0/src/core/ipv4/igmp.c"
#include "lwip-1.3.0/src/core/ipv4/inet.c"
#include "lwip-1.3.0/src/core/ipv4/inet_chksum.c"
#include "lwip-1.3.0/src/core/ipv4/ip.c"
#include "lwip-1.3.0/src/core/ipv4/ip_addr.c"
#include "lwip-1.3.0/src/core/ipv4/ip_frag.c"
		  
//*****************************************************************************
//
// Include the lwIP SNMP code.
//
//*****************************************************************************
#include "lwip-1.3.0/src/core/snmp/asn1_dec.c"
#include "lwip-1.3.0/src/core/snmp/asn1_enc.c"
#include "lwip-1.3.0/src/core/snmp/mib2.c"
#include "lwip-1.3.0/src/core/snmp/mib_structs.c"
#include "lwip-1.3.0/src/core/snmp/msg_in.c"
#include "lwip-1.3.0/src/core/snmp/msg_out.c"

//*****************************************************************************
//
// Include the Network Interface code.
//
//*****************************************************************************
#include "lwip-1.3.0/src/netif/etharp.c"
#include "lwip-1.3.0/src/netif/ethernetif.c"
#include "lwip-1.3.0/src/netif/loopif.c"
//#include "lwip-1.3.0/src/netif/slipif.c"

//*****************************************************************************
//
// Include the Network Interface PPP code.
//
//*****************************************************************************
#include "lwip-1.3.0/src/netif/ppp/auth.c"
#include "lwip-1.3.0/src/netif/ppp/chap.c"
#include "lwip-1.3.0/src/netif/ppp/chpms.c"
#include "lwip-1.3.0/src/netif/ppp/fsm.c"
#include "lwip-1.3.0/src/netif/ppp/ipcp.c"
#include "lwip-1.3.0/src/netif/ppp/lcp.c"
#include "lwip-1.3.0/src/netif/ppp/magic.c"
#include "lwip-1.3.0/src/netif/ppp/md5.c"
#include "lwip-1.3.0/src/netif/ppp/pap.c"
#include "lwip-1.3.0/src/netif/ppp/ppp.c"
#include "lwip-1.3.0/src/netif/ppp/ppp_oe.c"
#include "lwip-1.3.0/src/netif/ppp/randm.c"
#include "lwip-1.3.0/src/netif/ppp/vj.c"

//*****************************************************************************
//
//! \addtogroup lwiplib_api
//! @{
//
//*****************************************************************************

//*****************************************************************************
//
// The lwIP Library abstration layer provides for a host callback function
// to be called periodically in the lwIP context.  This is the timer
// interval, in ms, for this periodic callback.  If the timer interval is
// defined to 0 (the default value), then no periodic host callback is
// performed.
//
//*****************************************************************************
//#ifndef HOST_TMR_INTERVAL
//#define HOST_TMR_INTERVAL       0
//#else
//extern void lwIPHostTimerHandler(void);
//#endif


/*********************************************************************************************************
**包含声明这里定义所有函数的头文件
*********************************************************************************************************/

//#include "lwiplib.h"
#include "netif/etharp.h"
#include "lwip/init.h"
#include "stellarisif.h"


/*********************************************************************************************************
** 该文件需要用到的驱动库头文件
*********************************************************************************************************/
#include "hw_ethernet.h"
#include "hw_ints.h"
#include "hw_memmap.h"
#include "hw_nvic.h"
#include "hw_types.h"
#include "interrupt.h"
#include "ethernet.h"
#include "gpio.h"
#include "sysctl.h"
#include "debug.h"

static const unsigned char MACAddress[] = My_Mac_ID;
unsigned char IPAddress[] = MY_IP_ID;
unsigned char NetMaskAddr[] = IP_MARK_ID;
unsigned char GwWayAddr[] = MY_GATEWAY_ID;

static struct netif lwip_netif;                    /* 定义Ethernet MAC的lwip网络接口*/

static unsigned long g_ulLocalTimer = 0;           /* 决定主机与LwiIP周期性的回调函数调用*/

static unsigned long g_ulTCPTimer = 0;             /* 决定 TCP服务周期的定时器 */

#if HOST_TMR_INTERVAL
static unsigned long g_ulHostTimer = 0;            /* 决定主机服务周期的定时器 */
#endif

#if LWIP_ARP
static unsigned long g_ulARPTimer = 0;             /* 决定ARP服务周期的定时器 */
#endif

#if LWIP_AUTOIP
static unsigned long g_ulAutoIPTimer = 0;         /* 决定AutoIP服务周期的定时器*/
#endif

#if LWIP_DHCP
static unsigned long g_ulDHCPCoarseTimer = 0;    /* 决定DHCP Coarse服务周期的定时器*/
#endif

#if LWIP_DHCP
static unsigned long g_ulDHCPFineTimer = 0;     /* j决定DHCP Fine服务周期的定时器*/
#endif

static unsigned long g_ulIPMode = IPADDR_USE_STATIC; /* 默认的IP地址获取方式 */


/*********************************************************************************************************
** Function name:        lwIPServiceTimers
** Descriptions:           用于lwip定时器的服务。该函数用于lwip所有的周期性事件的定时器,包括TCP和主机的定时器。它应该在LWIP相
**                              关的上下文中(lwIP context)被调用,在无RTOS支持的情况下在以太网中断服务程序中被调用,而在有操作系统的支
**		  持下,直接在LWIP的线程里调用即可。
** Input parameters:    None 无
** Output parameters:  None 无
** Returned value:      None 无        
** Created by:	   任海波
** Created Date:          2008.8.28
**--------------------------------------------------------------------------------------------------------
** Modified by:             
** Modified date:           
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
static void lwIPServiceTimers(void)
{
#if HOST_TMR_INTERVAL                                                                        /* 服务于主机的定时器*/
    if((g_ulLocalTimer - g_ulHostTimer) >= HOST_TMR_INTERVAL)
    {
        g_ulHostTimer = g_ulLocalTimer;
        lwIPHostTimerHandler();
    }
#endif

#if LWIP_ARP                                                                                       /* 服务于ARP的定时器*/
    if((g_ulLocalTimer - g_ulARPTimer) >= ARP_TMR_INTERVAL)
    {
        g_ulARPTimer = g_ulLocalTimer;
        etharp_tmr();
    }
#endif
                                                   /* 服务于TCP的定时器 */
    if((g_ulLocalTimer - g_ulTCPTimer) >= TCP_TMR_INTERVAL)
    {
        g_ulTCPTimer = g_ulLocalTimer;
        tcp_tmr();
    }

#if LWIP_AUTOIP                                                                            /* 服务于AutoIP的定时器*/
    if((g_ulLocalTimer - g_ulAutoIPTimer) >= AUTOIP_TMR_INTERVAL)
    {
        g_ulAutoIPTimer = g_ulLocalTimer;
        autoip_tmr();
    }
#endif

#if LWIP_DHCP                                                                              /* 服务于DHCP Coarse的定时器*/
    if((g_ulLocalTimer - g_ulDHCPCoarseTimer) >= DHCP_COARSE_TIMER_MSECS)
    {
        g_ulDHCPCoarseTimer = g_ulLocalTimer;
        dhcp_coarse_tmr();
    }
#endif

#if LWIP_DHCP                                                                              /* 服务于DHCP Fine的定时器*/             
    if((g_ulLocalTimer - g_ulDHCPFineTimer) >= DHCP_FINE_TIMER_MSECS)
    {
        g_ulDHCPFineTimer = g_ulLocalTimer;
        dhcp_fine_tmr();
    }
#endif
}


/*********************************************************************************************************
** Function name:        lwIPInit
** Descriptions:           初始化TCP/IP协议栈——LwIP,初始化以太网的MAC,包括配置了的DHCP和AutoIP
** Input parameters:    pucMAC:初始化的MAC地址
**                               ulIPAddr:初始化的IP地址                            
**                               ulNetMask:初始化的子网掩码
**                               ulGWAddr:初始化的网关地址
**                               ulIPMode:初始化IP地址的获取方式
** Output parameters:  None 无
** Returned value:       None 无        
** Created by:	   任海波
** Created Date:          2008.8.28
**--------------------------------------------------------------------------------------------------------
** Modified by:             
** Modified date:           
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
void lwIPInit(const unsigned char *pucMAC, struct ip_addr ip_addr,
                struct ip_addr net_mask, struct ip_addr gw_addr,
                unsigned long ulIPMode)
{
    struct ip_addr IPAddr;
    struct ip_addr NetMask;
    struct ip_addr GwAddr;
                                       
#if LWIP_DHCP && LWIP_AUTOIP                               /* 检验参数的设置 */
    ASSERT((ulIPMode == IPADDR_USE_STATIC) ||
           (ulIPMode == IPADDR_USE_DHCP) ||
           (ulIPMode == IPADDR_USE_AUTOIP))
#elif LWIP_DHCP
    ASSERT((ulIPMode == IPADDR_USE_STATIC) ||
           (ulIPMode == IPADDR_USE_DHCP))
#elif LWIP_AUTOIP
    ASSERT((ulIPMode == IPADDR_USE_STATIC) ||
           (ulIPMode == IPADDR_USE_AUTOIP))
#else
    ASSERT(ulIPMode == IPADDR_USE_STATIC)
#endif

    SysCtlPeripheralEnable(SYSCTL_PERIPH_ETH); /* 使能以太网控制器*/

    EthernetMACAddrSet(ETH_BASE, (unsigned char *)pucMAC);
                                                   /* 编程以太网控制器的MAC地址*/

    lwip_init();                                 /* 初始化LwIP协议栈*/

    if(ulIPMode == IPADDR_USE_STATIC)              /* 设置网络IP地址等*/
    {
        IPAddr  = ip_addr;
        NetMask = net_mask;
        GwAddr  = gw_addr;
    }
#if LWIP_DHCP || LWIP_AUTOIP
    else
    {
        IPAddr.addr  = 0;
        NetMask.addr = 0;
        GwAddr.addr  = 0;
    }
#endif

     /*******创建、配置并添加默认的以太网控制器接口设置*********/
    netif_add(&lwip_netif, &IPAddr, &NetMask, &GwAddr, NULL,
              stellarisif_init, ip_input);

⌨️ 快捷键说明

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