OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [drivers/] [eth.c] - Diff between revs 246 and 405

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 246 Rev 405
Line 8... Line 8...
#include "int.h"
#include "int.h"
#include "spr-defs.h"
#include "spr-defs.h"
 
 
//#define PRINT_PACKETS
//#define PRINT_PACKETS
//#define ETHPHY_10MBPS
//#define ETHPHY_10MBPS
 
//#define ETHPHY_RESET_ON_INIT
 
 
extern int printf (const char *fmt, ...);
extern int printf (const char *fmt, ...);
extern void lolev_ie(void);
extern void lolev_ie(void);
extern void lolev_idis(void);
extern void lolev_idis(void);
 
 
Line 29... Line 30...
 
 
 
 
static void
static void
print_packet(unsigned long add, int len)
print_packet(unsigned long add, int len)
{
{
  int i;
  int truncate = (len > 256);
 
  int length_to_print = truncate ? 256 : len;
 
 
  printf("ipacket: add = %lx len = %d\n", add, len);
  int i;
  for(i = 0; i < len; i++) {
  printf("\nipacket: add = %lx len = %d\n", add, len);
      if(!(i % 16)) printf("\n");
  for(i = 0; i < length_to_print; i++) {
      else if(!(i % 8)) printf(" "); // space here, so output is like wireshark
    if(!(i % 8))
 
      printf(" ");
 
    if(!(i % 16))
 
      printf("\n");
      printf(" %.2x", *(((unsigned char *)add) + i));
      printf(" %.2x", *(((unsigned char *)add) + i));
 
 
  }
  }
  printf("\n");
  printf("\n");
 
 
 
  if (truncate)
 
    printf("\ttruncated....\n");
 
  /*
 
  int i;
 
  printf("ipacket: add = %lx len = %d\n", add, len);
 
  for(i = 0; i < len; i++) {
 
      if(!(i % 16)) printf("\n");
 
      else if(!(i % 8)) printf(" "); // space here, so output is like wireshark
 
      printf(" %.2x", *(((unsigned char *)add) + i));
 
  }
 
  printf("\n");
 
  */
}
}
 
 
void init_tx_bd_pool(void)
void init_tx_bd_pool(void)
{
{
  eth_bd  *bd;
  eth_bd  *bd;
Line 211... Line 230...
{
{
  /* Reset ethernet core */
  /* Reset ethernet core */
  REG32(ETH_REG_BASE + ETH_MODER) = ETH_MODER_RST;    /* Reset ON */
  REG32(ETH_REG_BASE + ETH_MODER) = ETH_MODER_RST;    /* Reset ON */
  REG32(ETH_REG_BASE + ETH_MODER) &= ~ETH_MODER_RST;  /* Reset OFF */
  REG32(ETH_REG_BASE + ETH_MODER) &= ~ETH_MODER_RST;  /* Reset OFF */
 
 
  /* Setting TX BD number */
#ifdef ETHPHY_RESET_ON_INIT
  REG32(ETH_REG_BASE + ETH_TX_BD_NUM) = ETH_TXBD_NUM;
  REG32(ETH_REG_BASE + ETH_MIIADDRESS) = 0<<8; // BMCR reg
 
  REG32(ETH_REG_BASE + ETH_MIITX_DATA) = 0x8000; // RESET bit
 
  REG32(ETH_REG_BASE + ETH_MIICOMMAND) = ETH_MIICOMMAND_WCTRLDATA;
 
  while(REG32(ETH_REG_BASE + ETH_MIISTATUS) & ETH_MIISTATUS_BUSY);
 
 
 
  while(1){
 
    REG32(ETH_REG_BASE + ETH_MIIADDRESS) = 1<<8;
 
    REG32(ETH_REG_BASE + ETH_MIICOMMAND) = ETH_MIICOMMAND_RSTAT;
 
    while(REG32(ETH_REG_BASE + ETH_MIISTATUS) & ETH_MIISTATUS_BUSY);
 
    if(REG32(ETH_REG_BASE + ETH_MIIRX_DATA) & 0x04)
 
      break;
 
  }
 
#endif
 
 
#ifdef ETHPHY_10MBPS
#ifdef ETHPHY_10MBPS
  // Set PHY to 10 Mbps full duplex
  // Set PHY to 10 Mbps full duplex
  REG32(ETH_REG_BASE + ETH_MIIADDRESS) = 0<<8;
  REG32(ETH_REG_BASE + ETH_MIIADDRESS) = 0<<8;
  REG32(ETH_REG_BASE + ETH_MIITX_DATA) = 0x0100;
  REG32(ETH_REG_BASE + ETH_MIITX_DATA) = 0x0100;
Line 231... Line 262...
      break;
      break;
  }
  }
 
 
#endif
#endif
 
 
 
 
 
  /* Setting TX BD number */
 
  REG32(ETH_REG_BASE + ETH_TX_BD_NUM) = ETH_TXBD_NUM;
 
 
  /* Set min/max packet length */
  /* Set min/max packet length */
  REG32(ETH_REG_BASE + ETH_PACKETLEN) = 0x00400600;
  REG32(ETH_REG_BASE + ETH_PACKETLEN) = 0x00400600;
 
 
  /* Set IPGT register to recomended value */
  /* Set IPGT register to recomended value */
  REG32(ETH_REG_BASE + ETH_IPGT) =  0x00000012;
  REG32(ETH_REG_BASE + ETH_IPGT) =  0x00000012;
Line 263... Line 298...
  tx_last = 0;
  tx_last = 0;
  tx_full = 0;
  tx_full = 0;
 
 
  /* Initialize rx pointers */
  /* Initialize rx pointers */
  rx_next = 0;
  rx_next = 0;
 
 
 
  /* Assign receive function pointer to what we were passed */
  receive = rec;
  receive = rec;
 
 
  /* Set local MAC address */
  /* Set local MAC address */
  REG32(ETH_REG_BASE + ETH_MAC_ADDR1) = ETH_MACADDR0 << 8 |
  REG32(ETH_REG_BASE + ETH_MAC_ADDR1) = ETH_MACADDR0 << 8 |
            ETH_MACADDR1;
            ETH_MACADDR1;
Line 276... Line 313...
            ETH_MACADDR5;
            ETH_MACADDR5;
 
 
  /* Clear all pending interrupts */
  /* Clear all pending interrupts */
  REG32(ETH_REG_BASE + ETH_INT) = 0xffffffff;
  REG32(ETH_REG_BASE + ETH_INT) = 0xffffffff;
 
 
 
  /* Register interrupt handler */
 
  int_add (ETH_IRQ, eth_int);
 
 
  /* Promisc, IFG, CRCEn */
  /* Promisc, IFG, CRCEn */
  REG32(ETH_REG_BASE + ETH_MODER) |= ETH_MODER_PAD | ETH_MODER_IFG | ETH_MODER_CRCEN;
  REG32(ETH_REG_BASE + ETH_MODER) |= ETH_MODER_PAD | ETH_MODER_IFG | ETH_MODER_CRCEN;
 
 
  /* Enable interrupt sources */
  /* Enable interrupt sources */
#if 0
#if 0
Line 298... Line 338...
#endif
#endif
 
 
  /* Enable receiver and transmiter */
  /* Enable receiver and transmiter */
  REG32(ETH_REG_BASE + ETH_MODER) |= ETH_MODER_RXEN | ETH_MODER_TXEN;
  REG32(ETH_REG_BASE + ETH_MODER) |= ETH_MODER_RXEN | ETH_MODER_TXEN;
 
 
  /* Register interrupt handler */
 
  int_add (ETH_IRQ, eth_int);
 
}
}
 
 
/* Returns pointer to next free buffer; NULL if none available */
/* Returns pointer to next free buffer; NULL if none available */
void *eth_get_tx_buf ()
void *eth_get_tx_buf ()
{
{
Line 318... Line 356...
  if(bd[tx_next].len_status & ETH_TX_BD_READY)
  if(bd[tx_next].len_status & ETH_TX_BD_READY)
    return (void *)0;
    return (void *)0;
 
 
  add = bd[tx_next].addr;
  add = bd[tx_next].addr;
 
 
  tx_next = (tx_next + 1) & ETH_TXBD_NUM_MASK;
  tx_next++;
 
 
  if(tx_next == tx_last)
  if (tx_next == ETH_TXBD_NUM)
      tx_full = 1;
    tx_next = 0;
 
 
 
  // Disabled for now - highly unlikely we'll ever run out of TX buffer spots
 
  //if(tx_next == tx_last)
 
  //tx_full = 1;
 
 
  return (void *)add;
  return (void *)add;
}
}
 
 
/* Send a packet at address */
/* Send a packet at address */
Line 333... Line 375...
{
{
    eth_bd  *bd;
    eth_bd  *bd;
    int i;
    int i;
 
 
#ifdef PRINT_PACKETS  
#ifdef PRINT_PACKETS  
  printf("transmitted packet:\t");
    printf("transmitted packet txbd %d:\t", tx_last);
  print_packet(buf, len);
  print_packet(buf, len);
#endif
#endif
 
 
  bd = (eth_bd *)ETH_BD_BASE;
  bd = (eth_bd *)ETH_BD_BASE;
 
 
Line 359... Line 401...
             bd[tx_last].len_status);
             bd[tx_last].len_status);
      sleep(1000);
      sleep(1000);
      goto retry_eth_send;
      goto retry_eth_send;
    }
    }
  */
  */
  tx_last = (tx_last + 1) & ETH_TXBD_NUM_MASK;
  tx_last++;
 
 
 
  if (tx_last == ETH_TXBD_NUM)
 
    tx_last = 0;
 
 
  tx_full = 0;
  tx_full = 0;
 
 
}
}
 
 
/* Waits for packet and pass it to the upper layers */
/* Waits for packet and pass it to the upper layers */
unsigned long eth_rx (void)
unsigned long
 
eth_rx (void)
{
{
  eth_bd  *bd;
  eth_bd  *bd;
  unsigned long len = 0;
  unsigned long len = 0;
  int i;
  int i;
 
 
Line 411... Line 458...
      bad = 1;
      bad = 1;
    }
    }
 
 
    if(!bad) {
    if(!bad) {
#ifdef PRINT_PACKETS
#ifdef PRINT_PACKETS
      printf("received packet:\t");
      printf("received packet: rxbd %d\t",rx_next);
      print_packet(bd[rx_next].addr, bd[rx_next].len_status >> 16);
      print_packet(bd[rx_next].addr, bd[rx_next].len_status >> 16);
#endif
#endif
 
 
      receive((void *)bd[rx_next].addr, bd[rx_next].len_status >> 16);
      receive((void *)bd[rx_next].addr, bd[rx_next].len_status >> 16);
      len += bd[rx_next].len_status >> 16;
      len += bd[rx_next].len_status >> 16;
    }
    }
 
 
    bd[rx_next].len_status &= ~ETH_RX_BD_STATS;
    bd[rx_next].len_status &= ~ETH_RX_BD_STATS;
    bd[rx_next].len_status |= ETH_RX_BD_EMPTY;
    bd[rx_next].len_status |= ETH_RX_BD_EMPTY;
 
 
    rx_next = (rx_next + 1) & ETH_RXBD_NUM_MASK;
    rx_next++;
 
 
 
    if (rx_next == ETH_RXBD_NUM)
 
      rx_next = 0;
  }
  }
}
}
 
 
void eth_int_enable(void)
void eth_int_enable(void)
{
{

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.