3 extern xdata leds _at_ 0x00c0;
6 // Register base address
7 #define DEV_REG_BASE 0x0000 // Hardwired to 0x0300
9 // Registers common to all pages.
10 xdata dev_cr _at_ 0x0000;
11 #define CR DEV_REG_BASE + 0x00 // Control register
12 // Control register bits
13 #define PS1 0x80 // Page select bit 1
14 #define PS0 0x40 // Page select bit 0
15 #define RD2 0x20 // Remote DMA control bit 2
16 #define RD1 0x10 // Remote DMA control bit 1
17 #define RD0 0x08 // Remote DMA control bit 0
18 #define TXP 0x04 // Transmit packet bit
19 #define STA 0x02 // Start bit (a flag only)
20 #define STP 0x01 // Stop bit transceiver ctrl
22 xdata dev_rdma _at_ 0x0010;
23 #define RDMA ETH_REG_BASE + 0x10 // Remote DMA port
25 xdata dev_reset _at_ 0x0018;
26 #define RESET ETH_REG_BASE + 0x18 // Reset port
28 // Page 0 read/write registers.
29 xdata dev_bnry _at_ 0x0003;
30 #define BNRY ETH_REG_BASE + 0x03 // Boundary register
32 xdata dev_isr _at_ 0x0007;
33 #define ISR ETH_REG_BASE + 0x07 // Interrupt status register
34 // Interrupt status register bits
35 #define RST 0x80 // Reset state indicator bit
36 #define RDC 0x40 // Remote DMA complete bit
37 #define CNT 0x20 // Network tally counter MSB set
38 #define OVW 0x10 // Receive buffer exhausted
39 #define TXE 0x08 // Transmit abort error bit
40 #define RXE 0x04 // Receive error report bit
41 #define PTX 0x02 // Successful packet transmit
42 #define PRX 0x01 // Successful packet receive
44 // Page 0 read only registers.
45 xdata dev_clda0 _at_ 0x0001;
46 #define CLDA0 ETH_REG_BASE + 0x01
47 xdata dev_clda1 _at_ 0x0002;
48 #define CLDA1 ETH_REG_BASE + 0x02
49 xdata dev_tsr _at_ 0x0004;
50 #define TSR ETH_REG_BASE + 0x04
51 xdata dev_ncr _at_ 0x0005;
52 #define NCR ETH_REG_BASE + 0x05
53 xdata dev_fifo _at_ 0x0006;
54 #define FIFO ETH_REG_BASE + 0x06
55 xdata dev_crda0 _at_ 0x0008;
56 #define CRDA0 ETH_REG_BASE + 0x08
57 xdata dev_crda1 _at_ 0x0009;
58 #define CRDA1 ETH_REG_BASE + 0x09
59 xdata dev_8019id0 _at_ 0x000A;
60 #define _8019ID0 ETH_REG_BASE + 0x0A
61 xdata dev_8019id1 _at_ 0x000B;
62 #define _8019ID1 ETH_REG_BASE + 0x0B
63 xdata dev_rsr _at_ 0x000C;
64 #define RSR ETH_REG_BASE + 0x0C
65 xdata dev_cntr0 _at_ 0x000D;
66 #define CNTR0 ETH_REG_BASE + 0x0D
67 xdata dev_cntr1 _at_ 0x000E;
68 #define CNTR1 ETH_REG_BASE + 0x0E
69 xdata dev_cntr2 _at_ 0x000F;
70 #define CNTR2 ETH_REG_BASE + 0x0F
72 // Page 0 write only registers.
73 xdata dev_pstart _at_ 0x0001;
74 #define PSTART ETH_REG_BASE + 0x01 // Receive page start register
75 xdata dev_pstop _at_ 0x0002;
76 #define PSTOP ETH_REG_BASE + 0x02 // Receive page stop register
77 xdata dev_tpsr _at_ 0x0004;
78 #define TPSR ETH_REG_BASE + 0x04 // Transmit page start register
79 xdata dev_tbcr0 _at_ 0x0005;
80 #define TBCR0 ETH_REG_BASE + 0x05 // Transmit byte count register 0
81 xdata dev_tbcr1 _at_ 0x0006;
82 #define TBCR1 ETH_REG_BASE + 0x06 // Transmit byte count register 1
83 xdata dev_rsar0 _at_ 0x0008;
84 #define RSAR0 ETH_REG_BASE + 0x08 // Remote start address register 0
85 xdata dev_rsar1 _at_ 0x0009;
86 #define RSAR1 ETH_REG_BASE + 0x09 // Remote start address register 0
87 xdata dev_rbcr0 _at_ 0x000A;
88 #define RBCR0 ETH_REG_BASE + 0x0A // Remote byte count register 0
89 xdata dev_rbcr1 _at_ 0x000B;
90 #define RBCR1 ETH_REG_BASE + 0x0B // Remote byte count register 1
91 xdata dev_rcr _at_ 0x000C;
92 #define RCR ETH_REG_BASE + 0x0C // Receive configuration register
93 // Receive configuration register bits (write in page 0, read in page 2)
94 #define MON 0x20 // Monitor mode select bit
95 #define PRO 0x10 // Promiscuous mode select bit
96 #define AM 0x08 // Multicast packet accept bit
97 #define AB 0x04 // Broadcast packet accept bit
98 #define AR 0x02 // Runt packet accept bit
99 #define SEP 0x01 // Error packet accept bit
100 xdata dev_tcr _at_ 0x000D;
101 #define TCR ETH_REG_BASE + 0x0D // Transmit configuration register
102 // Transmit configuration register bits
103 #define OFST 0x10 // Collision offset enable bit
104 #define ATD 0x08 // Auto transmit disable select bit
105 #define LB1 0x04 // Loopback mode select bit 1
106 #define LB0 0x02 // Loopback mode select bit 0
107 #define CRC 0x01 // CRC generation inhibit bit
108 xdata dev_dcr _at_ 0x000E;
109 #define DCR ETH_REG_BASE + 0x0E // Data configuration register
110 // Data configuration register bits (write in page 0, read in page 2)
111 #define FT1 0x40 // FIFO threshold select bit 1
112 #define FT0 0x20 // FIFO threshold select bit 0
113 #define ARM 0x10 // Auto-initialise remote
114 #define LS 0x08 // Loopback select bit
115 #define LAS 0x04 // Set to 0 (pwrup = 1)
116 #define BOS 0x02 // Byte order select bit
117 #define WTS 0x01 // Word transfer select bit
118 xdata dev_imr _at_ 0x000F;
119 #define IMR ETH_REG_BASE + 0x0F // Interrupt mask register
120 // Interrupt mask register bits
121 // Each enable bit correspons with an interrupt flag in ISR
123 // Page 1 read/write registers.
124 xdata dev_par0 _at_ 0x0001;
125 #define PAR0 ETH_REG_BASE + 0x01 // Physical address register 0
126 xdata dev_par1 _at_ 0x0002;
127 #define PAR1 ETH_REG_BASE + 0x02 // Physical address register 1
128 xdata dev_par2 _at_ 0x0003;
129 #define PAR2 ETH_REG_BASE + 0x03 // Physical address register 2
130 xdata dev_par3 _at_ 0x0004;
131 #define PAR3 ETH_REG_BASE + 0x04 // Physical address register 3
132 xdata dev_par4 _at_ 0x0005;
133 #define PAR4 ETH_REG_BASE + 0x05 // Physical address register 4
134 xdata dev_par5 _at_ 0x0006;
135 #define PAR5 ETH_REG_BASE + 0x06 // Physical address register 5
136 xdata dev_curr _at_ 0x0007;
137 #define CURR ETH_REG_BASE + 0x07 // Current receive buffer page
138 xdata dev_mar0 _at_ 0x0008;
139 #define MAR0 ETH_REG_BASE + 0x08
140 xdata dev_mar1 _at_ 0x0009;
141 #define MAR1 ETH_REG_BASE + 0x09
142 xdata dev_mar2 _at_ 0x000A;
143 #define MAR2 ETH_REG_BASE + 0x0A
144 xdata dev_mar3 _at_ 0x000B;
145 #define MAR3 ETH_REG_BASE + 0x0B
146 xdata dev_mar4 _at_ 0x000C;
147 #define MAR4 ETH_REG_BASE + 0x0C
148 xdata dev_mar5 _at_ 0x000D;
149 #define MAR5 ETH_REG_BASE + 0x0D
150 xdata dev_mar6 _at_ 0x000E;
151 #define MAR6 ETH_REG_BASE + 0x0E
152 xdata dev_mar7 _at_ 0x000F;
153 #define MAR7 ETH_REG_BASE + 0x0F
155 // Page 2 read only registers.
156 // Each previously defined in page 0 write only.
157 //#define PSTART ETH_REG_BASE + 0x01
158 //#define PSTOP ETH_REG_BASE + 0x02
159 //#define TPSR ETH_REG_BASE + 0x04
160 //#define RCR ETH_REG_BASE + 0x0C
161 //#define TCR ETH_REG_BASE + 0x0D
162 //#define DCR ETH_REG_BASE + 0x0E
163 //#define IMR ETH_REG_BASE + 0x0F
165 // Page 3 read/write registers.
166 xdata dev_9346cr _at_ 0x0001;
167 #define _9346CR ETH_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 xdata dev_bpage _at_ 0x0002;
176 #define BPAGE ETH_REG_BASE + 0x02
177 xdata dev_config1 _at_ 0x0004;
178 #define CONFIG1 ETH_REG_BASE + 0x04 // RTL9019AS config register 1
179 // RTL9019AS config register 1 bits
180 #define IRQEN 0x80 // IRQ enable bit (WR protected)
181 #define IRQS2 0x40 // IRQ line select bit 2
182 #define IRQS1 0x20 // IRQ line select bit 1
183 #define IRQS0 0x10 // IRQ line select bit 0
184 #define IOS3 0x08 // I/O base address select bit 3
185 #define IOS2 0x04 // I/O base address select bit 2
186 #define IOS1 0x02 // I/O base address select bit 1
187 #define IOS0 0x01 // I/O base address select bit 0
188 xdata dev_config2 _at_ 0x0005;
189 #define CONFIG2 ETH_REG_BASE + 0x05 //
190 // RTL9019AS config register 2 bits
191 #define PL1 0x80 // Network medium type select bit 1
192 #define PL0 0x40 // Network medium type select bit 0
193 #define BSELB 0x20 // Boot ROM disable (WR protected)
194 #define BS4 0x10 // Boot ROM configuration bit 4
195 #define BS3 0x08 // Boot ROM configuration bit 3
196 #define BS2 0x04 // Boot ROM configuration bit 2
197 #define BS1 0x02 // Boot ROM configuration bit 1
198 #define BS0 0x01 // Boot ROM configuration bit 0
199 xdata dev_config3 _at_ 0x0006;
200 #define CONFIG3 ETH_REG_BASE + 0x06 // RTL9019AS config register 3
201 // RTL9019AS config register 3 bits
202 #define PNP 0x80 // Plug & play mode indicator bit
203 #define FUDUP 0x40 // Full duplex mode select bit
204 #define LEDS1 0x20 // LED output select bit 1
205 #define LEDS0 0x10 // LED output select bit 0
206 #define SLEEP 0x04 // Sleep mode select bit
207 #define PWRDN 0x02 // Power down mode select bit
208 #define ACTIVEB 0x01 // Inverse of bit 0, PNP active reg
210 // Page 3 read only registers.
211 xdata dev_config0 _at_ 0x0003;
212 #define CONFIG0 ETH_REG_BASE + 0x03 // RTL9019AS config register 0
213 // RTL9019AS config register 0 bits
214 #define VERID1 0x80 // RTL9019AS version ID bit 1 (R/W)
215 #define VERID0 0x40 // RTL9019AS version ID bit 0 (R/W)
216 #define AUI 0x20 // AUI input pin state bit
217 #define PNPJP 0x10 // PNP jumper pin state bit
218 #define JP 0x08 // JP input pin state bit
219 #define BNC 0x04 // Thinnet mode indication bit
220 xdata dev_csnsav _at_ 0x0008;
221 #define CSNSAV ETH_REG_BASE + 0x08
222 xdata dev_intr _at_ 0x000B;
223 #define INTR ETH_REG_BASE + 0x0B
224 xdata dev_config4 _at_ 0x000D;
225 #define CONFIG4 ETH_REG_BASE + 0x0D
227 // Page 3 write only registers.
228 xdata dev_test _at_ 0x0007;
229 #define TEST ETH_REG_BASE + 0x07
230 xdata dev_hltclk _at_ 0x0009;
231 #define HLTCLK ETH_REG_BASE + 0x09
232 xdata dev_fmwp _at_ 0x000C;
233 #define FMWP ETH_REG_BASE + 0x0C
235 // Packet transmit & receive buffer configuration
236 #define ETH_TX_PAGE_START 0x40 // 0x4000 Tx buffer is 6 * 256 = 1536 bytes
237 #define ETH_RX_PAGE_START 0x46 // 0x4600 Rx buffer is 26 * 256 = 6656 bytes
238 #define ETH_RX_PAGE_STOP 0x60 // 0x6000
240 #define ETH_MIN_PACKET_LEN 0x3C
242 /* ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
243 º Private Macro Defines º
244 ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ */
245 // Manipulate PS1 & PS0 in CR to select RTL8019AS register page.
246 #define ETHERDEV_SELECT_REG_PAGE(page) \
249 dev_cr = dev_cr & ~(PS1 | PS0); \
250 dev_cr = dev_cr | (page << 6); \
254 /* ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
258 º Returns: 1 on success, 0 on failure. º
259 º Refer to National Semiconductor DP8390 App Note 874, July 1993. º
261 ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ */
262 unsigned char etherdev_init(void)
264 // Configure RTL8019AS ethernet controller.
266 // Keil startup code takes 4ms to execute (18.432MHz, X1 mode).
267 // That leaves plenty of time for the RTL8019AS to read it's
268 // configuration in from the 9346 EEPROM before we get here.
270 // Select RTL8019AS register page 0.
271 ETHERDEV_SELECT_REG_PAGE(0);
273 // Check if RTL8019AS fully reset.
279 // Select RTL8019AS register page 3.
280 ETHERDEV_SELECT_REG_PAGE(3);
282 // Temporarily disable config register write protection.
283 dev_9346cr = EEM1 | EEM0;
285 // Disable boot ROM & select 10BaseT with TP/CX auto-detect.
288 // Select half-duplex, awake, power-up & LED_TX/ LED_RX/ LED_LNK behaviour.
291 // Re-enable config register write protection.
294 // Select RTL8019AS register page 0.
295 ETHERDEV_SELECT_REG_PAGE(0);
297 // Stop RTL8019AS, select page 0 and abort DMA operation.
300 // Initialise data configuration register.
301 // FIFO threshold 8 bytes, no loopback, don't use auto send packet.
304 // Reset remote byte count registers.
308 // Receive configuration register to monitor mode.
311 // Initialise transmit configuration register to loopback internally.
314 // Clear interrupt status register bits by writing 1 to each.
317 // Mask all interrupts in mask register.
320 // Set transmit page start.
321 dev_tpsr = ETH_TX_PAGE_START;
323 // Set receive buffer page start.
324 dev_pstart = ETH_RX_PAGE_START;
326 // Initialise last receive buffer read pointer.
327 dev_bnry = ETH_RX_PAGE_START;
329 // Set receive buffer page stop.
330 dev_pstop = ETH_RX_PAGE_STOP;
332 // Select RTL8019AS register page 1.
333 dev_cr = RD2 | PS0 | STP;
335 // Initialise current packet receive buffer page pointer
336 dev_curr = ETH_RX_PAGE_START;
338 // Set physical address
346 // Select RTL8019AS register page 0 and abort DMA operation.
349 // Restart RTL8019AS.
352 // Initialise transmit configuration register for normal operation.
355 // Receive configuration register to accept broadcast packets.
361 unsigned char uip_buf[] =
363 //0x00, 0x0c, 0x6e, 0x37, 0x19, 0xbf, // MAC destino
364 0x00, 0x80, 0xc7, 0x42, 0x8d, 0x27, // MAC destino
365 0x00, 0x0c, 0x6e, 0x37, 0x19, 0xbe, // MAX fuente
368 unsigned int uip_len = 14;
370 /* ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
374 º Send the packet in the uip_buf and uip_appdata buffers using the º
375 º RTL8019AS ethernet card. º
377 ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ */
378 void etherdev_send(void)
385 // Setup for DMA transfer from uip_buf & uip_appdata buffers to RTL8019AS.
387 // Select RTL8019AS register page 0 and abort DMA operation.
393 // Wait until pending transmit operation completes.
394 while(dev_cr & TXP) break;
400 // Clear remote DMA complete interrupt status register bit.
405 // Set remote DMA start address registers to indicate where to load packet.
407 dev_rsar1 = ETH_TX_PAGE_START;
409 // Set remote DMA byte count registers to indicate length of packet load.
410 dev_rbcr0 = (unsigned char)(uip_len & 0xFF);
411 dev_rbcr1 = (unsigned char)(uip_len >> 8);
413 // Initiate DMA transfer of uip_buf & uip_appdata buffers to RTL8019AS.
416 // DMA transfer packet from uip_buf & uip_appdata to RTL8019AS local
417 // transmit buffer memory.
418 for(i = 0; i < uip_len; i++)
423 // Wait until remote DMA operation complete.
424 while(!(dev_isr & RDC)) continue;
426 // Abort/ complete DMA operation.
429 // Set transmit page start to indicate packet start.
430 dev_tpsr = ETH_TX_PAGE_START;
432 // Ethernet packets must be > 60 bytes, otherwise are rejected as runts.
433 if(uip_len < ETH_MIN_PACKET_LEN)
435 uip_len = ETH_MIN_PACKET_LEN;
438 // Set transmit byte count registers to indicate packet length.
439 dev_tbcr0 = (unsigned char)(uip_len & 0xFF);
440 dev_tbcr1 = (unsigned char)(uip_len >> 8);
442 // Issue command for RTL8019AS to transmit packet from it's local buffer.
443 dev_cr = RD2 | TXP | STA;
445 for (i = 0; i < 8; ++i)