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 // Límites de tamaño de paquete
28 #define MIN_PACKET_LEN 60u // Mínimo permitido por 802.3
29 #define MAX_PACKET_LEN 128u // Mínimo permitido por nuestra escasa memoria =)
31 // Configuración de paǵinas de buffers
32 #define TX_PAGE_START 0x40 // 0x4000 Tx buffer: 256 bytes (usamos 128)
33 #define RX_PAGE_START 0x41 // 0x4600 Rx buffer: 31 * 256 = 7936 bytes
34 #define RX_PAGE_STOP 0x60 // 0x6000
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 PAR_BASE REG_BASE + 0x01 // Physical address register base address
141 #define PAR0 REG_BASE + 0x01 // Physical address register 0
142 #define PAR1 REG_BASE + 0x02 // Physical address register 1
143 #define PAR2 REG_BASE + 0x03 // Physical address register 2
144 #define PAR3 REG_BASE + 0x04 // Physical address register 3
145 #define PAR4 REG_BASE + 0x05 // Physical address register 4
146 #define PAR5 REG_BASE + 0x06 // Physical address register 5
147 #define CURR REG_BASE + 0x07 // Current receive buffer page
148 #define MAR0 REG_BASE + 0x08
149 #define MAR1 REG_BASE + 0x09
150 #define MAR2 REG_BASE + 0x0A
151 #define MAR3 REG_BASE + 0x0B
152 #define MAR4 REG_BASE + 0x0C
153 #define MAR5 REG_BASE + 0x0D
154 #define MAR6 REG_BASE + 0x0E
155 #define MAR7 REG_BASE + 0x0F
157 // Page 2 read only registers.
158 // Each previously defined in page 0 write only.
159 //#define PSTART REG_BASE + 0x01
160 //#define PSTOP REG_BASE + 0x02
161 //#define TPSR REG_BASE + 0x04
162 //#define RCR REG_BASE + 0x0C
163 //#define TCR REG_BASE + 0x0D
164 //#define DCR REG_BASE + 0x0E
165 //#define IMR REG_BASE + 0x0F
167 // Page 3 read/write registers.
168 #define _9346CR REG_BASE + 0x01 // 9346 EEPROM command register
169 // 9346 EEPROM command register bits
170 #define EEM1 0x80 // RTL8019AS operating mode bit 1
171 #define EEM0 0x40 // RTL8019AS operating mode bit 0
172 #define EECS 0x08 // 9346 EEPROM chip select bit
173 #define EESK 0x04 // 9346 EEPROM serial clock bit
174 #define EEDI 0x02 // 9346 EEPROM data input bit
175 #define EEDO 0x01 // 9346 EEPROM data output bit
176 #define BPAGE REG_BASE + 0x02
177 #define CONFIG1 REG_BASE + 0x04 // RTL9019AS config register 1
178 // RTL9019AS config register 1 bits
179 #define IRQEN 0x80 // IRQ enable bit (WR protected)
180 #define IRQS2 0x40 // IRQ line select bit 2
181 #define IRQS1 0x20 // IRQ line select bit 1
182 #define IRQS0 0x10 // IRQ line select bit 0
183 #define IOS3 0x08 // I/O base address select bit 3
184 #define IOS2 0x04 // I/O base address select bit 2
185 #define IOS1 0x02 // I/O base address select bit 1
186 #define IOS0 0x01 // I/O base address select bit 0
187 #define CONFIG2 REG_BASE + 0x05 //
188 // RTL9019AS config register 2 bits
189 #define PL1 0x80 // Network medium type select bit 1
190 #define PL0 0x40 // Network medium type select bit 0
191 #define BSELB 0x20 // Boot ROM disable (WR protected)
192 #define BS4 0x10 // Boot ROM configuration bit 4
193 #define BS3 0x08 // Boot ROM configuration bit 3
194 #define BS2 0x04 // Boot ROM configuration bit 2
195 #define BS1 0x02 // Boot ROM configuration bit 1
196 #define BS0 0x01 // Boot ROM configuration bit 0
197 #define CONFIG3 REG_BASE + 0x06 // RTL9019AS config register 3
198 // RTL9019AS config register 3 bits
199 #define PNP 0x80 // Plug & play mode indicator bit
200 #define FUDUP 0x40 // Full duplex mode select bit
201 #define LEDS1 0x20 // LED output select bit 1
202 #define LEDS0 0x10 // LED output select bit 0
203 #define SLEEP 0x04 // Sleep mode select bit
204 #define PWRDN 0x02 // Power down mode select bit
205 #define ACTIVEB 0x01 // Inverse of bit 0, PNP active reg
207 // Page 3 read only registers.
208 #define CONFIG0 REG_BASE + 0x03 // RTL9019AS config register 0
209 // RTL9019AS config register 0 bits
210 #define VERID1 0x80 // RTL9019AS version ID bit 1 (R/W)
211 #define VERID0 0x40 // RTL9019AS version ID bit 0 (R/W)
212 #define AUI 0x20 // AUI input pin state bit
213 #define PNPJP 0x10 // PNP jumper pin state bit
214 #define JP 0x08 // JP input pin state bit
215 #define BNC 0x04 // Thinnet mode indication bit
216 #define CSNSAV REG_BASE + 0x08
217 #define INTR REG_BASE + 0x0B
218 #define CONFIG4 REG_BASE + 0x0D
220 // Page 3 write only registers.
221 #define TEST REG_BASE + 0x07
222 #define HLTCLK REG_BASE + 0x09
223 #define FMWP REG_BASE + 0x0C
226 // Bits del byte de status del frame recibido
227 #define RXSOK 0x01 /* Received a good packet */
228 #define RXSCRC 0x02 /* CRC error */
229 #define RXSFAE 0x04 /* frame alignment error */
230 #define RXSFO 0x08 /* FIFO overrun */
231 #define RXSMPA 0x10 /* missed pkt */
232 #define RXSPHY 0x20 /* physical/multicast address */
233 #define RXSDIS 0x40 /* receiver disable. set in monitor mode */
234 #define RXSDEF 0x80 /* deferring */