commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r7147 - in usrp2/trunk: firmware/apps firmware/include


From: eb
Subject: [Commit-gnuradio] r7147 - in usrp2/trunk: firmware/apps firmware/include firmware/lib host/apps host/lib
Date: Thu, 13 Dec 2007 04:24:32 -0700 (MST)

Author: eb
Date: 2007-12-13 04:24:31 -0700 (Thu, 13 Dec 2007)
New Revision: 7147

Added:
   usrp2/trunk/firmware/lib/dbsm.c
   usrp2/trunk/firmware/lib/dbsm.h
   usrp2/trunk/host/apps/rx_samples.cc
Modified:
   usrp2/trunk/firmware/apps/double_buffer_fragment.c
   usrp2/trunk/firmware/apps/rcv_eth_packets.c
   usrp2/trunk/firmware/apps/rx_only.c
   usrp2/trunk/firmware/include/usrp2_eth_packet.h
   usrp2/trunk/firmware/lib/Makefile.am
   usrp2/trunk/firmware/lib/memory_map.h
   usrp2/trunk/firmware/lib/u2_init.c
   usrp2/trunk/host/apps/
   usrp2/trunk/host/apps/Makefile.am
   usrp2/trunk/host/apps/find_usrps.cc
   usrp2/trunk/host/lib/usrp2_basic.cc
   usrp2/trunk/host/lib/usrp2_basic.h
Log:
work-in-progress: not working

Modified: usrp2/trunk/firmware/apps/double_buffer_fragment.c
===================================================================
--- usrp2/trunk/firmware/apps/double_buffer_fragment.c  2007-12-13 05:42:52 UTC 
(rev 7146)
+++ usrp2/trunk/firmware/apps/double_buffer_fragment.c  2007-12-13 11:24:31 UTC 
(rev 7147)
@@ -35,6 +35,7 @@
     }
     putstr("Int Proc'ed 0\n");
   }
+
   if(localstatus & BPS_DONE_1) {
     bp_clear_buf(1);
     if(buffer_state[1] == FILLING) {
@@ -67,6 +68,7 @@
     }
   putstr("Int Proc'ed 1\n");
   }
+
   if(localstatus & BPS_DONE_2) {
     bp_clear_buf(2);
     if(buffer_state[2] == FILLING) {
@@ -99,6 +101,7 @@
     }
   putstr("Int Proc'ed 2\n");
   }
+
   if(localstatus & BPS_DONE_3) {
     bp_clear_buf(3);
     if(buffer_state[3] == FILLING) {

Modified: usrp2/trunk/firmware/apps/rcv_eth_packets.c
===================================================================
--- usrp2/trunk/firmware/apps/rcv_eth_packets.c 2007-12-13 05:42:52 UTC (rev 
7146)
+++ usrp2/trunk/firmware/apps/rcv_eth_packets.c 2007-12-13 11:24:31 UTC (rev 
7147)
@@ -179,7 +179,7 @@
   bp_receive_to_buf(2, PORT_ETH, 1, 0, 511);
 
   while(1){
-    u2_eth_packet_t    pkt;
+    // u2_eth_packet_t pkt;
 
     new_leds = 0;
     if (link_is_up)

Modified: usrp2/trunk/firmware/apps/rx_only.c
===================================================================
--- usrp2/trunk/firmware/apps/rx_only.c 2007-12-13 05:42:52 UTC (rev 7146)
+++ usrp2/trunk/firmware/apps/rx_only.c 2007-12-13 11:24:31 UTC (rev 7147)
@@ -31,12 +31,15 @@
 #include "nonstdio.h"
 #include "usrp2_eth_packet.h"
 #include "memcpy_wa.h"
+#include "dbsm.h"
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
 
 #define        _AL4 __attribute__((aligned (4)))
 
+static int timer_delta = MASTER_CLK_RATE/1000; // tick at 1kHz
+
 /*
  * This program can respond to queries from the host
  * and stream rx samples.
@@ -51,17 +54,46 @@
 #define        DSP_RX_BUF_1    3       // dsp rx -> eth
 
 
-void link_changed_callback(int speed);
+/*
+ * ================================================================
+ *      configure DSP RX double buffering state machine
+ * ================================================================
+ */
 
-static volatile bool link_is_up = false;       // eth handler sets this
+// 4 lines of ethernet hdr + 1 line (word0)
+// DSP Rx writes timestamp followed by nlines_per_frame of samples
+#define DSP_RX_FIRST_LINE                5
+#define DSP_RX_SAMPLES_PER_FRAME       125
+#define        DSP_RX_EXTRA_LINES                1     // writes timestamp
 
+// receive from DSP
+buf_cmd_args_t dsp_rx_recv_args = {
+  PORT_DSP,
+  DSP_RX_FIRST_LINE,
+  DSP_RX_FIRST_LINE + DSP_RX_SAMPLES_PER_FRAME + DSP_RX_EXTRA_LINES - 1
+};
 
+// send to ETH
+buf_cmd_args_t dsp_rx_send_args = {
+  PORT_ETH,
+  0,           // starts with ethernet header in line 0
+  DSP_RX_FIRST_LINE + DSP_RX_SAMPLES_PER_FRAME + DSP_RX_EXTRA_LINES - 1
+};
+
+dbsm_t dsp_rx_sm;      // the state machine
+
+// ----------------------------------------------------------------
+
+
+
 // The mac address of the host we're sending to.
-unsigned char host_mac_addr[6];
+u2_mac_addr_t host_mac_addr;
 
 
-static int timer_delta = MASTER_CLK_RATE/1000; // tick at 1kHz
+void link_changed_callback(int speed);
+static volatile bool link_is_up = false;       // eth handler sets this
 
+
 void
 timer_irq_handler(unsigned irq)
 {
@@ -70,6 +102,53 @@
 
 
 static void
+start_rx_cmd(const u2_mac_addr_t *host)
+{
+  hal_toggle_leds(0x2);
+
+  host_mac_addr = *host;       // remember who we're sending to
+
+  /*
+   * Construct  ethernet header and word0 and preload into two buffers
+   */
+  u2_eth_packet_t      pkt;
+  memset(&pkt, 0, sizeof(pkt));
+  pkt.ehdr.dst = *host;
+  pkt.ehdr.ethertype = U2_ETHERTYPE;
+  u2p_set_word0(&pkt.fixed, 0, 0);
+  // DSP RX will fill in timestamp
+
+  memcpy_wordaligned(buffer_ram(DSP_RX_BUF_0), &pkt, sizeof(pkt));
+  memcpy_wordaligned(buffer_ram(DSP_RX_BUF_1), &pkt, sizeof(pkt));
+
+
+  // setup RX DSP regs
+  dsp_rx_regs->clear_state = 1;                // reset
+  dsp_rx_regs->freq = 0;
+  dsp_rx_regs->scale_iq = (1 << 16) | 1;
+  dsp_rx_regs->decim_rate = 24;                // register gets N - 1
+
+  dsp_rx_regs->rx_command =
+    MK_RX_CMD(10000 * DSP_RX_SAMPLES_PER_FRAME, DSP_RX_SAMPLES_PER_FRAME);
+
+  // kick off the state machine
+  dbsm_start(&dsp_rx_sm);
+
+  dsp_rx_regs->rx_time = T_NOW;                // start NOW!
+
+  // FIXME need to arrange to add additional stuff to cmd queue
+}
+
+
+static void
+stop_rx_cmd(void)
+{
+  dsp_rx_regs->clear_state = 1;        // FIXME need to flush cmd queue
+  bp_clear_buf(DSP_RX_BUF_0);
+  bp_clear_buf(DSP_RX_BUF_1);
+}
+
+static void
 set_reply_hdr(u2_eth_packet_t *reply_pkt, u2_eth_packet_t const *cmd_pkt)
 {
   reply_pkt->ehdr.dst = cmd_pkt->ehdr.src;
@@ -82,20 +161,18 @@
 static void
 handle_control_chan_frame(int bufno, u2_eth_packet_t *pkt, size_t len)
 {
-  static unsigned char buf[256] _AL4;
+  static unsigned char payload[256] _AL4;
   static unsigned char reply[sizeof(u2_eth_packet_t) + sizeof(u2_subpkt_t)] 
_AL4;
   unsigned char *s = &reply[sizeof(u2_eth_packet_t)];
   size_t reply_len = 0;
   int   i;
 
-  // copy 512 bytes of payload into stack buffer
+  // copy 256 bytes of payload into stack buffer
+  memcpy_wordaligned(payload,
+                    (unsigned char *) buffer_ram(bufno) + 
sizeof(u2_eth_packet_t),
+                    sizeof(payload));
 
-  unsigned char *src =
-    (unsigned char *) buffer_ram(bufno) + offsetof(u2_eth_packet_t,
-                                                  fixed.payload);
-  memcpy_wordaligned(buf, src, sizeof(buf));
-
-  unsigned char *p = buf;
+  unsigned char *p = payload;
   int opcode = p[0];
 
   switch(opcode){
@@ -110,7 +187,7 @@
       r->opcode = OP_ID_REPLY;
       r->len = sizeof(op_id_reply_t);
       r->rid_mbz = 0;          // FIXME
-      memcpy(r->mac_addr, eth_mac_addr(), 6);
+      memcpy(&r->addr, eth_mac_addr(), 6);
       r->hw_rev = 0x0000;      // FIXME
       for (i = 0; i < sizeof(r->serial_no); i++)
        r->serial_no[i] = '0';  // FIXME
@@ -127,9 +204,14 @@
     bp_send_from_buf(CPU_TX_BUF, PORT_ETH, 1, 0, reply_len / 4);
     break;
     
+  case OP_START_RX:
+    start_rx_cmd(&pkt->ehdr.src);
+    break;
     
-  case OP_START_RX:
   case OP_STOP_RX:
+    stop_rx_cmd();
+    break;
+    
   default:
     break;
   }
@@ -139,7 +221,6 @@
 handle_rcvd_eth_frame(int bufno)
 {
   u2_eth_packet_t pkt;
-  int   i;
   size_t byte_len = (buffer_pool_status->last_line[bufno] - 1) * 4;
 
   hal_toggle_leds(0x1);
@@ -149,15 +230,12 @@
   // copy first part of frame to stack buffer so we can byte address it
   memcpy_wordaligned(&pkt, buffer_ram(bufno), sizeof(pkt));
 
-#if 1
   if (pkt.ehdr.ethertype != U2_ETHERTYPE)
     return;            // ignore, probably bogus PAUSE frame from MAC
 
-
   int chan = u2p_chan(&pkt.fixed);
   switch (chan){
   case CONTROL_CHAN:
-    hal_toggle_leds(0x2);
     handle_control_chan_frame(bufno, &pkt, byte_len);
     break;
 
@@ -165,25 +243,6 @@
   default:
     break;
   }
-#else
-
-  if (pkt.ehdr.ethertype != U2_ETHERTYPE)
-    return;            // ignore, probably bogus PAUSE frame from MAC
-
-  // copy src to dst, and send it back
-  for (i = 0; i < 6; i++)
-    pkt.ehdr.dst_addr[i] = pkt.ehdr.src_addr[i];
-
-  memcpy_wordaligned((void *)buffer_ram(bufno), &pkt, sizeof(pkt));
-
-  bp_send_from_buf(CPU_RX_BUF, PORT_ETH, 1,
-                  0, byte_len / 4);
-
-  while((buffer_pool_status->status & BPS_DONE(CPU_RX_BUF)) == 0)
-    ;
-
-  bp_clear_buf(CPU_RX_BUF);
-#endif
 }
 
 void
@@ -207,8 +266,7 @@
     bp_clear_buf(CPU_TX_BUF);
   }
 
-  // FIXME if we're streaming...
-  
+  dbsm_process_status(&dsp_rx_sm, status);
 }
 
 int
@@ -235,14 +293,14 @@
   eth_mac_init();
   eth_driver_init();
 
-  // FIXME initialize state machine
+  // initialize double buffering state machine for DSP RX -> Ethernet
+  dbsm_init(&dsp_rx_sm, DSP_RX_BUF_0, &dsp_rx_recv_args, &dsp_rx_send_args);
 
+
   // setup receive from ETH
   bp_receive_to_buf(CPU_RX_BUF, PORT_ETH, 1, 0, 255);
 
   while(1){
-    // buffer_irq_handler(0);
-
     // FIXME perhaps handle low-pri stuff here
   }
 }

Modified: usrp2/trunk/firmware/include/usrp2_eth_packet.h
===================================================================
--- usrp2/trunk/firmware/include/usrp2_eth_packet.h     2007-12-13 05:42:52 UTC 
(rev 7146)
+++ usrp2/trunk/firmware/include/usrp2_eth_packet.h     2007-12-13 11:24:31 UTC 
(rev 7147)
@@ -85,8 +85,7 @@
 typedef struct {
   uint32_t     word0;          // flags etc
   uint32_t     timestamp;      // time of rx or tx (100 MHz)
-  uint32_t     payload[];      // samples, typically ((I << 16) | Q)
-} u2_eth_fixed_hdr_t;
+} u2_fixed_hdr_t;
 
 
 #define U2P_CHAN_MASK          0x1f
@@ -101,45 +100,59 @@
 #define        CONTROL_CHAN            0x1f
 
 static inline int
-u2p_chan(u2_eth_fixed_hdr_t *p)
+u2p_chan(u2_fixed_hdr_t *p)
 {
   return (ntohl(p->word0) >> U2P_CHAN_SHIFT) & U2P_CHAN_MASK;
 }
 
 inline static uint32_t
-u2p_word0(u2_eth_fixed_hdr_t *p)
+u2p_word0(u2_fixed_hdr_t *p)
 {
   return ntohl(p->word0);
 }
 
 inline static uint32_t
-u2p_timestamp(u2_eth_fixed_hdr_t *p)
+u2p_timestamp(u2_fixed_hdr_t *p)
 {
   return ntohl(p->timestamp);
 }
 
 inline static void
-u2p_set_word0(u2_eth_fixed_hdr_t *p, int flags, int chan)
+u2p_set_word0(u2_fixed_hdr_t *p, int flags, int chan)
 {
   p->word0 = htonl((flags & U2P_ALL_FLAGS)
                   | ((chan & U2P_CHAN_MASK) << U2P_CHAN_SHIFT));
 }
 
 inline static void
-u2p_set_timestamp(u2_eth_fixed_hdr_t *p, uint32_t ts)
+u2p_set_timestamp(u2_fixed_hdr_t *p, uint32_t ts)
 {
   p->timestamp = htonl(ts);
 }
 
 /*
- * consolidated packet: ethernet header + pad + payload
+ * consolidated packet: ethernet header + pad + fixed header
  */
 typedef struct {
   u2_eth_hdr_with_pad_t        ehdr;
-  u2_eth_fixed_hdr_t   fixed;
+  u2_fixed_hdr_t       fixed;
 } u2_eth_packet_t;
 
 /*
+ * full load of samples:
+ *   ethernet header + pad + fixed header + maximum number of samples.
+ *   sizeof(u2_eth_samples_t) == 2048
+ */
+
+#define U2_MAX_SAMPLES 506
+
+typedef struct {
+  u2_eth_hdr_with_pad_t        ehdr;
+  u2_fixed_hdr_t       fixed;
+  uint32_t             samples[U2_MAX_SAMPLES];
+} u2_eth_samples_t;
+
+/*
  * Opcodes for control channel
  */
 #define OP_ID                  0
@@ -164,7 +177,7 @@
   uint8_t      opcode;
   uint8_t      len;
   uint16_t     rid_mbz;
-  uint8_t      mac_addr[6];
+  u2_mac_addr_t        addr;
   uint16_t     hw_rev;
   uint8_t      serial_no[8];
   uint8_t      fpga_md5sum[16];

Modified: usrp2/trunk/firmware/lib/Makefile.am
===================================================================
--- usrp2/trunk/firmware/lib/Makefile.am        2007-12-13 05:42:52 UTC (rev 
7146)
+++ usrp2/trunk/firmware/lib/Makefile.am        2007-12-13 11:24:31 UTC (rev 
7147)
@@ -22,6 +22,7 @@
 
 libu2fw_a_SOURCES = \
        buffer_pool.c \
+       dbsm.c \
        eeprom.c \
        eth_driver.c \
        eth_mac.c \

Added: usrp2/trunk/firmware/lib/dbsm.c
===================================================================
--- usrp2/trunk/firmware/lib/dbsm.c                             (rev 0)
+++ usrp2/trunk/firmware/lib/dbsm.c     2007-12-13 11:24:31 UTC (rev 7147)
@@ -0,0 +1,141 @@
+/* -*- c++ -*- */
+/*
+ * 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/>.
+ */
+
+/*
+ * Double Buffering State Machine
+ */
+
+#include "dbsm.h"
+#include "memory_map.h"
+#include "buffer_pool.h"
+#include "bool.h"
+#include <stdlib.h>
+
+typedef enum {
+  BS_EMPTY,
+  BS_FILLING,
+  BS_FULL,
+  BS_EMPTYING,
+} buffer_state_t;
+
+buffer_state_t buffer_state[NBUFFERS];
+
+
+void
+dbsm_init(dbsm_t *sm, int buf0,
+         const buf_cmd_args_t *recv, const buf_cmd_args_t *send)
+{
+  if (buf0 & 0x1)      // must be even
+    abort();
+
+  sm->buf0 = buf0;
+  sm->running = false;
+  sm->recv_args = *recv;
+  sm->send_args = *send;
+
+  sm->rx_idle = true;
+  sm->tx_idle = true;
+
+  buffer_state[sm->buf0] = BS_EMPTY;
+  buffer_state[sm->buf0 ^ 1] = BS_EMPTY;
+}
+
+
+void
+dbsm_start(dbsm_t *sm)
+{
+  sm->running = true;
+
+  buffer_state[sm->buf0] = BS_EMPTY;
+  buffer_state[sm->buf0 ^ 1] = BS_EMPTY;
+
+  bp_clear_buf(sm->buf0);
+  bp_clear_buf(sm->buf0 ^ 1);
+
+  sm->tx_idle = true;
+  sm->rx_idle = false;
+  bp_receive_to_buf(sm->buf0, sm->recv_args.port, 1,
+                   sm->recv_args.first_line, sm->recv_args.last_line);
+  buffer_state[sm->buf0] = BS_FILLING;
+}
+
+
+void
+dbsm_stop(dbsm_t *sm)
+{
+  sm->running = false;
+  bp_clear_buf(sm->buf0);
+  bp_clear_buf(sm->buf0 ^ 1);
+  buffer_state[sm->buf0] = BS_EMPTY;
+  buffer_state[sm->buf0 ^ 1] = BS_EMPTY;
+}
+
+
+void
+dbsm_process_helper(dbsm_t *sm, uint32_t status, int buf_this)
+{
+  int buf_other = buf_this ^ 1;
+
+  if (status & BPS_DONE(buf_this)){
+    bp_clear_buf(buf_this);
+
+    if (buffer_state[buf_this] == BS_FILLING){
+      buffer_state[buf_this] = BS_FULL;
+      if(buffer_state[buf_other] == BS_EMPTY){
+       bp_receive_to_buf(buf_other, sm->recv_args.port, 1,
+                         sm->recv_args.first_line, sm->recv_args.last_line);
+       buffer_state[buf_other] = BS_FILLING;
+      }
+      else
+       sm->rx_idle = true;
+
+      if (sm->tx_idle){
+       sm->tx_idle = false;
+       bp_send_from_buf(buf_this, sm->send_args.port, 1,
+                        sm->send_args.first_line, sm->send_args.last_line);
+       buffer_state[buf_this] = BS_EMPTYING;
+      }
+    }
+    else {  // buffer was emptying
+      buffer_state[buf_this] = BS_EMPTY;
+      if (sm->rx_idle){
+       sm->rx_idle = false;
+       bp_receive_to_buf(buf_this, sm->recv_args.port, 1,
+                         sm->recv_args.first_line, sm->recv_args.last_line);
+       buffer_state[buf_this] = BS_FILLING;
+      }
+      if (buffer_state[buf_other] == BS_FULL){
+       bp_send_from_buf(buf_other, sm->send_args.port, 1,
+                        sm->send_args.first_line, sm->send_args.last_line);
+       buffer_state[buf_other] = BS_EMPTYING;
+      }
+      else
+       sm->tx_idle = true;
+    }
+  }
+}
+
+void
+dbsm_process_status(dbsm_t *sm, uint32_t status)
+{
+  if (!sm->running)
+    return;
+
+  dbsm_process_helper(sm, status, sm->buf0);
+  dbsm_process_helper(sm, status, sm->buf0 ^ 1);
+}


Property changes on: usrp2/trunk/firmware/lib/dbsm.c
___________________________________________________________________
Name: svn:eol-style
   + native

Added: usrp2/trunk/firmware/lib/dbsm.h
===================================================================
--- usrp2/trunk/firmware/lib/dbsm.h                             (rev 0)
+++ usrp2/trunk/firmware/lib/dbsm.h     2007-12-13 11:24:31 UTC (rev 7147)
@@ -0,0 +1,54 @@
+/* -*- c++ -*- */
+/*
+ * 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/>.
+ */
+#ifndef INCLUDED_DBSM_H
+#define INCLUDED_DBSM_H
+
+/*
+ * Double Buffering State Machine
+ */
+
+#include <stdint.h>
+
+typedef struct
+{
+  uint16_t     port;
+  uint16_t     first_line;
+  uint16_t     last_line;
+} buf_cmd_args_t;
+
+/*!
+ * double buffer state machine
+ */
+typedef struct
+{
+  uint8_t        buf0;      // Must be even. This machine uses buf0 and buf0+1
+  uint8_t        running;
+  uint8_t        rx_idle;
+  uint8_t        tx_idle;
+  buf_cmd_args_t  recv_args;
+  buf_cmd_args_t  send_args;
+  
+} dbsm_t;
+
+void dbsm_init(dbsm_t *sm, int buf0,
+              const buf_cmd_args_t *recv, const buf_cmd_args_t *send);
+void dbsm_start(dbsm_t *sm);
+void dbsm_stop(dbsm_t *sm);
+void dbsm_process_status(dbsm_t *sm, uint32_t status);
+
+#endif /* INCLUDED_DBSM_H */


Property changes on: usrp2/trunk/firmware/lib/dbsm.h
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: usrp2/trunk/firmware/lib/memory_map.h
===================================================================
--- usrp2/trunk/firmware/lib/memory_map.h       2007-12-13 05:42:52 UTC (rev 
7146)
+++ usrp2/trunk/firmware/lib/memory_map.h       2007-12-13 11:24:31 UTC (rev 
7147)
@@ -162,9 +162,9 @@
 #define BUFFER_POOL_STATUS_BASE 0xB000
 
 typedef struct {
-  volatile uint32_t last_line[8];     // last line xfer'd in buffer
-  volatile uint32_t status;          // error and done flags
-  volatile uint32_t hw_config;       // see below
+  volatile uint32_t last_line[NBUFFERS]; // last line xfer'd in buffer
+  volatile uint32_t status;             // error and done flags
+  volatile uint32_t hw_config;          // see below
 } buffer_pool_status_t;
 
 #define buffer_pool_status ((buffer_pool_status_t *) BUFFER_POOL_STATUS_BASE)
@@ -328,6 +328,8 @@
 
 // --- dsp rx regs ---
 
+#define T_NOW (-1)
+
 typedef struct {
   volatile int32_t     freq;
   volatile uint32_t    scale_iq;       // {scale_i,scale_q}
@@ -339,6 +341,9 @@
   
 #define dsp_rx_regs ((dsp_rx_regs_t *) DSP_RX_BASE)
 
+#define MK_RX_CMD(num_lines, lines_per_frame) \
+  (((num_lines) << 9) | ((lines_per_frame) & 0x1ff))
+
 ///////////////////////////////////////////////////
 // Simple Programmable Interrupt Controller, Slave 8
 

Modified: usrp2/trunk/firmware/lib/u2_init.c
===================================================================
--- usrp2/trunk/firmware/lib/u2_init.c  2007-12-13 05:42:52 UTC (rev 7146)
+++ usrp2/trunk/firmware/lib/u2_init.c  2007-12-13 11:24:31 UTC (rev 7147)
@@ -55,7 +55,7 @@
   output_regs->clk_ctrl = 0x1C;
 
 
-#if 0
+#if 1
   // Enable ADCs
   output_regs->adc_ctrl = 0; // Power up and enable outputs
 #endif


Property changes on: usrp2/trunk/host/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
find_usrps

   + *-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
find_usrps
rx_samples


Modified: usrp2/trunk/host/apps/Makefile.am
===================================================================
--- usrp2/trunk/host/apps/Makefile.am   2007-12-13 05:42:52 UTC (rev 7146)
+++ usrp2/trunk/host/apps/Makefile.am   2007-12-13 11:24:31 UTC (rev 7147)
@@ -22,7 +22,9 @@
 LDADD = ../lib/libusrp2.la
 
 bin_PROGRAMS = \
-       find_usrps
+       find_usrps \
+       rx_samples
 
 find_usrps_SOURCES = find_usrps.cc
+rx_samples_SOURCES = rx_samples.cc
 

Modified: usrp2/trunk/host/apps/find_usrps.cc
===================================================================
--- usrp2/trunk/host/apps/find_usrps.cc 2007-12-13 05:42:52 UTC (rev 7146)
+++ usrp2/trunk/host/apps/find_usrps.cc 2007-12-13 11:24:31 UTC (rev 7147)
@@ -45,6 +45,5 @@
     return 1;
   }
 
-  
-  
+  return 0;
 }

Copied: usrp2/trunk/host/apps/rx_samples.cc (from rev 7144, 
usrp2/trunk/host/apps/find_usrps.cc)
===================================================================
--- usrp2/trunk/host/apps/rx_samples.cc                         (rev 0)
+++ usrp2/trunk/host/apps/rx_samples.cc 2007-12-13 11:24:31 UTC (rev 7147)
@@ -0,0 +1,75 @@
+/* -*- c++ -*- */
+/*
+ * 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/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include "usrp2_basic.h"
+#include <iostream>
+
+
+int
+main(int argc, char **argv)
+{
+  const char *interface = "eth0";
+  usrp2_basic *u2 = new usrp2_basic();
+
+  if (!u2->open(interface)){
+    std::cerr << "couldn't open " << interface << std::endl;
+    return 0;
+  }
+
+  std::vector<op_id_reply_t> r = u2->find_usrps();
+
+  for (size_t i = 0; i < r.size(); i++){
+    std::cout << r[i] << std::endl;
+  }
+
+  if (r.size() == 0){
+    std::cerr << "No USRP2 found.\n";
+    return 1;
+  }
+
+  u2_mac_addr_t which = r[0].addr;     // pick the first one
+
+  if (!u2->start_rx(which)){
+    std::cerr << "start_rx failed\n";
+    return 1;
+  }
+
+  while (1){
+    u2_eth_samples_t   pkt;
+    
+    // read samples
+    int n = u2->read_samples(which, &pkt);
+    if (n <= 0)
+      break;
+
+    int16_t *p = (int16_t *) pkt.samples;
+    for (int i = 0; i < n; i++){
+      printf("%6d %6d\n", p[2*i + 0], p[2*i + 1]);
+    }
+  }
+
+  if (!u2->stop_rx(which)){
+    std::cerr << "stop_rx failed\n";
+    return 1;
+  }
+
+  return 0;
+}

Modified: usrp2/trunk/host/lib/usrp2_basic.cc
===================================================================
--- usrp2/trunk/host/lib/usrp2_basic.cc 2007-12-13 05:42:52 UTC (rev 7146)
+++ usrp2/trunk/host/lib/usrp2_basic.cc 2007-12-13 11:24:31 UTC (rev 7147)
@@ -40,6 +40,7 @@
 usrp2_basic::usrp2_basic()
   : d_ethernet(new gri_ethernet()), d_pf(0)
 {
+  assert(sizeof(u2_eth_samples_t) == (size_t) MAX_PKTLEN);
 }
 
 usrp2_basic::~usrp2_basic()
@@ -70,6 +71,8 @@
   return d_ethernet->close();
 }
 
+// ------------------------------------------------------------------------
+
 std::vector<op_id_reply_t> 
 usrp2_basic::find_usrps()
 {
@@ -142,16 +145,117 @@
   return result;
 }
 
-std::ostream& operator<<(std::ostream &os, const op_id_reply_t &r)
+bool
+usrp2_basic::start_rx(const u2_mac_addr_t &which)
 {
-  char buf[512];
+  uint8_t      pktbuf[MAX_PKTLEN];
+  memset(pktbuf, 0, sizeof(pktbuf));
 
+  struct command {
+    u2_eth_packet_t    h;
+    op_id_t            op_start_rx;
+  };
+    
+  command      *c = (command *) pktbuf;
+  c->h.ehdr.ethertype = htons(U2_ETHERTYPE);
+  c->h.ehdr._pad = 0;
+  c->h.ehdr.dst = which;
+  memcpy(&c->h.ehdr.src, d_ethernet->mac(), 6);
+  u2p_set_word0(&c->h.fixed, 0, CONTROL_CHAN);
+  u2p_set_timestamp(&c->h.fixed, -1);
+
+  c->op_start_rx.opcode = OP_START_RX;
+  c->op_start_rx.len = sizeof(op_start_rx_t);
+  int len = std::max((size_t) MIN_PKTLEN, sizeof(command));
+  if (d_ethernet->write_packet(c, len) != len)
+    return false;
+
+  return true;
+}
+
+bool
+usrp2_basic::stop_rx(const u2_mac_addr_t &which)
+{
+  uint8_t      pktbuf[MAX_PKTLEN];
+  memset(pktbuf, 0, sizeof(pktbuf));
+
+  struct command {
+    u2_eth_packet_t    h;
+    op_id_t            op_stop_rx;
+  };
+    
+  command      *c = (command *) pktbuf;
+  c->h.ehdr.ethertype = htons(U2_ETHERTYPE);
+  c->h.ehdr._pad = 0;
+  c->h.ehdr.dst = which;
+  memcpy(&c->h.ehdr.src, d_ethernet->mac(), 6);
+  u2p_set_word0(&c->h.fixed, 0, CONTROL_CHAN);
+  u2p_set_timestamp(&c->h.fixed, -1);
+
+  c->op_stop_rx.opcode = OP_STOP_RX;
+  c->op_stop_rx.len = sizeof(op_stop_rx_t);
+  int len = std::max((size_t) MIN_PKTLEN, sizeof(command));
+  if (d_ethernet->write_packet(c, len) != len)
+    return false;
+
+  return true;
+}
+
+// ------------------------------------------------------------------------
+
+int
+usrp2_basic::read_raw_samples(const u2_mac_addr_t &which,
+                             u2_eth_samples_t *pkt)
+{
+  int len = d_ethernet->read_packet(pkt, sizeof(pkt), 0);
+  if (len <= 0)
+    return len;
+
+  // FIXME check channel
+
+  // convert to samples
+  return (len - sizeof(u2_eth_packet_t)) / sizeof(uint32_t);
+}
+
+int
+usrp2_basic::read_samples(const u2_mac_addr_t &which,
+                         u2_eth_samples_t *pkt)
+{
+  int r = read_raw_samples(which, pkt);
+
+#ifndef WORDS_BIGENDIAN
+  for (int i = 0; i < r; i++)
+    pkt->samples[i] = ntohl(pkt->samples[i]);
+#endif  
+
+  return r;
+}
+
+// ------------------------------------------------------------------------
+
+std::ostream& operator<<(std::ostream &os, const op_id_reply_t &x)
+{
+  os << x.addr;
+
+  char buf[128];
   snprintf(buf, sizeof(buf),
-          "%02x:%02x:%02x:%02x:%02x:%02x hw_rev = 0x%04x serial_no = %.8s",
-          r.mac_addr[0],r.mac_addr[1],r.mac_addr[2],
-          r.mac_addr[3],r.mac_addr[4],r.mac_addr[5],
-          r.hw_rev, r.serial_no);
+          " hw_rev = 0x%04x serial_no = %.8s",
+          x.hw_rev, x.serial_no);
 
   os << buf;
   return os;
 }
+
+std::ostream& operator<<(std::ostream &os, const u2_mac_addr_t &x)
+{
+  char buf[128];
+
+  snprintf(buf, sizeof(buf),
+          "%02x:%02x:%02x:%02x:%02x:%02x",
+          x.addr[0],x.addr[1],x.addr[2],
+          x.addr[3],x.addr[4],x.addr[5]);
+
+  os << buf;
+  return os;
+}
+

Modified: usrp2/trunk/host/lib/usrp2_basic.h
===================================================================
--- usrp2/trunk/host/lib/usrp2_basic.h  2007-12-13 05:42:52 UTC (rev 7146)
+++ usrp2/trunk/host/lib/usrp2_basic.h  2007-12-13 11:24:31 UTC (rev 7147)
@@ -47,10 +47,30 @@
    */
   std::vector<op_id_reply_t> find_usrps();
 
-  bool start_rx(const u2_mac_addr_t &addr);
+  bool start_rx(const u2_mac_addr_t &which);
+  bool stop_rx(const u2_mac_addr_t &which);
+
+  /*!
+   * \brief Read raw samples from USRP2.
+   *
+   * \param pkt contains the raw (non-endian corrected) samples
+   * \returns number of valid samples in pkt.
+   */
+  int read_raw_samples(const u2_mac_addr_t &which,
+                      u2_eth_samples_t *pkt);
+
+  /*!
+   * \brief Read native-endian samples from USRP2.
+   *
+   * \param pkt contains native-endian samples.
+   * \returns number of valid samples in pkt.
+   */
+  int read_samples(const u2_mac_addr_t &which,
+                  u2_eth_samples_t *pkt);
+
 };
 
-std::ostream& operator<<(std::ostream &os,
-                        const op_id_reply_t &r);
+std::ostream& operator<<(std::ostream &os, const op_id_reply_t &x);
+std::ostream& operator<<(std::ostream &os, const u2_mac_addr_t &x);
 
 #endif /* INCLUDED_USRP2_BASIC_H */





reply via email to

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