commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r6797 - gnuradio/branches/developers/matt/u2f/firmware


From: eb
Subject: [Commit-gnuradio] r6797 - gnuradio/branches/developers/matt/u2f/firmware
Date: Fri, 2 Nov 2007 18:45:51 -0600 (MDT)

Author: eb
Date: 2007-11-02 18:45:50 -0600 (Fri, 02 Nov 2007)
New Revision: 6797

Added:
   gnuradio/branches/developers/matt/u2f/firmware/rcv_eth_packets.c
Modified:
   gnuradio/branches/developers/matt/u2f/firmware/Makefile
   gnuradio/branches/developers/matt/u2f/firmware/gen_eth_packets.c
   gnuradio/branches/developers/matt/u2f/firmware/hal_io.c
Log:
work-in-progress

Modified: gnuradio/branches/developers/matt/u2f/firmware/Makefile
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/Makefile     2007-11-03 
00:22:59 UTC (rev 6796)
+++ gnuradio/branches/developers/matt/u2f/firmware/Makefile     2007-11-03 
00:45:50 UTC (rev 6797)
@@ -25,7 +25,7 @@
 ROMS = test1.rom eth_test.rom timer_test.rom \
        ibs_tx_test.rom ibs_rx_test.rom \
        test_phy_comm.rom blink_leds.rom blink_leds2.rom \
-       gen_eth_packets.rom
+       gen_eth_packets.rom rcv_eth_packets.rom
 
 
 DUMPS = $(ROMS:.rom=.dump)
@@ -74,6 +74,9 @@
 gen_eth_packets.exe:  gen_eth_packets.o libu2fw.a
        $(CC) $(LDFLAGS) $^ -o $@
 
+rcv_eth_packets.exe:  rcv_eth_packets.o libu2fw.a
+       $(CC) $(LDFLAGS) $^ -o $@
+
 clean:
        rm -f *.a *.o *.bin *.rom *.exe *.dump
 

Modified: gnuradio/branches/developers/matt/u2f/firmware/gen_eth_packets.c
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/gen_eth_packets.c    
2007-11-03 00:22:59 UTC (rev 6796)
+++ gnuradio/branches/developers/matt/u2f/firmware/gen_eth_packets.c    
2007-11-03 00:45:50 UTC (rev 6797)
@@ -14,14 +14,14 @@
 
 // ----------------------------------------------------------------
 
-unsigned char src_mac_addr[6] = {
-  0x00, 0x0A, 0x35, 0x98, 0x76, 0x54
-};
-
 unsigned char dst_mac_addr[6] = {
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff
 };
 
+unsigned char src_mac_addr[6] = {
+  0x00, 0x0A, 0x35, 0x98, 0x76, 0x54
+};
+
 #define U2_ETHERTYPE 0xBEEF
 
 
@@ -176,8 +176,8 @@
   }
   pkt.ehdr.ethertype = U2_ETHERTYPE;
 
-  init_packet(buffer_ram(0), &pkt);
-  init_packet(buffer_ram(1), &pkt);
+  init_packet((void *)buffer_ram(0), &pkt);
+  init_packet((void *)buffer_ram(1), &pkt);
 }
 
 static int led_counter = 0;
@@ -187,9 +187,8 @@
 {
   u2_init();
 
-  // setup Rx gpio bits for GPIOM_FPGA_1 -- fpga debug output
-  //hal_gpio_set_rx_mode(15, 0, GPIOM_FPGA_1);
-  hal_gpio_set_rx_mode(15, 0, GPIOM_FPGA_0);
+  // setup tx gpio bits for GPIOM_FPGA_1 -- fpga debug output
+  hal_gpio_set_tx_mode(15, 0, GPIOM_FPGA_1);
 
   hal_puts("\ngen_eth_packets\n");
   
@@ -211,7 +210,7 @@
 
 
   while(1){
-    if (/*link_is_up &&*/ send_packet_now){
+    if (link_is_up && send_packet_now){
       send_packet_now = false;
 
       // kick off the next packet
@@ -223,7 +222,7 @@
        ;
       bp_clear_buf(0);
 
-      output_regs->leds = (led_counter++) & 0x1;
+      output_regs->leds = ((led_counter++) & 0x1) | (link_is_up ? 0x2 : 0x0);
     }
   }
 

Modified: gnuradio/branches/developers/matt/u2f/firmware/hal_io.c
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/hal_io.c     2007-11-03 
00:22:59 UTC (rev 6796)
+++ gnuradio/branches/developers/matt/u2f/firmware/hal_io.c     2007-11-03 
00:45:50 UTC (rev 6797)
@@ -78,7 +78,7 @@
 // ================================================================
 
 //
-// Does i/o using high 9-bits of tx daughterboard pins.
+// Does i/o using high 9-bits of rx daughterboard pins.
 //
 //  1 1 1 1 1 1
 //  5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
@@ -97,18 +97,18 @@
 hal_io_init(void)
 {
   // make high 9 bits of tx daughterboard outputs
-  hal_gpio_set_tx_mode(15, 7, GPIOM_OUTPUT);
+  hal_gpio_set_rx_mode(15, 7, GPIOM_OUTPUT);
 
   // and set them to zero
-  hal_gpio_set_tx(0x0000, 0xff80);
+  hal_gpio_set_rx(0x0000, 0xff80);
 }
 
 // %c
 inline void 
 hal_putc(unsigned char s)
 {
-  hal_gpio_set_tx((s << 8) | W, 0xff80);
-  hal_gpio_set_tx(0, 0xff80);
+  hal_gpio_set_rx((s << 8) | W, 0xff80);
+  hal_gpio_set_rx(0, 0xff80);
 }
 
 void

Copied: gnuradio/branches/developers/matt/u2f/firmware/rcv_eth_packets.c (from 
rev 6795, gnuradio/branches/developers/matt/u2f/firmware/gen_eth_packets.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/rcv_eth_packets.c            
                (rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/rcv_eth_packets.c    
2007-11-03 00:45:50 UTC (rev 6797)
@@ -0,0 +1,418 @@
+#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"
+
+typedef int intptr_t;
+typedef unsigned size_t;
+void exit(int status);
+
+// ----------------------------------------------------------------
+
+unsigned char dst_mac_addr[6] = {
+  0xff, 0xff, 0xff, 0xff, 0xff, 0xff
+};
+
+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
+
+#define TIMER_RATE 100000000           // 100 MHz clock
+
+static int timer_delta = TIMER_RATE/ETH_PACKET_RATE;   // ticks between 
interrupts
+
+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 */
+
+  hal_puts("\neth link changed: speed = ");
+  hal_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)
+{
+#if 1
+  // copy header into buffer
+  memcpy_wordaligned(buf, pkt, sizeof(*pkt));
+#else
+  buf[1] = 0xffff000A;
+  buf[2] = 0x35987654;
+  buf[3] = 0xBEEF0000;
+#endif
+
+  union {
+    int         i;
+    char c[4];
+  } u;
+
+  int *p = (int *)((char *) buf + sizeof(*pkt));
+  int *end = buf + BUFFER_POOL_BUFFER_SIZE;
+
+  int i = 0;
+  for (; p < end; p++, i += 4){
+    u.c[0] = i;
+    u.c[1] = i+1;
+    u.c[2] = i+2;
+    u.c[3] = i+3;
+    *p = u.i;
+  }
+}
+
+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;
+
+  init_packet((void *) buffer_ram(0), &pkt);
+  init_packet((void *) buffer_ram(1), &pkt);
+}
+
+void
+print_mac_addr(const char *addr)  /* 6-bytes */
+{
+  hal_puthex8(addr[0]); hal_putc(':');
+  hal_puthex8(addr[1]); hal_putc(':');
+  hal_puthex8(addr[2]); hal_putc(':');
+  hal_puthex8(addr[3]); hal_putc(':');
+  hal_puthex8(addr[4]); hal_putc(':');
+  hal_puthex8(addr[5]);
+}
+
+
+int
+main(void)
+{
+  u2_init();
+
+  int  prev_leds = -1;
+  int  new_leds  = 0x00;
+  output_regs->leds = 0x00;
+
+  int peak_hold_count = 0;
+
+  // setup tx gpio bits for GPIOM_FPGA_1 -- fpga debug output
+  hal_gpio_set_tx_mode(15, 0, GPIOM_FPGA_1);
+
+  hal_puts("\nrcv_eth_packets\n");
+  
+  init_packets();
+
+  // pic_register_handler(IRQ_BUFFER, buffer_irq_handler);  // poll for now
+
+  // FIXME turn off timer since I don't think MTS and MFS instructions are 
implemented
+  // 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();
+  eth_driver_init();
+  eth_mac->speed = 4;  // FIXME hardcode mac speed to 1000
+
+
+  // kick off a receive
+  bp_receive_to_buf(2, PORT_ETH, 1, 0, 511);
+
+  while(1){
+    ethernet_packet_t  pkt __attribute__((aligned (4)));
+
+    new_leds = 0;
+    if (link_is_up)
+      new_leds = 0x2;
+
+    if ((buffer_pool_status->status & (BPS_DONE_2|BPS_ERROR_2)) != 0){
+      // we've got a packet!
+
+#if 0
+      // copy to stack buffer so we can byte address it
+      memcpy_wordaligned(&pkt, (void *)buffer_ram(2), sizeof(pkt));
+      
+      hal_puts("Rx: src: ");
+      print_mac_addr(pkt.ehdr.dst_addr);
+      hal_puts(" dst: ");
+      print_mac_addr(pkt.ehdr.src_addr);
+      hal_puts(" ethtype: ");
+      hal_puthex16(pkt.ehdr.ethertype);
+      hal_puts(" len: ");
+      int len = (buffer_pool_status->last_line[2] + 1) * 4;
+      hal_puthex16_nl(len);
+#else
+      volatile int *bp = buffer_ram(2);
+      int      i;
+      for (i = 0; i < 16; i++){
+       hal_puthex8(i);
+       hal_putc(':');
+       hal_puthex32_nl(bp[i]);
+      }
+#endif
+      
+      // kick off next receive
+      bp_clear_buf(2);
+      bp_receive_to_buf(2, PORT_ETH, 1, 0, 511);
+
+      peak_hold_count = 2048 * 10;
+    }
+
+    if (peak_hold_count > 0){
+      peak_hold_count--;
+      new_leds |= 0x1;
+    }
+
+    if (new_leds != prev_leds){
+      prev_leds = new_leds;
+      output_regs->leds = new_leds;
+    }
+  }
+
+  hal_finish();
+  return 1;
+}
+
+#if 0
+void 
+double_buffering(int port) {
+  unsigned int localstatus = buffer_pool_status->status;
+
+  if(localstatus & BPS_DONE_0) {
+    bp_clear_buf(0);
+    if(buffer_state[0] == FILLING) {
+      buffer_state[0] = FULL;
+      if(buffer_state[1] == EMPTY) {
+       bp_receive_to_buf(1, 1, 1, 10, 509);  // DSP_RX to buffer 1, use 500 
lines
+       buffer_state[1] = FILLING;
+      }
+      else
+       dsp_rx_idle = 1;
+      if(serdes_tx_idle) {
+       serdes_tx_idle = 0;
+       bp_send_from_buf(0, port, 1, 10, 509);  // SERDES_TX from buffer 0
+       buffer_state[0] = EMPTYING;
+      }
+    }
+    else {  // buffer was emptying
+      buffer_state[0] = EMPTY;
+      if(dsp_rx_idle) {
+       dsp_rx_idle = 0;
+       bp_receive_to_buf(0, 1, 1, 10, 509);  // DSP_RX to buffer 0, use 500 
lines
+       buffer_state[0] = FILLING;
+      }
+      if(buffer_state[1] == FULL) {
+       bp_send_from_buf(1, port, 1, 10, 509);  // SERDES_TX from buffer 1
+       buffer_state[1] = EMPTYING;
+      }
+      else
+       serdes_tx_idle = 1;
+    }
+    hal_puts("Int Proc'ed 0\n");
+  }
+  if(localstatus & BPS_DONE_1) {
+    bp_clear_buf(1);
+    if(buffer_state[1] == FILLING) {
+      buffer_state[1] = FULL;
+      if(buffer_state[0] == EMPTY) {
+       bp_receive_to_buf(0, 1, 1, 10, 509);  // DSP_RX to buffer 1, use 500 
lines
+       buffer_state[0] = FILLING;
+      }
+      else
+       dsp_rx_idle = 1;
+      if(serdes_tx_idle) {
+       serdes_tx_idle = 0;
+       bp_send_from_buf(1, port, 1, 10, 509);  // SERDES_TX from buffer 1
+       buffer_state[1] = EMPTYING;
+      }
+    }
+    else {  // buffer was emptying
+      buffer_state[1] = EMPTY;
+      if(dsp_rx_idle) {
+       dsp_rx_idle = 0;
+       bp_receive_to_buf(1, 1, 1, 10, 509);  // DSP_RX to buffer 1, use 500 
lines
+       buffer_state[1] = FILLING;
+      }
+      if(buffer_state[0] == FULL) {
+       bp_send_from_buf(0, port, 1, 10, 509);  // SERDES_TX from buffer 0
+       buffer_state[0] = EMPTYING;
+      }
+      else
+       serdes_tx_idle = 1;
+    }
+  hal_puts("Int Proc'ed 1\n");
+  }
+  if(localstatus & BPS_DONE_2) {
+    bp_clear_buf(2);
+    if(buffer_state[2] == FILLING) {
+      buffer_state[2] = FULL;
+      if(buffer_state[3] == EMPTY) {
+       bp_receive_to_buf(3, port, 1, 5, 504);  // SERDES_RX to buffer 3, use 
500 lines
+       buffer_state[3] = FILLING;
+      }
+      else
+       serdes_rx_idle = 1;
+      if(dsp_tx_idle) {
+       dsp_tx_idle = 0;
+       bp_send_from_buf(2, 1, 1, 5, 504);  // DSP_TX from buffer 2
+       buffer_state[2] = EMPTYING;
+      }
+    }
+    else {  // buffer was emptying
+      buffer_state[2] = EMPTY;
+      if(serdes_rx_idle) {
+       serdes_rx_idle = 0;
+       bp_receive_to_buf(2, port, 1, 5, 504);  // SERDES_RX to buffer 2
+       buffer_state[2] = FILLING;
+      }
+      if(buffer_state[3] == FULL) {
+       bp_send_from_buf(3, 1, 1, 5, 504);  // DSP_TX from buffer 3
+       buffer_state[3] = EMPTYING;
+      }
+      else
+       dsp_tx_idle = 1;
+    }
+  hal_puts("Int Proc'ed 2\n");
+  }
+  if(localstatus & BPS_DONE_3) {
+    bp_clear_buf(3);
+    if(buffer_state[3] == FILLING) {
+      buffer_state[3] = FULL;
+      if(buffer_state[2] == EMPTY) {
+       bp_receive_to_buf(2, port, 1, 5, 504);  // SERDES_RX to buffer 2, use 
500 lines
+       buffer_state[2] = FILLING;
+      }
+      else
+       serdes_rx_idle = 1;
+      if(dsp_tx_idle) {
+       dsp_tx_idle = 0;
+       bp_send_from_buf(3, 1, 1, 5, 504);  // DSP_TX from buffer 3
+       buffer_state[3] = EMPTYING;
+      }
+    }
+    else {  // buffer was emptying
+      buffer_state[3] = EMPTY;
+      if(serdes_rx_idle) {
+       serdes_rx_idle = 0;
+       bp_receive_to_buf(3, port, 1, 5, 504);  // SERDES_RX to buffer 3
+       buffer_state[3] = FILLING;
+      }
+      if(buffer_state[2] == FULL) {
+       bp_send_from_buf(2, 1, 1, 5, 504);  // DSP_TX from buffer 2
+       buffer_state[2] = EMPTYING;
+      }
+      else
+       dsp_tx_idle = 1;
+    }
+  hal_puts("Int Proc'ed 3\n");
+  }
+}
+#endif





reply via email to

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