URL
https://opencores.org/ocsvn/or1k/or1k/trunk
Subversion Repositories or1k
[/] [or1k/] [branches/] [stable_0_2_x/] [or1ksim/] [testbench/] [eth.c] - Rev 258
Go to most recent revision | Compare with Previous | Blame | View Log
/* Ethernet test */ #include "support.h" typedef struct FILE FILE; #include "../peripheral/fields.h" #include "../peripheral/dma.h" #include "../peripheral/ethernet.h" #define ETH_BASE 0x88000000LU #define DMA_BASE 0x90000000LU typedef volatile unsigned long *REGISTER; REGISTER eth_moder = (unsigned long *)(ETH_BASE + ETH_MODER), eth_int_source = (unsigned long *)(ETH_BASE + ETH_INT_SOURCE), eth_int_mask = (unsigned long *)(ETH_BASE + ETH_INT_MASK), eth_ipgt = (unsigned long *)(ETH_BASE + ETH_IPGT), eth_ipgr1 = (unsigned long *)(ETH_BASE + ETH_IPGR1), eth_ipgr2 = (unsigned long *)(ETH_BASE + ETH_IPGR2), eth_packetlen = (unsigned long *)(ETH_BASE + ETH_PACKETLEN), eth_collconf = (unsigned long *)(ETH_BASE + ETH_COLLCONF), eth_rx_bd_adr = (unsigned long *)(ETH_BASE + ETH_RX_BD_ADR), eth_controlmoder = (unsigned long *)(ETH_BASE + ETH_CTRLMODER), eth_miimoder = (unsigned long *)(ETH_BASE + ETH_MIIMODER), eth_miicommand = (unsigned long *)(ETH_BASE + ETH_MIICOMMAND), eth_miiaddress = (unsigned long *)(ETH_BASE + ETH_MIIADDRESS), eth_miitx_data = (unsigned long *)(ETH_BASE + ETH_MIITX_DATA), eth_miirx_data = (unsigned long *)(ETH_BASE + ETH_MIIRX_DATA), eth_miistatus = (unsigned long *)(ETH_BASE + ETH_MIISTATUS), eth_mac_addr0 = (unsigned long *)(ETH_BASE + ETH_MAC_ADDR0), eth_mac_addr1 = (unsigned long *)(ETH_BASE + ETH_MAC_ADDR1), 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), dma_int_msk_b = (unsigned long *)(DMA_BASE + DMA_INT_MSK_B), dma_int_src_a = (unsigned long *)(DMA_BASE + DMA_INT_SRC_A), 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), 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), dma_ch0_a1 = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_A1), dma_ch0_am1 = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_AM1), dma_ch0_desc = (unsigned long *)(DMA_BASE + DMA_CH_BASE + DMA_CH_DESC); struct DMA_DESCRIPTOR { unsigned long csr; unsigned long adr0; unsigned long adr1; unsigned long next; }; void transmit_one_packet( void ) { unsigned i; unsigned char packet[1003]; struct DMA_DESCRIPTOR desc; /* Initialize packet */ for ( i = 0; i < sizeof(packet); ++ i ) packet[i] = (unsigned char)i; /* Set Ethernet BD size */ *eth_bd_base = sizeof(packet) << ETH_TX_BD_LENGTH_OFFSET; /* Set dma stuff */ desc.csr = 1600; /* transfer size; Ethernet will stop the DMA after packet is sent */ desc.adr0 = (unsigned long)packet; desc.adr1 = ETH_BASE + ETH_DMA_RX_TX; desc.csr |= FLAG_MASK( DMA_DESC_CSR, EOL ) | FLAG_MASK( DMA_DESC_CSR, INC_SRC ); desc.next = 0xDEADDEADUL; /* just to help debugging */ *dma_ch0_sz = 1UL << DMA_CH_SZ_CHK_SZ_OFFSET; /* Chunk size = 1 word */ *dma_ch0_desc = (unsigned long)&desc; /* Tell DMA channel where the descriptor is */ /* Start DMA (it will wait for request from Ethernet) */ *dma_ch0_csr = FLAG_MASK( DMA_CH_CSR, CH_EN ) /* Enable channel */ | 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 */ *eth_bd_base |= FLAG_MASK( ETH_TX_BD, READY ); /* signal BD as ready */ *eth_moder |= FLAG_MASK( ETH_MODER, TXEN ) | FLAG_MASK( ETH_MODER, DMAEN ); /* Now wait till DMA finishes */ while ( TEST_FLAG( *dma_ch0_csr, DMA_CH_CSR, BUSY ) ) ; } int main() { printf( "Starting Ethernet test\n" ); transmit_one_packet(); printf( "Ending Ethernet test\n" ); exit( 0 ); }
Go to most recent revision | Compare with Previous | Blame | View Log