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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [sw/] [tests/] [ethmac/] [sim/] [ethmac-rxtx.c] - Blame information for rev 409

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

Line No. Rev Author Line
1 349 julius
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  Interrupt-driven Ethernet MAC transmit test code            ////
4
////                                                              ////
5
////  Description                                                 ////
6
////  Send packets while receiving packets                        ////
7
////                                                              ////
8
////  Test data comes from pre-calculated array of random values, ////
9
////  MAC TX buffer pointers are set to addresses in this array,  ////
10
////  saving copying the data around before transfers.            ////
11
////                                                              ////
12
////  Author(s):                                                  ////
13
////      - jb, jb@orsoc.se, with parts taken from Linux kernel   ////
14
////        open_eth driver.                                      ////
15
////                                                              ////
16
////                                                              ////
17
//////////////////////////////////////////////////////////////////////
18
////                                                              ////
19
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
20
////                                                              ////
21
//// This source file may be used and distributed without         ////
22
//// restriction provided that this copyright statement is not    ////
23
//// removed from the file and that any derivative work contains  ////
24
//// the original copyright notice and the associated disclaimer. ////
25
////                                                              ////
26
//// This source file is free software; you can redistribute it   ////
27
//// and/or modify it under the terms of the GNU Lesser General   ////
28
//// Public License as published by the Free Software Foundation; ////
29
//// either version 2.1 of the License, or (at your option) any   ////
30
//// later version.                                               ////
31
////                                                              ////
32
//// This source is distributed in the hope that it will be       ////
33
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
34
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
35
//// PURPOSE.  See the GNU Lesser General Public License for more ////
36
//// details.                                                     ////
37
////                                                              ////
38
//// You should have received a copy of the GNU Lesser General    ////
39
//// Public License along with this source; if not, download it   ////
40
//// from http://www.opencores.org/lgpl.shtml                     ////
41
////                                                              ////
42
//////////////////////////////////////////////////////////////////////
43
 
44
#include "or32-utils.h"
45
#include "spr-defs.h"
46
#include "board.h"
47
#include "int.h"
48
//#include "uart.h" // comment this out, UART uses simulation putc()
49
#include "open-eth.h"
50
#include "printf.h"
51
#include "eth-phy-mii.h"
52
 
53
volatile unsigned tx_done;
54
volatile unsigned rx_done;
55
static int next_tx_buf_num;
56
 
57
/* Functions in this file */
58
void ethmac_setup(void);
59
/* Interrupt functions */
60
void oeth_interrupt(void);
61
static void oeth_rx(void);
62
static void oeth_tx(void);
63
 
64
/* Defining RTLSIM turns off use of real printf'ing to save time in simulation */
65
#define RTLSIM
66
 
67
#ifdef RTLSIM
68
#define printk
69
#else
70
#define printk printf
71
#endif
72
/* Let the ethernet packets use a space beginning here for buffering */
73
#define ETH_BUFF_BASE 0x01000000
74
 
75
 
76
#define RXBUFF_PREALLOC 1
77
#define TXBUFF_PREALLOC 1
78
//#undef RXBUFF_PREALLOC
79
//#undef TXBUFF_PREALLOC
80
 
81
/* The transmitter timeout
82
*/
83
#define TX_TIMEOUT      (2*HZ)
84
 
85
/* Buffer number (must be 2^n)
86
*/
87
#define OETH_RXBD_NUM           16
88
#define OETH_TXBD_NUM           16
89
#define OETH_RXBD_NUM_MASK      (OETH_RXBD_NUM-1)
90
#define OETH_TXBD_NUM_MASK      (OETH_TXBD_NUM-1)
91
 
92
/* Buffer size
93
*/
94
#define OETH_RX_BUFF_SIZE       0x600-4
95
#define OETH_TX_BUFF_SIZE       0x600-4
96
 
97
/* OR32 Page size def */
98
#define PAGE_SHIFT              13
99
#define PAGE_SIZE               (1UL << PAGE_SHIFT)
100
 
101
/* How many buffers per page
102
*/
103
#define OETH_RX_BUFF_PPGAE      (PAGE_SIZE/OETH_RX_BUFF_SIZE)
104
#define OETH_TX_BUFF_PPGAE      (PAGE_SIZE/OETH_TX_BUFF_SIZE)
105
 
106
/* How many pages is needed for buffers
107
*/
108
#define OETH_RX_BUFF_PAGE_NUM   (OETH_RXBD_NUM/OETH_RX_BUFF_PPGAE)
109
#define OETH_TX_BUFF_PAGE_NUM   (OETH_TXBD_NUM/OETH_TX_BUFF_PPGAE)
110
 
111
/* Buffer size  (if not XXBUF_PREALLOC
112
*/
113
#define MAX_FRAME_SIZE          1518
114
 
115
/* The buffer descriptors track the ring buffers.
116
*/
117
struct oeth_private {
118
  //struct      sk_buff* rx_skbuff[OETH_RXBD_NUM];
119
  //struct      sk_buff* tx_skbuff[OETH_TXBD_NUM];
120
 
121
  unsigned short        tx_next; /* Next buffer to be sent */
122
  unsigned short        tx_last; /* Next buffer to be checked if packet sent */
123
  unsigned short        tx_full; /* Buffer ring fuul indicator */
124
  unsigned short        rx_cur;  /* Next buffer to be checked if packet
125
                                    received */
126
 
127
  oeth_regs     *regs;                  /* Address of controller registers. */
128
  oeth_bd               *rx_bd_base;            /* Address of Rx BDs. */
129
  oeth_bd               *tx_bd_base;            /* Address of Tx BDs. */
130
 
131
  //    struct net_device_stats stats;
132
};
133
 
134
#define PHYNUM 7
135
 
136
// Data array of data to transmit, tx_data_array[]
137
#include "eth-rxtx-data.h"
138
int tx_data_pointer;
139
 
140
/* Scan the MIIM bus for PHYs */
141
void scan_ethphys(void)
142
{
143
  unsigned int phynum,regnum, i;
144
 
145
  volatile oeth_regs *regs;
146
  regs = (oeth_regs *)(OETH_REG_BASE);
147
 
148
  regs->miitx_data = 0;
149
 
150
  for(phynum=0;phynum<32;phynum++)
151
    {
152
      for (regnum=0;regnum<8;regnum++)
153
        {
154
          printk("scan_ethphys: phy %d r%d ",phynum, regnum);
155
 
156
          /* Now actually perform the read on the MIIM bus*/
157
          regs->miiaddress = (regnum << 8) | phynum;
158
          regs->miicommand = OETH_MIICOMMAND_RSTAT;
159
           /* Wait for command to be registered*/
160
          while(!(regs->miistatus & OETH_MIISTATUS_BUSY));
161
 
162
          regs->miicommand = 0;
163
 
164
          while(regs->miistatus & OETH_MIISTATUS_BUSY);
165
 
166
          printk("%x\n",regs->miirx_data);
167
        }
168
    }
169
}
170
 
171
 
172
 
173
void ethmac_scanstatus(void)
174
{
175
  volatile oeth_regs *regs;
176
  regs = (oeth_regs *)(OETH_REG_BASE);
177
 
178
 
179
  printk("Oeth: regs->miistatus %x regs->miirx_data %x\n",regs->miistatus, regs->miirx_data);
180
  regs->miiaddress = 0;
181
  regs->miitx_data = 0;
182
  regs->miicommand = OETH_MIICOMMAND_SCANSTAT;
183
  printk("Oeth: regs->miiaddress %x regs->miicommand %x\n",regs->miiaddress, regs->miicommand);
184
  //regs->miicommand = 0; 
185
  volatile int i; for(i=0;i<1000;i++);
186
  while(regs->miistatus & OETH_MIISTATUS_BUSY) ;
187
  //spin_cursor(); 
188
  //printk("\r"); 
189
  //or32_exit(0);
190
}
191
 
192
void
193
eth_mii_write(char phynum, short regnum, short data)
194
{
195
  static volatile oeth_regs *regs = (oeth_regs *)(OETH_REG_BASE);
196
  regs->miiaddress = (regnum << 8) | phynum;
197
  regs->miitx_data = data;
198
  regs->miicommand = OETH_MIICOMMAND_WCTRLDATA;
199
  regs->miicommand = 0;
200
  while(regs->miistatus & OETH_MIISTATUS_BUSY);
201
}
202
 
203
short
204
eth_mii_read(char phynum, short regnum)
205
{
206
  static volatile oeth_regs *regs = (oeth_regs *)(OETH_REG_BASE);
207
  regs->miiaddress = (regnum << 8) | phynum;
208
  regs->miicommand = OETH_MIICOMMAND_RSTAT;
209
  regs->miicommand = 0;
210
  while(regs->miistatus & OETH_MIISTATUS_BUSY);
211
 
212
  return regs->miirx_data;
213
}
214
 
215
 
216
 
217
// Wait here until all packets have been transmitted
218
void wait_until_all_tx_clear(void)
219
{
220
 
221
  int i;
222
  volatile oeth_bd *tx_bd;
223
  tx_bd = (volatile oeth_bd *)OETH_BD_BASE; /* Search from beginning*/
224
 
225
  int some_tx_waiting = 1;
226
 
227
  while (some_tx_waiting)
228
    {
229
      some_tx_waiting = 0;
230
      /* Go through the TX buffs, search for unused one */
231
      for(i = 0; i < OETH_TXBD_NUM; i++) {
232
 
233
        if((tx_bd[i].len_status & OETH_TX_BD_READY)) // Looking for buffer ready for transmit
234
          some_tx_waiting = 1;
235
 
236
      }
237
    }
238
}
239
 
240
 
241
void
242
ethphy_set_10mbit(int phynum)
243
{
244
  wait_until_all_tx_clear();
245
  // Hardset PHY to just use 10Mbit mode
246
  short cr = eth_mii_read(phynum, MII_BMCR);
247
  cr &= ~BMCR_ANENABLE; // Clear auto negotiate bit
248
  cr &= ~BMCR_SPEED100; // Clear fast eth. bit
249
  eth_mii_write(phynum, MII_BMCR, cr);
250
}
251
 
252
 
253
void
254
ethphy_set_100mbit(int phynum)
255
{
256
  wait_until_all_tx_clear();
257
  // Hardset PHY to just use 100Mbit mode
258
  short cr = eth_mii_read(phynum, MII_BMCR);
259
  cr |= BMCR_ANENABLE; // Clear auto negotiate bit
260
  cr |= BMCR_SPEED100; // Clear fast eth. bit
261
  eth_mii_write(phynum, MII_BMCR, cr);
262
}
263
 
264
 
265
void ethmac_setup(void)
266
{
267
  // from arch/or32/drivers/open_eth.c
268
  volatile oeth_regs *regs;
269
 
270
  regs = (oeth_regs *)(OETH_REG_BASE);
271
 
272
  /* Reset MII mode module */
273
  regs->miimoder = OETH_MIIMODER_RST; /* MII Reset ON */
274
  regs->miimoder &= ~OETH_MIIMODER_RST; /* MII Reset OFF */
275
  regs->miimoder = 0x64; /* Clock divider for MII Management interface */
276
 
277
  /* Reset the controller.
278
  */
279
  regs->moder = OETH_MODER_RST; /* Reset ON */
280
  regs->moder &= ~OETH_MODER_RST;       /* Reset OFF */
281
 
282
  /* Setting TXBD base to OETH_TXBD_NUM.
283
  */
284
  regs->tx_bd_num = OETH_TXBD_NUM;
285
 
286
 
287
  /* Set min/max packet length
288
  */
289
  regs->packet_len = 0x00400600;
290
 
291
  /* Set IPGT register to recomended value
292
  */
293
  regs->ipgt = 0x12;
294
 
295
  /* Set IPGR1 register to recomended value
296
  */
297
  regs->ipgr1 = 0x0000000c;
298
 
299
  /* Set IPGR2 register to recomended value
300
  */
301
  regs->ipgr2 = 0x00000012;
302
 
303
  /* Set COLLCONF register to recomended value
304
  */
305
  regs->collconf = 0x000f003f;
306
 
307
  /* Set control module mode
308
  */
309
#if 0
310
  regs->ctrlmoder = OETH_CTRLMODER_TXFLOW | OETH_CTRLMODER_RXFLOW;
311
#else
312
  regs->ctrlmoder = 0;
313
#endif
314
 
315
  /* Clear MIIM registers */
316
  regs->miitx_data = 0;
317
  regs->miiaddress = 0;
318
  regs->miicommand = 0;
319
 
320
  regs->mac_addr1 = ETH_MACADDR0 << 8 | ETH_MACADDR1;
321
  regs->mac_addr0 = ETH_MACADDR2 << 24 | ETH_MACADDR3 << 16 | ETH_MACADDR4 << 8 | ETH_MACADDR5;
322
 
323
  /* Clear all pending interrupts
324
  */
325
  regs->int_src = 0xffffffff;
326
 
327
  /* Promisc, IFG, CRCEn
328
  */
329
  regs->moder |= OETH_MODER_PRO | OETH_MODER_PAD | OETH_MODER_IFG | OETH_MODER_CRCEN | OETH_MODER_FULLD;
330
 
331
  /* Enable interrupt sources.
332
  */
333
 
334
  regs->int_mask = OETH_INT_MASK_TXB    |
335
    OETH_INT_MASK_TXE   |
336
    OETH_INT_MASK_RXF   |
337
    OETH_INT_MASK_RXE   |
338
    OETH_INT_MASK_BUSY  |
339
    OETH_INT_MASK_TXC   |
340
    OETH_INT_MASK_RXC;
341
 
342
  // Buffer setup stuff
343
  volatile oeth_bd *tx_bd, *rx_bd;
344
  int i,j,k;
345
 
346
  /* Initialize TXBD pointer
347
  */
348
  tx_bd = (volatile oeth_bd *)OETH_BD_BASE;
349
 
350
  /* Initialize RXBD pointer
351
  */
352
  rx_bd = ((volatile oeth_bd *)OETH_BD_BASE) + OETH_TXBD_NUM;
353
 
354
  /* Preallocated ethernet buffer setup */
355
  unsigned long mem_addr = ETH_BUFF_BASE; /* Defined at top */
356
 
357
  // Setup TX Buffers
358
  for(i = 0; i < OETH_TXBD_NUM; i++) {
359
    //tx_bd[i].len_status = OETH_TX_BD_PAD | OETH_TX_BD_CRC | OETH_RX_BD_IRQ;
360
    tx_bd[i].len_status = OETH_TX_BD_PAD | OETH_TX_BD_CRC;
361
    tx_bd[i].addr = mem_addr;
362
    mem_addr += OETH_TX_BUFF_SIZE;
363
  }
364
  tx_bd[OETH_TXBD_NUM - 1].len_status |= OETH_TX_BD_WRAP;
365
 
366
  // Setup RX buffers
367
  for(i = 0; i < OETH_RXBD_NUM; i++) {
368
    rx_bd[i].len_status = OETH_RX_BD_EMPTY | OETH_RX_BD_IRQ; // Init. with IRQ
369
    rx_bd[i].addr = mem_addr;
370
    mem_addr += OETH_RX_BUFF_SIZE;
371
  }
372
  rx_bd[OETH_RXBD_NUM - 1].len_status |= OETH_RX_BD_WRAP; // Last buffer wraps
373
 
374
  /* Enable JUST the transmiter
375
  */
376
  regs->moder &= ~(OETH_MODER_RXEN | OETH_MODER_TXEN);
377
  regs->moder |= /*OETH_MODER_RXEN |*/ OETH_MODER_TXEN;
378
 
379
  next_tx_buf_num = 0; // init tx buffer pointer
380
 
381
  return;
382
}
383
 
384
// Enable RX in ethernet MAC
385
void
386
oeth_enable_rx(void)
387
{
388
  volatile oeth_regs *regs;
389
  regs = (oeth_regs *)(OETH_REG_BASE);
390
  regs->moder |= OETH_MODER_RXEN;
391
}
392
 
393
// Disable RX in ethernet MAC
394
void
395
oeth_disable_rx(void)
396
{
397
  volatile oeth_regs *regs;
398
  regs = (oeth_regs *)(OETH_REG_BASE);
399
  regs->moder &= ~(OETH_MODER_RXEN);
400
}
401
 
402
 
403
/* Setup buffer descriptors with data */
404
/* length is in BYTES */
405
void tx_packet(void* data, int length)
406
{
407
  volatile oeth_regs *regs;
408
  regs = (oeth_regs *)(OETH_REG_BASE);
409
 
410
  volatile oeth_bd *tx_bd;
411
  volatile int i;
412
 
413
  tx_bd = (volatile oeth_bd *)OETH_BD_BASE;
414
  tx_bd = (struct oeth_bd*) &tx_bd[next_tx_buf_num];
415
 
416
  // If it's in use - wait
417
  while ((tx_bd->len_status & OETH_TX_BD_IRQ));
418
 
419
  /* Clear all of the status flags.
420
  */
421
  tx_bd->len_status &= ~OETH_TX_BD_STATS;
422
 
423
  /* If the frame is short, tell CPM to pad it.
424
  */
425
#define ETH_ZLEN        60   /* Min. octets in frame sans FCS */
426
  if (length <= ETH_ZLEN)
427
    tx_bd->len_status |= OETH_TX_BD_PAD;
428
  else
429
    tx_bd->len_status &= ~OETH_TX_BD_PAD;
430
 
431
#ifdef _ETH_RXTX_DATA_H_
432
  // Set the address pointer to the place
433
  // in memory where the data is and transmit from there
434
 
435
  tx_bd->addr = (char*) &tx_data_array[tx_data_pointer&~(0x3)];
436
 
437
  tx_data_pointer += length + 1;
438
  if (tx_data_pointer > (255*1024))
439
    tx_data_pointer = 0;
440
 
441
 
442
#else
443
  if (data){
444
    //Copy the data into the transmit buffer, byte at a time 
445
    char* data_p = (char*) data;
446
    char* data_b = (char*) tx_bd->addr;
447
    for(i=0;i<length;i++)
448
      {
449
        data_b[i] = data_p[i];
450
      }
451
  }
452
#endif
453
 
454
  /* Set the length of the packet's data in the buffer descriptor */
455
  tx_bd->len_status = (tx_bd->len_status & 0x0000ffff) |
456
    ((length&0xffff) << 16);
457
 
458
  /* Send it on its way.  Tell controller its ready, interrupt when sent
459
  * and to put the CRC on the end.
460
  */
461
  tx_bd->len_status |= (OETH_TX_BD_READY  | OETH_TX_BD_CRC | OETH_TX_BD_IRQ);
462
 
463
  next_tx_buf_num = (next_tx_buf_num + 1) & OETH_TXBD_NUM_MASK;
464
 
465
  return;
466
 
467
 
468
}
469
 
470
/* The interrupt handler.
471
*/
472
void
473
oeth_interrupt(void)
474
{
475
 
476
  volatile oeth_regs *regs;
477
  regs = (oeth_regs *)(OETH_REG_BASE);
478
 
479
  uint  int_events;
480
  int serviced;
481
 
482
  serviced = 0;
483
 
484
  /* Get the interrupt events that caused us to be here.
485
  */
486
  int_events = regs->int_src;
487
  regs->int_src = int_events;
488
 
489
  /* Handle receive event in its own function.
490
  */
491
  if (int_events & (OETH_INT_RXF | OETH_INT_RXE)) {
492
    serviced |= 0x1;
493
    oeth_rx();
494
  }
495
 
496
  /* Handle transmit event in its own function.
497
  */
498
  if (int_events & (OETH_INT_TXB | OETH_INT_TXE)) {
499
    serviced |= 0x2;
500
    oeth_tx();
501
    serviced |= 0x2;
502
 
503
  }
504
 
505
  /* Check for receive busy, i.e. packets coming but no place to
506
  * put them.
507
  */
508
  if (int_events & OETH_INT_BUSY) {
509
    serviced |= 0x4;
510
    if (!(int_events & (OETH_INT_RXF | OETH_INT_RXE)))
511
      oeth_rx();
512
  }
513
 
514
  return;
515
}
516
 
517
 
518
 
519
static void
520
oeth_rx(void)
521
{
522
  volatile oeth_regs *regs;
523
  regs = (oeth_regs *)(OETH_REG_BASE);
524
 
525
  volatile oeth_bd *rx_bdp;
526
  int   pkt_len, i;
527
  int   bad = 0;
528
 
529
  rx_bdp = ((oeth_bd *)OETH_BD_BASE) + OETH_TXBD_NUM;
530
 
531
  printk("r");
532
 
533
 
534
  /* Find RX buffers marked as having received data */
535
  for(i = 0; i < OETH_RXBD_NUM; i++)
536
    {
537
      bad=0;
538
      if(!(rx_bdp[i].len_status & OETH_RX_BD_EMPTY)){ /* Looking for NOT empty buffers desc. */
539
        /* Check status for errors.
540
        */
541
        if (rx_bdp[i].len_status & (OETH_RX_BD_TOOLONG | OETH_RX_BD_SHORT)) {
542
          bad = 1;
543
          report(0xbaad0001);
544
        }
545
        if (rx_bdp[i].len_status & OETH_RX_BD_DRIBBLE) {
546
          bad = 1;
547
          report(0xbaad0002);
548
        }
549
        if (rx_bdp[i].len_status & OETH_RX_BD_CRCERR) {
550
          bad = 1;
551
          report(0xbaad0003);
552
        }
553
        if (rx_bdp[i].len_status & OETH_RX_BD_OVERRUN) {
554
          bad = 1;
555
          report(0xbaad0004);
556
        }
557
        if (rx_bdp[i].len_status & OETH_RX_BD_MISS) {
558
          report(0xbaad0005);
559
        }
560
        if (rx_bdp[i].len_status & OETH_RX_BD_LATECOL) {
561
          bad = 1;
562
          report(0xbaad0006);
563
        }
564
        if (bad) {
565
          rx_bdp[i].len_status &= ~OETH_RX_BD_STATS;
566
          rx_bdp[i].len_status |= OETH_RX_BD_EMPTY;
567
          exit(0xbaaaaaad);
568
 
569
          continue;
570
        }
571
        else {
572
          /* Process the incoming frame.
573
          */
574
          pkt_len = rx_bdp[i].len_status >> 16;
575
 
576
          /* finish up */
577
          rx_bdp[i].len_status &= ~OETH_RX_BD_STATS; /* Clear stats */
578
          rx_bdp[i].len_status |= OETH_RX_BD_EMPTY; /* Mark RX BD as empty */
579
          rx_done++;
580
        }
581
      }
582
    }
583
}
584
 
585
 
586
 
587
static void
588
oeth_tx(void)
589
{
590
  volatile oeth_bd *tx_bd;
591
  int i;
592
 
593
  tx_bd = (volatile oeth_bd *)OETH_BD_BASE; /* Search from beginning*/
594
 
595
  /* Go through the TX buffs, search for one that was just sent */
596
  for(i = 0; i < OETH_TXBD_NUM; i++)
597
    {
598
      /* Looking for buffer NOT ready for transmit. and IRQ enabled */
599
      if( (!(tx_bd[i].len_status & (OETH_TX_BD_READY))) && (tx_bd[i].len_status & (OETH_TX_BD_IRQ)) )
600
        {
601
          /* Single threaded so no chance we have detected a buffer that has had its IRQ bit set but not its BD_READ flag. Maybe this won't work in linux */
602
          tx_bd[i].len_status &= ~OETH_TX_BD_IRQ;
603
 
604
          /* Probably good to check for TX errors here */
605
 
606
          /* set our test variable */
607
          tx_done++;
608
 
609
          printk("T%d",i);
610
 
611
        }
612
    }
613
  return;
614
}
615
 
616
// A function and defines to fill and transmit a packet
617
#define MAX_TX_BUFFER 1532
618
static char tx_buffer[MAX_TX_BUFFER];
619
static unsigned long tx_data = 0x26fab2f2;
620
static inline char gen_next_tx_byte(void)
621
{
622
  // Bit of LFSR action
623
  tx_data = ((~(((((tx_data&(1<<25))>>25)^((tx_data&(1<<13))>>13))^((tx_data&(1<<2))>>2)))&0x01) | (tx_data<<1));
624
  //tx_data =(!((tx_data>>26) ^ (tx_data>>14) ^ (tx_data>>5) ^ (tx_data>>3)) & 0x1) | (tx_data<<1);
625
return (char) tx_data & 0xff;
626
}
627
 
628
void
629
fill_and_tx_packet(int size)
630
{
631
  int i;
632
  char tx_byte;
633
 
634
 
635
  volatile oeth_regs *regs;
636
  regs = (oeth_regs *)(OETH_REG_BASE);
637
 
638
  volatile oeth_bd *tx_bd;
639
 
640
  //tx_bd = (volatile oeth_bd *)OETH_BD_BASE;
641
  tx_bd = (volatile oeth_bd*) &tx_bd[next_tx_buf_num];
642
 
643
 
644
  // If it's in use - wait
645
  while ((tx_bd->len_status & OETH_TX_BD_IRQ));
646
 
647
#ifndef _ETH_RXTX_DATA_H_  
648
  /* Copy the data into the transmit buffer, byte at a time */
649
  char* data_b = (char*) tx_bd->addr;
650
  for(i=0;i<size;i++)
651
    {
652
      data_b[i] = gen_next_tx_byte();
653
    }
654
#endif
655
 
656
  tx_packet((void*)0, size);
657
}
658
 
659
 
660
// Loop to check if a number is prime by doing mod divide of the number
661
// to test by every number less than it
662
int
663
is_prime_number(unsigned long n)
664
{
665
  unsigned long c;
666
  if (n < 2) return 0;
667
  for(c=2;c<n;c++)
668
    if ((n % c) == 0)
669
      return 0;
670
  return 1;
671
}
672
 
673
 
674
//#define WAIT_PACKET_TX(x) while(tx_done<x)
675
#define WAIT_PACKET_TX(x)
676
 
677
int main ()
678
{
679
  tx_data_pointer = 0;
680
  /* Initialise handler vector */
681
  int_init();
682
 
683
  /* Install ethernet interrupt handler, it is enabled here too */
684
  int_add(ETH0_IRQ, oeth_interrupt, 0);
685
 
686
  /* Enable interrupts in supervisor register */
687
  mtspr (SPR_SR, mfspr (SPR_SR) | SPR_SR_IEE);
688
 
689
  ethmac_setup(); /* Configure MAC, TX/RX BDs and enable RX and TX in MODER */
690
 
691
  /* clear tx_done, the tx interrupt handler will set it when it's been
692
     transmitted */
693
  tx_done = 0;
694
  rx_done = 0;
695
 
696
  printf("Start of large txdata buffer: 0x%x\n",
697
         (unsigned long)&tx_data_array[0]);
698
  printf("Slut of large txdata buffer: 0x%x\n",
699
         (unsigned long)&tx_data_array[262144]);
700
 
701
 
702
  ethphy_set_100mbit(0);
703
 
704
  oeth_enable_rx();
705
 
706
#define ETH_TX_MIN_PACKET_SIZE 512
707
#define ETH_TX_NUM_PACKETS (ETH_TX_MIN_PACKET_SIZE + 32)
708
 
709
  #define CALCULATE_PRIMES 0
710
 
711
  char prime_check_results[2048];
712
  unsigned long num_to_check;
713
  for(num_to_check=ETH_TX_MIN_PACKET_SIZE;
714
      num_to_check<ETH_TX_NUM_PACKETS;
715
      num_to_check++)
716
    {
717
      fill_and_tx_packet(num_to_check);
718
#if CALCULATE_PRIMES==1
719
      prime_check_results[num_to_check-5]
720
        = (char) is_prime_number(num_to_check);
721
      report(num_to_check | (0x1e<<24));
722
      report(prime_check_results[num_to_check-5] | (0x2e<<24));
723
#endif
724
    }
725
 
726
  oeth_disable_rx();
727
 
728
  // Now for 10mbit mode...
729
  ethphy_set_10mbit(0);
730
 
731
  oeth_enable_rx();
732
 
733
  for(num_to_check=ETH_TX_MIN_PACKET_SIZE;
734
      num_to_check<ETH_TX_NUM_PACKETS;
735
      num_to_check++)
736
    {
737
      fill_and_tx_packet(num_to_check);
738
#if CALCULATE_PRIMES==1
739
      prime_check_results[num_to_check+(OETH_TX_BUFF_SIZE-5)]
740
        = (char) is_prime_number(num_to_check+OETH_TX_BUFF_SIZE);
741
      report(num_to_check | (0x1e<<24));
742
      report(prime_check_results[num_to_check+(OETH_TX_BUFF_SIZE-5)]
743
             | (0x2e<<24)
744
             );
745
#endif
746
    }
747
 
748
  oeth_disable_rx();
749
 
750
  // Go back to 100-mbit mode
751
  ethphy_set_100mbit(0);
752
 
753
  oeth_enable_rx();
754
 
755
  for(num_to_check=ETH_TX_MIN_PACKET_SIZE;
756
      num_to_check<ETH_TX_NUM_PACKETS;
757
      num_to_check++)
758
    {
759
      fill_and_tx_packet(num_to_check);
760
#if CALCULATE_PRIMES==1
761
      prime_check_results[num_to_check+(OETH_TX_BUFF_SIZE-5)]
762
        = (char) is_prime_number(num_to_check+OETH_TX_BUFF_SIZE);
763
      report(num_to_check | (0x1e<<24));
764
      report(prime_check_results[num_to_check+(OETH_TX_BUFF_SIZE-5)]
765
             | (0x2e<<24)
766
             );
767
#endif
768
    }
769
 
770
 
771
  exit(0x8000000d);
772
 
773
 
774
}

powered by: WebSVN 2.1.0

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