📄 cs8900.java
字号:
private static final int ISQ_EVENT_MASK = 0x003F; /* ISQ mask to find out type of event */// private static final int ISQ_HIST = 16; /* small history buffer */// private static final int AUTOINCREMENT = 0x8000; /* Bit mask to set bit-15 for autoincrement */// private static final int TXRXBUFSIZE = 0x0600;// private static final int RXDMABUFSIZE = 0x8000;// private static final int RXDMASIZE = 0x4000;// private static final int TXRX_LENGTH_MASK = 0x07FF;/* rx options bits */// private static final int RCV_WITH_RXON = 1; /* Set SerRx ON */// private static final int RCV_COUNTS = 2; /* Use Framecnt1 */// private static final int RCV_PONG = 4; /* Pong respondent */// private static final int RCV_DONG = 8; /* Dong operation */// private static final int RCV_POLLING = 0x10; /* Poll RxEvent */// private static final int RCV_ISQ = 0x20; /* Use ISQ, int */// private static final int RCV_AUTO_DMA = 0x100; /* Set AutoRxDMAE */// private static final int RCV_DMA = 0x200; /* Set RxDMA only */// private static final int RCV_DMA_ALL = 0x400; /* Copy all DMA'ed */// private static final int RCV_FIXED_DATA = 0x800; /* Every frame same */// private static final int RCV_IO = 0x1000; /* Use ISA IO only */// private static final int RCV_MEMORY = 0x2000; /* Use ISA Memory *///// private static final int RAM_SIZE = 0x1000; /* The card has 4k bytes or RAM */// private static final int PKT_START = PP_TxFrame; /* Start of packet RAM */ private static final int RX_FRAME_PORT = 0x0000; private static final int TX_FRAME_PORT = RX_FRAME_PORT; private static final int TX_CMD_PORT = 0x0004;// private static final int TX_NOW = 0x0000; /* Tx packet after 5 bytes copied */// private static final int TX_AFTER_381 = 0x0040; /* Tx packet after 381 bytes copied */ private static final int TX_AFTER_ALL = 0x00c0; /* Tx packet after all bytes copied */ private static final int TX_LEN_PORT = 0x0006;// private static final int ISQ_PORT = 0x0008; private static final int ADD_PORT = 0x000A; private static final int DATA_PORT = 0x000C;/* Receive Header *//* Description of header of each packet in receive area of memory */// private static final int RBUF_EVENT_LOW = 0; /* Low byte of RxEvent - status of received frame */// private static final int RBUF_EVENT_HIGH = 1; /* High byte of RxEvent - status of received frame */// private static final int RBUF_LEN_LOW = 2; /* Length of received data - low byte */// private static final int RBUF_LEN_HI = 3; /* Length of received data - high byte */// private static final int RBUF_HEAD_LEN = 4; /* Length of this header */// private static final int CHIP_READ = 0x1; /* Used to mark state of the repins code (chip or dma) */// private static final int DMA_READ = 0x2; /* Used to mark state of the repins code (chip or dma) */// private static final int IMM_BIT = 0x0040; /* ignore missing media */// private static final int A_CNF_10B_T = 0x0001;// private static final int A_CNF_AUI = 0x0002;// private static final int A_CNF_10B_2 = 0x0004;// private static final int A_CNF_MEDIA_TYPE = 0x0060;// private static final int A_CNF_MEDIA_AUTO = 0x0000;// private static final int A_CNF_MEDIA_10B_T = 0x0020;// private static final int A_CNF_MEDIA_AUI = 0x0040;// private static final int A_CNF_MEDIA_10B_2 = 0x0060;// private static final int A_CNF_DC_DC_POLARITY = 0x0080;// private static final int A_CNF_NO_AUTO_POLARITY = 0x2000;// private static final int A_CNF_LOW_RX_SQUELCH = 0x4000;// private static final int A_CNF_EXTND_10B_2 = 0x8000;//// private static final int PACKET_PAGE_OFFSET = 0x8;/*** an ARP frame.*/ static final int ETH_ARP = 0x0806;/*** an IP frame.*/ static final int ETH_IP = 0x0800;/*** The one and only reference to this object.*/ static CS8900 single;/*** private constructor. The singleton object is created in init().*/ private CS8900() { } public int getIpAddress() { return ip; } /** * Set connection strings and connect. */ public void startConnection(StringBuffer dialstr, StringBuffer connect, StringBuffer user, StringBuffer passwd) { // useless on Ethernet } /** * Forces the connection to be new established. * On Ethernet ignored. */ public void reconnect() { }/*** the polling loop.*/ public void loop() { Packet p; poll(); if (txFree) { // // get a ready to send packet with source from this driver. // p = Packet.getPacket(single, Packet.SND, Packet.ALLOC); if (p!=null) { Arp.fillETH(p); // fill in dest MAC send(p); // send one packet } } }/*** allocate buffer, reset chip and start Thread.*/ public static LinkLayer init(int[] mac, int ipaddr) { if (single != null) return single; // allready called init() Arp.init(); txFree = true; eth = new int[6]; for (int i=0; i<6; ++i) eth[i] = mac[i]; // intel byte order !!! mac_hi = mac[0]<<8 | mac[1]; mac_mid = mac[2]<<8 | mac[3]; mac_low = mac[4]<<8 | mac[5]; ip = ipaddr; tx_packets = 0;// tx_bytes = 0;// collisions = 0; rx_packets = 0; rx_bytes = 0; rx_dropped = 0; single = new CS8900(); single.reset(); return single; }//// ISA bus handling// private static final int ISA_RESET = 0x20; private static final int ISA_RD = 0x40; private static final int ISA_WR = 0x80; private static final int ISA_DIR = 0x100; // means driving out/* VHDL definition: isa_a <= din(4 downto 0); isa_reset <= din(5); isa_nior <= not din(6); isa_niow <= not din(7); isa_dir <= din(8);*//*** reset isa bus*/ // private void resetIsa() { void resetIsa() { int i; for (i=0; i<10; ++i) { Native.wr(ISA_RESET, Const.IO_CTRL); // isa bus reset } for (i=0; i<10; ++i) { Native.wr(0, Const.IO_CTRL); // disable reset } }/*** 'ISA Bus' io read cycle 2x8 bit.*/ private static int readWord(int port) { Native.wr(port, Const.IO_CTRL); // port Native.wr(port | ISA_RD, Const.IO_CTRL); // nior lowNative.wr(port | ISA_RD, Const.IO_CTRL); // nior low int ret = Native.rd(Const.IO_DATA); // read data Native.wr(port, Const.IO_CTRL); // nior high again ++port; Native.wr(port, Const.IO_CTRL); // port Native.wr(port | ISA_RD, Const.IO_CTRL); // nior lowNative.wr(port | ISA_RD, Const.IO_CTRL); // nior low ret += Native.rd(Const.IO_DATA)<<8; // read data Native.wr(port, Const.IO_CTRL); // nior high again return ret; }/*** 'ISA Bus' io read cycle 2x8 bit with high byte first.*/ private static int readWordHighFirst(int port) { ++port; Native.wr(port, Const.IO_CTRL); // addr Native.wr(port | ISA_RD, Const.IO_CTRL); // nior lowNative.wr(port | ISA_RD, Const.IO_CTRL); // nior low int ret = Native.rd(Const.IO_DATA)<<8; // read data Native.wr(port, Const.IO_CTRL); // nior high again --port; Native.wr(port, Const.IO_CTRL); // addr Native.wr(port | ISA_RD, Const.IO_CTRL); // nior lowNative.wr(port | ISA_RD, Const.IO_CTRL); // nior low ret += Native.rd(Const.IO_DATA)&0xff; // read data Native.wr(port, Const.IO_CTRL); // nior high again return ret; }/*** 'ISA Bus' io write cycle 2x8 bit.* first low byte than high byte at higher address.*/ private static void writeWord(int port, int value) { Native.wr(value, Const.IO_DATA); // value in buffer Native.wr(port | ISA_DIR, Const.IO_CTRL); // port and drive value out Native.wr(port | ISA_WR | ISA_DIR, Const.IO_CTRL); // niow lowNative.wr(port | ISA_WR | ISA_DIR, Const.IO_CTRL); // niow low Native.wr(port | ISA_DIR, Const.IO_CTRL); // niow high again ++port; Native.wr(value>>8, Const.IO_DATA); // value in buffer Native.wr(port | ISA_DIR, Const.IO_CTRL); // port and drive value out Native.wr(port | ISA_WR | ISA_DIR, Const.IO_CTRL); // niow lowNative.wr(port | ISA_WR | ISA_DIR, Const.IO_CTRL); // niow low Native.wr(port | ISA_DIR, Const.IO_CTRL); // niow high again Native.wr(port, Const.IO_CTRL); // disable dout } private static int readReg(int reg) { writeWord(ADD_PORT, reg); return readWord(DATA_PORT); } private static void writeReg(int reg, int value) { writeWord(ADD_PORT, reg); writeWord(DATA_PORT, value); }/*** write ethernet header.*/ private static void writeHead(Packet p) { int i, val; p.llh[3] = mac_hi; p.llh[4] = mac_mid; p.llh[5] = mac_low; for (i=0; i<ETH_HLEN/2; ++i) { val = p.llh[i]; Native.wr(val>>>8, Const.IO_DATA); // value in buffer Native.wr(TX_FRAME_PORT | ISA_DIR, Const.IO_CTRL); // port and drive value out Native.wr(TX_FRAME_PORT | ISA_WR | ISA_DIR, Const.IO_CTRL); // niow lowNative.wr(TX_FRAME_PORT | ISA_WR | ISA_DIR, Const.IO_CTRL); // niow low Native.wr(TX_FRAME_PORT | ISA_DIR, Const.IO_CTRL); // niow high again Native.wr(val, Const.IO_DATA); // value in buffer Native.wr(TX_FRAME_PORT+1 | ISA_DIR, Const.IO_CTRL); // port and drive value out Native.wr(TX_FRAME_PORT+1 | ISA_WR | ISA_DIR, Const.IO_CTRL); // niow lowNative.wr(TX_FRAME_PORT+1 | ISA_WR | ISA_DIR, Const.IO_CTRL); // niow low Native.wr(TX_FRAME_PORT+1 | ISA_DIR, Const.IO_CTRL); // niow high again } Native.wr(TX_FRAME_PORT+1, Const.IO_CTRL); // disable dout }/*** write tx data.*/ private static void writeData(Packet p) { int i, val; int[] buf = p.buf; int length = p.len; if ((length & 1) == 1) ++length; // even bytes val = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -