|
求高手指点----LM3S9B96以太网问题>
[复制链接]
// systick中断处理函数//-----------------------------------------------------------------------------
void SysTickHandler(void)
{ // 调用lwip定时处理函数
lwIPTimer(SYSTICKMS);
}
//这是一个回调函数,当有UDP数据收到时会被调用
void UDP_Receive(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, u16_t port)
{ struct ip_addr destAddr = *addr;
if(p != NULL){ // 如果收到的数据不为空
udp_sendto(upcb,p,&destAddr,port); // 将收到的数据再发送出去
pbuf_free(p); // 释放缓冲区数据
}
}
void lwIPHostTimerHandler(void)
{
static uLong ulLastIPAddress = 0;
static long lStarPos = 0;
static tBoolean bIncrementing = true; uLong ulIPAddress; tRectangle sRect;
ulIPAddress = lwIPLocalIPAddrGet();
// If IP Address has not yet been assigned, update the display accordingly if(ulIPAddress == 0){
UART_TxStr("ulIPAddress == 0\r\n>");
} // Check if IP address has changed, and display if it has.
else{
if(ulLastIPAddress != ulIPAddress)
{ ulLastIPAddress = ulIPAddress; // 显示IP
UART_TxStr("IP地址:");
DisplayIPAddress(ulIPAddress);
ulIPAddress = lwIPLocalNetMaskGet();
UART_TxStr("子网掩码:");
DisplayIPAddress(ulIPAddress);
ulIPAddress = lwIPLocalGWAddrGet();
UART_TxStr("默认网关:");
DisplayIPAddress(ulIPAddress);
}
}
}
void EthernetConfig(void)
{
uLong ulUser0, ulUser1;
uChar pucMACArray[8]; // 使能端口F来作为以太网的LED使用
GPIOPinConfigure(GPIO_PF2_LED1);
GPIOPinConfigure(GPIO_PF3_LED0);
GPIOPinTypeEthernetLED(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3); //从用户寄存器中 读取MAC地址
//ROM_FlashUserGet(&ulUser0, &ulUser1);
ulUser0 = 0x00563412; // 配置MAC地址为12-34-56-78-9a-ef
ulUser1 = 0x00ef9a78;
if((ulUser0 == 0xffffffff) || (ulUser1 == 0xffffffff)){ // MAC没有编程
UARTprintf("MAC Address Not Programmed!\r\n");
}
else{ //转换用户寄存器到MAC地址
pucMACArray[0] = ((ulUser0 >> 0) & 0xff);
pucMACArray[1] = ((ulUser0 >> 8) & 0xff);
pucMACArray[2] = ((ulUser0 >> 16) & 0xff);
pucMACArray[3] = ((ulUser1 >> 0) & 0xff);
pucMACArray[4] = ((ulUser1 >> 8) & 0xff);
pucMACArray[5] = ((ulUser1 >> 16) & 0xff);
// 初始化lwIP协议栈 静态IP
// IP地址: 192.168.1.20
// 子网掩码:255.255.255.0
// 默认网关:192.168.1.254
lwIPInit(pucMACArray,(Ethernet_Addr[0]<<24)|(Ethernet_Addr[1]<<16)|(Ethernet_Addr[2]<<8)|Ethernet_Addr[3],
(GateWay_Addr[0]<<24)|(GateWay_Addr[1]<<16)|(GateWay_Addr[2]<<8)|GateWay_Addr[3],
(Subnet_Addr[0]<<24)|(Subnet_Addr[1]<<16)|(Subnet_Addr[2]<<8)|Subnet_Addr[3], IPADDR_USE_STATIC);
}
}
int main(void)
{
struct udp_pcb *UdpPcb;
struct ip_addr ipaddr;
struct pbuf *p;
const static unsigned char UDPData[]="TI lm3s9b96 测试!\r\n LwIP UDP客户端测试!\r\n";
//JtagWait(); // 防止JTAG失效,重要!
SystemInit(); // 设置时钟 66.7Mhz 初始化 定时器 串口
/****************** 初始化客户端UDP ******************/
EthernetConfig();
IP4_ADDR(&ipaddr,DEthernet_Addr[0],DEthernet_Addr[1],
DEthernet_Addr[2],DEthernet_Addr[3]); // 远程主机地址
UdpPcb = udp_new();
udp_bind(UdpPcb,IP_ADDR_ANY,4000); // 绑定本地IP地址
udp_connect(UdpPcb,&ipaddr,5000); // 连接远程主机
udp_recv(UdpPcb,UDP_Receive,NULL); // 设置数据接收时的回调函数
// 主循环
while(1){
if(systemVariable.xFlag_200ms){
systemVariable.xFlag_200ms=0;
p = pbuf_alloc(PBUF_TRANSPORT,strlen(UDPData),PBUF_RAM);
if(p != NULL){
memcpy(p->payload, UDPData,strlen(UDPData));
udp_send(UdpPcb,p);
pbuf_free(p);
}
}
}
说明: 其他的API函数都是调用TI驱动程序.
麻烦高手指点下!
|
|