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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [testsuite/] [test-code-or1k/] [eth/] [eth.c] - Blame information for rev 90

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 90 jeremybenn
/* eth.c. Test of Or1ksim Ethernet
2
 
3
   Copyright (C) 1999-2006 OpenCores
4
   Copyright (C) 2010 Embecosm Limited
5
 
6
   Contributors various OpenCores participants
7
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
8
 
9
   This file is part of OpenRISC 1000 Architectural Simulator.
10
 
11
   This program is free software; you can redistribute it and/or modify it
12
   under the terms of the GNU General Public License as published by the Free
13
   Software Foundation; either version 3 of the License, or (at your option)
14
   any later version.
15
 
16
   This program is distributed in the hope that it will be useful, but WITHOUT
17
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
19
   more details.
20
 
21
   You should have received a copy of the GNU General Public License along
22
   with this program.  If not, see <http:  www.gnu.org/licenses/>.  */
23
 
24
/* ----------------------------------------------------------------------------
25
   This code is commented throughout for use with Doxygen.
26
   --------------------------------------------------------------------------*/
27
 
28
#include "spr-defs.h"
29
#include "support.h"
30
#include "board.h"
31
 
32
typedef long off_t;
33
 
34
#include "fields.h"
35
#include "eth.h"
36
 
37
typedef volatile unsigned long *REGISTER;
38
 
39
REGISTER
40
    eth_moder = (unsigned long *)(ETH_BASE + ETH_MODER),
41
        eth_int_source = (unsigned long *)(ETH_BASE + ETH_INT_SOURCE),
42
        eth_int_mask = (unsigned long *)(ETH_BASE + ETH_INT_MASK),
43
        eth_ipgt = (unsigned long *)(ETH_BASE + ETH_IPGT),
44
        eth_ipgr1 = (unsigned long *)(ETH_BASE + ETH_IPGR1),
45
        eth_ipgr2 = (unsigned long *)(ETH_BASE + ETH_IPGR2),
46
        eth_packetlen = (unsigned long *)(ETH_BASE + ETH_PACKETLEN),
47
        eth_collconf = (unsigned long *)(ETH_BASE + ETH_COLLCONF),
48
        eth_tx_bd_num = (unsigned long *)(ETH_BASE + ETH_TX_BD_NUM),
49
        eth_controlmoder = (unsigned long *)(ETH_BASE + ETH_CTRLMODER),
50
        eth_miimoder = (unsigned long *)(ETH_BASE + ETH_MIIMODER),
51
        eth_miicommand = (unsigned long *)(ETH_BASE + ETH_MIICOMMAND),
52
        eth_miiaddress = (unsigned long *)(ETH_BASE + ETH_MIIADDRESS),
53
        eth_miitx_data = (unsigned long *)(ETH_BASE + ETH_MIITX_DATA),
54
        eth_miirx_data = (unsigned long *)(ETH_BASE + ETH_MIIRX_DATA),
55
        eth_miistatus = (unsigned long *)(ETH_BASE + ETH_MIISTATUS),
56
        eth_mac_addr0 = (unsigned long *)(ETH_BASE + ETH_MAC_ADDR0),
57
        eth_mac_addr1 = (unsigned long *)(ETH_BASE + ETH_MAC_ADDR1),
58
        eth_bd_base = (unsigned long *)(ETH_BASE + ETH_BD_BASE);
59
 
60
volatile unsigned int_happend;
61
unsigned char r_packet[2000];
62
unsigned char s_packet[1003];
63
unsigned tx_bindex;
64
unsigned rx_bindex;
65
 
66
void interrupt_handler()
67
{
68
    unsigned i,len;
69
 
70
    printf ("Int\n");
71
    switch (*eth_int_source & 0x7f) {
72
    case 0x2 :
73
        printf ("Transmit Error.\n");
74
        *eth_int_source = 0x2;
75
         break;
76
    case 0x8 :
77
        printf ("Receive Error\n");
78
        *eth_int_source = 0x8;
79
        break;
80
    case 0x4 :
81
        printf ("Receive Frame\n");
82
        *eth_int_source = 0x4;
83
 
84
        CLEAR_FLAG(*eth_moder, ETH_MODER, RXEN);
85
 
86
        len = GET_FIELD(eth_bd_base[(*eth_tx_bd_num << 1) + 2], ETH_RX_BD, LENGTH);
87
        for (i=0; i<len; i++)
88
          if (r_packet[i] != (unsigned char)i)
89
          {
90
              printf("Failed at byte %d. expect %d, received %d\n", i, i, r_packet[i]);
91
              exit(1);
92
          }
93
        break;
94
    case 0x10:
95
        printf ("Busy\n");
96
        *eth_int_source = 0x10;
97
        break;
98
    case 0x1 :
99
        printf ("Transmit Frame.\n");
100
        *eth_int_source = 0x1;
101
        CLEAR_FLAG(*eth_moder, ETH_MODER, TXEN);
102
 
103
        break;
104
    default:
105
        printf ("Invalid int @ %0x\n", (unsigned int)*eth_int_source & 0x7f);
106
        *eth_int_source = 0x7f;
107
        exit (1);
108
    }
109
 
110
    mtspr(SPR_PICSR, 0);
111
    int_happend = 1;
112
}
113
 
114
static void set_mac( void )
115
{
116
        *eth_mac_addr0 = 0x04030201LU;
117
        *eth_mac_addr1 = 0x00000605LU;
118
}
119
 
120
static void transmit_one_packet( void )
121
{
122
        unsigned i;
123
 
124
        /* Initialize packet */
125
        for ( i = 0; i < sizeof(s_packet); ++ i )
126
                s_packet[i] = (unsigned char)i;
127
 
128
        /* Set Ethernet BD */
129
        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
 
132
        /* Start Ethernet */
133
        SET_FLAG(eth_bd_base[tx_bindex], ETH_TX_BD, READY);
134
        SET_FLAG(*eth_moder, ETH_MODER, TXEN);
135
 
136
        /* Now wait till sent */
137
        while ( TEST_FLAG( eth_bd_base[tx_bindex], ETH_TX_BD, READY ) );
138
        CLEAR_FLAG(*eth_moder, ETH_MODER, TXEN);
139
        *eth_int_source = 0x7f;
140
}
141
 
142
static void transmit_one_packet_int( void )
143
{
144
        unsigned i;
145
 
146
        int_happend = 0;
147
        /* Initialize packet */
148
        printf("Init\n");
149
        for ( i = 0; i < sizeof(s_packet); ++ i )
150
                s_packet[i] = (unsigned char)i;
151
 
152
        /* Set Ethernet BD */
153
        printf("Set BD\n");
154
        SET_FIELD(eth_bd_base[tx_bindex], ETH_TX_BD, LENGTH, sizeof(s_packet));
155
        eth_bd_base[tx_bindex + 1] = (unsigned long)s_packet;
156
 
157
        /* Start Ethernet */
158
        printf("Set Flags\n");
159
        SET_FLAG(eth_bd_base[tx_bindex], ETH_TX_BD, IRQ);
160
        SET_FLAG(eth_bd_base[tx_bindex], ETH_TX_BD, READY);
161
        SET_FLAG(*eth_moder, ETH_MODER, TXEN);
162
}
163
 
164
 
165
static void receive_one_packet(void)
166
{
167
  unsigned int i;
168
  unsigned int len;
169
 
170
  eth_bd_base[rx_bindex + 1] = (unsigned long)r_packet;
171
 
172
  SET_FLAG(eth_bd_base[rx_bindex], ETH_RX_BD, READY);
173
  SET_FLAG(*eth_moder, ETH_MODER, RXEN);
174
 
175
  while ( TEST_FLAG( eth_bd_base[rx_bindex], ETH_RX_BD, READY ) );
176
  CLEAR_FLAG(*eth_moder, ETH_MODER, RXEN);
177
  *eth_int_source = 0x7f;
178
 
179
  len = GET_FIELD(eth_bd_base[rx_bindex], ETH_RX_BD, LENGTH);
180
  for (i=0; i<len; i++)
181
      if (r_packet[i] != (unsigned char)i)
182
      {
183
          printf("Failed at byte %d. expect %d, received %d\n", i, i, r_packet[i]);
184
          exit(1);
185
      }
186
}
187
 
188
static void receive_one_packet_int(void)
189
{
190
  int_happend = 0;
191
  printf("Set BD\n");
192
  eth_bd_base[rx_bindex + 1] = (unsigned long)r_packet;
193
 
194
  printf("SetFlags\n");
195
  SET_FLAG(eth_bd_base[rx_bindex], ETH_RX_BD, IRQ);
196
  SET_FLAG(eth_bd_base[rx_bindex], ETH_RX_BD, READY);
197
  SET_FLAG(*eth_moder, ETH_MODER, RXEN);
198
}
199
 
200
int main()
201
{
202
        printf( "Starting Ethernet test\n" );
203
 
204
        tx_bindex = 0;
205
        rx_bindex = *eth_tx_bd_num << 1;
206
 
207
        set_mac();
208
 
209
        /*-------------------*/
210
        /* non iterrupt test */
211
        transmit_one_packet();
212
        tx_bindex += 2;
213
        receive_one_packet();
214
        rx_bindex += 2;
215
        transmit_one_packet();
216
        tx_bindex += 2;
217
        receive_one_packet();
218
        rx_bindex += 2;
219
 
220
 
221
        /*-------------------*/
222
        /* interrupt test    */
223
        excpt_int = (unsigned long)interrupt_handler;
224
        /* Enable interrup      ts */
225
        printf("enable ints\n");
226
        mtspr (SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
227
        mtspr (SPR_PICMR, mfspr(SPR_PICMR) | (0x00000001L << ETH_IRQ));
228
 
229
        printf("set mask flags TX\n");
230
        SET_FLAG(*eth_int_mask, ETH_INT_MASK, TXB_M);
231
        transmit_one_packet_int();
232
        tx_bindex += 2;
233
        /* printf("waiting for int\n"); */
234
        while (!int_happend);
235
        CLEAR_FLAG(*eth_int_mask, ETH_INT_MASK, TXB_M);
236
 
237
        printf("seting mask flag RX\n");
238
        SET_FLAG(*eth_int_mask, ETH_INT_MASK, RXB_M);
239
        receive_one_packet_int();
240
        rx_bindex += 2;
241
        /* printf("waiting for int\n"); */
242
        while (!int_happend);
243
        CLEAR_FLAG(*eth_int_mask, ETH_INT_MASK, RXB_M);
244
 
245
 
246
        printf( "Ending Ethernet test\n" );
247
 
248
        report (0xdeaddead);
249
        exit(0);
250
}
251
 
252
 

powered by: WebSVN 2.1.0

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