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

Subversion Repositories or1k

[/] [or1k/] [branches/] [stable_0_2_x/] [or1ksim/] [testbench/] [eth.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 258 erez
/* Ethernet test */
2
 
3 702 ivang
#include "spr_defs.h"
4 258 erez
#include "support.h"
5 970 simons
#include "board.h"
6 258 erez
 
7 325 erez
typedef long off_t;
8 258 erez
 
9
#include "../peripheral/fields.h"
10
#include "../peripheral/ethernet.h"
11
 
12
typedef volatile unsigned long *REGISTER;
13
 
14 325 erez
REGISTER
15 702 ivang
    eth_moder = (unsigned long *)(ETH_BASE + ETH_MODER),
16 258 erez
        eth_int_source = (unsigned long *)(ETH_BASE + ETH_INT_SOURCE),
17
        eth_int_mask = (unsigned long *)(ETH_BASE + ETH_INT_MASK),
18
        eth_ipgt = (unsigned long *)(ETH_BASE + ETH_IPGT),
19
        eth_ipgr1 = (unsigned long *)(ETH_BASE + ETH_IPGR1),
20
        eth_ipgr2 = (unsigned long *)(ETH_BASE + ETH_IPGR2),
21
        eth_packetlen = (unsigned long *)(ETH_BASE + ETH_PACKETLEN),
22
        eth_collconf = (unsigned long *)(ETH_BASE + ETH_COLLCONF),
23 418 erez
        eth_tx_bd_num = (unsigned long *)(ETH_BASE + ETH_TX_BD_NUM),
24 258 erez
        eth_controlmoder = (unsigned long *)(ETH_BASE + ETH_CTRLMODER),
25
        eth_miimoder = (unsigned long *)(ETH_BASE + ETH_MIIMODER),
26
        eth_miicommand = (unsigned long *)(ETH_BASE + ETH_MIICOMMAND),
27
        eth_miiaddress = (unsigned long *)(ETH_BASE + ETH_MIIADDRESS),
28
        eth_miitx_data = (unsigned long *)(ETH_BASE + ETH_MIITX_DATA),
29
        eth_miirx_data = (unsigned long *)(ETH_BASE + ETH_MIIRX_DATA),
30
        eth_miistatus = (unsigned long *)(ETH_BASE + ETH_MIISTATUS),
31
        eth_mac_addr0 = (unsigned long *)(ETH_BASE + ETH_MAC_ADDR0),
32
        eth_mac_addr1 = (unsigned long *)(ETH_BASE + ETH_MAC_ADDR1),
33 702 ivang
        eth_bd_base = (unsigned long *)(ETH_BASE + ETH_BD_BASE);
34 258 erez
 
35 970 simons
volatile unsigned int_happend;
36 705 ivang
unsigned char r_packet[2000];
37 702 ivang
unsigned char s_packet[1003];
38 705 ivang
unsigned tx_bindex;
39
unsigned rx_bindex;
40 702 ivang
 
41
void interrupt_handler()
42 258 erez
{
43 705 ivang
    unsigned i,len;
44
 
45 1024 simons
    printf ("Int\n");
46 705 ivang
    switch (*eth_int_source & 0x7f) {
47 836 ivang
    case 0x2 :
48 1024 simons
        printf ("Transmit Error.\n");
49 836 ivang
        *eth_int_source = 0x2;
50
         break;
51
    case 0x8 :
52 1024 simons
        printf ("Receive Error\n");
53 836 ivang
        *eth_int_source = 0x8;
54
        break;
55 705 ivang
    case 0x4 :
56 1024 simons
        printf ("Receive Frame\n");
57 836 ivang
        *eth_int_source = 0x4;
58
 
59 705 ivang
        CLEAR_FLAG(*eth_moder, ETH_MODER, RXEN);
60
 
61 1024 simons
        len = GET_FIELD(eth_bd_base[(*eth_tx_bd_num << 1) + 2], ETH_RX_BD, LENGTH);
62 705 ivang
        for (i=0; i<len; i++)
63
          if (r_packet[i] != (unsigned char)i)
64
          {
65 1024 simons
              printf("Failed at byte %d. expect %d, received %d\n", i, i, r_packet[i]);
66 705 ivang
              exit(1);
67
          }
68
        break;
69 836 ivang
    case 0x10:
70 1024 simons
        printf ("Busy\n");
71 836 ivang
        *eth_int_source = 0x10;
72
        break;
73 705 ivang
    case 0x1 :
74 1024 simons
        printf ("Transmit Frame.\n");
75 836 ivang
        *eth_int_source = 0x1;
76
        CLEAR_FLAG(*eth_moder, ETH_MODER, TXEN);
77 705 ivang
 
78
        break;
79 702 ivang
    default:
80 1024 simons
        printf ("Invalid int @ %0x\n", (unsigned int)*eth_int_source & 0x7f);
81 836 ivang
        *eth_int_source = 0x7f;
82
        exit (1);
83 702 ivang
    }
84 705 ivang
 
85 702 ivang
    mtspr(SPR_PICSR, 0);
86
    int_happend = 1;
87
}
88 258 erez
 
89 418 erez
static void set_mac( void )
90 258 erez
{
91 418 erez
        *eth_mac_addr0 = 0x04030201LU;
92
        *eth_mac_addr1 = 0x00000605LU;
93
}
94
 
95
static void transmit_one_packet( void )
96
{
97 258 erez
        unsigned i;
98 702 ivang
 
99 258 erez
        /* Initialize packet */
100 702 ivang
        for ( i = 0; i < sizeof(s_packet); ++ i )
101
                s_packet[i] = (unsigned char)i;
102 258 erez
 
103 702 ivang
        /* Set Ethernet BD */
104 705 ivang
        SET_FIELD(eth_bd_base[tx_bindex], ETH_TX_BD, LENGTH, sizeof(s_packet));
105
        eth_bd_base[tx_bindex + 1] = (unsigned long)s_packet;
106 258 erez
 
107 702 ivang
        /* Start Ethernet */
108 705 ivang
        SET_FLAG(eth_bd_base[tx_bindex], ETH_TX_BD, READY);
109 702 ivang
        SET_FLAG(*eth_moder, ETH_MODER, TXEN);
110
 
111
        /* Now wait till sent */
112 705 ivang
        while ( TEST_FLAG( eth_bd_base[tx_bindex], ETH_TX_BD, READY ) );
113
        CLEAR_FLAG(*eth_moder, ETH_MODER, TXEN);
114 836 ivang
        *eth_int_source = 0x7f;
115 702 ivang
}
116 258 erez
 
117 702 ivang
static void transmit_one_packet_int( void )
118
{
119
        unsigned i;
120
 
121 705 ivang
        int_happend = 0;
122 702 ivang
        /* Initialize packet */
123 1024 simons
        printf("Init\n");
124 702 ivang
        for ( i = 0; i < sizeof(s_packet); ++ i )
125
                s_packet[i] = (unsigned char)i;
126 258 erez
 
127 702 ivang
        /* Set Ethernet BD */
128 1024 simons
        printf("Set BD\n");
129 705 ivang
        SET_FIELD(eth_bd_base[tx_bindex], ETH_TX_BD, LENGTH, sizeof(s_packet));
130
        eth_bd_base[tx_bindex + 1] = (unsigned long)s_packet;
131 702 ivang
 
132 258 erez
        /* Start Ethernet */
133 1024 simons
        printf("Set Flags\n");
134 970 simons
        SET_FLAG(eth_bd_base[tx_bindex], ETH_TX_BD, IRQ);
135 705 ivang
        SET_FLAG(eth_bd_base[tx_bindex], ETH_TX_BD, READY);
136 702 ivang
        SET_FLAG(*eth_moder, ETH_MODER, TXEN);
137
}
138 258 erez
 
139 702 ivang
 
140
static void receive_one_packet(void)
141
{
142
  unsigned int i;
143
  unsigned int len;
144
 
145 705 ivang
  eth_bd_base[rx_bindex + 1] = (unsigned long)r_packet;
146 702 ivang
 
147 705 ivang
  SET_FLAG(eth_bd_base[rx_bindex], ETH_RX_BD, READY);
148 702 ivang
  SET_FLAG(*eth_moder, ETH_MODER, RXEN);
149
 
150 705 ivang
  while ( TEST_FLAG( eth_bd_base[rx_bindex], ETH_RX_BD, READY ) );
151 702 ivang
  CLEAR_FLAG(*eth_moder, ETH_MODER, RXEN);
152 836 ivang
  *eth_int_source = 0x7f;
153 702 ivang
 
154 705 ivang
  len = GET_FIELD(eth_bd_base[rx_bindex], ETH_RX_BD, LENGTH);
155 702 ivang
  for (i=0; i<len; i++)
156
      if (r_packet[i] != (unsigned char)i)
157
      {
158 1024 simons
          printf("Failed at byte %d. expect %d, received %d\n", i, i, r_packet[i]);
159 702 ivang
          exit(1);
160
      }
161 258 erez
}
162
 
163 702 ivang
static void receive_one_packet_int(void)
164
{
165 705 ivang
  int_happend = 0;
166 1024 simons
  printf("Set BD\n");
167 705 ivang
  eth_bd_base[rx_bindex + 1] = (unsigned long)r_packet;
168 702 ivang
 
169 1024 simons
  printf("SetFlags\n");
170 970 simons
  SET_FLAG(eth_bd_base[rx_bindex], ETH_RX_BD, IRQ);
171 705 ivang
  SET_FLAG(eth_bd_base[rx_bindex], ETH_RX_BD, READY);
172 702 ivang
  SET_FLAG(*eth_moder, ETH_MODER, RXEN);
173
}
174
 
175 258 erez
int main()
176
{
177 1024 simons
        printf( "Starting Ethernet test\n" );
178 258 erez
 
179 705 ivang
        tx_bindex = 0;
180 1024 simons
        rx_bindex = *eth_tx_bd_num << 1;
181 705 ivang
 
182 418 erez
        set_mac();
183 705 ivang
 
184
        /*-------------------*/
185 702 ivang
        /* non iterrupt test */
186 705 ivang
        transmit_one_packet();
187
        tx_bindex += 2;
188 702 ivang
        receive_one_packet();
189 705 ivang
        rx_bindex += 2;
190
        transmit_one_packet();
191
        tx_bindex += 2;
192
        receive_one_packet();
193
        rx_bindex += 2;
194 702 ivang
 
195
 
196 705 ivang
        /*-------------------*/
197
        /* interrupt test    */
198
        excpt_int = (unsigned long)interrupt_handler;
199
        /* Enable interrup      ts */
200 1024 simons
        printf("enable ints\n");
201 705 ivang
        mtspr (SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
202 970 simons
        mtspr (SPR_PICMR, mfspr(SPR_PICMR) | (0x00000001L << ETH_IRQ));
203 702 ivang
 
204 1024 simons
        printf("set mask flags TX\n");
205 705 ivang
        SET_FLAG(*eth_int_mask, ETH_INT_MASK, TXB_M);
206
        transmit_one_packet_int();
207 836 ivang
        tx_bindex += 2;
208 1024 simons
        printf("waiting for int\n");
209 705 ivang
        while (!int_happend);
210
        CLEAR_FLAG(*eth_int_mask, ETH_INT_MASK, TXB_M);
211 702 ivang
 
212 1024 simons
        printf("seting mask flag RX\n");
213 705 ivang
        SET_FLAG(*eth_int_mask, ETH_INT_MASK, RXB_M);
214 702 ivang
        receive_one_packet_int();
215 836 ivang
        rx_bindex += 2;
216 1024 simons
        printf("waiting for int\n");
217 702 ivang
        while (!int_happend);
218 705 ivang
        CLEAR_FLAG(*eth_int_mask, ETH_INT_MASK, RXB_M);
219 702 ivang
 
220 705 ivang
 
221 1024 simons
        printf( "Ending Ethernet test\n" );
222 258 erez
 
223 702 ivang
        report (0xdeaddead);
224 838 ivang
        exit(0);
225 258 erez
}
226
 
227
 

powered by: WebSVN 2.1.0

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