X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=usrp2%2Fhost%2Flib%2Fusrp2_impl.h;fp=usrp2%2Fhost%2Flib%2Fusrp2_impl.h;h=eee26358eaca556852b83f68e55cf9699719d0f7;hb=8a9ddbb0675f9bfcc6e03b457fba6c79474a3693;hp=ec96f3a7095d8692c0c9c8ec4ff73d33072d227c;hpb=82d471b9b4a8b389b5da44b19c69c36420828382;p=debian%2Fgnuradio diff --git a/usrp2/host/lib/usrp2_impl.h b/usrp2/host/lib/usrp2_impl.h index ec96f3a7..eee26358 100644 --- a/usrp2/host/lib/usrp2_impl.h +++ b/usrp2/host/lib/usrp2_impl.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2008,2009 Free Software Foundation, Inc. + * Copyright 2008,2009,2010 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 @@ -22,6 +22,7 @@ #include #include #include +#include #include #include "control.h" #include "ring.h" @@ -30,7 +31,7 @@ #define MAX_SUBPKT_LEN 252 namespace usrp2 { - + class eth_buffer; class pktfilter; class usrp2_thread; @@ -60,9 +61,10 @@ namespace usrp2 { std::string d_interface_name; pktfilter *d_pf; std::string d_addr; // FIXME: use u2_mac_addr_t instead - usrp2_thread *d_bg_thread; + + boost::thread_group d_rx_tg; volatile bool d_bg_running; // TODO: multistate if needed - + int d_rx_seqno; int d_tx_seqno; int d_next_rid; @@ -72,40 +74,44 @@ namespace usrp2 { unsigned int d_num_rx_bytes; unsigned int d_num_enqueued; - omni_mutex d_enqueued_mutex; - omni_condition d_bg_pending_cond; + gruel::mutex d_enqueued_mutex; + gruel::condition_variable d_bg_pending_cond; // all pending_replies are stack allocated, thus no possibility of leaking these pending_reply *d_pending_replies[NRIDS]; // indexed by 8-bit reply id std::vector d_channel_rings; // indexed by 5-bit channel number - omni_mutex d_channel_rings_mutex; + gruel::mutex d_channel_rings_mutex; db_info d_tx_db_info; db_info d_rx_db_info; - int d_tx_interp; // shadow tx interp + int d_tx_interp; // shadow tx interp int d_rx_decim; // shadow rx decim + bool d_dont_enqueue; + void inc_enqueued() { - omni_mutex_lock l(d_enqueued_mutex); + gruel::scoped_lock l(d_enqueued_mutex); d_num_enqueued++; } - + void dec_enqueued() { - omni_mutex_lock l(d_enqueued_mutex); + gruel::scoped_lock l(d_enqueued_mutex); if (--d_num_enqueued == 0) - d_bg_pending_cond.signal(); + d_bg_pending_cond.notify_one(); } - + static bool parse_mac_addr(const std::string &s, u2_mac_addr_t *p); void init_et_hdrs(u2_eth_packet_t *p, const std::string &dst); void init_etf_hdrs(u2_eth_packet_t *p, const std::string &dst, int word0_flags, int chan, uint32_t timestamp); + void start_bg(); void stop_bg(); void init_config_rx_v2_cmd(op_config_rx_v2_cmd *cmd); void init_config_tx_v2_cmd(op_config_tx_v2_cmd *cmd); - bool transmit_cmd(void *cmd, size_t len, pending_reply *p, double secs=0.0); + bool transmit_cmd_and_wait(void *cmd, size_t len, pending_reply *p, double secs=0.0); + bool transmit_cmd(void *cmd, size_t len); virtual data_handler::result operator()(const void *base, size_t len); data_handler::result handle_control_packet(const void *base, size_t len); data_handler::result handle_data_packet(const void *base, size_t len); @@ -115,14 +121,13 @@ namespace usrp2 { public: impl(const std::string &ifc, props *p, size_t rx_bufsize); ~impl(); - - void bg_loop(); std::string mac_addr() const { return d_addr; } // FIXME: convert from u2_mac_addr_t std::string interface_name() const { return d_interface_name; } // Rx + bool set_rx_antenna(int ant); bool set_rx_gain(double gain); double rx_gain_min() { return d_rx_db_info.gain_min; } double rx_gain_max() { return d_rx_db_info.gain_max; } @@ -140,13 +145,17 @@ namespace usrp2 { bool write_gpio(int bank, uint16_t value, uint16_t mask); bool read_gpio(int bank, uint16_t *value); bool start_rx_streaming(unsigned int channel, unsigned int items_per_frame); + bool start_rx_streaming_at(unsigned int channel, unsigned int items_per_frame, unsigned int time); + bool sync_and_start_rx_streaming_at(unsigned int channel, unsigned int items_per_frame, unsigned int time); bool rx_samples(unsigned int channel, rx_sample_handler *handler); + bool flush_rx_samples(unsigned int channel); bool stop_rx_streaming(unsigned int channel); unsigned int rx_overruns() const { return d_num_rx_overruns; } unsigned int rx_missing() const { return d_num_rx_missing; } // Tx + bool set_tx_antenna(int ant); bool set_tx_gain(double gain); double tx_gain_min() { return d_tx_db_info.gain_min; } double tx_gain_max() { return d_tx_db_info.gain_max; } @@ -191,8 +200,11 @@ namespace usrp2 { bool sync_every_pps(bool enable); std::vector peek32(uint32_t addr, uint32_t words); bool poke32(uint32_t addr, const std::vector &data); + + // Receive thread, need to be public for boost::bind + void bg_loop(); }; - + } // namespace usrp2 #endif /* INCLUDED_USRP2_IMPL_H */