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

📄 globals.h

📁 51单片机加rt8019硬件平台,上web方案及详细代码
💻 H
字号:

//延时常数定义
#define TRUE		     1
#define FALSE		     0 
#define SPACE		     0x20
#define DY1MS    	     228
#define DY10MS   	     2288
#define DY100MS  	     22893
#define DY200MS  	     45788
#define MAXBUF         1500

//以太网帧类型
#define IP_PACKET      0x0800
#define ARP_PACKET     0x0806
#define RARP_PACKET	  0x8035 

//端口
#define ECHO_PORT		  7
#define DAYTIME_PORT	  13
#define CHARGEN_PORT	  19
#define TIME_PORT		  37
#define HTTP_PORT  	  80
#define CUSTOM_PORT    2518

//IP包协议类型
#define ICMP_TYPE      1
#define IGMP_TYPE	     2
#define TCP_TYPE       6
#define UDP_TYPE       17

#define CACHESIZE 	  5
#define NULL ((void *) 0L)
#define CP   (uchar *)


#ifdef OSCAR_DEBUG
	#define TRACE(a, b, c, d)			print(a,b,c,d)
#else
	#define TRACE(a, b, c, d)			
#endif


/*************************************************************************
数据类型定义
***************************************************************************/
typedef unsigned char   uchar; 
typedef unsigned int    uint;
typedef unsigned long   ulong;

typedef struct
{
  uchar dest_macaddr[6];
  uchar source_macaddr[6];
  uint  frame_type;
} Eth_Header;

//ARP消息类型
typedef enum
{
	ARP_REQUEST   = 1,	// ARP请求
	ARP_RESPONSE  = 2,	// ARP应答
	RARP_REQUEST  = 3,	// RARP请求
	RARP_RESPONSE = 4
} ArpMsg_Type;

typedef struct
{
	uint  hardware_type; 
	uint  protocol_type;           
	uchar macaddr_len;
	uchar ipaddr_len;               
	uint  message_type;
	uchar source_macaddr[6];              
	ulong source_ipaddr;
	uchar dest_macaddr[6];    
	ulong dest_ipaddr;
} Arp_Header;

//ARP缓存
typedef struct
{
   ulong ipaddr;
   uchar macaddr[6];
   uchar timer; 
   uchar type;
} Arp_Cache; 

typedef struct
{
	uchar xdata * buf;
	ulong ipaddr;
	uchar proto_id;
	uint  len;
	uchar timer;
} Arp_Wait;

 typedef struct
{
   uchar ver_len;
   uchar tos;
   uint  total_len;
   uint  id;
   uint  fragment_info;
   uchar ttl;
   uchar protocol_id;
   uint  hd_cksum;
   ulong source_ipaddr;
   ulong dest_ipaddr;
} Ip_Header;

typedef struct 
{
   uint  source_port;
   uint  dest_port;
   uint  len;
   uint  checksum;
   uchar msg_data;
} Udp_Header;

typedef struct
{
   uchar msg_type;
   uchar msg_code;
   uint  checksum;
   uint  identifier;
   uint  sequence;
   uchar echo_data;
} Ping_Header; 

typedef struct
{
   uchar msg_type;
   uchar msg_code;
   uint  checksum;
   ulong msg_data;
   uchar echo_data;
} Icmp_Err_Header;

typedef struct
{
   uint  source_port;
   uint  dest_port;
   ulong sn;
   ulong ack_sn;
   uint  flags;
   uint  window;
   uint  checksum;
   uint  urgent_ptr;
   uchar options;
} Tcp_Header;

typedef struct
{
  ulong ipaddr;
  uint  port;
  ulong his_sn;
  ulong my_sn;
  ulong old_sn;
  ulong his_ack;
  uchar timer;
  uchar inactivity;	 
  uchar state;
  char  query[20];
} TCB;

/*************************************************************************
全局变量
***************************************************************************/
#ifdef  GLOBALS
#define GEXT 
#else
#define GEXT extern
#endif

 GEXT uchar xdata outbuf[MAXBUF];
 GEXT uchar xdata inbuf[MAXBUF];
 GEXT uchar xdata bakbuf[MAXBUF];
// GEXT uchar xdata urxbuf[MAXBUF];
 GEXT uchar xdata urxbuf[200];


 GEXT  Arp_Wait wait;
 GEXT uchar  waiting_for_arp;
 GEXT  Arp_Cache idata arp_cache[CACHESIZE];

 GEXT  ulong myipaddr;
 GEXT  ulong mysubnet;
 GEXT  ulong mygateway;
 GEXT  uchar mymac[6];  
/*************************************************************************
函数列表
***************************************************************************/
void delay_us(uint us);
void clean_buf(uchar *buf,uint len);
uint cksum(uchar *check,uint len);
uchar * strfind(uchar * s1, uchar * set);
itoa(uint value, char * buf, uchar radix);
void replace_tag(uchar * start, char * tag, char * sub,unsigned char Replacelength); 

⌨️ 快捷键说明

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