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

Subversion Repositories or1k

[/] [or1k/] [branches/] [stable_0_1_x/] [or1ksim/] [testbench/] [eth.c] - Blame information for rev 325

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
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
        eth_rx_bd_adr = (unsigned long *)(ETH_BASE + ETH_RX_BD_ADR),
26
        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
void transmit_one_packet( void )
58
{
59
        unsigned i;
60
        unsigned char packet[1003];
61
        struct DMA_DESCRIPTOR desc;
62
 
63
        /* Initialize packet */
64
        for ( i = 0; i < sizeof(packet); ++ i )
65
                packet[i] = (unsigned char)i;
66
 
67
        /* Set Ethernet BD size */
68
        *eth_bd_base = sizeof(packet) << ETH_TX_BD_LENGTH_OFFSET;
69
 
70
        /* Set dma stuff */
71
        desc.csr = 1600; /* transfer size; Ethernet will stop the DMA after packet is sent */
72
        desc.adr0 = (unsigned long)packet;
73
        desc.adr1 = ETH_BASE + ETH_DMA_RX_TX;
74
        desc.csr |= FLAG_MASK( DMA_DESC_CSR, EOL ) | FLAG_MASK( DMA_DESC_CSR, INC_SRC );
75
        desc.next = 0xDEADDEADUL; /* just to help debugging */
76
        *dma_ch0_sz = 1UL << DMA_CH_SZ_CHK_SZ_OFFSET; /* Chunk size = 1 word */
77
        *dma_ch0_desc = (unsigned long)&desc; /* Tell DMA channel where the descriptor is */
78
 
79
        /* Start DMA (it will wait for request from Ethernet) */
80
        *dma_ch0_csr = FLAG_MASK( DMA_CH_CSR, CH_EN ) /* Enable channel */ |
81
                FLAG_MASK( DMA_CH_CSR, USE_ED ) /* Use linked lists */ |
82
                FLAG_MASK( DMA_CH_CSR, MODE ) /* Wait for HW handshake */ |
83
                FLAG_MASK( DMA_CH_CSR, DST_SEL ) /* Interface 1 is the destination (meaningless for simulation) */;
84
 
85
        /* Start Ethernet */
86
        *eth_bd_base |= FLAG_MASK( ETH_TX_BD, READY ); /* signal BD as ready */
87
        *eth_moder |= FLAG_MASK( ETH_MODER, TXEN ) | FLAG_MASK( ETH_MODER, DMAEN );
88
 
89
        /* Now wait till DMA finishes */
90
        while ( TEST_FLAG( *dma_ch0_csr, DMA_CH_CSR, BUSY ) )
91
                ;
92
}
93
 
94
 
95
int main()
96
{
97
        printf( "Starting Ethernet test\n" );
98
 
99
        transmit_one_packet();
100
 
101
        printf( "Ending Ethernet test\n" );
102
 
103 310 markom
        report (0xdeaddead);
104
        return 0;
105 258 erez
}
106
 
107
 

powered by: WebSVN 2.1.0

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