Line 1... |
Line 1... |
/* Ethernet test */
|
/* Ethernet test */
|
|
|
|
#include "spr_defs.h"
|
#include "support.h"
|
#include "support.h"
|
|
|
typedef long off_t;
|
typedef long off_t;
|
|
|
#include "../peripheral/fields.h"
|
#include "../peripheral/fields.h"
|
#include "../peripheral/dma.h"
|
|
#include "../peripheral/ethernet.h"
|
#include "../peripheral/ethernet.h"
|
|
|
#define ETH_BASE 0x88000000LU
|
#define ETH_BASE 0x88000000LU
|
#define DMA_BASE 0x90000000LU
|
#define ETH_INT_LINE 0x15
|
|
|
typedef volatile unsigned long *REGISTER;
|
typedef volatile unsigned long *REGISTER;
|
|
|
REGISTER
|
REGISTER
|
eth_moder = (unsigned long *)(ETH_BASE + ETH_MODER),
|
eth_moder = (unsigned long *)(ETH_BASE + ETH_MODER),
|
Line 30... |
Line 30... |
eth_miitx_data = (unsigned long *)(ETH_BASE + ETH_MIITX_DATA),
|
eth_miitx_data = (unsigned long *)(ETH_BASE + ETH_MIITX_DATA),
|
eth_miirx_data = (unsigned long *)(ETH_BASE + ETH_MIIRX_DATA),
|
eth_miirx_data = (unsigned long *)(ETH_BASE + ETH_MIIRX_DATA),
|
eth_miistatus = (unsigned long *)(ETH_BASE + ETH_MIISTATUS),
|
eth_miistatus = (unsigned long *)(ETH_BASE + ETH_MIISTATUS),
|
eth_mac_addr0 = (unsigned long *)(ETH_BASE + ETH_MAC_ADDR0),
|
eth_mac_addr0 = (unsigned long *)(ETH_BASE + ETH_MAC_ADDR0),
|
eth_mac_addr1 = (unsigned long *)(ETH_BASE + ETH_MAC_ADDR1),
|
eth_mac_addr1 = (unsigned long *)(ETH_BASE + ETH_MAC_ADDR1),
|
eth_bd_base = (unsigned long *)(ETH_BASE + ETH_BD_BASE),
|
eth_bd_base = (unsigned long *)(ETH_BASE + ETH_BD_BASE);
|
dma_csr = (unsigned long *)(DMA_BASE + DMA_CSR),
|
|
dma_int_msk_a = (unsigned long *)(DMA_BASE + DMA_INT_MSK_A),
|
unsigned int_happend;
|
dma_int_msk_b = (unsigned long *)(DMA_BASE + DMA_INT_MSK_B),
|
unsigned char r_packet[0x1000];
|
dma_int_src_a = (unsigned long *)(DMA_BASE + DMA_INT_SRC_A),
|
unsigned char s_packet[1003];
|
dma_int_src_b = (unsigned long *)(DMA_BASE + DMA_INT_SRC_B),
|
|
dma_ch0_csr = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_CSR),
|
|
dma_ch0_sz = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_SZ),
|
void interrupt_handler()
|
dma_ch0_a0 = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_A0),
|
{
|
dma_ch0_am0 = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_AM0),
|
unsigned x;
|
dma_ch0_a1 = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_A1),
|
printf ("Int\n");
|
dma_ch0_am1 = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_AM1),
|
switch (*eth_int_source & 0xf) {
|
dma_ch0_desc = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_DESC);
|
case 0x1: printf ("Transmit Error.\n"); break;
|
|
case 0x2: printf ("Receive Buffer\n");break;
|
struct DMA_DESCRIPTOR
|
case 0x4: printf ("Receive Frame\n");break;
|
{
|
case 0x8: printf ("Busy\n"); break;
|
unsigned long csr;
|
case 0x0: printf ("Modem Status.\n"); break;
|
unsigned long adr0;
|
default:
|
unsigned long adr1;
|
printf ("Invalid iir @ %i\n", __LINE__);
|
unsigned long next;
|
exit (1);
|
};
|
}
|
|
mtspr(SPR_PICSR, 0);
|
|
int_happend = 1;
|
|
}
|
|
|
static void set_mac( void )
|
static void set_mac( void )
|
{
|
{
|
*eth_mac_addr0 = 0x04030201LU;
|
*eth_mac_addr0 = 0x04030201LU;
|
*eth_mac_addr1 = 0x00000605LU;
|
*eth_mac_addr1 = 0x00000605LU;
|
}
|
}
|
|
|
static void transmit_one_packet( void )
|
static void transmit_one_packet( void )
|
{
|
{
|
unsigned i;
|
unsigned i;
|
unsigned char packet[1003];
|
|
struct DMA_DESCRIPTOR desc;
|
|
|
|
/* Initialize packet */
|
/* Initialize packet */
|
for ( i = 0; i < sizeof(packet); ++ i )
|
for ( i = 0; i < sizeof(s_packet); ++ i )
|
packet[i] = (unsigned char)i;
|
s_packet[i] = (unsigned char)i;
|
|
|
|
/* Set Ethernet BD */
|
|
SET_FIELD(eth_bd_base[0], ETH_TX_BD, LENGTH, sizeof(s_packet));
|
|
eth_bd_base[1] = (unsigned long)s_packet;
|
|
|
|
/* Start Ethernet */
|
|
SET_FLAG(eth_bd_base[0], ETH_TX_BD, READY);
|
|
SET_FLAG(*eth_moder, ETH_MODER, TXEN);
|
|
|
/* Set Ethernet BD size */
|
/* Now wait till sent */
|
*eth_bd_base = sizeof(packet) << ETH_TX_BD_LENGTH_OFFSET;
|
while ( TEST_FLAG( eth_bd_base[0], ETH_TX_BD, READY ) );
|
|
CLEAR_FLAG(*eth_moder, ETH_MODER, TXEN);
|
|
}
|
|
|
/* Set dma stuff */
|
static void transmit_one_packet_int( void )
|
desc.csr = 1600; /* transfer size; Ethernet will stop the DMA after packet is sent */
|
{
|
desc.adr0 = (unsigned long)packet;
|
unsigned i;
|
desc.adr1 = ETH_BASE + ETH_DMA_RX_TX;
|
|
desc.csr |= FLAG_MASK( DMA_DESC_CSR, EOL ) | FLAG_MASK( DMA_DESC_CSR, INC_SRC );
|
/* Initialize packet */
|
desc.next = 0xDEADDEADUL; /* just to help debugging */
|
for ( i = 0; i < sizeof(s_packet); ++ i )
|
*dma_ch0_sz = 1UL << DMA_CH_SZ_CHK_SZ_OFFSET; /* Chunk size = 1 word */
|
s_packet[i] = (unsigned char)i;
|
*dma_ch0_desc = (unsigned long)&desc; /* Tell DMA channel where the descriptor is */
|
|
|
/* Set Ethernet BD */
|
/* Start DMA (it will wait for request from Ethernet) */
|
SET_FIELD(eth_bd_base[2], ETH_TX_BD, LENGTH, sizeof(s_packet));
|
*dma_ch0_csr = FLAG_MASK( DMA_CH_CSR, CH_EN ) /* Enable channel */ |
|
eth_bd_base[3] = (unsigned long)s_packet;
|
FLAG_MASK( DMA_CH_CSR, USE_ED ) /* Use linked lists */ |
|
|
FLAG_MASK( DMA_CH_CSR, MODE ) /* Wait for HW handshake */ |
|
|
FLAG_MASK( DMA_CH_CSR, DST_SEL ) /* Interface 1 is the destination (meaningless for simulation) */;
|
|
|
|
/* Start Ethernet */
|
/* Start Ethernet */
|
*eth_bd_base |= FLAG_MASK( ETH_TX_BD, READY ); /* signal BD as ready */
|
SET_FLAG(eth_bd_base[2], ETH_TX_BD, READY);
|
*eth_moder |= FLAG_MASK( ETH_MODER, TXEN ) | FLAG_MASK( ETH_MODER, DMAEN );
|
SET_FLAG(*eth_moder, ETH_MODER, TXEN);
|
|
}
|
|
|
|
|
|
static void receive_one_packet(void)
|
|
{
|
|
unsigned int i;
|
|
unsigned int len;
|
|
|
|
eth_bd_base[*eth_tx_bd_num + 1] = (unsigned long)r_packet;
|
|
|
|
SET_FLAG(eth_bd_base[*eth_tx_bd_num], ETH_RX_BD, READY);
|
|
SET_FLAG(*eth_moder, ETH_MODER, RXEN);
|
|
|
/* Now wait till DMA finishes */
|
while ( TEST_FLAG( eth_bd_base[*eth_tx_bd_num], ETH_RX_BD, READY ) );
|
while ( TEST_FLAG( *dma_ch0_csr, DMA_CH_CSR, BUSY ) )
|
CLEAR_FLAG(*eth_moder, ETH_MODER, RXEN);
|
;
|
|
|
len = GET_FIELD(eth_bd_base[*eth_tx_bd_num], ETH_RX_BD, LENGTH);
|
|
for (i=0; i<len; i++)
|
|
if (r_packet[i] != (unsigned char)i)
|
|
{
|
|
printf("Failed at byte %d. expect %d, received %d\n", i, i, r_packet[i]);
|
|
exit(1);
|
}
|
}
|
|
}
|
|
|
|
static void receive_one_packet_int(void)
|
|
{
|
|
unsigned int i;
|
|
unsigned int len;
|
|
|
|
eth_bd_base[*eth_tx_bd_num + 3] = (unsigned long)r_packet;
|
|
|
|
SET_FLAG(eth_bd_base[*eth_tx_bd_num + 2], ETH_RX_BD, READY);
|
|
SET_FLAG(*eth_moder, ETH_MODER, RXEN);
|
|
|
|
while ( TEST_FLAG( eth_bd_base[*eth_tx_bd_num + 2], ETH_RX_BD, READY ) );
|
|
CLEAR_FLAG(*eth_moder, ETH_MODER, RXEN);
|
|
|
|
len = GET_FIELD(eth_bd_base[*eth_tx_bd_num + 2], ETH_RX_BD, LENGTH);
|
|
for (i=0; i<len; i++)
|
|
if (r_packet[i] != (unsigned char)i)
|
|
{
|
|
printf("Failed at byte %d. expect %d, received %d\n", i, i, r_packet[i]);
|
|
exit(1);
|
|
}
|
|
}
|
|
|
int main()
|
int main()
|
{
|
{
|
printf( "Starting Ethernet test\n" );
|
printf( "Starting Ethernet test\n" );
|
|
|
set_mac();
|
set_mac();
|
|
/* non iterrupt test */
|
transmit_one_packet();
|
transmit_one_packet();
|
|
receive_one_packet();
|
|
|
|
/* interrupt test */
|
|
excpt_int = (unsigned long)interrupt_handler;
|
|
/* Enable interrupts */
|
|
mtspr (SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
|
|
mtspr (SPR_PICMR, mfspr(SPR_PICMR) | (0x00000001L << ETH_INT_LINE));
|
|
|
|
|
|
|
|
transmit_one_packet_int();
|
|
/*
|
|
while (!int_happend);
|
|
receive_one_packet_int();
|
|
while (!int_happend);
|
|
*/
|
|
|
printf( "Ending Ethernet test\n" );
|
printf( "Ending Ethernet test\n" );
|
|
|
report (0xdeaddead);
|
report (0xdeaddead);
|
return 0;
|
return 0;
|