1 // vim: set et sw=4 sts=4 :
10 // Configuración de puertos para comunicarse con la placa de red
11 #define DATA_PORT P2 // Adjust this to suit hardware.
12 #define DATA_PORT_MASK 0xFF // Máscara para leer del puerto
13 #define ADDR_PORT P1 // Adjust this to suit hardware.
14 #define ADDR_PORT_MASK 0x1F // Máscara de direcciones (para no cambiar
15 // bits que no se usan)
17 sbit at 0xB4 IOW; // ISA slot pin B13, RTL8019AS pin 30, active low
18 sbit at 0xB5 IOR; // ISA slot pin B14, RTL8019AS pin 29, active low
19 sbit at 0xB2 NICE; // A7, usado para activar placa de red
21 #define CTRL_PORT P3 // Adjust this to suit hardware.
22 sbit IOW = CTRL_PORT^4; // ISA slot pin B13, RTL8019AS pin 30, active low
23 sbit IOR = CTRL_PORT^5; // ISA slot pin B14, RTL8019AS pin 29, active low
24 sbit NICE = CTRL_PORT^2; // A7, usado para activar placa de red
27 // Configuración de paǵinas de buffers
28 #define TX_PAGE_START 0x40 // 0x4000 Tx buffer: 6 * 256 = 1536 bytes
29 #define RX_PAGE_START 0x46 // 0x4600 Rx buffer: 26 * 256 = 6656 bytes
30 #define RX_PAGE_STOP 0x60 // 0x6000
32 // Límites de tamaño de paquete
33 #define MIN_PACKET_LEN 60u // Mínimo permitido por 802.3
34 #define MAX_PACKET_LEN 128u // Mínimo permitido por nuestra escasa memoria =)
36 // Register base address
37 #define REG_BASE 0x0000 // Hardwired to 0x0300
39 // Registers common to all pages.
40 #define CR REG_BASE + 0x00 // Control register
41 // Control register bits
42 #define PS1 0x80 // Page select bit 1
43 #define PS0 0x40 // Page select bit 0
44 #define RD2 0x20 // Remote DMA control bit 2
45 #define RD1 0x10 // Remote DMA control bit 1
46 #define RD0 0x08 // Remote DMA control bit 0
47 #define TXP 0x04 // Transmit packet bit
48 #define STA 0x02 // Start bit (a flag only)
49 #define STP 0x01 // Stop bit transceiver ctrl
51 #define PAGE0 0x00 // Page 0
52 #define PAGE1 PS0 // Page 1
53 #define PAGE2 PS1 // Page 2
54 #define PAGE3 (PS0 | PS1) // Page 3 (Reserved!)
55 #define ABORT RD2 // Abort/Complete DMA
56 #define READ (RD0 | STA) // Remote Read
57 #define WRITE (RD1 | STA) // Remote Write
58 #define SENDPKT (RD0 | RD1 | STA) // Send Packet
59 #define STOP (ABORT | STP) // Para la placa de red
60 #define START (ABORT | STA) // Inicia la placa de red
62 #define RDMA 0x10 // Remote DMA port
63 #define RESET 0x18 // Reset port
65 // Page 0 read/write registers.
66 #define BNRY REG_BASE + 0x03 // Boundary register
67 #define ISR REG_BASE + 0x07 // Interrupt status register
68 // Interrupt status register bits
69 #define RST 0x80 // Reset state indicator bit
70 #define RDC 0x40 // Remote DMA complete bit
71 #define CNT 0x20 // Network tally counter MSB set
72 #define OVW 0x10 // Receive buffer exhausted
73 #define TXE 0x08 // Transmit abort error bit
74 #define RXE 0x04 // Receive error report bit
75 #define PTX 0x02 // Successful packet transmit
76 #define PRX 0x01 // Successful packet receive
78 #define ALL 0xFF // Todos los bits
79 #define NONE 0x00 // Ninguno
81 // Page 0 read only registers.
82 #define CLDA0 REG_BASE + 0x01
83 #define CLDA1 REG_BASE + 0x02
84 #define TSR REG_BASE + 0x04
85 #define NCR REG_BASE + 0x05
86 #define FIFO REG_BASE + 0x06
87 #define CRDA0 REG_BASE + 0x08
88 #define CRDA1 REG_BASE + 0x09
89 #define CONFIGA REG_BASE + 0x0A
90 #define CONFIGB REG_BASE + 0x0B
91 #define RSR REG_BASE + 0x0C
92 #define CNTR0 REG_BASE + 0x0D
93 #define CNTR1 REG_BASE + 0x0E
94 #define CNTR2 REG_BASE + 0x0F
96 // Page 0 write only registers.
97 #define PSTART REG_BASE + 0x01 // Receive page start register
98 #define PSTOP REG_BASE + 0x02 // Receive page stop register
99 #define TPSR REG_BASE + 0x04 // Transmit page start register
100 #define TBCR0 REG_BASE + 0x05 // Transmit byte count register 0
101 #define TBCR1 REG_BASE + 0x06 // Transmit byte count register 1
102 #define RSAR0 REG_BASE + 0x08 // Remote start address register 0
103 #define RSAR1 REG_BASE + 0x09 // Remote start address register 0
104 #define RBCR0 REG_BASE + 0x0A // Remote byte count register 0
105 #define RBCR1 REG_BASE + 0x0B // Remote byte count register 1
106 #define RCR REG_BASE + 0x0C // Receive configuration register
107 // Receive configuration register bits (write in page 0, read in page 2)
108 #define MON 0x20 // Monitor mode select bit
109 #define PRO 0x10 // Promiscuous mode select bit
110 #define AM 0x08 // Multicast packet accept bit
111 #define AB 0x04 // Broadcast packet accept bit
112 #define AR 0x02 // Runt packet accept bit
113 #define SEP 0x01 // Error packet accept bit
114 #define TCR REG_BASE + 0x0D // Transmit configuration register
115 // Transmit configuration register bits
116 #define OFST 0x10 // Collision offset enable bit
117 #define ATD 0x08 // Auto transmit disable select bit
118 #define LB1 0x04 // Loopback mode select bit 1
119 #define LB0 0x02 // Loopback mode select bit 0
120 #define CRC 0x01 // CRC generation inhibit bit
122 #define MODE0 0x00 // Loopback mode 0
123 #define MODE1 LB0 // Loopback mode 1
124 #define MODE2 LB1 // Loopback mode 2
125 #define MODE3 (LB0 | LB1) // Loopback mode 3
126 #define DCR REG_BASE + 0x0E // Data configuration register
127 // Data configuration register bits (write in page 0, read in page 2)
128 #define FT1 0x40 // FIFO threshold select bit 1
129 #define FT0 0x20 // FIFO threshold select bit 0
130 #define ARM 0x10 // Auto-initialise remote
131 #define LS 0x08 // Loopback select bit
132 #define LAS 0x04 // Set to 0 (pwrup = 1)
133 #define BOS 0x02 // Byte order select bit
134 #define WTS 0x01 // Word transfer select bit
135 #define IMR REG_BASE + 0x0F // Interrupt mask register
136 // Interrupt mask register bits
137 // Each enable bit correspons with an interrupt flag in ISR
139 // Page 1 read/write registers.
140 #define PAR0 REG_BASE + 0x01 // Physical address register 0
141 #define PAR1 REG_BASE + 0x02 // Physical address register 1
142 #define PAR2 REG_BASE + 0x03 // Physical address register 2
143 #define PAR3 REG_BASE + 0x04 // Physical address register 3
144 #define PAR4 REG_BASE + 0x05 // Physical address register 4
145 #define PAR5 REG_BASE + 0x06 // Physical address register 5
146 #define CURR REG_BASE + 0x07 // Current receive buffer page
147 #define MAR0 REG_BASE + 0x08
148 #define MAR1 REG_BASE + 0x09
149 #define MAR2 REG_BASE + 0x0A
150 #define MAR3 REG_BASE + 0x0B
151 #define MAR4 REG_BASE + 0x0C
152 #define MAR5 REG_BASE + 0x0D
153 #define MAR6 REG_BASE + 0x0E
154 #define MAR7 REG_BASE + 0x0F
156 // Page 2 read only registers.
157 // Each previously defined in page 0 write only.
158 //#define PSTART REG_BASE + 0x01
159 //#define PSTOP REG_BASE + 0x02
160 //#define TPSR REG_BASE + 0x04
161 //#define RCR REG_BASE + 0x0C
162 //#define TCR REG_BASE + 0x0D
163 //#define DCR REG_BASE + 0x0E
164 //#define IMR REG_BASE + 0x0F
166 // Page 3 read/write registers.
167 #define _9346CR REG_BASE + 0x01 // 9346 EEPROM command register
168 // 9346 EEPROM command register bits
169 #define EEM1 0x80 // RTL8019AS operating mode bit 1
170 #define EEM0 0x40 // RTL8019AS operating mode bit 0
171 #define EECS 0x08 // 9346 EEPROM chip select bit
172 #define EESK 0x04 // 9346 EEPROM serial clock bit
173 #define EEDI 0x02 // 9346 EEPROM data input bit
174 #define EEDO 0x01 // 9346 EEPROM data output bit
175 #define BPAGE REG_BASE + 0x02
176 #define CONFIG1 REG_BASE + 0x04 // RTL9019AS config register 1
177 // RTL9019AS config register 1 bits
178 #define IRQEN 0x80 // IRQ enable bit (WR protected)
179 #define IRQS2 0x40 // IRQ line select bit 2
180 #define IRQS1 0x20 // IRQ line select bit 1
181 #define IRQS0 0x10 // IRQ line select bit 0
182 #define IOS3 0x08 // I/O base address select bit 3
183 #define IOS2 0x04 // I/O base address select bit 2
184 #define IOS1 0x02 // I/O base address select bit 1
185 #define IOS0 0x01 // I/O base address select bit 0
186 #define CONFIG2 REG_BASE + 0x05 //
187 // RTL9019AS config register 2 bits
188 #define PL1 0x80 // Network medium type select bit 1
189 #define PL0 0x40 // Network medium type select bit 0
190 #define BSELB 0x20 // Boot ROM disable (WR protected)
191 #define BS4 0x10 // Boot ROM configuration bit 4
192 #define BS3 0x08 // Boot ROM configuration bit 3
193 #define BS2 0x04 // Boot ROM configuration bit 2
194 #define BS1 0x02 // Boot ROM configuration bit 1
195 #define BS0 0x01 // Boot ROM configuration bit 0
196 #define CONFIG3 REG_BASE + 0x06 // RTL9019AS config register 3
197 // RTL9019AS config register 3 bits
198 #define PNP 0x80 // Plug & play mode indicator bit
199 #define FUDUP 0x40 // Full duplex mode select bit
200 #define LEDS1 0x20 // LED output select bit 1
201 #define LEDS0 0x10 // LED output select bit 0
202 #define SLEEP 0x04 // Sleep mode select bit
203 #define PWRDN 0x02 // Power down mode select bit
204 #define ACTIVEB 0x01 // Inverse of bit 0, PNP active reg
206 // Page 3 read only registers.
207 #define CONFIG0 REG_BASE + 0x03 // RTL9019AS config register 0
208 // RTL9019AS config register 0 bits
209 #define VERID1 0x80 // RTL9019AS version ID bit 1 (R/W)
210 #define VERID0 0x40 // RTL9019AS version ID bit 0 (R/W)
211 #define AUI 0x20 // AUI input pin state bit
212 #define PNPJP 0x10 // PNP jumper pin state bit
213 #define JP 0x08 // JP input pin state bit
214 #define BNC 0x04 // Thinnet mode indication bit
215 #define CSNSAV REG_BASE + 0x08
216 #define INTR REG_BASE + 0x0B
217 #define CONFIG4 REG_BASE + 0x0D
219 // Page 3 write only registers.
220 #define TEST REG_BASE + 0x07
221 #define HLTCLK REG_BASE + 0x09
222 #define FMWP REG_BASE + 0x0C
225 // Bits del byte de status del frame recibido
226 #define RXSOK 0x01 /* Received a good packet */
227 #define RXSCRC 0x02 /* CRC error */
228 #define RXSFAE 0x04 /* frame alignment error */
229 #define RXSFO 0x08 /* FIFO overrun */
230 #define RXSMPA 0x10 /* missed pkt */
231 #define RXSPHY 0x20 /* physical/multicast address */
232 #define RXSDIS 0x40 /* receiver disable. set in monitor mode */
233 #define RXSDEF 0x80 /* deferring */