3 * Copyright 2007 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <mb_class_registry.h>
30 #include <usrp_inband_usb_packet.h>
31 #include <fpga_regs_common.h>
32 #include <usrp_standard.h>
35 #include <symbols_usrp_tx_cs.h>
37 typedef usrp_inband_usb_packet transport_pkt;
39 static const bool verbose = false;
41 usrp_tx::usrp_tx(mb_runtime *rt, const std::string &instance_name, pmt_t user_arg)
42 : mb_mblock(rt, instance_name, user_arg),
45 d_cs = define_port("cs", "usrp-tx-cs", true, mb_port::EXTERNAL);
50 d_ofile.open("tx_data.dat",std::ios::binary|std::ios::out);
51 d_cs_ofile.open("tx_cs.dat",std::ios::binary|std::ios::out);
64 usrp_tx::initial_transition()
70 * \brief Handles incoming signals to to the m-block, wihch should only ever be
71 * a single message: cmd-usrp-tx-write.
74 usrp_tx::handle_message(mb_message_sptr msg)
76 pmt_t event = msg->signal();
77 pmt_t port_id = msg->port_id();
78 pmt_t data = msg->data();
80 // Theoretically only have 1 message to ever expect, but
81 // want to make sure its at least what we want
82 if(pmt_eq(port_id, d_cs->port_symbol())) {
84 if(pmt_eqv(event, s_cmd_usrp_tx_write))
90 * \brief Performs the actual writing of data to the USB bus, called by
91 * handle_message() when a cmd-usrp-tx-write signal is received.
93 * The \p data parameter is a PMT list which contains three mandatory elements,
94 * in the following order: an invocation handle, a channel, and a uniform vector
95 * of memory which contains the packets to be written to the bus.
98 usrp_tx::write(pmt_t data)
100 pmt_t invocation_handle = pmt_nth(0, data);
101 pmt_t channel = pmt_nth(1, data);
102 pmt_t v_packets = pmt_nth(2, data);
103 d_utx = boost::any_cast<usrp_standard_tx *>(pmt_any_ref(pmt_nth(3, data)));
106 bool underrun; // this will need to go, as it is taken care of in the packet headers
108 transport_pkt *pkts = (transport_pkt *) pmt_u8vector_writeable_elements(v_packets, n_bytes);
110 int ret = d_utx->write (pkts, n_bytes, &underrun);
113 fprintf(stderr, "uU");
115 if (ret == (int) n_bytes) {
117 std::cout << "[usrp_server] Write of " << n_bytes << " successful\n";
118 // need to respond with the channel so the USRP server knows who to forward the result of
119 // the write to by looking up the owner of the channel
120 d_cs->send(s_response_usrp_tx_write,
121 pmt_list3(invocation_handle, PMT_T, channel));
125 std::cout << "[usrp_server] Error writing " << n_bytes << " bytes to USB bus\n";
126 d_cs->send(s_response_usrp_tx_write,
127 pmt_list3(invocation_handle, PMT_F, channel));
131 static_cast<long>(std::ceil(n_bytes / (double)transport_pkt::max_pkt_size()));
133 for(int i=0; i < n_packets; i++) {
136 if(pkts[i].chan() == CONTROL_CHAN)
137 d_cs_ofile.write((const char *)&pkts[i], transport_pkt::max_pkt_size());
139 d_ofile.write((const char *)&pkts[i], transport_pkt::max_pkt_size());
150 REGISTER_MBLOCK_CLASS(usrp_tx);