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 705

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 702 ivang
#define ETH_INT_LINE 0x15
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
    case 0x2 : printf ("Transmit Error.\n"); break;
50
    case 0x8 : printf ("Receive Error\n");break;
51
    case 0x4 :
52
        printf ("Receive Frame\n");
53
        CLEAR_FLAG(*eth_moder, ETH_MODER, RXEN);
54
 
55
        len = GET_FIELD(eth_bd_base[*eth_tx_bd_num + 2], ETH_RX_BD, LENGTH);
56
        for (i=0; i<len; i++)
57
          if (r_packet[i] != (unsigned char)i)
58
          {
59
              printf("Failed at byte %d. expect %d, received %d\n", i, i, r_packet[i]);
60
              exit(1);
61
          }
62
        break;
63
    case 0x10: printf ("Busy\n"); break;
64
    case 0x1 :
65
        printf ("Transmit Frame.\n");
66
        CLEAR_FLAG(*eth_moder, ETH_MODER, RXEN);
67
 
68
        break;
69 702 ivang
    default:
70 705 ivang
      printf ("Invalid int @ %0x\n", *eth_int_source & 0x1f);
71 702 ivang
      exit (1);
72
    }
73 705 ivang
    *eth_int_source = 0;
74
 
75 702 ivang
    mtspr(SPR_PICSR, 0);
76
    int_happend = 1;
77
}
78 258 erez
 
79 418 erez
static void set_mac( void )
80 258 erez
{
81 418 erez
        *eth_mac_addr0 = 0x04030201LU;
82
        *eth_mac_addr1 = 0x00000605LU;
83
}
84
 
85
static void transmit_one_packet( void )
86
{
87 258 erez
        unsigned i;
88 702 ivang
 
89 258 erez
        /* Initialize packet */
90 702 ivang
        for ( i = 0; i < sizeof(s_packet); ++ i )
91
                s_packet[i] = (unsigned char)i;
92 258 erez
 
93 702 ivang
        /* Set Ethernet BD */
94 705 ivang
        SET_FIELD(eth_bd_base[tx_bindex], ETH_TX_BD, LENGTH, sizeof(s_packet));
95
        eth_bd_base[tx_bindex + 1] = (unsigned long)s_packet;
96 258 erez
 
97 702 ivang
        /* Start Ethernet */
98 705 ivang
        SET_FLAG(eth_bd_base[tx_bindex], ETH_TX_BD, READY);
99 702 ivang
        SET_FLAG(*eth_moder, ETH_MODER, TXEN);
100
 
101
        /* Now wait till sent */
102 705 ivang
        while ( TEST_FLAG( eth_bd_base[tx_bindex], ETH_TX_BD, READY ) );
103
        CLEAR_FLAG(*eth_moder, ETH_MODER, TXEN);
104
        *eth_int_source = 0;
105 702 ivang
}
106 258 erez
 
107 702 ivang
static void transmit_one_packet_int( void )
108
{
109
        unsigned i;
110
 
111 705 ivang
        int_happend = 0;
112 702 ivang
        /* Initialize packet */
113 705 ivang
        printf("Init\n");
114 702 ivang
        for ( i = 0; i < sizeof(s_packet); ++ i )
115
                s_packet[i] = (unsigned char)i;
116 258 erez
 
117 702 ivang
        /* Set Ethernet BD */
118 705 ivang
        printf("Set BD\n");
119
        SET_FIELD(eth_bd_base[tx_bindex], ETH_TX_BD, LENGTH, sizeof(s_packet));
120
        eth_bd_base[tx_bindex + 1] = (unsigned long)s_packet;
121 702 ivang
 
122 258 erez
        /* Start Ethernet */
123 705 ivang
        printf("Set Flags\n");
124
        SET_FLAG(eth_bd_base[tx_bindex], ETH_TX_BD, READY);
125 702 ivang
        SET_FLAG(*eth_moder, ETH_MODER, TXEN);
126
}
127 258 erez
 
128 702 ivang
 
129
static void receive_one_packet(void)
130
{
131
  unsigned int i;
132
  unsigned int len;
133
 
134 705 ivang
  eth_bd_base[rx_bindex + 1] = (unsigned long)r_packet;
135 702 ivang
 
136 705 ivang
  SET_FLAG(eth_bd_base[rx_bindex], ETH_RX_BD, READY);
137 702 ivang
  SET_FLAG(*eth_moder, ETH_MODER, RXEN);
138
 
139 705 ivang
  while ( TEST_FLAG( eth_bd_base[rx_bindex], ETH_RX_BD, READY ) );
140 702 ivang
  CLEAR_FLAG(*eth_moder, ETH_MODER, RXEN);
141 705 ivang
  *eth_int_source = 0;
142 702 ivang
 
143 705 ivang
  len = GET_FIELD(eth_bd_base[rx_bindex], ETH_RX_BD, LENGTH);
144 702 ivang
  for (i=0; i<len; i++)
145
      if (r_packet[i] != (unsigned char)i)
146
      {
147
          printf("Failed at byte %d. expect %d, received %d\n", i, i, r_packet[i]);
148
          exit(1);
149
      }
150 258 erez
}
151
 
152 702 ivang
static void receive_one_packet_int(void)
153
{
154 705 ivang
  int_happend = 0;
155
  printf("Set BD\n");
156
  eth_bd_base[rx_bindex + 1] = (unsigned long)r_packet;
157 702 ivang
 
158 705 ivang
  printf("SetFlags\n");
159
  SET_FLAG(eth_bd_base[rx_bindex], ETH_RX_BD, READY);
160 702 ivang
  SET_FLAG(*eth_moder, ETH_MODER, RXEN);
161
}
162
 
163 258 erez
int main()
164
{
165
        printf( "Starting Ethernet test\n" );
166
 
167 705 ivang
        tx_bindex = 0;
168
        rx_bindex = *eth_tx_bd_num;
169
 
170 418 erez
        set_mac();
171 705 ivang
 
172
        /*-------------------*/
173 702 ivang
        /* non iterrupt test */
174 705 ivang
        transmit_one_packet();
175
        tx_bindex += 2;
176 702 ivang
        receive_one_packet();
177 705 ivang
        rx_bindex += 2;
178
        transmit_one_packet();
179
        tx_bindex += 2;
180
        receive_one_packet();
181
        rx_bindex += 2;
182 702 ivang
 
183
 
184 705 ivang
        /*-------------------*/
185
        /* interrupt test    */
186
        excpt_int = (unsigned long)interrupt_handler;
187
        /* Enable interrup      ts */
188
        printf("enable ints\n");
189
        mtspr (SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
190
        mtspr (SPR_PICMR, mfspr(SPR_PICMR) | (0x00000001L << ETH_INT_LINE));
191 702 ivang
 
192 705 ivang
        printf("set mask flags\n");
193
        SET_FLAG(*eth_int_mask, ETH_INT_MASK, TXB_M);
194
        transmit_one_packet_int();
195
        printf("waiting for int\n");
196
        while (!int_happend);
197
        CLEAR_FLAG(*eth_int_mask, ETH_INT_MASK, TXB_M);
198 702 ivang
 
199 705 ivang
        printf("seting mask flagx RX\n");
200
        SET_FLAG(*eth_int_mask, ETH_INT_MASK, RXB_M);
201 702 ivang
        receive_one_packet_int();
202 705 ivang
        printf("waiting for int RX\n");
203 702 ivang
        while (!int_happend);
204 705 ivang
        CLEAR_FLAG(*eth_int_mask, ETH_INT_MASK, RXB_M);
205 702 ivang
 
206 705 ivang
 
207 258 erez
        printf( "Ending Ethernet test\n" );
208
 
209 702 ivang
        report (0xdeaddead);
210 310 markom
        return 0;
211 258 erez
}
212
 
213
 

powered by: WebSVN 2.1.0

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