1 |
258 |
erez |
/* Ethernet test */
|
2 |
|
|
|
3 |
|
|
#include "support.h"
|
4 |
|
|
|
5 |
325 |
erez |
typedef long off_t;
|
6 |
258 |
erez |
|
7 |
|
|
#include "../peripheral/fields.h"
|
8 |
|
|
#include "../peripheral/dma.h"
|
9 |
|
|
#include "../peripheral/ethernet.h"
|
10 |
|
|
|
11 |
|
|
#define ETH_BASE 0x88000000LU
|
12 |
|
|
#define DMA_BASE 0x90000000LU
|
13 |
|
|
|
14 |
|
|
typedef volatile unsigned long *REGISTER;
|
15 |
|
|
|
16 |
325 |
erez |
REGISTER
|
17 |
|
|
eth_moder = (unsigned long *)(ETH_BASE + ETH_MODER),
|
18 |
258 |
erez |
eth_int_source = (unsigned long *)(ETH_BASE + ETH_INT_SOURCE),
|
19 |
|
|
eth_int_mask = (unsigned long *)(ETH_BASE + ETH_INT_MASK),
|
20 |
|
|
eth_ipgt = (unsigned long *)(ETH_BASE + ETH_IPGT),
|
21 |
|
|
eth_ipgr1 = (unsigned long *)(ETH_BASE + ETH_IPGR1),
|
22 |
|
|
eth_ipgr2 = (unsigned long *)(ETH_BASE + ETH_IPGR2),
|
23 |
|
|
eth_packetlen = (unsigned long *)(ETH_BASE + ETH_PACKETLEN),
|
24 |
|
|
eth_collconf = (unsigned long *)(ETH_BASE + ETH_COLLCONF),
|
25 |
418 |
erez |
eth_tx_bd_num = (unsigned long *)(ETH_BASE + ETH_TX_BD_NUM),
|
26 |
258 |
erez |
eth_controlmoder = (unsigned long *)(ETH_BASE + ETH_CTRLMODER),
|
27 |
|
|
eth_miimoder = (unsigned long *)(ETH_BASE + ETH_MIIMODER),
|
28 |
|
|
eth_miicommand = (unsigned long *)(ETH_BASE + ETH_MIICOMMAND),
|
29 |
|
|
eth_miiaddress = (unsigned long *)(ETH_BASE + ETH_MIIADDRESS),
|
30 |
|
|
eth_miitx_data = (unsigned long *)(ETH_BASE + ETH_MIITX_DATA),
|
31 |
|
|
eth_miirx_data = (unsigned long *)(ETH_BASE + ETH_MIIRX_DATA),
|
32 |
|
|
eth_miistatus = (unsigned long *)(ETH_BASE + ETH_MIISTATUS),
|
33 |
|
|
eth_mac_addr0 = (unsigned long *)(ETH_BASE + ETH_MAC_ADDR0),
|
34 |
|
|
eth_mac_addr1 = (unsigned long *)(ETH_BASE + ETH_MAC_ADDR1),
|
35 |
|
|
eth_bd_base = (unsigned long *)(ETH_BASE + ETH_BD_BASE),
|
36 |
|
|
dma_csr = (unsigned long *)(DMA_BASE + DMA_CSR),
|
37 |
|
|
dma_int_msk_a = (unsigned long *)(DMA_BASE + DMA_INT_MSK_A),
|
38 |
|
|
dma_int_msk_b = (unsigned long *)(DMA_BASE + DMA_INT_MSK_B),
|
39 |
|
|
dma_int_src_a = (unsigned long *)(DMA_BASE + DMA_INT_SRC_A),
|
40 |
|
|
dma_int_src_b = (unsigned long *)(DMA_BASE + DMA_INT_SRC_B),
|
41 |
|
|
dma_ch0_csr = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_CSR),
|
42 |
|
|
dma_ch0_sz = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_SZ),
|
43 |
|
|
dma_ch0_a0 = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_A0),
|
44 |
|
|
dma_ch0_am0 = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_AM0),
|
45 |
|
|
dma_ch0_a1 = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_A1),
|
46 |
|
|
dma_ch0_am1 = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_AM1),
|
47 |
|
|
dma_ch0_desc = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_DESC);
|
48 |
|
|
|
49 |
|
|
struct DMA_DESCRIPTOR
|
50 |
|
|
{
|
51 |
|
|
unsigned long csr;
|
52 |
|
|
unsigned long adr0;
|
53 |
|
|
unsigned long adr1;
|
54 |
|
|
unsigned long next;
|
55 |
|
|
};
|
56 |
|
|
|
57 |
418 |
erez |
static void set_mac( void )
|
58 |
258 |
erez |
{
|
59 |
418 |
erez |
*eth_mac_addr0 = 0x04030201LU;
|
60 |
|
|
*eth_mac_addr1 = 0x00000605LU;
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
static void transmit_one_packet( void )
|
64 |
|
|
{
|
65 |
258 |
erez |
unsigned i;
|
66 |
|
|
unsigned char packet[1003];
|
67 |
|
|
struct DMA_DESCRIPTOR desc;
|
68 |
|
|
|
69 |
|
|
/* Initialize packet */
|
70 |
|
|
for ( i = 0; i < sizeof(packet); ++ i )
|
71 |
|
|
packet[i] = (unsigned char)i;
|
72 |
|
|
|
73 |
|
|
/* Set Ethernet BD size */
|
74 |
|
|
*eth_bd_base = sizeof(packet) << ETH_TX_BD_LENGTH_OFFSET;
|
75 |
|
|
|
76 |
|
|
/* Set dma stuff */
|
77 |
|
|
desc.csr = 1600; /* transfer size; Ethernet will stop the DMA after packet is sent */
|
78 |
|
|
desc.adr0 = (unsigned long)packet;
|
79 |
|
|
desc.adr1 = ETH_BASE + ETH_DMA_RX_TX;
|
80 |
|
|
desc.csr |= FLAG_MASK( DMA_DESC_CSR, EOL ) | FLAG_MASK( DMA_DESC_CSR, INC_SRC );
|
81 |
|
|
desc.next = 0xDEADDEADUL; /* just to help debugging */
|
82 |
|
|
*dma_ch0_sz = 1UL << DMA_CH_SZ_CHK_SZ_OFFSET; /* Chunk size = 1 word */
|
83 |
|
|
*dma_ch0_desc = (unsigned long)&desc; /* Tell DMA channel where the descriptor is */
|
84 |
|
|
|
85 |
|
|
/* Start DMA (it will wait for request from Ethernet) */
|
86 |
|
|
*dma_ch0_csr = FLAG_MASK( DMA_CH_CSR, CH_EN ) /* Enable channel */ |
|
87 |
|
|
FLAG_MASK( DMA_CH_CSR, USE_ED ) /* Use linked lists */ |
|
88 |
|
|
FLAG_MASK( DMA_CH_CSR, MODE ) /* Wait for HW handshake */ |
|
89 |
|
|
FLAG_MASK( DMA_CH_CSR, DST_SEL ) /* Interface 1 is the destination (meaningless for simulation) */;
|
90 |
|
|
|
91 |
|
|
/* Start Ethernet */
|
92 |
|
|
*eth_bd_base |= FLAG_MASK( ETH_TX_BD, READY ); /* signal BD as ready */
|
93 |
|
|
*eth_moder |= FLAG_MASK( ETH_MODER, TXEN ) | FLAG_MASK( ETH_MODER, DMAEN );
|
94 |
|
|
|
95 |
|
|
/* Now wait till DMA finishes */
|
96 |
|
|
while ( TEST_FLAG( *dma_ch0_csr, DMA_CH_CSR, BUSY ) )
|
97 |
|
|
;
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
int main()
|
102 |
|
|
{
|
103 |
|
|
printf( "Starting Ethernet test\n" );
|
104 |
|
|
|
105 |
418 |
erez |
set_mac();
|
106 |
258 |
erez |
transmit_one_packet();
|
107 |
|
|
|
108 |
|
|
printf( "Ending Ethernet test\n" );
|
109 |
|
|
|
110 |
310 |
markom |
report (0xdeaddead);
|
111 |
|
|
return 0;
|
112 |
258 |
erez |
}
|
113 |
|
|
|
114 |
|
|
|