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

📄 socket1.h

📁 这是本人以前用C51做的TCP/IP协议,也是借鉴了一些前辈的东西,,,,绝对可用!
💻 H
📖 第 1 页 / 共 2 页
字号:
//define begin
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
typedef unsigned char	u_char;		// 8-bit value
typedef unsigned char	SOCKET;
typedef unsigned int	u_int;		// 16-bit value
typedef unsigned long	u_long;		// 32-bit value
typedef unsigned char   uchar;
typedef unsigned int    uint;
typedef unsigned int    UINT;

#define zonex        0x04   //
#define channel     0x10
#define dev_type    0x02  //01=64;02=16*4=64;03=16
#define scale0      0x00  //
#define send_sum    0x230  //560

//#define send_sum    94  //138 //0x200   //send real datas sum.
#define totalcha    0xa     //10 channel

#define vscal0    0x49b     //v
#define vscal1    0x170A     //v
#define vscal2    0x30A3     //v
//#define vscal3    0xa     //v
#define iscal0    0x4B3     //v
#define iscal1    0x1780     //v
#define iscal2    0x2F00     //v
//ck
#define cvscal0    181 //0x49b     //v
#define cvscal1    901 //0x170A     //v
#define cvscal2    1801 //;0x30A3     //v

#define ciscal0    121 //0x4B3     //v
#define ciscal1    601 //0x1780     //v
#define ciscal2    1201 //0x2F00     //v

/*//// i/o;  (*((volatile u_char  xdata *)(I2CHIP_BASE + 0x08)))
#define  dridata   (*((volatile u_char  xdata *)(0x0500))) // 0x0500     //v  0X8000  //
#define  driadds   (*((volatile u_char  xdata *)(0x0520))) // 0x0500
#define  extdadd   (*((volatile u_char  xdata *)(0x0540))) // 0x0500
#define  add245   (*((volatile u_char  xdata *)(0x0580))) // 0x0500
#define  pic245   (*((volatile u_char  xdata *)(0x0560))) // 0x0500   */


#define  dridata    0x0500     //v  0X8000  //
#define  driadds    0x0520     //v    0X8020  //
#define  extdadd    0x0540     //v  0X8040  // q1=piccs,q2=ena14,q3=ena13,q8,7,6=m2,1,0
#define  add245     0x0580     //v  0X8080  //
#define  pic245     0x0560     //v  0X8060  //
#define  cs12_at256a 0x2000  //  2000-3fff;  8k

//constant define

#define  da2ld1    0x90
#define  da2ld2    0x91
#define  scldata   0x92
#define  scale574  0x93
#define  lightdis  0x97
#define  noselect  0xff //;0x00


/////////////define sbit/////////////////////
/////////for adc1255
sbit sclk=P1^0;        //OUT         for 1390 too  8 pin
sbit sdi=P1^1;      //IN             sdi for 1390 7 pin -->>mcu
sbit din=P1^2;         //OUT  1255's sdo   //for 1390 sdo din  6 in -->>1390
sbit drdy=P1^3;      //IN          1
sbit m691e=P1^4;         //OUT
sbit cs1255=P1^5;     //OUT
sbit cs1390=P1^6;         //OUT
sbit en489=P1^7;          //OUT           //max489 tx enable
//sbit polien=P1^7;          //in

sbit en509=P3^4;      //out          1
sbit rets=P3^5;      //out         w3100 reset
///////
// TCP

//sbit serilight=P1^2;
//sbit success=P1^3;
//sbit en489=P1^7;
//sbit enm0=P1^4;
//sbit enm1=P1^5;
//sbit enm2=P1^6;
//sbit rets=P3^5;
sbit chekint1=P3^3;
uchar bdata tiflag=0;
uchar bdata riflag=0;
//TCP END

/////////////define bit//////////////////////
bit bdata sflag;
//////////////define sbit/////
uchar data  startflag=0;
//extern  unsigned long int result ;

#define __TCP_SERVER
#define timela  0xff
#define timeha  0xff
#define buf8000   0x8000    //
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
#define	MAX_BUF_SIZE	1480 //2048			// Max size received_buffer
#define SBUFSIZE 0x03 //0x03 // 4096//8192    			//发送队列大小
#define RBUFSIZE 0x03 // //4096//8192   			        //接收队列大小
#define frame_BUFSIZE 20  //30    			//帧记录队列大小
//#define IdlesseTimer  300000                    //空闲计时
#define IdlesseTimer  120000                    //空闲计时

/* Type for treating 4 byte variables with byte by byte */
typedef union _un_l2cval {
	unsigned long  lVal;
	unsigned char  cVal[4];
}un_l2cval;  //_at_ 0xe000;

/* Type for treating 2 byte variables with byte by byte */
typedef union _un_i2cval {
	unsigned int 	iVal;
	unsigned char 	cVal[2];
}un_i2cval;// _at_ 0xe010;




//stocket.h
#define	MAX_SOCK_NUM	1			// Concurrent maxmium number of socket


#define I2CHIP_BASE   0x0000
#define	SEND_DATA_BUF	(I2CHIP_BASE+0x4000)    // Internal Tx buffer address of W3100A
#define	RECV_DATA_BUF	(I2CHIP_BASE+0x6000)    // Internal Rx buffer address of W3100A

#define MAX_SEGMENT_SIZE	1000		// Maximum TCP transmission packet size
#define MAX_BUF_SIZE1		0

              /* Internal register set of W3100A */
#define COMMAND(i)		(*(( volatile  u_char  xdata*)(I2CHIP_BASE + i)))
#define	INT_STATUS(i)		(*((  volatile  u_char  xdata * )(I2CHIP_BASE + 0x04 + i))) // _AT_ 0X002
#define	INT_REG			(*((volatile u_char  xdata *)(I2CHIP_BASE + 0x08)))
#define	INTMASK			(*((volatile u_char  xdata *)(I2CHIP_BASE + 0x09)))
#define	RESETSOCK		(*((volatile u_char xdata  *)(I2CHIP_BASE + 0x0A)))

#define RX_PTR_BASE		0x10
#define RX_PTR_SIZE		0x0C

#define	RX_WR_PTR(i)		((volatile u_char  xdata *)(I2CHIP_BASE + RX_PTR_BASE + RX_PTR_SIZE * i))
#define	RX_RD_PTR(i)   		((volatile u_char  xdata *)(I2CHIP_BASE + RX_PTR_BASE + RX_PTR_SIZE * i + 0x04))
#define	RX_ACK_PTR(i)		((volatile u_char  xdata *)(I2CHIP_BASE + TX_PTR_BASE + TX_PTR_SIZE * i + 0x08))

#define TX_PTR_BASE		0x40
#define TX_PTR_SIZE		0x0C

#define	TX_WR_PTR(i)		((volatile u_char  xdata *)(I2CHIP_BASE + TX_PTR_BASE + TX_PTR_SIZE * i))
#define	TX_RD_PTR(i)		((volatile u_char  xdata *)(I2CHIP_BASE + TX_PTR_BASE + TX_PTR_SIZE * i + 0x04))
#define	TX_ACK_PTR(i)		((volatile u_char  xdata *)(I2CHIP_BASE + RX_PTR_BASE + RX_PTR_SIZE * i + 0x08))

/* Shadow Register Pointer Define */
#define SHADOW_RXWR_PTR(i)	((volatile u_char  xdata *)(I2CHIP_BASE + 0x1E0 + 3*i))
#define	SHADOW_RXRD_PTR(i)	((volatile u_char  xdata *)(I2CHIP_BASE + 0x1E1 + 3*i))
#define	SHADOW_TXACK_PTR(i)	((volatile u_char  xdata *)(I2CHIP_BASE + 0x1E2 + 3*i))
#define	SHADOW_TXWR_PTR(i)	((volatile u_char  xdata *)(I2CHIP_BASE + 0x1F0 + 3*i))
#define SHADOW_TXRD_PTR(i)	((volatile u_char  xdata *)(I2CHIP_BASE + 0x1F1 + 3*i))

#define SOCK_BASE		0xA0
#define SOCK_SIZE		0x18

#define SOCK_STATUS(i)		(*((volatile u_char  xdata *)(I2CHIP_BASE + SOCK_BASE + SOCK_SIZE * i)))
#define OPT_PROTOCOL(i)		(*((volatile u_char  xdata *)(I2CHIP_BASE + SOCK_BASE + SOCK_SIZE * i + 0x01)))
#define DST_HA_PTR(i)  		((volatile u_char  xdata *)(I2CHIP_BASE + SOCK_BASE + SOCK_SIZE * i + 0x02))
#define DST_IP_PTR(i)		((volatile u_char  xdata *)(I2CHIP_BASE + SOCK_BASE + SOCK_SIZE * i + 0x08))
#define DST_PORT_PTR(i)		((volatile u_char  xdata *)(I2CHIP_BASE + SOCK_BASE + SOCK_SIZE * i + 0x0C))
#define SRC_PORT_PTR(i)		((volatile u_char  xdata *)(I2CHIP_BASE + SOCK_BASE + SOCK_SIZE * i + 0x0E))
#define IP_PROTOCOL(i)		(*((volatile u_char  xdata *)(I2CHIP_BASE + SOCK_BASE + SOCK_SIZE * i + 0x10)))
#define TOS(i)			(*((volatile u_char  xdata *)(I2CHIP_BASE + SOCK_BASE + SOCK_SIZE * i + 0x11)))
#define MSS(i)			(*((volatile u_int  xdata *)(I2CHIP_BASE + SOCK_BASE + SOCK_SIZE * i + 0x12)))
#define P_WINDOW(i)		(*((volatile u_int  xdata *)(I2CHIP_BASE + SOCK_BASE + SOCK_SIZE * i + 0x14)))
#define WINDOW(i)		(*((volatile u_int  xdata *)(I2CHIP_BASE + SOCK_BASE + SOCK_SIZE * i + 0x16)))


#define GATEWAY_PTR		((volatile u_char  xdata *)(I2CHIP_BASE + 0x80))
#define SUBNET_MASK_PTR		((volatile u_char  xdata *)(I2CHIP_BASE + 0x84))
#define SRC_HA_PTR	      (( volatile   u_char xdata  *)(I2CHIP_BASE + 0x88))
#define SRC_IP_PTR		((volatile u_char  xdata *)(I2CHIP_BASE + 0x8E))
#define TIMEOUT_PTR		((volatile u_char  xdata *)(I2CHIP_BASE + 0x92))

#define RX_DMEM_SIZE		(*((volatile u_char  xdata *)(I2CHIP_BASE + 0x95)))
#define TX_DMEM_SIZE		(*((volatile u_char  xdata *)(I2CHIP_BASE + 0x96)))

#define IDM_OR_PTR          	((volatile u_char  xdata *)(I2CHIP_BASE + 0x0C))
#define IDM_AR_PTR   		((volatile u_char  xdata *)(I2CHIP_BASE + 0x0D))
#define IDM_DR_PTR   		((volatile u_char  xdata *)(I2CHIP_BASE + 0x0F))

/* SOCKET OPTION(Settting OPT_PROTOCOL REG.) */
#define SOCKOPT_BROADCAST	0x80		// Transmission, Reception of broadcasting data
#define SOCKOPT_NDTIMEOUT	0x40		// Setting timeout
#define SOCKOPT_NDACK		0x20		// Setting No Delayed Ack(TCP)
#define SOCKOPT_SWS		0x10		// Setting Silly Window Syndrome(TCP)

/* OPTION(Setting OPT_PROTOCOL REG.) for MAC LAYER RAW MODE */
#define MACLOPT_RXERR		0x80		// Setting reception of error packet
#define MACLOPT_BROADCAST	0x40		// Setting reception of broadcast packet
#define MACLOPT_PROMISC		0x20		// Setting reception of promiscuous packet

/* Distinguish TCP / UDP / IP RAW / MAC RAW (Setting OPT_PROTOCOL REG.) */
#define	SOCK_CLOSEDM		0x00 		// unused socket
#define	SOCK_STREAM		0x01		// TCP
#define	SOCK_DGRAM		0x02		// UDP
#define	SOCK_IPL_RAW		0x03		// IP LAYER RAW SOCK
#define	SOCK_MACL_RAW		0x04		// MAC LAYER RAW SOCK

/* Setting IP PROTOCOL */
#define IPPROTO_IP              0               // dummy for IP
#define IPPROTO_ICMP            1               // control message protocol
#define IPPROTO_IGMP            2               // internet group management protocol
#define IPPROTO_GGP             3               // gateway^2 (deprecated)
#define IPPROTO_TCP             6               // tcp
#define IPPROTO_PUP             12              // pup
#define IPPROTO_UDP             17              // user datagram protocol
#define IPPROTO_IDP             22              // xns idp
#define IPPROTO_ND              77              // UNOFFICIAL net disk proto
#define IPPROTO_RAW             255             // raw IP packet

/* Select parameter to use */
#define SEL_CONTROL		0	// Confirm socket status
#define SEL_SEND		1	       	// Confirm Tx free buffer size
#define SEL_RECV		2	       	// Confirm Rx data size

/* Command variables */
#define CSYS_INIT		0x01	   	// To set up network information(mac address, gateway address, subnet mask, source ip)
#define CSOCK_INIT		0x02		// To initialize socket
#define CCONNECT		0x04		// To establish connection as tcp client mode
#define CLISTEN			0x08		// To wait for connection request as tcp server mode
#define CCLOSE			0x10		// To terminate connection
#define CSEND			0x20		// To send data
#define CRECV			0x40		// To receive data
#define CSW_RESET		0x80		// To do software reset

/* Status Variables */
#define SSYS_INIT_OK		0x01		// Completion of CSYS_INIT command
#define SSOCK_INIT_OK		0x02		// Completion of CSOCK_INIT command
#define SESTABLISHED		0x04		// Completion of connection setup
#define SCLOSED			0x08		// Completion of CCLOSED command
#define STIMEOUT		0x10		// Timout occured at send,sendto command
#define SSEND_OK		0x20		// Completion of sending data
#define SRECV_OK		0x40		// Completion of receiving data

/* Socket Status Vabiables */
#define SOCK_CLOSED		0x00		// Status of connection closed
#define SOCK_ARP		0x01		// Status of ARP
#define SOCK_LISTEN		0x02		// Status of waiting for TCP connection setup
#define SOCK_SYNSENT		0x03		// Status of setting up TCP connection
#define SOCK_SYNSENT_ACK	0x04		// Status of setting up TCP connection
#define SOCK_SYNRECV		0x05		// Status of setting up TCP connection
#define SOCK_ESTABLISHED	0x06		// Status of TCP connection established
#define SOCK_CLOSE_WAIT		0x07		// Status of closing TCP connection
#define SOCK_LAST_ACK		0x08		// Status of closing TCP connection
#define SOCK_FIN_WAIT1		0x09		// Status of closing TCP connection
#define SOCK_FIN_WAIT2		0x0A		// Status of closing TCP connection
#define SOCK_CLOSING		0x0B		// Status of closing TCP connection
#define SOCK_TIME_WAIT		0x0C		// Status of closing TCP connection
#define SOCK_RESET		0x0D		// Status of closing TCP connection
#define SOCK_INIT		0x0E		// Status of socket initialization
#define SOCK_UDP		0x0F		// Status of UDP
#define SOCK_RAW		0x10		// Status of IP RAW


#define Int7_En() EX1=1
#define Int7_Ds() EX1=0



///socket.c
u_char I_STATUS[4];              // Store Interrupt Status according to channels
u_int  Local_Port;                // Designate Local Port
un_l2cval  SEQ_NUM;               // Set initial sequence number

u_long  SMASK[MAX_SOCK_NUM];      // Variable to store MASK of Tx in each channel, on setting dynamic memory size.
u_long  RMASK[MAX_SOCK_NUM];      // Variable to store MASK of Rx in each channel, on setting dynamic memory size.
int  SSIZE[MAX_SOCK_NUM];         // Maximun Tx memory size by each channel
int  RSIZE[MAX_SOCK_NUM];         // Maximun Rx memory size by each channel
u_char  xdata  *SBUFBASEADDRESS[MAX_SOCK_NUM];     // Maximun Tx memory base address by each channel
u_char  xdata  *RBUFBASEADDRESS[MAX_SOCK_NUM];     // Maximun Rx memory base address by each channel


//
///////formation
#define RAM_BASEC2   0Xc400 //0x8000  //
#define	relatitm			(*((volatile u_int  xdata *)(RAM_BASEC2 + 0x00)))  //2
#define tcpinitfg		(*(( volatile  u_char  xdata*)(RAM_BASEC2+0x04)))  //   1
#define realtstfg		(*(( volatile  u_char  xdata*)(RAM_BASEC2+0x06)))  //   1
#define realchafg		(*(( volatile  u_char  xdata*)(RAM_BASEC2+0x07)))  //   1
#define exadd574bk		(*(( volatile  u_char  xdata*)(RAM_BASEC2+0x08)))  //   1

#define scalefg		(*(( volatile  u_char  xdata*)(RAM_BASEC2+0x09)))  //   1



#define newschfg(i)		(*(( volatile  u_char  xdata*)(RAM_BASEC2+0xf0+i)))  //   2*4


#define RAM_BASEC1   0x8100  //

⌨️ 快捷键说明

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