comparison packages/devs/eth/cl/cs8900a/current/src/if_cs8900a.c @ 1599:bf994e1a516c

Big/Little endian changes from Bob Koninckx
author gthomas
date Wed, 21 Apr 2004 17:03:23 +0000
parents 9c818dd5d9fa
children e2264d5f9337
comparison
equal deleted inserted replaced
1598:d177755187d3 1599:bf994e1a516c
157 157
158 static int 158 static int
159 cs8900a_int_vector(struct eth_drv_sc *sc) 159 cs8900a_int_vector(struct eth_drv_sc *sc)
160 { 160 {
161 cs8900a_priv_data_t *cpd = (cs8900a_priv_data_t *)sc->driver_private; 161 cs8900a_priv_data_t *cpd = (cs8900a_priv_data_t *)sc->driver_private;
162 return (cpd->interrupt) ? 1 : 0; 162 return (cpd->interrupt);
163 } 163 }
164 164
165 static bool 165 static bool
166 cs8900a_init(struct cyg_netdevtab_entry *tab) 166 cs8900a_init(struct cyg_netdevtab_entry *tab)
167 { 167 {
262 } 262 }
263 if (!esa_configured && (chip_status & PP_SelfStat_EEPROM)) { 263 if (!esa_configured && (chip_status & PP_SelfStat_EEPROM)) {
264 // Get ESA from EEPROM - via the PP_IA registers 264 // Get ESA from EEPROM - via the PP_IA registers
265 cyg_uint16 esa_word; 265 cyg_uint16 esa_word;
266 for (i = 0; i < sizeof(cpd->esa); i += 2) { 266 for (i = 0; i < sizeof(cpd->esa); i += 2) {
267 #if(CYG_BYTEORDER == CYG_LSBFIRST) 267 #ifndef CYGIMP_DEVS_ETH_CL_CS8900A_DATABUS_BYTE_SWAPPED
268 esa_word = get_reg(base, PP_IA+i); 268 esa_word = get_reg(base, PP_IA+i);
269 cpd->esa[i] = (esa_word & 0xFF); 269 cpd->esa[i] = (esa_word & 0xFF);
270 cpd->esa[i+1] = (esa_word >> 8) & 0xFF; 270 cpd->esa[i+1] = (esa_word >> 8) & 0xFF;
271 #elif(CYG_BYTEORDER == CYG_MSBFIRST) 271 #else
272 esa_word = get_reg(base, PP_IA+CYG_SWAP16(i)); 272 esa_word = get_reg(base, PP_IA+CYG_SWAP16(i));
273 cpd->esa[i+1] = (esa_word & 0xFF); 273 cpd->esa[i+1] = (esa_word & 0xFF);
274 cpd->esa[i] = (esa_word >> 8) & 0xFF; 274 cpd->esa[i] = (esa_word >> 8) & 0xFF;
275 #else
276 # error You must define CYG_BYTEORDER to equal CYG_LSBFIRST or CYG_MSBFIRST
277 #endif 275 #endif
278 } 276 }
279 esa_configured = true; 277 esa_configured = true;
280 } 278 }
281 if (!esa_configured) { 279 if (!esa_configured) {
285 return false; 283 return false;
286 } 284 }
287 285
288 // Tell the chip what ESA to use 286 // Tell the chip what ESA to use
289 for (i = 0; i < sizeof(cpd->esa); i += 2) { 287 for (i = 0; i < sizeof(cpd->esa); i += 2) {
290 #if(CYG_BYTEORDER == CYG_LSBFIRST) 288 #ifndef CYGIMP_DEVS_ETH_CL_CS8900A_DATABUS_BYTE_SWAPPED
291 put_reg(base, PP_IA+i, cpd->esa[i] | (cpd->esa[i+1] << 8)); 289 put_reg(base, PP_IA+i, cpd->esa[i] | (cpd->esa[i+1] << 8));
292 #elif(CYG_BYTEORDER == CYG_MSBFIRST) 290 #else
293 put_reg(base, PP_IA+CYG_SWAP16(i), cpd->esa[i+1] | (cpd->esa[i] << 8)); 291 put_reg(base, PP_IA+CYG_SWAP16(i), cpd->esa[i+1] | (cpd->esa[i] << 8));
294 #endif 292 #endif
295 } 293 }
296 // Set logical address mask 294 // Set logical address mask
297 for (i = 0; i < 8; i += 2) { 295 for (i = 0; i < 8; i += 2) {
298 #if(CYG_BYTEORDER == CYG_LSBFIRST) 296 #ifndef CYGIMP_DEVS_ETH_CL_CS8900A_DATABUS_BYTE_SWAPPED
299 put_reg(base, PP_LAF+i, 0xFFFF); 297 put_reg(base, PP_LAF+i, 0xFFFF);
300 #elif(CYG_BYTEORDER == CYG_MSBFIRST) 298 #else
301 put_reg(base, PP_LAF+CYG_SWAP16(i), 0xFFFF); 299 put_reg(base, PP_LAF+CYG_SWAP16(i), 0xFFFF);
302 #endif 300 #endif
303 } 301 }
304 # if DEBUG & 8 302 # if DEBUG & 8
305 diag_printf("ESA %02x:%02x:%02x:%02x:%02x:%02x\n", 303 diag_printf("ESA %02x:%02x:%02x:%02x:%02x:%02x\n",
436 #ifdef CYGPKG_KERNEL 434 #ifdef CYGPKG_KERNEL
437 cpd->txstart = cyg_current_time(); 435 cpd->txstart = cyg_current_time();
438 #endif 436 #endif
439 437
440 // Start the xmit sequence 438 // Start the xmit sequence
441 #if(CYG_BYTEORDER == CYG_MSBFIRST) 439 #ifdef CYGIMP_DEVS_ETH_CL_CS8900A_DATABUS_BYTE_SWAPPED
442 total_len = CYG_SWAP16(total_len); 440 total_len = CYG_SWAP16(total_len);
443 #endif 441 #endif
444 442
445 // The hardware indicates that there are options as to when the actual 443 // The hardware indicates that there are options as to when the actual
446 // packet transmission will start wrt moving of data into the transmit 444 // packet transmission will start wrt moving of data into the transmit
470 len = sg_list[i].len; 468 len = sg_list[i].len;
471 469
472 if (len > 0) { 470 if (len > 0) {
473 /* Finish the last word. */ 471 /* Finish the last word. */
474 if (odd_byte) { 472 if (odd_byte) {
475 #if(CYG_BYTEORDER == CYG_LSBFIRST) 473 // This new byte must get on the bus _after_ the last saved odd byte, it therefore
476 // Add data to the most significant byte 474 // belongs in the MSB of the CS8900a
475 #ifdef CYGIMP_DEVS_ETH_CL_CS8900A_DATABUS_BYTE_SWAPPED
476 saved_data |= *data++;
477 #else
477 saved_data |= ((cyg_uint16)*data++) << 8; 478 saved_data |= ((cyg_uint16)*data++) << 8;
478 #elif(CYG_BYTEORDER == CYG_MSBFIRST)
479 // Add data to the least significant byte
480 saved_data |= *data++;
481 #endif 479 #endif
482 HAL_WRITE_UINT16(cpd->base+CS8900A_RTDATA, saved_data); 480 HAL_WRITE_UINT16(cpd->base+CS8900A_RTDATA, saved_data);
483 len--; 481 len--;
484 odd_byte = false; 482 odd_byte = false;
485 } 483 }
486 if (((CYG_ADDRESS)data & 0x1) == 0) { 484 if (((CYG_ADDRESS)data & 0x1) == 0) {
487 /* Aligned on 16-bit boundary, so output contiguous words. */ 485 /* Aligned on 16-bit boundary, so output contiguous words. */
488 sdata = (cyg_uint16 *)data; 486 sdata = (cyg_uint16 *)data;
489 while (len > 1) { 487 while (len > 1) {
488 // Make sure data get on the bus in Big Endian format
489 #if((CYG_BYTEORDER == CYG_MSBFIRST) && defined(CYGIMP_DEVS_ETH_CL_CS8900A_DATABUS_BYTE_SWAPPED) || \
490 (CYG_BYTEORDER == CYG_LSBFIRST) && !defined(CYGIMP_DEVS_ETH_CL_CS8900A_DATABUS_BYTE_SWAPPED ))
490 HAL_WRITE_UINT16(cpd->base+CS8900A_RTDATA, *sdata++); 491 HAL_WRITE_UINT16(cpd->base+CS8900A_RTDATA, *sdata++);
492 #else
493 HAL_WRITE_UINT16(cpd->base+CS8900A_RTDATA, CYG_SWAP16(*sdata++));
494 #endif
491 len -= sizeof(cyg_uint16); 495 len -= sizeof(cyg_uint16);
492 } 496 }
493 data = (cyg_uint8 *)sdata; 497 data = (cyg_uint8 *)sdata;
494 } else { 498 } else {
495 /* Not 16-bit aligned, so byte copy */ 499 /* Not 16-bit aligned, so byte copy */
496 while (len > 1) { 500 while (len > 1) {
497 saved_data = (cyg_uint16)*data++; // reuse saved_data 501 saved_data = (cyg_uint16)*data++; // reuse saved_data
498 #if CYG_BYTEORDER == CYG_MSBFIRST 502 // Make sure data get on the bus in Big Endian format, the first byte belongs in the
503 // LSB of the CS8900A
504 #ifdef CYGIMP_DEVS_ETH_CL_CS8900A_DATABUS_BYTE_SWAPPED
499 saved_data = ((cyg_uint16)*data++) | (saved_data << 8); 505 saved_data = ((cyg_uint16)*data++) | (saved_data << 8);
500 #else 506 #else
501 saved_data |= ((cyg_uint16)*data++) << 8; 507 saved_data |= ((cyg_uint16)*data++) << 8;
502 #endif 508 #endif
503 HAL_WRITE_UINT16(cpd->base+CS8900A_RTDATA, saved_data); 509 HAL_WRITE_UINT16(cpd->base+CS8900A_RTDATA, saved_data);
505 } 511 }
506 } 512 }
507 /* Save last byte, if necessary. */ 513 /* Save last byte, if necessary. */
508 if (len == 1) { 514 if (len == 1) {
509 saved_data = (cyg_uint16)*data; 515 saved_data = (cyg_uint16)*data;
510 #if CYG_BYTEORDER == CYG_MSBFIRST 516 // This _last_ byte must get on the bus _first_, it therefore belongs in the LSB of
517 // the CS8900a
518 #ifdef CYGIMP_DEVS_ETH_CL_CS8900A_DATABUS_BYTE_SWAPPED
511 saved_data = (saved_data << 8); 519 saved_data = (saved_data << 8);
512 #endif 520 #endif
513 odd_byte = true; 521 odd_byte = true;
514 } 522 }
515 } 523 }
532 cyg_uint16 stat, len; 540 cyg_uint16 stat, len;
533 541
534 HAL_READ_UINT16(base+CS8900A_RTDATA, stat); 542 HAL_READ_UINT16(base+CS8900A_RTDATA, stat);
535 HAL_READ_UINT16(base+CS8900A_RTDATA, len); 543 HAL_READ_UINT16(base+CS8900A_RTDATA, len);
536 544
537 #if(CYG_BYTEORDER == CYG_MSBFIRST) 545 #ifdef CYGIMP_DEVS_ETH_CL_CS8900A_DATABUS_BYTE_SWAPPED
538 len = CYG_SWAP16(len); 546 len = CYG_SWAP16(len);
539 #endif 547 #endif
540 548
541 #ifdef CYGDBG_IO_ETH_DRIVERS_DEBUG 549 #ifdef CYGDBG_IO_ETH_DRIVERS_DEBUG
542 if (cyg_io_eth_net_debug) { 550 if (cyg_io_eth_net_debug) {
564 data = (cyg_uint16 *)sg_list[i].buf; 572 data = (cyg_uint16 *)sg_list[i].buf;
565 mlen = sg_list[i].len; 573 mlen = sg_list[i].len;
566 while (mlen >= sizeof(*data)) { 574 while (mlen >= sizeof(*data)) {
567 HAL_READ_UINT16(base+CS8900A_RTDATA, val); 575 HAL_READ_UINT16(base+CS8900A_RTDATA, val);
568 if (data) { 576 if (data) {
577 #if((CYG_BYTEORDER == CYG_MSBFIRST) && defined(CYGIMP_DEVS_ETH_CL_CS8900A_DATABUS_BYTE_SWAPPED) || \
578 (CYG_BYTEORDER == CYG_LSBFIRST) && !defined(CYGIMP_DEVS_ETH_CL_CS8900A_DATABUS_BYTE_SWAPPED ))
569 *data++ = val; 579 *data++ = val;
580 #else
581 *data++ = CYG_SWAP16(val);
582 #endif
570 } 583 }
571 mlen -= sizeof(*data); 584 mlen -= sizeof(*data);
572 } 585 }
573 if (mlen) { 586 if (mlen) {
574 HAL_READ_UINT16(base+CS8900A_RTDATA, val); 587 HAL_READ_UINT16(base+CS8900A_RTDATA, val);
575 #if(CYG_BYTEORDER == CYG_LSBFIRST) 588 #ifndef CYGIMP_DEVS_ETH_CL_CS8900A_DATABUS_BYTE_SWAPPED
576 // last odd byte will be in the LSB 589 // last odd byte will be in the LSB
577 cval = (cyg_uint8)(val); 590 cval = (cyg_uint8)(val);
578 #elif(CYG_BYTEORDER == CYG_MSBFIRST) 591 #elif(CYG_BYTEORDER == CYG_MSBFIRST)
579 // last odd byte will be in the MSB 592 // last odd byte will be in the MSB
580 cval = (cyg_uint8)(val >> 8); 593 cval = (cyg_uint8)(val >> 8);