📄 main.c
字号:
/*
TITLE: Keil C51 v7.00 port of Adam Dunkels' uIP v0.9
*/
#include "main.h"
#define IP_addr0 192 //远程主机的IP地址
#define IP_addr1 168
#define IP_addr2 1
#define IP_addr3 4
#define RO_port 1280
unsigned char tick_count;
sbit P10 = P1^0;
sbit P11 = P1^1; //add1
sbit P12 = P1^2; //add1
#define TURNON 1
#define TURNOFF 0
#define DATANUM 200
#define OK 1
#define NOT 0
unsigned char connect_state; //add8
extern unsigned int temp_len; //串口接收数据长度
extern unsigned char *ptr_tx;
extern u8_t xdata count_rx[DATANUM];
static unsigned int ipptr[2];
static unsigned int tport;
//extern u16_t idata uip_hostaddr[2];
//extern u16_t idata uip_arp_draddr[2];
//extern u16_t idata uip_arp_netmask[2];
static unsigned char state_ip;
void main(void)
{
u8_t i;
uip_ipaddr(ipptr, IP_addr0,IP_addr1,IP_addr2,IP_addr3);
tport=htons(RO_port);
connect_state=TURNOFF;
// uip_ipaddr(uip_hostaddr,192,168,1,5); //设置暂时IP
// uip_ipaddr(uip_arp_draddr,192,168,1,8);
//uip_ipaddr(uip_arp_netmask,255,255,255,0);
state_ip=NOT;
uip_init(); //初始化uIP TCP/IP堆栈
datatrans_init(); //初始化app
encInit(); //设备驱动的初始化
// Timer_Init();
uip_arp_init(); //初始化ARP缓存
tick_count=0;
while(1)
{ /* if((RI==0)&&(temp_len!=0)&&(temp_len>=15))
{ if((count_rx[0]==0x47)&&(count_rx[1]==0x45)&&(count_rx[2]==0x54)&&(state_ip==NOT))
{
uip_ipaddr(uip_hostaddr,count_rx[3],count_rx[4],count_rx[5],count_rx[6]);
uip_ipaddr(uip_arp_draddr,count_rx[7],count_rx[8],count_rx[9],count_rx[10]);
uip_ipaddr(uip_arp_netmask,count_rx[11],count_rx[12],count_rx[13],count_rx[14]);
state_ip=OK;
}
temp_len=0; //串口接收到的数据已经发送出去,串口接收指针复位
ptr_tx = &count_rx[0];
} */
uip_len = EthdevSPI_read();
if(uip_len!=0)/* (uip_len != 0) Process incoming */
{
if(BUF->type == htons(UIP_ETHTYPE_IP)) //IP包
{
uip_arp_ipin();
uip_input(); //#define uip_input() uip_process(UIP_DATA)
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0.为什么带外回应数据 */
if(uip_len > 0) //syn 重启包
{
uip_arp_out();
EthdevSPI_Sendpack();
}
}
else if(BUF->type == htons(UIP_ETHTYPE_ARP)) //ARP包
{
uip_arp_arpin();
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0)
{
EthdevSPI_Sendpack();
}
}
}
else
{
for(i = 0; i < UIP_CONNS; i++) //UIP_CONNS=5
{
uip_periodic(i); //uip_conn = &uip_conns[conn]; uip_process(UIP_TIMER)
/* If the above function invocation 请求resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0.
由于函数的调用,使得有数据输入的话,从而uip_len>0而要求发送数据*/
if(uip_len > 0) //如果重新装载了数据
{
uip_arp_out();
EthdevSPI_Sendpack();
}
}
#if UIP_UDP
for(i = 0; i < UIP_UDP_CONNS; i++)
{
uip_udp_periodic(i);
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0)
{
uip_arp_out();
EthdevSPI_Sendpack();
}
}
#endif /* UIP_UDP */
// Call the ARP timer function every 10 seconds.
//可以定义一时间0.5ms的中断计数
// if(connect_state==TURNOFF) {Timer1on();}
if(connect_state==TURNOFF) //无连接,并且串口缓冲有数据
{ if(temp_len!=0)
{
#if UIP_ACTIVE_OPEN
uip_connect(ipptr, tport);
connect_state=TURNON;
P10=~P10;
#endif/* UIP_ACTIVE_OPEN UIP_ACTIVE_OPEN */
}
}
if(tick_count >= 10) //add6
{
uip_arp_timer();
tick_count = 0;
}
}
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -