[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r6392 - in gnuradio/branches/developers/gnychis/inband
From: |
gnychis |
Subject: |
[Commit-gnuradio] r6392 - in gnuradio/branches/developers/gnychis/inband/usrp/host: apps-inband lib/inband |
Date: |
Mon, 10 Sep 2007 19:39:51 -0600 (MDT) |
Author: gnychis
Date: 2007-09-10 19:39:51 -0600 (Mon, 10 Sep 2007)
New Revision: 6392
Modified:
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/Makefile.am
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.cc
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.h
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.mbh
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc
Log:
Error in MBH, that's what I get for copy+paste
GMAC now successfully connects to usrp_server and is fully initialized.
Modified:
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/Makefile.am
===================================================================
---
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/Makefile.am
2007-09-11 01:12:44 UTC (rev 6391)
+++
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/Makefile.am
2007-09-11 01:39:51 UTC (rev 6392)
@@ -37,6 +37,7 @@
test_usrp_inband_timestamps \
test_usrp_inband_overrun \
test_usrp_inband_underrun \
+ test_gmac_tx \
read_packets
noinst_HEADERS = \
@@ -64,9 +65,8 @@
libgmac_la_LDFLAGS = $(NO_UNDEFINED) -avoid-version
-libgmac_inband_la_LIBADD = \
- $(MBLOCK_LA) \
- $(USRP_LA) \
+libgmac_la_LIBADD = \
+ $(CPPUNIT_LIBS) \
-lstdc++
@@ -94,5 +94,8 @@
test_usrp_inband_rx_SOURCES = test_usrp_inband_rx.cc ui_sincos.c
test_usrp_inband_rx_LDADD = $(USRP_LA) $(USRP_INBAND_LA)
+test_gmac_tx_SOURCES = test_gmac_tx.cc ui_sincos.c
+test_gmac_tx_LDADD = $(USRP_LA) $(USRP_INBAND_LA) libgmac.la
+
read_packets_SOURCES = read_packets.cc
read_packets_LDADD = $(USRP_LA) $(USRP_INBAND_LA)
Modified:
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.cc
===================================================================
--- gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.cc
2007-09-11 01:12:44 UTC (rev 6391)
+++ gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.cc
2007-09-11 01:39:51 UTC (rev 6392)
@@ -47,10 +47,11 @@
#include <symbols_usrp_tx.h>
#include <symbols_usrp_rx.h>
-static bool verbose = false;
+static bool verbose = true;
gmac::gmac(mb_runtime *rt, const std::string &instance_name, pmt_t user_arg)
- : mb_mblock(rt, instance_name, user_arg)
+ : mb_mblock(rt, instance_name, user_arg),
+ d_us_rx_chan(PMT_NIL), d_us_tx_chan(PMT_NIL)
{
// When the MAC layer is initialized, we must connect to the USRP and setup
@@ -63,8 +64,6 @@
// Initialize the connection to the USRP
initialize_usrp();
- // Initialize the MAC layer
- initialize_gmac();
}
gmac::~gmac()
@@ -92,8 +91,7 @@
switch(d_state) {
//---------------------------- INIT ------------------------------------//
- // In the INIT state, there should be no messages across the ports. It is
- // used as a state to initialize the MAC protocol.
+ // In the INIT state, there should be no messages across the ports.
case INIT:
error_msg = "no messages should be passed during the INIT state:";
goto unhandled;
@@ -129,21 +127,21 @@
// ************* TX ALLOCATION RESPONSE ***************** //
if(pmt_eq(event, s_response_allocate_channel)
- && pmt_eq(d_tx->port_symbol(), port_id))
+ && pmt_eq(d_us_tx->port_symbol(), port_id))
{
status = pmt_nth(1, data);
if(pmt_eq(status, PMT_T)) { // extract channel on success
- d_tx_chan = pmt_nth(2, data);
+ d_us_tx_chan = pmt_nth(2, data);
if(verbose)
std::cout << "[GMAC] Received TX allocation"
- << " on channel " << d_tx_chan << std::endl;
+ << " on channel " << d_us_tx_chan << std::endl;
// If the RX has also been allocated already, we can continue
- if(!pmt_eqv(d_rx_chan, PMT_NIL)) {
+ if(!pmt_eqv(d_us_rx_chan, PMT_NIL)) {
enter_receiving();
- enter_idle();
+ initialize_gmac();
}
return;
@@ -156,22 +154,22 @@
// ************* RX ALLOCATION RESPONSE ****************//
if(pmt_eq(event, s_response_allocate_channel)
- && pmt_eq(d_rx->port_symbol(), port_id))
+ && pmt_eq(d_us_rx->port_symbol(), port_id))
{
status = pmt_nth(1, data);
if(pmt_eq(status, PMT_T)) {
- d_rx_chan = pmt_nth(2, data);
+ d_us_rx_chan = pmt_nth(2, data);
if(verbose)
- std::cout << "[TEST_USRP_INBAND_UNDERRUN] Received RX allocation"
- << " on channel " << d_rx_chan << std::endl;
+ std::cout << "[GMAC] Received RX allocation"
+ << " on channel " << d_us_rx_chan << std::endl;
// If the TX has also been allocated already, we can continue
- if(!pmt_eqv(d_tx_chan, PMT_NIL)) {
+ if(!pmt_eqv(d_us_tx_chan, PMT_NIL)) {
enter_receiving();
- enter_idle();
+ initialize_gmac();
}
return;
@@ -184,6 +182,13 @@
goto unhandled;
+ //----------------------------- INIT GMAC
--------------------------------//
+ // In the INIT_GMAC state, now that the USRP is initialized we can do
things
+ // like right the carrier sense threshold to the FPGA register.
+ case INIT_GMAC:
+ goto unhandled;
+
+
//----------------------------- IDLE ------------------------------------//
// In the idle state the MAC is not quite 'idle', it is just not doing
// anything specific. It is still being passive with data between the
@@ -193,6 +198,58 @@
//------------------------ CLOSING CHANNELS -----------------------------//
case CLOSING_CHANNELS:
+
+ if (pmt_eq(event, s_response_deallocate_channel)
+ && pmt_eq(d_us_tx->port_symbol(), port_id))
+ {
+ status = pmt_nth(1, data);
+
+ if(pmt_eq(status, PMT_T)) {
+ d_us_tx_chan = PMT_NIL;
+
+ if(verbose)
+ std::cout << "[GMAC] Received TX deallocation\n";
+
+ // If the RX is also deallocated, we can close the USRP
+ if(pmt_eq(d_us_rx_chan, PMT_NIL))
+ close_usrp();
+
+ return;
+
+ } else {
+
+ error_msg = "failed to deallocate TX channel:";
+ goto bail;
+
+ }
+ }
+
+ if (pmt_eq(event, s_response_deallocate_channel)
+ && pmt_eq(d_us_rx->port_symbol(), port_id))
+ {
+ status = pmt_nth(1, data);
+
+ // If successful, set the port to NIL
+ if(pmt_eq(status, PMT_T)) {
+ d_us_rx_chan = PMT_NIL;
+
+ if(verbose)
+ std::cout << "[GMAC] Received RX deallocation\n";
+
+ // If the TX is also deallocated, we can close the USRP
+ if(pmt_eq(d_us_tx_chan, PMT_NIL))
+ close_usrp();
+
+ return;
+
+ } else {
+
+ error_msg = "failed to deallocate RX channel:";
+ goto bail;
+
+ }
+ }
+
goto unhandled;
//-------------------------- CLOSING USRP -------------------------------//
@@ -211,7 +268,7 @@
// Received an unhandled message for a specific state
unhandled:
if(verbose && !pmt_eq(event, pmt_intern("%shutdown")))
- std::cout << "test_usrp_inband_tx: unhandled msg: " << msg
+ std::cout << "test_usrp_inband_us_tx: unhandled msg: " << msg
<< "in state "<< d_state << std::endl;
}
@@ -220,9 +277,15 @@
// forth to the application, or a physical layer once available.
void gmac::define_ports()
{
- d_tx = define_port("tx0", "usrp-tx", false, mb_port::INTERNAL);
- d_rx = define_port("rx0", "usrp-rx", false, mb_port::INTERNAL);
- d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL);
+ // Ports we use to connect to usrp_server
+ d_us_tx = define_port("us-tx0", "usrp-tx", false, mb_port::INTERNAL);
+ d_us_rx = define_port("us-rx0", "usrp-rx", false, mb_port::INTERNAL);
+ d_us_cs = define_port("us-cs", "usrp-server-cs", false, mb_port::INTERNAL);
+
+ // Ports applications used to connect to us
+ d_tx = define_port("tx0", "gmac-tx", true, mb_port::EXTERNAL);
+ d_rx = define_port("rx0", "gmac-rx", true, mb_port::EXTERNAL);
+ d_cs = define_port("cs", "gmac-cs", true, mb_port::EXTERNAL);
}
// To initialize the USRP we must pass several parameters to 'usrp_server' such
@@ -232,6 +295,9 @@
void gmac::initialize_usrp()
{
+ if(verbose)
+ std::cout << "[GMAC] Initializing USRP\n";
+
// The initialization parameters are passed to usrp_server via a PMT
// dictionary.
pmt_t usrp_dict = pmt_make_dict();
@@ -253,8 +319,20 @@
pmt_dict_set(usrp_dict,
pmt_intern("rf-freq"),
pmt_from_long((long)10e6));
+
+ // Default is to use USRP considered '0' (incase of multiple)
+ d_which_usrp = pmt_from_long(0);
- define_component("server", "usrp_server", usrp_dict);
+ define_component("USRP-SERVER", "usrp_server", usrp_dict);
+
+ connect("self", "us-tx0", "USRP-SERVER", "tx0");
+ connect("self", "us-rx0", "USRP-SERVER", "rx0");
+ connect("self", "us-cs", "USRP-SERVER", "cs");
+
+ // Finally, enter the OPENING_USRP state by sending a request to open the
+ // USRP.
+ open_usrp();
+
}
// In the initialization state of the MAC layer we set default values for
@@ -263,7 +341,7 @@
{
// The initial state is the INIT state.
- d_state = INIT;
+ d_state = INIT_GMAC;
// Set carrier sense to enabled by default with the specified threshold
set_carrier_sense(true, 21, PMT_NIL);
@@ -281,7 +359,7 @@
d_carrier_sense = toggle;
d_cs_thresh = threshold;
- d_tx->send(s_cmd_to_control_channel, // C/S packet
+ d_us_tx->send(s_cmd_to_control_channel, // C/S packet
pmt_list2(invocation, // invoc handle
pmt_list1(
pmt_list2(s_op_write_reg,
@@ -290,6 +368,32 @@
pmt_from_long(d_cs_thresh))))));
}
+// The following sends a command to open the USRP, which will upload the
+// specified RBF when creating the instance of the USRP server and set all
other
+// relevant parameters.
+void gmac::open_usrp()
+{
+ d_state = OPENING_USRP;
+
+ d_us_cs->send(s_cmd_open, pmt_list2(PMT_NIL, d_which_usrp));
+
+ if(verbose)
+ std::cout << "[GMAC] Opening USRP "
+ << d_which_usrp << std::endl;
+}
+
+// Before sending the close to the USRP we wait a couple seconds to let any
data
+// through the USB exit, else a bug in the driver will kick an error and cause
+// an abnormal termination.
+void gmac::close_usrp()
+{
+ d_state = CLOSING_USRP;
+
+ sleep(2);
+
+ d_us_cs->send(s_cmd_close, pmt_list1(PMT_NIL));
+}
+
// RX and TX channels must be allocated so that the USRP server can
// properly share bandwidth across multiple USRPs. No commands will be
// successful to the USRP through the USRP server on the TX or RX channels
until
@@ -297,21 +401,35 @@
void gmac::allocate_channels()
{
d_state = ALLOCATING_CHANNELS;
+
+ if(verbose)
+ std::cout << "[GMAC] Sending channel allocation requests\n";
long capacity = (long) 16e6;
- d_tx->send(s_cmd_allocate_channel, pmt_list2(PMT_T,
pmt_from_long(capacity)));
- d_rx->send(s_cmd_allocate_channel, pmt_list2(PMT_T,
pmt_from_long(capacity)));
+ d_us_tx->send(s_cmd_allocate_channel, pmt_list2(PMT_T,
pmt_from_long(capacity)));
+ d_us_rx->send(s_cmd_allocate_channel, pmt_list2(PMT_T,
pmt_from_long(capacity)));
+}
+
+// Before closing the USRP connection, we deallocate our channels so that the
+// capacity can be reused.
+void gmac::close_channels()
+{
+ d_state = CLOSING_CHANNELS;
+
+ d_us_tx->send(s_cmd_deallocate_channel, pmt_list2(PMT_NIL, d_us_tx_chan));
+ d_us_rx->send(s_cmd_deallocate_channel, pmt_list2(PMT_NIL, d_us_rx_chan));
+
if(verbose)
- std::cout << "[GMAC] Sending channel allocation requests\n";
+ std::cout << "[GMAC] Closing channels...\n";
}
// Used to enter the receiving state
void gmac::enter_receiving()
{
- d_rx->send(s_cmd_start_recv_raw_samples,
+ d_us_rx->send(s_cmd_start_recv_raw_samples,
pmt_list2(PMT_F,
- d_rx_chan));
+ d_us_rx_chan));
if(verbose)
std::cout << "[GMAC] Started RX sample stream\n";
@@ -322,3 +440,5 @@
{
d_state = IDLE;
}
+
+REGISTER_MBLOCK_CLASS(gmac);
Modified:
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.h
===================================================================
--- gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.h
2007-09-11 01:12:44 UTC (rev 6391)
+++ gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.h
2007-09-11 01:39:51 UTC (rev 6392)
@@ -28,28 +28,31 @@
class gmac : public mb_mblock
{
-
+
// The state is used to determine how to handle incoming messages and of
// course, the state of the MAC protocol.
enum state_t {
INIT,
OPENING_USRP,
ALLOCATING_CHANNELS,
+ INIT_GMAC,
IDLE,
CLOSING_CHANNELS,
CLOSING_USRP,
};
state_t d_state;
- // Ports used to connect to usrp_server, and the physical layer (in the
- // future).
- mb_port_sptr d_cs;
- mb_port_sptr d_tx;
- mb_port_sptr d_rx;
+ // Ports used for applications to connect to this block
+ mb_port_sptr d_tx, d_rx, d_cs;
+ // Ports to connect to usrp_server (us)
+ mb_port_sptr d_us_tx, d_us_rx, d_us_cs;
+
// The channel numbers assigned for use
- pmt_t d_rx_chan, d_tx_chan;
+ pmt_t d_us_rx_chan, d_us_tx_chan;
+ pmt_t d_which_usrp;
+
bool d_carrier_sense;
long d_cs_thresh;
@@ -70,6 +73,9 @@
void allocate_channels();
void enter_receiving();
void enter_idle();
+ void close_channels();
+ void open_usrp();
+ void close_usrp();
};
Modified:
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.mbh
===================================================================
--- gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.mbh
2007-09-11 01:12:44 UTC (rev 6391)
+++ gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.mbh
2007-09-11 01:39:51 UTC (rev 6392)
@@ -83,7 +83,7 @@
;; The protocol class is defined from the client's point-of-view.
;; (The client port is unconjugated, the server port is conjugated.)
-(define-protocol-class usrp-rx
+(define-protocol-class gmac-rx
(:outgoing
Modified:
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc
===================================================================
---
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc
2007-09-11 01:12:44 UTC (rev 6391)
+++
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc
2007-09-11 01:39:51 UTC (rev 6392)
@@ -53,6 +53,8 @@
: mb_mblock(rt, instance_name, user_arg),
d_fake_rx(false)
{
+ if(verbose)
+ std::cout << "[USRP_SERVER] Initializing...\n";
// Dictionary for arguments to all of the components
pmt_t usrp_dict = user_arg;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r6392 - in gnuradio/branches/developers/gnychis/inband/usrp/host: apps-inband lib/inband,
gnychis <=