Line 49... |
Line 49... |
#include "line-buffer.h"
|
#include "line-buffer.h"
|
#include "packet.h"
|
#include "packet.h"
|
#include "ethmac.h"
|
#include "ethmac.h"
|
|
|
|
|
void close_link (void)
|
/* open a link */
|
|
void init_ethmac()
|
{
|
{
|
/* Disable EthMac interrupts in Ethmac core */
|
/* initialize the packet rx buffer */
|
*(unsigned int *) ( ADR_ETHMAC_INT_MASK ) = 0x0;
|
init_packet();
|
|
|
/* Disable Ethmac interrupt in interrupt controller */
|
|
*(unsigned int *) ( ADR_AMBER_IC_IRQ0_ENABLECLR ) = 0x100;
|
|
|
|
/* Disable Rx & Tx - MODER Register
|
|
[15] = Add pads to short frames
|
|
[13] = CRCEN
|
|
[10] = Enable full duplex
|
|
[7] = loopback
|
|
[5] = 1 for promiscuous, 0 rx only frames that match mac address
|
|
[1] = txen
|
|
[0] = rxen */
|
|
*(unsigned int *) ( ADR_ETHMAC_MODER ) = 0xa420;
|
|
|
|
/* Put the PHY into reset */
|
|
phy_rst(0); /* reset is active low */
|
|
|
|
|
/* open ethernet port and wait for connection requests
|
|
keep trying forever */
|
|
while (!open_link());
|
}
|
}
|
|
|
|
|
|
|
/* return 1 if link comes up */
|
/* return 1 if link comes up */
|
int open_link (void)
|
int open_link (void)
|
{
|
{
|
int packet;
|
int packet;
|
int n;
|
int n;
|
Line 90... |
Line 79... |
*(unsigned int *) ( ADR_ETHMAC_MAC_ADDR0 ) = d32;
|
*(unsigned int *) ( ADR_ETHMAC_MAC_ADDR0 ) = d32;
|
|
|
d32 = self_g.mac[0]<<8|self_g.mac[1];
|
d32 = self_g.mac[0]<<8|self_g.mac[1];
|
*(unsigned int *) ( ADR_ETHMAC_MAC_ADDR1 ) = d32;
|
*(unsigned int *) ( ADR_ETHMAC_MAC_ADDR1 ) = d32;
|
|
|
if (!config_phy()) return 0;
|
if (!init_phy())
|
|
return 0;
|
|
|
/* Write the Receive Packet Buffer Descriptor */
|
/* Write the Receive Packet Buffer Descriptor */
|
/* Buffer Pointer */
|
/* Buffer Pointer */
|
for (packet=0; packet<ETHMAC_RX_BUFFERS; packet++) {
|
for (packet=0; packet<ETHMAC_RX_BUFFERS; packet++) {
|
*(unsigned int *) ( ADR_ETHMAC_BDBASE + 0x204 + packet*8 ) = ETHMAC_RX_BUFFER + packet * 0x1000;
|
*(unsigned int *) ( ADR_ETHMAC_BDBASE + 0x204 + packet*8 ) = ETHMAC_RX_BUFFER + packet * 0x1000;
|
Line 139... |
Line 129... |
|
|
return 1;
|
return 1;
|
}
|
}
|
|
|
|
|
|
|
|
void close_link (void)
|
|
{
|
|
/* Disable EthMac interrupts in Ethmac core */
|
|
*(unsigned int *) ( ADR_ETHMAC_INT_MASK ) = 0x0;
|
|
|
|
/* Disable Ethmac interrupt in interrupt controller */
|
|
*(unsigned int *) ( ADR_AMBER_IC_IRQ0_ENABLECLR ) = 0x100;
|
|
|
|
/* Disable Rx & Tx - MODER Register
|
|
[15] = Add pads to short frames
|
|
[13] = CRCEN
|
|
[10] = Enable full duplex
|
|
[7] = loopback
|
|
[5] = 1 for promiscuous, 0 rx only frames that match mac address
|
|
[1] = txen
|
|
[0] = rxen */
|
|
*(unsigned int *) ( ADR_ETHMAC_MODER ) = 0xa420;
|
|
|
|
/* Put the PHY into reset */
|
|
phy_rst(0); /* reset is active low */
|
|
|
|
}
|
|
|
|
|
void tx_packet(int len)
|
void tx_packet(int len)
|
{
|
{
|
unsigned int status = 0;
|
unsigned int status = 0;
|
|
|
|
|
Line 168... |
Line 183... |
*(unsigned int *) ( ADR_ETHMAC_BDBASE + 0 ) = len<<16 | 0xf800;
|
*(unsigned int *) ( ADR_ETHMAC_BDBASE + 0 ) = len<<16 | 0xf800;
|
}
|
}
|
|
|
|
|
/* returns 1 if link comes up */
|
/* returns 1 if link comes up */
|
int config_phy (void)
|
int init_phy (void)
|
{
|
{
|
int addr;
|
int addr;
|
int bmcr;
|
int bmcr;
|
int stat;
|
int stat;
|
int phy_id;
|
int phy_id;
|
int link_up = 1;
|
int link_up = 1;
|
time_t* link_timer;
|
time_t* link_timer;
|
|
|
link_timer = init_timer();
|
link_timer = new_timer();
|
|
|
/* Bring PHY out of reset */
|
/* Bring PHY out of reset */
|
phy_rst(1); /* reset is active low */
|
phy_rst(1); /* reset is active low */
|
|
|
/* Discover phy addr by searching addrs in order {1,0,2,..., 31} */
|
/* Discover phy addr by searching addrs in order {1,0,2,..., 31} */
|
Line 301... |
Line 316... |
for (buffer=0; buffer<ETHMAC_RX_BUFFERS; buffer++) {
|
for (buffer=0; buffer<ETHMAC_RX_BUFFERS; buffer++) {
|
|
|
rx_buf_status = *(volatile unsigned int *) ( ADR_ETHMAC_BDBASE + 0x200 + buffer*8 );
|
rx_buf_status = *(volatile unsigned int *) ( ADR_ETHMAC_BDBASE + 0x200 + buffer*8 );
|
|
|
if ((rx_buf_status & 0x8000) == 0) {
|
if ((rx_buf_status & 0x8000) == 0) {
|
|
|
parse_rx_packet((char*)(ETHMAC_RX_BUFFER+buffer*0x1000), rx_packet_g);
|
parse_rx_packet((char*)(ETHMAC_RX_BUFFER+buffer*0x1000), rx_packet_g);
|
|
|
/* set empty flag again */
|
/* set empty flag again */
|
if (buffer == ETHMAC_RX_BUFFERS-1) /* last receive buffer ? */
|
if (buffer == ETHMAC_RX_BUFFERS-1) /* last receive buffer ? */
|
*(unsigned int *) ( ADR_ETHMAC_BDBASE + 0x200 + buffer*8 ) = 0x0000e000;
|
*(unsigned int *) ( ADR_ETHMAC_BDBASE + 0x200 + buffer*8 ) = 0x0000e000;
|