📄 socket.h
字号:
/*
********************************************************************************
* Wiznet.
* 5F Simmtech Bldg., 228-3, Nonhyun-dong, Kangnam-gu,
* Seoul, Korea
*
* (c) Copyright 2002, Wiznet, Seoul, Korea
*
* Filename : socket.h
* Version : 2.1
* Programmer(s):
* Created : 2002/01/10/25
* Description : Header file of W3100A for 8051
********************************************************************************
*/
#include "type.h"
#ifndef __SOCKET_H__
#define __SOCKET_H__
#define MAX_SOCK_NUM 4 // Concurrent maxmium number of socket
#define I2CHIP_BASE 0x8000 // Address of W3100A
#define SEND_DATA_BUF 0xC000 // Internal Tx buffer address of W3100A
#define RECV_DATA_BUF 0xE000 // Internal Rx buffer address of W3100A
#define MAX_SEGMENT_SIZE 1460 // 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)))
#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)))
/* 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
#endif /* __SOCKET_H__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -