commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r7092 - in usrp2/trunk/firmware: apps lib


From: eb
Subject: [Commit-gnuradio] r7092 - in usrp2/trunk/firmware: apps lib
Date: Sun, 9 Dec 2007 21:38:23 -0700 (MST)

Author: eb
Date: 2007-12-09 21:38:23 -0700 (Sun, 09 Dec 2007)
New Revision: 7092

Added:
   usrp2/trunk/firmware/apps/gen_pause_frames.c
Modified:
   usrp2/trunk/firmware/apps/
   usrp2/trunk/firmware/apps/Makefile.am
   usrp2/trunk/firmware/apps/gen_eth_packets.c
   usrp2/trunk/firmware/apps/rcv_eth_packets.c
   usrp2/trunk/firmware/apps/test_i2c.c
   usrp2/trunk/firmware/apps/test_phy_comm.c
   usrp2/trunk/firmware/lib/eth_mac.c
   usrp2/trunk/firmware/lib/eth_mac.h
   usrp2/trunk/firmware/lib/mdelay.c
Log:
tell mac our src address


Property changes on: usrp2/trunk/firmware/apps
___________________________________________________________________
Name: svn:ignore
   - *-stamp
*.a
*.bin
*.dump
*.log
*.rom
.deps
Makefile
Makefile.in
aclocal.m4
autom4te.cache
blink_leds
blink_leds2
build
compile
config.h
config.h.in
config.log
config.status
configure
depcomp
eth_test
gen_eth_packets
ibs_rx_test
ibs_tx_test
install-sh
libtool
ltmain.sh
missing
py-compile
rcv_eth_packets
run_tests.sh
stamp-h1
test1
test_phy_comm
timer_test
buf_ram_test
buf_ram_zero
hello
test_printf
test_spi
test_i2c

   + *-stamp
*.a
*.bin
*.dump
*.log
*.rom
.deps
Makefile
Makefile.in
aclocal.m4
autom4te.cache
blink_leds
blink_leds2
build
compile
config.h
config.h.in
config.log
config.status
configure
depcomp
eth_test
gen_eth_packets
ibs_rx_test
ibs_tx_test
install-sh
libtool
ltmain.sh
missing
py-compile
rcv_eth_packets
run_tests.sh
stamp-h1
test1
test_phy_comm
timer_test
buf_ram_test
buf_ram_zero
hello
test_printf
test_spi
test_i2c
gen_pause_frames



Modified: usrp2/trunk/firmware/apps/Makefile.am
===================================================================
--- usrp2/trunk/firmware/apps/Makefile.am       2007-12-10 02:17:52 UTC (rev 
7091)
+++ usrp2/trunk/firmware/apps/Makefile.am       2007-12-10 04:38:23 UTC (rev 
7092)
@@ -26,6 +26,7 @@
        buf_ram_zero \
        eth_test \
        gen_eth_packets \
+       gen_pause_frames \
        hello \
        ibs_rx_test \
        ibs_tx_test \

Modified: usrp2/trunk/firmware/apps/gen_eth_packets.c
===================================================================
--- usrp2/trunk/firmware/apps/gen_eth_packets.c 2007-12-10 02:17:52 UTC (rev 
7091)
+++ usrp2/trunk/firmware/apps/gen_eth_packets.c 2007-12-10 04:38:23 UTC (rev 
7092)
@@ -208,7 +208,7 @@
 
   eth_driver_register_link_changed_callback(link_changed_callback);
 
-  eth_mac_init();
+  eth_mac_init(src_mac_addr);
   eth_driver_init();
 
   // eth_mac->speed = 4;       // FIXME hardcode mac speed to 1000

Copied: usrp2/trunk/firmware/apps/gen_pause_frames.c (from rev 7090, 
usrp2/trunk/firmware/apps/gen_eth_packets.c)
===================================================================
--- usrp2/trunk/firmware/apps/gen_pause_frames.c                                
(rev 0)
+++ usrp2/trunk/firmware/apps/gen_pause_frames.c        2007-12-10 04:38:23 UTC 
(rev 7092)
@@ -0,0 +1,251 @@
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "u2_init.h"
+#include "memory_map.h"
+#include "spi.h"
+#include "hal_io.h"
+#include "buffer_pool.h"
+#include "pic.h"
+#include "bool.h"
+#include "eth_driver.h"
+#include "eth_mac.h"
+#include "nonstdio.h"
+
+typedef int intptr_t;
+typedef unsigned size_t;
+void exit(int status);
+
+// ----------------------------------------------------------------
+
+unsigned char dst_mac_addr[6] = {
+  0xff, 0xff, 0xff, 0xff, 0xff, 0xff
+};
+
+// our address
+unsigned char src_mac_addr[6] = {
+  0x00, 0x0A, 0x35, 0x98, 0x76, 0x54
+};
+
+#define U2_ETHERTYPE 0xBEEF
+
+
+typedef struct {
+  unsigned char dst_addr[6];
+  unsigned char src_addr[6];
+  unsigned short ethertype;
+} ethernet_hdr_t;
+
+typedef struct {
+  ethernet_hdr_t       ehdr;
+  unsigned short       pktno;
+  unsigned char                data[];
+} ethernet_packet_t;           // gives us 32-bit aligned packet
+
+
+// ----------------------------------------------------------------
+
+// #define     PACKET_SIZE 1500                // bytes
+// #define ETH_DATA_RATE 1000000               // 1MB/s
+// #define     ETH_PACKET_RATE (ETH_DATA_RATE/PACKET_SIZE)     // 13,3333 
pkts/s
+
+// static int timer_delta = MASTER_CLK_RATE/ETH_PACKET_RATE;   // ticks 
between interrupts
+
+static int timer_delta = MASTER_CLK_RATE/1000; // tick at 1kHz
+
+static volatile bool send_packet_now = false;   // timer handler sets this
+static volatile bool link_is_up = false;       // eth handler sets this
+
+int packet_number = 0;
+
+// ----------------------------------------------------------------
+
+// debugging output on tx pins
+#define LS_MASK  0xE0000
+#define LS_1000  0x80000
+#define LS_100   0x40000
+#define LS_10    0x20000
+
+
+/*
+ * Called when eth phy state changes (w/ interrupts disabled)
+ */
+void
+link_changed_callback(int speed)
+{
+  int v = 0;
+  switch(speed){
+  case 10:
+    v = LS_10;
+    link_is_up = true;
+    break;
+    
+  case 100:
+    v = LS_100;
+    link_is_up = true;
+    break;
+    
+  case 1000:
+    v = LS_100;
+    link_is_up = true;
+    break;
+
+  default:
+    v = 0;
+    link_is_up = false;
+    break;
+  }
+
+  hal_gpio_set_tx(v, LS_MASK); /* set debug bits on d'board */
+
+  putstr("\neth link changed: speed = ");
+  puthex16_nl(speed);
+}
+
+void
+timer_irq_handler(unsigned irq)
+{
+  hal_set_timeout(timer_delta);        // schedule next timeout
+  send_packet_now = 1;
+}
+
+
+void
+buffer_irq_handler(unsigned irq)
+{
+  // FIXME
+}
+
+/*
+ * For copying to/from non-byte-adressable memory, such as
+ * the buffers
+ */
+void
+memcpy_wordaligned(void *dst, const void *src, size_t nbytes)
+{
+  if (((intptr_t) dst & 0x3)
+      || ((intptr_t) src & 0x3)
+      || (nbytes & 0x3))
+    exit(1);                   /* die! */
+
+  int *dp = (int *) dst;
+  int *sp = (int *) src;
+  unsigned  nw = nbytes/4;
+
+  unsigned i;
+  for (i = 0; i < nw; i++)
+    dp[i] = sp[i];
+}
+
+
+static void
+init_packet(int *buf, const ethernet_packet_t *pkt, int bufnum)
+{
+  int i = 0;
+  int mark = ((bufnum & 0xff) << 24) | 0x005A0000;
+
+  for (i = 0; i < BUFFER_POOL_BUFFER_SIZE; i++){
+    buf[i] = mark | i;
+    mark ^= 0x00FF0000;
+  }
+
+  // copy header into buffer
+  memcpy_wordaligned(buf, pkt, sizeof(*pkt));
+}
+
+static void
+init_packets(void)
+{
+  int  i;
+  
+  ethernet_packet_t    pkt __attribute__((aligned (4)));
+
+  for (i = 0; i < 6; i++){
+    pkt.ehdr.dst_addr[i] = dst_mac_addr[i];
+    pkt.ehdr.src_addr[i] = src_mac_addr[i];
+  }
+  pkt.ehdr.ethertype = U2_ETHERTYPE;
+
+  // fill ALL buffers for debugging
+  for (i = 0; i < 8; i++)
+    init_packet((void *)buffer_ram(i), &pkt, i);
+}
+
+static int led_counter = 0;
+
+int
+main(void)
+{
+  int send_pause = 1;
+  
+  u2_init();
+
+  // setup tx gpio bits for GPIOM_FPGA_1 -- fpga debug output
+  hal_gpio_set_tx_mode(15, 0, GPIOM_FPGA_0);
+  hal_gpio_set_rx_mode(15, 0, GPIOM_FPGA_0);   // no printing...
+
+  putstr("\ngen_eth_packets\n");
+  
+  // Control LEDs
+  output_regs->leds = 0x00;
+
+  init_packets();
+
+  // pic_register_handler(IRQ_BUFFER, buffer_irq_handler);  // poll for now
+  pic_register_handler(IRQ_TIMER, timer_irq_handler);
+  hal_set_timeout(timer_delta);
+
+  eth_driver_register_link_changed_callback(link_changed_callback);
+
+  eth_mac_init(src_mac_addr);
+  eth_driver_init();
+
+  eth_mac->pause_frame_send_en = 1;
+  eth_mac->pause_quanta_set = 16384 / 512;
+
+  // eth_mac->speed = 4;       // FIXME hardcode mac speed to 1000
+
+  while(1){
+    if (link_is_up && send_packet_now){
+      send_packet_now = false;
+
+
+      if (send_pause)
+       eth_mac->xon_cpu = 1;
+      else
+       eth_mac->xon_cpu = 0;
+
+      send_pause ^= 1;
+
+      // kick off the next packet
+      // FIXME set packet number in packet
+
+#if 0
+      bp_send_from_buf(0, PORT_ETH, 1, 0, 255);        // 1KB total
+
+      while ((buffer_pool_status->status & (BPS_DONE_0|BPS_ERROR_0)) == 0)
+       ;
+      bp_clear_buf(0);
+#endif
+
+      output_regs->leds = ((++led_counter) & 0x1) | (link_is_up ? 0x2 : 0x0);
+    }
+  }
+
+  hal_finish();
+  return 1;
+}

Modified: usrp2/trunk/firmware/apps/rcv_eth_packets.c
===================================================================
--- usrp2/trunk/firmware/apps/rcv_eth_packets.c 2007-12-10 02:17:52 UTC (rev 
7091)
+++ usrp2/trunk/firmware/apps/rcv_eth_packets.c 2007-12-10 04:38:23 UTC (rev 
7092)
@@ -237,7 +237,7 @@
 
   eth_driver_register_link_changed_callback(link_changed_callback);
 
-  eth_mac_init();
+  eth_mac_init(src_mac_addr);
   eth_driver_init();
 
   //eth_mac->speed = 4;        // FIXME hardcode mac speed to 1000

Modified: usrp2/trunk/firmware/apps/test_i2c.c
===================================================================
--- usrp2/trunk/firmware/apps/test_i2c.c        2007-12-10 02:17:52 UTC (rev 
7091)
+++ usrp2/trunk/firmware/apps/test_i2c.c        2007-12-10 04:38:23 UTC (rev 
7092)
@@ -96,10 +96,14 @@
     }
   }
   
-  if (nerrors == 0)
+  if (nerrors == 0){
+    output_regs->leds = 0x3;
     puts("PASSED\n");
-  else
+  }
+  else {
+    output_regs->leds = 0x0;
     puts("FAILED\n");
+  }
 
   hal_finish();
   return 0;

Modified: usrp2/trunk/firmware/apps/test_phy_comm.c
===================================================================
--- usrp2/trunk/firmware/apps/test_phy_comm.c   2007-12-10 02:17:52 UTC (rev 
7091)
+++ usrp2/trunk/firmware/apps/test_phy_comm.c   2007-12-10 04:38:23 UTC (rev 
7092)
@@ -36,6 +36,13 @@
 #define LS_10    0x20000
 
 
+unsigned char src_mac_addr[6] = {
+  0x00, 0x0A, 0x35, 0x98, 0x76, 0x54
+};
+
+#define U2_ETHERTYPE 0xBEEF
+
+
 static volatile int led_link_up_flag = 0;
 
 /*
@@ -99,7 +106,7 @@
   output_regs->phy_ctrl = 1;   /* reset the eth PHY */
   output_regs->phy_ctrl = 0;
 
-  eth_mac_init();
+  eth_mac_init(src_mac_addr);
   eth_driver_init();
 
   u2_infinite_loop();

Modified: usrp2/trunk/firmware/lib/eth_mac.c
===================================================================
--- usrp2/trunk/firmware/lib/eth_mac.c  2007-12-10 02:17:52 UTC (rev 7091)
+++ usrp2/trunk/firmware/lib/eth_mac.c  2007-12-10 04:38:23 UTC (rev 7092)
@@ -24,11 +24,30 @@
 #define PHY_ADDR 1
 
 void 
-eth_mac_init(void)
+eth_mac_init(unsigned char src_mac_addr[6])
 {
+  int i;
   // FIXME more to do?
 
   eth_mac->miimoder = 16;      // divider from CPU clock (33MHz / 16 ~= 2MHz)
+
+  // tell mac our source address and enable automatic insertion on Tx.
+  for (i = 0; i < 6; i++){
+    eth_mac->mac_tx_add_prom_add = i;
+    eth_mac->mac_tx_add_prom_data = src_mac_addr[i];
+    eth_mac->mac_tx_add_prom_wr = 1;
+    eth_mac->mac_tx_add_prom_wr = 0;
+  }
+  eth_mac->mac_tx_add_en = 1;  // overwrite pkt src addr field with this stuff
+
+  // set up receive destination address filter
+  for (i = 0; i < 6; i++){
+    eth_mac->mac_rx_add_prom_add = i;
+    eth_mac->mac_rx_add_prom_data = src_mac_addr[i];
+    eth_mac->mac_rx_add_prom_wr = 1;
+    eth_mac->mac_rx_add_prom_wr = 0;
+  }
+  // eth_mac->mac_rx_add_chk_en = 1;  // FIXME enable when everything's working
 }
 
 int

Modified: usrp2/trunk/firmware/lib/eth_mac.h
===================================================================
--- usrp2/trunk/firmware/lib/eth_mac.h  2007-12-10 02:17:52 UTC (rev 7091)
+++ usrp2/trunk/firmware/lib/eth_mac.h  2007-12-10 04:38:23 UTC (rev 7092)
@@ -19,7 +19,7 @@
 #ifndef INCLUDED_ETH_MAC_H
 #define INCLUDED_ETH_MAC_H
 
-void eth_mac_init(void);
+void eth_mac_init(unsigned char src_mac_addr[6]);
 int  eth_mac_read_rmon(int addr);
 int  eth_mac_miim_read(int addr);
 void eth_mac_miim_write(int addr, int value);

Modified: usrp2/trunk/firmware/lib/mdelay.c
===================================================================
--- usrp2/trunk/firmware/lib/mdelay.c   2007-12-10 02:17:52 UTC (rev 7091)
+++ usrp2/trunk/firmware/lib/mdelay.c   2007-12-10 04:38:23 UTC (rev 7092)
@@ -48,6 +48,9 @@
 {
   static int loop_count = -1;
 
+  if (hwconfig_simulation_p())
+    return;
+
   if (loop_count < 0){
     // set correct loop_count
     static unsigned short lc[8] = {
@@ -61,11 +64,7 @@
       LOOPCNT(7)
     };
 
-    if (hwconfig_simulation_p())
-      loop_count = 0;
-    else {
-      loop_count = lc[hwconfig_wishbone_divisor() & 0x7];
-    }
+    loop_count = lc[hwconfig_wishbone_divisor() & 0x7];
   }
 
   int i;





reply via email to

[Prev in Thread] Current Thread [Next in Thread]