comparison packages/devs/eth/arm/edb7xxx/current/src/if_edb7xxx.c @ 115:6ed91473a1cd ecos-sw-2000-08-21

Merge from eCos master repository on 2000-08-21-22:40:54-BST
author jlarmour
date Fri, 25 Aug 2000 17:32:38 +0000
parents 6736c52df507
children bd1a71e3e476
comparison
equal deleted inserted replaced
114:5ad2b71d525e 115:6ed91473a1cd
53 //========================================================================== 53 //==========================================================================
54 54
55 // Ethernet device driver for Cirrus Logic EDB7xxx 55 // Ethernet device driver for Cirrus Logic EDB7xxx
56 // Based on CS8900A 56 // Based on CS8900A
57 57
58 #include <pkgconf/system.h>
59 #include <pkgconf/devs_eth_arm_edb7xxx.h>
60 #ifdef CYGPKG_NET
58 #include <pkgconf/net.h> 61 #include <pkgconf/net.h>
62 #endif
59 #include <cyg/infra/cyg_type.h> 63 #include <cyg/infra/cyg_type.h>
60 #include <cyg/hal/hal_arch.h> 64 #include <cyg/hal/hal_arch.h>
65 #include <cyg/hal/hal_intr.h>
61 #include <cyg/infra/diag.h> 66 #include <cyg/infra/diag.h>
62 #include <cyg/hal/drv_api.h> 67 #include <cyg/hal/drv_api.h>
63 #include <netdev.h> 68 #include <netdev.h>
64 #include <eth_drv.h> 69 #include <eth_drv.h>
70
71 #ifndef CYGSEM_ARM_EDB7XXX_SET_ESA
72 #ifdef CYGPKG_REDBOOT
73 #include <pkgconf/redboot.h>
74 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG
75 #include <redboot.h>
76 #include <flash_config.h>
77 RedBoot_config_option("Network hardware address [MAC]",
78 edb7xxx_esa,
79 ALWAYS_ENABLED, true,
80 CONFIG_ESA
81 );
82 #endif
83 #endif
84 #endif
65 85
66 #define INTS_DONT_WORK 86 #define INTS_DONT_WORK
67 #undef INTS_DONT_WORK 87 #undef INTS_DONT_WORK
68 88
69 #ifdef INTS_DONT_WORK 89 #ifdef INTS_DONT_WORK
91 cs8900_start, 111 cs8900_start,
92 cs8900_stop, 112 cs8900_stop,
93 cs8900_control, 113 cs8900_control,
94 cs8900_can_send, 114 cs8900_can_send,
95 cs8900_send, 115 cs8900_send,
96 cs8900_recv); 116 cs8900_recv,
117 cs8900_int);
97 118
98 NETDEVTAB_ENTRY(edb7xxx_netdev, 119 NETDEVTAB_ENTRY(edb7xxx_netdev,
99 "edb7xxx", 120 "edb7xxx",
100 edb7xxx_cs8900_init, 121 edb7xxx_cs8900_init,
101 &edb7xxx_sc); 122 &edb7xxx_sc);
102 123
103 // FIXME 124 #ifdef CYGSEM_ARM_EDB7XXX_SET_ESA
104 static unsigned char enaddr[] = { 0x08, 0x88, 0x12, 0x34, 0x56, 0x78}; 125 static unsigned char enaddr[] = CYGDAT_ARM_EDB7XXX_ESA;
126 #else
127 static unsigned char enaddr[ETHER_ADDR_LEN];
128 #endif
105 129
106 static void cs8900_int(struct eth_drv_sc *sc); 130 static void cs8900_int(struct eth_drv_sc *sc);
107 static cyg_interrupt cs8900_interrupt; 131 static cyg_interrupt cs8900_interrupt;
108 static cyg_handle_t cs8900_interrupt_handle; 132 static cyg_handle_t cs8900_interrupt_handle;
109 133
129 edb7xxx_cs8900_init(struct cyg_netdevtab_entry *tab) 153 edb7xxx_cs8900_init(struct cyg_netdevtab_entry *tab)
130 { 154 {
131 struct eth_drv_sc *sc = (struct eth_drv_sc *)tab->device_instance; 155 struct eth_drv_sc *sc = (struct eth_drv_sc *)tab->device_instance;
132 unsigned short chip_type, chip_rev, chip_status; 156 unsigned short chip_type, chip_rev, chip_status;
133 int i; 157 int i;
134
135 diag_printf("cs8900 init\n");
136 158
137 // Initialize environment, setup interrupt handler 159 // Initialize environment, setup interrupt handler
138 cyg_drv_interrupt_create(CYGNUM_HAL_INTERRUPT_EINT3, 160 cyg_drv_interrupt_create(CYGNUM_HAL_INTERRUPT_EINT3,
139 99, // Priority - what goes here? 161 99, // Priority - what goes here?
140 (cyg_addrword_t)sc, // Data item passed to interrupt handler 162 (cyg_addrword_t)sc, // Data item passed to interrupt handler
160 #endif 182 #endif
161 183
162 chip_type = get_reg(PP_ChipID); 184 chip_type = get_reg(PP_ChipID);
163 chip_rev = get_reg(PP_ChipRev); 185 chip_rev = get_reg(PP_ChipRev);
164 186
187 #if 0
165 diag_printf("CS8900 - type: %x, rev: %x\n", chip_type, chip_rev); 188 diag_printf("CS8900 - type: %x, rev: %x\n", chip_type, chip_rev);
189 #endif
190
191 // Fetch hardware address
192 #if defined(CYGPKG_REDBOOT) && \
193 defined(CYGSEM_REDBOOT_FLASH_CONFIG) && \
194 !defined(CYGSEM_ARM_EDB7XXX_SET_ESA)
195 flash_get_config("edb7xxx_esa", enaddr, CONFIG_ESA);
196 #else
197 for (i = 0; i < ETHER_ADDR_LEN; i += 2) {
198 unsigned short esa_reg = get_reg(PP_IA+i);
199 enaddr[i] = esa_reg & 0xFF;
200 enaddr[i+1] = esa_reg >> 8;
201 }
202 #endif
166 203
167 put_reg(PP_SelfCtl, PP_SelfCtl_Reset); // Reset chip 204 put_reg(PP_SelfCtl, PP_SelfCtl_Reset); // Reset chip
168 while ((get_reg(PP_SelfStat) & PP_SelfStat_InitD) == 0) ; 205 while ((get_reg(PP_SelfStat) & PP_SelfStat_InitD) == 0) ;
169 206
170 chip_status = get_reg(PP_SelfStat); 207 chip_status = get_reg(PP_SelfStat);
208 #if 0
171 diag_printf("CS8900 - status: %x (%sEEPROM present)\n", chip_status, 209 diag_printf("CS8900 - status: %x (%sEEPROM present)\n", chip_status,
172 chip_status&PP_SelfStat_EEPROM ? "" : "no "); 210 chip_status&PP_SelfStat_EEPROM ? "" : "no ");
173 211 #endif
174 // Set up hardware address - FIXME 212
213 // Set up hardware address
175 for (i = 0; i < ETHER_ADDR_LEN; i += 2) { 214 for (i = 0; i < ETHER_ADDR_LEN; i += 2) {
176 put_reg(PP_LAF+i, 0xFFFF); 215 put_reg(PP_LAF+i, 0xFFFF);
177 put_reg(PP_IA+i, enaddr[i] | (enaddr[i+1] << 8)); 216 put_reg(PP_IA+i, enaddr[i] | (enaddr[i+1] << 8));
178 } 217 }
179 218
180 // Initialize upper level driver 219 // Initialize upper level driver
181 eth_drv_init(sc, enaddr); 220 (sc->funs->eth_drv->init)(sc, enaddr);
182 221
183 return true; 222 return true;
184 } 223 }
185 224
186 static void 225 static void
241 // 280 //
242 static int 281 static int
243 cs8900_can_send(struct eth_drv_sc *sc) 282 cs8900_can_send(struct eth_drv_sc *sc)
244 { 283 {
245 struct cs8900_priv_data *cpd = (struct cs8900_priv_data *)sc->driver_private; 284 struct cs8900_priv_data *cpd = (struct cs8900_priv_data *)sc->driver_private;
285 unsigned short stat;
286 stat = get_reg(PP_LineStat);
287 if ((stat & PP_LineStat_LinkOK) == 0) {
288 return false; // Link not connected
289 }
246 return (cpd->txbusy == 0); 290 return (cpd->txbusy == 0);
247 } 291 }
248 292
249 // 293 //
250 // This routine is called to send data to the hardware. 294 // This routine is called to send data to the hardware.
316 stat = CS8900_RTDATA; 360 stat = CS8900_RTDATA;
317 len = CS8900_RTDATA; 361 len = CS8900_RTDATA;
318 if (net_debug) { 362 if (net_debug) {
319 diag_printf("RxEvent - stat: %x, len: %d\n", stat, len); 363 diag_printf("RxEvent - stat: %x, len: %d\n", stat, len);
320 } 364 }
321 eth_drv_recv(sc, len); 365 (sc->funs->eth_drv->recv)(sc, len);
322 } 366 }
323 367
324 // 368 //
325 // This function is called as a result of the "eth_drv_recv()" call above. 369 // This function is called as a result of the "eth_drv_recv()" call above.
326 // It's job is to actually fetch data for a packet from the hardware once 370 // It's job is to actually fetch data for a packet from the hardware once
346 mlen -= sizeof(*data); 390 mlen -= sizeof(*data);
347 } 391 }
348 if (mlen) { 392 if (mlen) {
349 // Fetch last odd byte 393 // Fetch last odd byte
350 cval = CS8900_RTDATA & 0xFF; 394 cval = CS8900_RTDATA & 0xFF;
351 if (cp = (unsigned char *)data) { 395 if ((cp = (unsigned char *)data) != 0) {
352 *cp = cval; 396 *cp = cval;
353 } 397 }
354 } 398 }
355 } 399 }
356 } 400 }
362 stat = get_reg(PP_TER); 406 stat = get_reg(PP_TER);
363 if (net_debug) { 407 if (net_debug) {
364 diag_printf("Tx event: %x\n", stat); 408 diag_printf("Tx event: %x\n", stat);
365 } 409 }
366 cpd->txbusy = 0; 410 cpd->txbusy = 0;
367 eth_drv_tx_done(sc, cpd->txkey, 0); 411 (sc->funs->eth_drv->tx_done)(sc, cpd->txkey, 0);
368 } 412 }
369 413
370 static void 414 static void
371 cs8900_BufEvent(struct eth_drv_sc *sc, int stat) 415 cs8900_BufEvent(struct eth_drv_sc *sc, int stat)
372 { 416 {