#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_nvic.h"
#include "inc/hw_types.h"
#include "driverlib/ethernet.h"
#include "driverlib/flash.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "utils/locator.h"
#include "utils/lwiplib.h"
#include "driverlib/timer.h"
#include "utils/uartstdio.h"
#include "httpserver_raw/httpd.h"
//#include "DAQwendu.h"
//#include "driverlib/watchdog.h"
//#include "get_temperature.h"
#define SYSTICKHZ 100
#define SYSTICKMS (1000 / SYSTICKHZ)
/********************************************************************************************************/
//定义网络通信的IP地址、网关、子网掩码
#define My_Mac_ID {0X00,0x1A,0xFF,0x00,0x05,0xA7} //存储以太网控制器的物理地址,即MAC地址
#define IP_MARK_ID {255,255,255,0} //255.255.255.0,子网掩码
#define MY_IP_ID {192,168,1,10} //以太网通信的IP地址
#define MY_GATEWAY_ID {192,168,1,1} //以太网通信的网关地址
unsigned int pack;
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;
typedef unsigned char uint8; //数据类型重定义—ZZH
typedef signed char int8; //数据类型重定义—ZZH
const static int8 UDPData[]="LwIP UDP客户端在Luminary微控制器上的测试\r\n";
//*****************************************************************************
// The error routine that is called if the driver library encounters an error.
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif
//*****************************************************************************
//
// Required by lwIP library to support any host-related timer functions.
//
//*****************************************************************************
void
lwIPHostTimerHandler(void)
{
UARTprintf("FA SONG CHENG GONG!!!!!!!!!!!!!!!!!!! \n");
}
//*****************************************************************************
//
// The interrupt handler for the SysTick interrupt.
//
//*****************************************************************************
void
SysTickIntHandler(void)
{
//
// Call the lwIP timer handler.
//
lwIPTimer(SYSTICKMS);
}
/******* 这是一个回调函数,当有UDP数据收到时会被调用UDP_Receive********/
void UDP_Receive(void *arg, struct udp_pcb *upcb, struct pbuf *p_rx,
struct ip_addr *addr, u16_t port)
{
//struct ip_addr destAddr = *addr; /* 获取远程主机 IP 地址 */
UARTprintf("FA SONG CHENG GONG!!!!!!!!!!!!!!!!!!! \n");
pbuf_free(p_rx); // 释放缓冲区数据
// if(p!= NULL) //如果收到的数据不为空
//{
// UARTprintf("FA SONG CHENG GONG!!!!!!!!!!!!!!!!!!! \n");
//udp_sendto(upcb,p,&destAddr,port); //将收到的数据再发送出去
// pbuf_free(p); // 释放缓冲区数据
//}
}
void Delay(unsigned long ulVal)//延时函数
{
while ( --ulVal != 0 );
}
//*****************************************************************************
//
// This example demonstrates the use of the Ethernet Controller.
//
//*****************************************************************************
int
main(void)
{
//int i;
struct ip_addr xIpAddr, xNetMask, xGateway;
//
// Set the clocking to run directly from the crystal.
//
ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
//
// Initialize the UART.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTStdioInit(0);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ETH);//初始化以太网时钟
ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_ETH);
//
// Enable Port F for Ethernet LEDs.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinConfigure(GPIO_PF2_LED1);
GPIOPinConfigure(GPIO_PF3_LED0);
ROM_GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3,GPIO_DIR_MODE_HW); //这两条也是趟师兄调剂的,不象??——ZZH
ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3,
GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
ROM_IntMasterEnable(); /* 使能总的中断*/
UARTprintf("\r通道1数据为:\n");
IP4_ADDR(&xIpAddr,IPAddress[0],IPAddress[1],IPAddress[2],IPAddress[3]);
IP4_ADDR(&xNetMask,NetMaskAddr[0],NetMaskAddr[1],NetMaskAddr[2],NetMaskAddr[3]);
IP4_ADDR(&xGateway,GwWayAddr[0],GwWayAddr[1],GwWayAddr[2],GwWayAddr[3]);
UARTprintf("\r进入lwip:\n");
lwIPInit(MACAddress,xIpAddr, xNetMask,xGateway,IPADDR_USE_STATIC); /* 初始化协议栈*/
struct udp_pcb *UdpPcb;
//struct ip_addr ipaddr;
struct pbuf *p_tx;
p_tx = pbuf_alloc(PBUF_RAW,sizeof(UDPData),PBUF_RAM);
UARTprintf("\r进入 p = pbuf_alloc:\n");
p_tx->payload=(void *)UDPData;
//IP4_ADDR(&ipaddr,192,168,1,16); //远程Ip地址
UdpPcb = udp_new();
udp_bind(UdpPcb,&xIpAddr,1025);//为指定的连接绑定本地IP 地址和端口号IP_ADDR_ANY
udp_connect(UdpPcb,IP_ADDR_ANY,1025); //ipaddr为远程ip,1666为远程端口&ipaddr1
udp_recv(UdpPcb,UDP_Receive,NULL); /* 设置数据接收时的回调函数 */
Delay(1000000UL);
Delay(1000000UL);
IntMasterEnable(); /* 使能总的中断*/
while(1)
{
//udp_send(UdpPcb,p_tx);
// Delay(1000000UL);
// Delay(1000000UL);
//Delay(1000000UL);
}
}
总是运行到 p_tx = pbuf_alloc(PBUF_RAW,sizeof(UDPData),PBUF_RAM); 这一句就进入了死循环,麻烦各位看看,指点指点啊。。谢谢