commit-gnuradio
[Top][All Lists]
Advanced

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

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


From: eb
Subject: [Commit-gnuradio] r6779 - gnuradio/branches/developers/matt/u2f/firmware
Date: Thu, 1 Nov 2007 18:12:44 -0600 (MDT)

Author: eb
Date: 2007-11-01 18:12:43 -0600 (Thu, 01 Nov 2007)
New Revision: 6779

Added:
   gnuradio/branches/developers/matt/u2f/firmware/bool.h
Modified:
   gnuradio/branches/developers/matt/u2f/firmware/Makefile
   gnuradio/branches/developers/matt/u2f/firmware/blink_leds2.c
   gnuradio/branches/developers/matt/u2f/firmware/gen_eth_packets.c
   gnuradio/branches/developers/matt/u2f/firmware/hal_io.h
   gnuradio/branches/developers/matt/u2f/firmware/memory_map.h
   gnuradio/branches/developers/matt/u2f/firmware/test_phy_comm.c
Log:
work-in-progress

Modified: gnuradio/branches/developers/matt/u2f/firmware/Makefile
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/Makefile     2007-11-02 
00:08:44 UTC (rev 6778)
+++ gnuradio/branches/developers/matt/u2f/firmware/Makefile     2007-11-02 
00:12:43 UTC (rev 6779)
@@ -24,8 +24,10 @@
 
 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
+       test_phy_comm.rom blink_leds.rom blink_leds2.rom \
+       gen_eth_packets.rom
 
+
 DUMPS = $(ROMS:.rom=.dump)
 
 LIBS = libu2fw.a
@@ -69,6 +71,9 @@
 blink_leds2.exe:  blink_leds2.o libu2fw.a
        $(CC) $(LDFLAGS) $^ -o $@
 
+gen_eth_packets.exe:  gen_eth_packets.o libu2fw.a
+       $(CC) $(LDFLAGS) $^ -o $@
+
 clean:
        rm -f *.a *.o *.bin *.rom *.exe *.dump
 

Modified: gnuradio/branches/developers/matt/u2f/firmware/blink_leds2.c
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/blink_leds2.c        
2007-11-02 00:08:44 UTC (rev 6778)
+++ gnuradio/branches/developers/matt/u2f/firmware/blink_leds2.c        
2007-11-02 00:12:43 UTC (rev 6779)
@@ -33,15 +33,12 @@
 #define DELTA_T  500                   // 5 us (10ns per tick)
 
 static int led_state_1 = 0;
-static int led_state_2 = 0;
+volatile static int led_state_2 = 0;
 
 void
 timer_handler(unsigned irq)
 {
-
-  int t = timer_regs->time;
-  timer_regs->time = t + DELTA_T;
-
+  hal_set_timeout(DELTA_T);    // schedule next timeout
   led_state_2 ^= 0x2;
 }
 
@@ -52,10 +49,8 @@
 
   //hal_puts("Setting up timer\n");
   pic_register_handler(IRQ_TIMER, timer_handler);
+  hal_set_timeout(DELTA_T);    // schedule next timeout
 
-  int t = timer_regs->time;
-  timer_regs->time = t + DELTA_T;
-
   while(1){
     led_state_1 ^= 0x1;
     output_regs->leds = led_state_1 | led_state_2;

Added: gnuradio/branches/developers/matt/u2f/firmware/bool.h
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/bool.h                       
        (rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/bool.h       2007-11-02 
00:12:43 UTC (rev 6779)
@@ -0,0 +1,29 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio 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, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef INCLUDED_BOOL_H
+#define INCLUDED_BOOL_H
+
+typedef int bool;
+#define true   1
+#define        false   0
+
+#endif /* INCLUDED_BOOL_H */


Property changes on: gnuradio/branches/developers/matt/u2f/firmware/bool.h
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: gnuradio/branches/developers/matt/u2f/firmware/gen_eth_packets.c
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/gen_eth_packets.c    
2007-11-02 00:08:44 UTC (rev 6778)
+++ gnuradio/branches/developers/matt/u2f/firmware/gen_eth_packets.c    
2007-11-02 00:12:43 UTC (rev 6779)
@@ -4,8 +4,12 @@
 #include "hal_io.h"
 #include "buffer_pool.h"
 #include "pic.h"
-#include "timer.h"
+#include "bool.h"
+// #include <stdint.h>
 
+typedef int intptr_t;
+typedef unsigned size_t;
+void exit(int status);
 
 // ----------------------------------------------------------------
 
@@ -26,57 +30,179 @@
   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
 
 
 // ----------------------------------------------------------------
 
-void buffer_irq_handler(unsigned irq);
-void timer_irq_handler(unsigned irq);
+#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_puthex_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 *p)
+init_packet(int *buf, const ethernet_packet_t *pkt)
 {
+  // copy header into buffer
+  memcpy_wordaligned(buf, pkt, sizeof(pkt));
+  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(buffer_ram(0), &pkt);
+  init_packet(buffer_ram(1), &pkt);
+}
+
+
 int
 main(void)
 {
   u2_init();
 
+  hal_puts("\n\n@@@ gen_eth_packets @@@\n\n");
+  
   // Control LEDs
   output_regs->leds = 0x00;
 
+  init_packets();
 
-  // Set up DSP RX
-  buffer_state[0] = FILLING;
-  serdes_tx_idle = 1;
-  bp_receive_to_buf(0, 1, 1, 10, 509);  // DSP_RX to buffer 0, use 500 lines
+  // pic_register_handler(IRQ_BUFFER, buffer_irq_handler);  // poll for now
+  pic_register_handler(IRQ_TIMER, timer_irq_handler);
+  hal_set_timeout(timer_delta);
 
-  dsp_rx_regs->run_rx = 1;           // Start DSP_RX
-  hal_puts("Done DSP RX setup\n");
+  int cb = 0;                  // current buffer; alternates btwn 0 & 1.
+  while(1){
+    if (link_is_up && send_packet_now){
+      send_packet_now = false;
+      // kick off the next packet
+      // FIXME set packet number in packet
+    }
+  }
 
-  // Set up serdes RX
-  buffer_state[2] = FILLING;
-  dsp_tx_idle = 1;
-  bp_receive_to_buf(2, PORT, 1, 5, 504);
-
-  while (buffer_pool_status->status == 0)  // wait for completion of DSP RX
-    ;
-
-  hal_puts("Done DSP TX setup\n");
-  dsp_tx_regs->run_tx = 1;
-
-  // register interrupt handler
-  pic_register_handler(IRQ_BUFFER, buffer_irq_handler);
-
-  u2_infinite_loop();
-
   hal_finish();
   return 1;
 }
 
+#if 0
 void 
 double_buffering(int port) {
   unsigned int localstatus = buffer_pool_status->status;
@@ -210,63 +336,4 @@
   hal_puts("Int Proc'ed 3\n");
   }
 }
-
-// Spare Code
-
-#if 0  
-  // Set up LSDAC
-  int i = 0;
-  while(1) {
-    int command = (3 << 19) | (0 << 16) |  (i & 0xffff);
-    spi_transact(SPI_TXONLY, SPI_SS_TX_DAC, command, 24, 1); // negate TX phase
-    i++;
-  }
 #endif
-
-#if 0  
-  // Write to buffer 0
-  int *buf = (int *)(BUFFER_BASE + BUFFER_0);
-  hal_puthex_nl((int)buf);
-
-  for(i=0;i<BUFFER_SIZE;i++)
-    buf[i] = i;
-
-  hal_puts("Filled buffer 0\n");
-
-  // Write to buffer 1
-  buf = (int *)(BUFFER_BASE + BUFFER_1);
-  hal_puthex_nl((int)buf);
-  for(i=0;i<BUFFER_SIZE;i++)
-    buf[i] =  i + ((i^0xFFFF) << 16);
-
-  hal_puts("Filled buffer 1\n");
-
-#endif
-
-#if 0
-  // rx SERDES into buffer #2  (buf,port,step,fl,ll)
-  bp_receive_to_buf(2, 0, 1, 10, 300);
-  hal_puts("SERDES RX buffer setup\n");
-
-  // send SERDES from buffer #0 (buf,port,step,fl,ll)
-  bp_send_from_buf(0, 0, 1, 20, 200);
-  hal_puts("SERDES TX buffer setup\n");
-
-#endif
-
-#if 0
-  // send to DACs from buffer #1
-  bp_send_from_buf(1 /*buf#*/, 1 /*port*/, 1 /*step*/, 20 /*fl*/, 250 /*ll*/);
-  hal_puts("DAC Buffer setup\n");
-#endif
-
-#if 0
-  //hal_puts("ENTER INT\n");
-  for(i=0;i<8;i++)
-    if(*status & (1<<i)) {
-      //hal_puts("Clearing buf ");
-      hal_puthex_nl(i);
-      bp_clear_buf(i);
-    }
-  //hal_puts("EXIT INT\n");
-#endif

Modified: gnuradio/branches/developers/matt/u2f/firmware/hal_io.h
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/hal_io.h     2007-11-02 
00:08:44 UTC (rev 6778)
+++ gnuradio/branches/developers/matt/u2f/firmware/hal_io.h     2007-11-02 
00:12:43 UTC (rev 6779)
@@ -19,6 +19,11 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#ifndef INCLUDED_HAL_IO_H
+#define INCLUDED_HAL_IO_H
+
+#include "memory_map.h"
+
 void hal_io_init(void);
 void hal_finish();
 
@@ -39,3 +44,15 @@
 
 void hal_gpio_set_tx(int value, int mask);
 void hal_gpio_set_rx(int value, int mask);
+
+static inline void
+hal_set_timeout(int delta_ticks)
+{
+  int t = timer_regs->time + delta_ticks;
+  if (t == 0)                  // kills timer
+    t = 1;
+  timer_regs->time = t;
+}
+
+
+#endif /* INCLUDED_HAL_IO_H */

Modified: gnuradio/branches/developers/matt/u2f/firmware/memory_map.h
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/memory_map.h 2007-11-02 
00:08:44 UTC (rev 6778)
+++ gnuradio/branches/developers/matt/u2f/firmware/memory_map.h 2007-11-02 
00:12:43 UTC (rev 6779)
@@ -1,3 +1,24 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio 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, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
 #ifndef INCLUDED_MEMORY_MAP_H
 #define INCLUDED_MEMORY_MAP_H
 
@@ -322,5 +343,4 @@
 
 #define timer_regs ((timer_regs_t *) TIMER_BASE)
 
-
 #endif

Modified: gnuradio/branches/developers/matt/u2f/firmware/test_phy_comm.c
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/test_phy_comm.c      
2007-11-02 00:08:44 UTC (rev 6778)
+++ gnuradio/branches/developers/matt/u2f/firmware/test_phy_comm.c      
2007-11-02 00:12:43 UTC (rev 6779)
@@ -38,7 +38,7 @@
 #define LS_10    0x20000
 
 
-static int led_link_up_flag = 0;
+static volatile int led_link_up_flag = 0;
 
 /*
  * Called when eth phy state changes (w/ interrupts disabled)
@@ -80,9 +80,7 @@
 {
   static int led_counter = 0;
 
-  int t = timer_regs->time;
-  timer_regs->time = t + DELTA_T;
-
+  hal_set_timeout(DELTA_T);    // schedule next timeout
   output_regs->leds = (led_counter++ & 0x1) | led_link_up_flag;
 }
 
@@ -95,10 +93,8 @@
 
   hal_puts("Setting up timer\n");
   pic_register_handler(IRQ_TIMER, timer_handler);
+  hal_set_timeout(DELTA_T);    // schedule timeout
 
-  int t = timer_regs->time;
-  timer_regs->time = t + DELTA_T;
-
   hal_gpio_set_tx_mode(15,13, GPIOM_OUTPUT);
 
   eth_driver_register_link_changed_callback(link_changed_callback);





reply via email to

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