URL
https://opencores.org/ocsvn/or1k/or1k/trunk
Subversion Repositories or1k
[/] [or1k/] [tags/] [nog_patch_34/] [or1ksim/] [testbench/] [eth.c] - Rev 702
Go to most recent revision | Compare with Previous | Blame | View Log
/* Ethernet test */ #include "spr_defs.h" #include "support.h" typedef long off_t; #include "../peripheral/fields.h" #include "../peripheral/ethernet.h" #define ETH_BASE 0x88000000LU #define ETH_INT_LINE 0x15 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_tx_bd_num = (unsigned long *)(ETH_BASE + ETH_TX_BD_NUM), 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); unsigned int_happend; unsigned char r_packet[0x1000]; unsigned char s_packet[1003]; void interrupt_handler() { unsigned x; printf ("Int\n"); switch (*eth_int_source & 0xf) { case 0x1: printf ("Transmit Error.\n"); break; case 0x2: printf ("Receive Buffer\n");break; case 0x4: printf ("Receive Frame\n");break; case 0x8: printf ("Busy\n"); break; case 0x0: printf ("Modem Status.\n"); break; default: printf ("Invalid iir @ %i\n", __LINE__); exit (1); } mtspr(SPR_PICSR, 0); int_happend = 1; } static void set_mac( void ) { *eth_mac_addr0 = 0x04030201LU; *eth_mac_addr1 = 0x00000605LU; } static void transmit_one_packet( void ) { unsigned i; /* Initialize packet */ for ( i = 0; i < sizeof(s_packet); ++ 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); /* Now wait till sent */ while ( TEST_FLAG( eth_bd_base[0], ETH_TX_BD, READY ) ); CLEAR_FLAG(*eth_moder, ETH_MODER, TXEN); } static void transmit_one_packet_int( void ) { unsigned i; /* Initialize packet */ for ( i = 0; i < sizeof(s_packet); ++ i ) s_packet[i] = (unsigned char)i; /* Set Ethernet BD */ SET_FIELD(eth_bd_base[2], ETH_TX_BD, LENGTH, sizeof(s_packet)); eth_bd_base[3] = (unsigned long)s_packet; /* Start Ethernet */ SET_FLAG(eth_bd_base[2], ETH_TX_BD, READY); 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); while ( TEST_FLAG( eth_bd_base[*eth_tx_bd_num], ETH_RX_BD, READY ) ); 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() { printf( "Starting Ethernet test\n" ); set_mac(); /* non iterrupt test */ 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" ); report (0xdeaddead); return 0; }
Go to most recent revision | Compare with Previous | Blame | View Log