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 836

Go to most recent revision | 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
 
6 325 erez
typedef long off_t;
7 258 erez
 
8
#include "../peripheral/fields.h"
9
#include "../peripheral/ethernet.h"
10
 
11
#define ETH_BASE 0x88000000LU
12 733 ivang
#define ETH_INT_LINE 15
13 258 erez
 
14
typedef volatile unsigned long *REGISTER;
15
 
16 325 erez
REGISTER
17 702 ivang
    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 702 ivang
        eth_bd_base = (unsigned long *)(ETH_BASE + ETH_BD_BASE);
36 258 erez
 
37 702 ivang
unsigned int_happend;
38 705 ivang
unsigned char r_packet[2000];
39 702 ivang
unsigned char s_packet[1003];
40 705 ivang
unsigned tx_bindex;
41
unsigned rx_bindex;
42 702 ivang
 
43
void interrupt_handler()
44 258 erez
{
45 705 ivang
    unsigned i,len;
46
 
47 702 ivang
    printf ("Int\n");
48 705 ivang
    switch (*eth_int_source & 0x7f) {
49 836 ivang
    case 0x2 :
50
        printf ("Transmit Error.\n");
51
        *eth_int_source = 0x2;
52
         break;
53
    case 0x8 :
54
        printf ("Receive Error\n");
55
        *eth_int_source = 0x8;
56
        break;
57 705 ivang
    case 0x4 :
58
        printf ("Receive Frame\n");
59 836 ivang
        *eth_int_source = 0x4;
60
 
61 705 ivang
        CLEAR_FLAG(*eth_moder, ETH_MODER, RXEN);
62
 
63
        len = GET_FIELD(eth_bd_base[*eth_tx_bd_num + 2], ETH_RX_BD, LENGTH);
64
        for (i=0; i<len; i++)
65
          if (r_packet[i] != (unsigned char)i)
66
          {
67
              printf("Failed at byte %d. expect %d, received %d\n", i, i, r_packet[i]);
68
              exit(1);
69
          }
70
        break;
71 836 ivang
    case 0x10:
72
        printf ("Busy\n");
73
        *eth_int_source = 0x10;
74
        break;
75 705 ivang
    case 0x1 :
76
        printf ("Transmit Frame.\n");
77 836 ivang
        *eth_int_source = 0x1;
78
        CLEAR_FLAG(*eth_moder, ETH_MODER, TXEN);
79 705 ivang
 
80
        break;
81 702 ivang
    default:
82 836 ivang
        printf ("Invalid int @ %0x\n", (unsigned int)*eth_int_source & 0x7f);
83
        *eth_int_source = 0x7f;
84
        exit (1);
85 702 ivang
    }
86 705 ivang
 
87 702 ivang
    mtspr(SPR_PICSR, 0);
88
    int_happend = 1;
89
}
90 258 erez
 
91 418 erez
static void set_mac( void )
92 258 erez
{
93 418 erez
        *eth_mac_addr0 = 0x04030201LU;
94
        *eth_mac_addr1 = 0x00000605LU;
95
}
96
 
97
static void transmit_one_packet( void )
98
{
99 258 erez
        unsigned i;
100 702 ivang
 
101 258 erez
        /* Initialize packet */
102 702 ivang
        for ( i = 0; i < sizeof(s_packet); ++ i )
103
                s_packet[i] = (unsigned char)i;
104 258 erez
 
105 702 ivang
        /* Set Ethernet BD */
106 705 ivang
        SET_FIELD(eth_bd_base[tx_bindex], ETH_TX_BD, LENGTH, sizeof(s_packet));
107
        eth_bd_base[tx_bindex + 1] = (unsigned long)s_packet;
108 258 erez
 
109 702 ivang
        /* Start Ethernet */
110 705 ivang
        SET_FLAG(eth_bd_base[tx_bindex], ETH_TX_BD, READY);
111 702 ivang
        SET_FLAG(*eth_moder, ETH_MODER, TXEN);
112
 
113
        /* Now wait till sent */
114 705 ivang
        while ( TEST_FLAG( eth_bd_base[tx_bindex], ETH_TX_BD, READY ) );
115
        CLEAR_FLAG(*eth_moder, ETH_MODER, TXEN);
116 836 ivang
        *eth_int_source = 0x7f;
117 702 ivang
}
118 258 erez
 
119 702 ivang
static void transmit_one_packet_int( void )
120
{
121
        unsigned i;
122
 
123 705 ivang
        int_happend = 0;
124 702 ivang
        /* Initialize packet */
125 705 ivang
        printf("Init\n");
126 702 ivang
        for ( i = 0; i < sizeof(s_packet); ++ i )
127
                s_packet[i] = (unsigned char)i;
128 258 erez
 
129 702 ivang
        /* Set Ethernet BD */
130 705 ivang
        printf("Set BD\n");
131
        SET_FIELD(eth_bd_base[tx_bindex], ETH_TX_BD, LENGTH, sizeof(s_packet));
132
        eth_bd_base[tx_bindex + 1] = (unsigned long)s_packet;
133 702 ivang
 
134 258 erez
        /* Start Ethernet */
135 705 ivang
        printf("Set Flags\n");
136
        SET_FLAG(eth_bd_base[tx_bindex], ETH_TX_BD, READY);
137 702 ivang
        SET_FLAG(*eth_moder, ETH_MODER, TXEN);
138
}
139 258 erez
 
140 702 ivang
 
141
static void receive_one_packet(void)
142
{
143
  unsigned int i;
144
  unsigned int len;
145
 
146 705 ivang
  eth_bd_base[rx_bindex + 1] = (unsigned long)r_packet;
147 702 ivang
 
148 705 ivang
  SET_FLAG(eth_bd_base[rx_bindex], ETH_RX_BD, READY);
149 702 ivang
  SET_FLAG(*eth_moder, ETH_MODER, RXEN);
150
 
151 705 ivang
  while ( TEST_FLAG( eth_bd_base[rx_bindex], ETH_RX_BD, READY ) );
152 702 ivang
  CLEAR_FLAG(*eth_moder, ETH_MODER, RXEN);
153 836 ivang
  *eth_int_source = 0x7f;
154 702 ivang
 
155 705 ivang
  len = GET_FIELD(eth_bd_base[rx_bindex], ETH_RX_BD, LENGTH);
156 702 ivang
  for (i=0; i<len; i++)
157
      if (r_packet[i] != (unsigned char)i)
158
      {
159
          printf("Failed at byte %d. expect %d, received %d\n", i, i, r_packet[i]);
160
          exit(1);
161
      }
162 258 erez
}
163
 
164 702 ivang
static void receive_one_packet_int(void)
165
{
166 705 ivang
  int_happend = 0;
167
  printf("Set BD\n");
168
  eth_bd_base[rx_bindex + 1] = (unsigned long)r_packet;
169 702 ivang
 
170 705 ivang
  printf("SetFlags\n");
171
  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
        printf( "Starting Ethernet test\n" );
178
 
179 705 ivang
        tx_bindex = 0;
180
        rx_bindex = *eth_tx_bd_num;
181
 
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
        printf("enable ints\n");
201
        mtspr (SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
202
        mtspr (SPR_PICMR, mfspr(SPR_PICMR) | (0x00000001L << ETH_INT_LINE));
203 702 ivang
 
204 836 ivang
        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 705 ivang
        printf("waiting for int\n");
209
        while (!int_happend);
210
        CLEAR_FLAG(*eth_int_mask, ETH_INT_MASK, TXB_M);
211 702 ivang
 
212 836 ivang
        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
        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 258 erez
        printf( "Ending Ethernet test\n" );
222
 
223 702 ivang
        report (0xdeaddead);
224 836 ivang
        exit(1);
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.