?? lwiplib.c
字號:
//*****************************************************************************
//
// 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 + -