8 #ifndef INCLUDED_UHD_UTILS_SOFT_REGISTER_HPP     9 #define INCLUDED_UHD_UTILS_SOFT_REGISTER_HPP    12 #include <boost/noncopyable.hpp>    16 #include <boost/thread/mutex.hpp>    17 #include <boost/thread/locks.hpp>    18 #include <boost/unordered_map.hpp>    19 #include <boost/tokenizer.hpp>    20 #include <boost/foreach.hpp>    41 #define UHD_DEFINE_SOFT_REG_FIELD(name, width, shift) \    42     static const uhd::soft_reg_field_t name = (((shift & 0xFF) << 8) | (width & 0xFF))    52     return __builtin_expect(expr, 
true);
    62     return __builtin_expect(expr, 
false);
    77 namespace soft_reg_field {
    79         return (field & 0xFF);
    83         return ((field >> 8) & 0xFF);
    86     template<
typename data_t>
    88         static const data_t ONE = 
static_cast<data_t
>(1);
    93             return ((ONE<<
width(field))-ONE)<<
shift(field);
    95             return (0-ONE)<<
shift(field);
   103     virtual void initialize(
wb_iface& iface, 
bool sync = 
false) = 0;
   104     virtual void flush() = 0;
   105     virtual void refresh() = 0;
   106     virtual size_t get_bitwidth() = 0;
   107     virtual bool is_readable() = 0;
   108     virtual bool is_writable() = 0;
   113     template <
typename soft_reg_t>
   115         soft_reg_t* ptr = 
dynamic_cast<soft_reg_t*
>(®);
   131 template<
typename reg_data_t, 
bool readable, 
bool writable>
   134     typedef boost::shared_ptr< soft_register_t<reg_data_t, readable, writable> > 
sptr;
   146         _iface(NULL), _wr_addr(wr_addr), _rd_addr(rd_addr), _soft_copy(0), _flush_mode(mode)
   156         _iface(NULL), _wr_addr(addr), _rd_addr(addr), _soft_copy(0), _flush_mode(mode)
   169         if (sync && writable) flush();
   170         if (sync && readable) refresh();
   178     UHD_INLINE void set(
const soft_reg_field_t field, 
const reg_data_t value)
   180         _soft_copy = (_soft_copy & ~soft_reg_field::mask<reg_data_t>(field)) |
   181                      ((value << soft_reg_field::shift(field)) & soft_reg_field::mask<reg_data_t>(field));
   198         if (writable && _iface) {
   202             if (_flush_mode == ALWAYS_FLUSH || _soft_copy.is_dirty()) {
   203                 if (get_bitwidth() <= 16) {
   204                     _iface->poke16(_wr_addr, static_cast<uint16_t>(_soft_copy));
   205                 } 
else if (get_bitwidth() <= 32) {
   206                     _iface->poke32(_wr_addr, static_cast<uint32_t>(_soft_copy));
   207                 } 
else if (get_bitwidth() <= 64) {
   208                     _iface->poke64(_wr_addr, static_cast<uint64_t>(_soft_copy));
   212                 _soft_copy.mark_clean();
   224         if (readable && _iface) {
   225             if (get_bitwidth() <= 16) {
   226                 _soft_copy = 
static_cast<reg_data_t
>(_iface->peek16(_rd_addr));
   227             } 
else if (get_bitwidth() <= 32) {
   228                 _soft_copy = 
static_cast<reg_data_t
>(_iface->peek32(_rd_addr));
   229             } 
else if (get_bitwidth() <= 64) {
   230                 _soft_copy = 
static_cast<reg_data_t
>(_iface->peek64(_rd_addr));
   234             _soft_copy.mark_clean();
   263         static const size_t BITS_IN_BYTE = 8;
   264         return sizeof(reg_data_t) * BITS_IN_BYTE;
   295 template<
typename reg_data_t, 
bool readable, 
bool writable>
   298     typedef boost::shared_ptr< soft_register_sync_t<reg_data_t, readable, writable> > 
sptr;
   304         soft_register_t<reg_data_t, readable, writable>(wr_addr, rd_addr, mode), _mutex()
   315         boost::lock_guard<boost::mutex> lock(_mutex);
   319     UHD_INLINE void set(
const soft_reg_field_t field, 
const reg_data_t value)
   321         boost::lock_guard<boost::mutex> lock(_mutex);
   327         boost::lock_guard<boost::mutex> lock(_mutex);
   333         boost::lock_guard<boost::mutex> lock(_mutex);
   339         boost::lock_guard<boost::mutex> lock(_mutex);
   345         boost::lock_guard<boost::mutex> lock(_mutex);
   351         boost::lock_guard<boost::mutex> lock(_mutex);
   435     typedef boost::shared_ptr<soft_regmap_accessor_t> 
sptr;
   439     virtual std::vector<std::string> enumerate() 
const = 0;
   440     virtual const std::string& get_name() 
const = 0;
   470         boost::lock_guard<boost::mutex> lock(_mutex);
   482         boost::lock_guard<boost::mutex> lock(_mutex);
   494         boost::lock_guard<boost::mutex> lock(_mutex);
   505         regmap_t::const_iterator iter = _regmap.find(name);
   506         if (iter != _regmap.end()) {
   507             return *(iter->second);
   518         std::vector<std::string> temp;
   519         BOOST_FOREACH(
const regmap_t::value_type& reg, _regmap) {
   520             temp.push_back(_name + 
"/" + reg.first);
   535         boost::lock_guard<boost::mutex> lock(_mutex);
   536         if (visible == PUBLIC) {
   538             if (not _regmap.insert(regmap_t::value_type(name, ®)).second) {
   542         _reglist.push_back(®);
   546     typedef boost::unordered_map<std::string, soft_register_base*> regmap_t;
   547     typedef std::list<soft_register_base*>                         reglist_t;
   549     const std::string   _name;
   564     typedef boost::shared_ptr<soft_regmap_db_t> 
sptr;
   579     const std::string& 
get_name()
 const { 
return _name; }
   585         boost::lock_guard<boost::mutex> lock(_mutex);
   586         _regmaps.push_back(®map);
   593         boost::lock_guard<boost::mutex> lock(_mutex);
   597             _regmap_dbs.push_back(&db);
   614         std::list<std::string> tokens;
   616             const std::string& node,
   617             boost::tokenizer< boost::char_separator<char> >(path, boost::char_separator<char>(
"/")))
   619             tokens.push_back(node);
   621         if ((tokens.size() > 2 && tokens.front() == _name) ||   
   622             (tokens.size() > 1 && _name == 
"")) {               
   623             if (_name != 
"") tokens.pop_front();
   624             if (tokens.size() == 2) {                   
   626                     if (regmap->
get_name() == tokens.front()) {
   627                         return regmap->
lookup(tokens.back());
   631             } 
else if (not _regmap_dbs.empty()) {       
   634                 BOOST_FOREACH(
const std::string& node, tokens) {
   635                     newpath += (
"/" + node);
   640                         return db->
lookup(newpath.substr(1));
   641                     } 
catch (std::exception&) {
   654         std::vector<std::string> paths;
   656             const std::vector<std::string>& regs = regmap->
enumerate();
   657             paths.insert(paths.end(), regs.begin(), regs.end());
   660             const std::vector<std::string>& regs = db->
enumerate();
   661             paths.insert(paths.end(), regs.begin(), regs.end());
   667     typedef std::list<soft_regmap_accessor_t*> db_t;
   669     const std::string   _name;
 void refresh()
Definition: soft_register.hpp:493
 
soft_register_sync_t< uint16_t, false, true > soft_reg16_wo_sync_t
Definition: soft_register.hpp:375
 
uint32_t soft_reg_field_t
Definition: soft_register.hpp:75
 
UHD_INLINE void flush()
Definition: soft_register.hpp:196
 
Definition: soft_register.hpp:124
 
soft_reg_flush_mode_t
Definition: soft_register.hpp:124
 
boost::shared_ptr< soft_register_t< reg_data_t, readable, writable > > sptr
Definition: soft_register.hpp:134
 
Definition: soft_register.hpp:296
 
Definition: exception.hpp:106
 
soft_regmap_t(const std::string &name)
Definition: soft_register.hpp:455
 
UHD_INLINE bool unlikely(bool expr)
hint for the branch prediction 
Definition: soft_register.hpp:59
 
UHD_INLINE void refresh()
Definition: soft_register.hpp:222
 
soft_register_t< uint64_t, false, true > soft_reg64_wo_t
Definition: soft_register.hpp:386
 
virtual std::vector< std::string > enumerate() const
Definition: soft_register.hpp:517
 
soft_register_t(wb_iface::wb_addr_type addr, soft_reg_flush_mode_t mode=ALWAYS_FLUSH)
Definition: soft_register.hpp:153
 
#define UHD_DEFINE_SOFT_REG_FIELD(name, width, shift)
Definition: soft_register.hpp:41
 
soft_register_t< uint32_t, true, false > soft_reg32_ro_t
Definition: soft_register.hpp:380
 
UHD_INLINE size_t get_bitwidth()
Definition: soft_register.hpp:261
 
virtual soft_register_base & lookup(const std::string &name) const
Definition: soft_register.hpp:504
 
soft_register_sync_t(wb_iface::wb_addr_type addr, soft_reg_flush_mode_t mode=ALWAYS_FLUSH)
Definition: soft_register.hpp:307
 
UHD_INLINE bool is_writable()
Definition: soft_register.hpp:278
 
soft_register_sync_t< uint64_t, true, true > soft_reg64_rw_sync_t
Definition: soft_register.hpp:391
 
Definition: exception.hpp:91
 
Definition: soft_register.hpp:562
 
virtual std::vector< std::string > enumerate() const
Definition: soft_register.hpp:653
 
soft_register_sync_t< uint32_t, false, true > soft_reg32_wo_sync_t
Definition: soft_register.hpp:382
 
soft_register_t< uint32_t, false, true > soft_reg32_wo_t
Definition: soft_register.hpp:379
 
UHD_INLINE size_t width(const soft_reg_field_t field)
Definition: soft_register.hpp:78
 
Definition: soft_register.hpp:527
 
UHD_INLINE void set(const soft_reg_field_t field, const reg_data_t value)
Definition: soft_register.hpp:178
 
soft_regmap_db_t(const std::string &name)
Definition: soft_register.hpp:574
 
virtual ~soft_regmap_accessor_t()
Definition: soft_register.hpp:437
 
Definition: soft_register.hpp:132
 
UHD_INLINE reg_data_t get(const soft_reg_field_t field)
Definition: soft_register.hpp:188
 
Definition: build_info.hpp:14
 
soft_regmap_db_t()
Definition: soft_register.hpp:569
 
UHD_INLINE void write(const soft_reg_field_t field, const reg_data_t value)
Definition: soft_register.hpp:343
 
virtual std::vector< std::string > enumerate() const =0
 
virtual soft_register_base & lookup(const std::string &path) const =0
 
virtual ~soft_register_base()
Definition: soft_register.hpp:101
 
void flush()
Definition: soft_register.hpp:481
 
visibility_t
Definition: soft_register.hpp:526
 
UHD_INLINE void initialize(wb_iface &iface, bool sync=false)
Definition: soft_register.hpp:164
 
boost::shared_ptr< soft_register_sync_t< reg_data_t, readable, writable > > sptr
Definition: soft_register.hpp:298
 
void initialize(wb_iface &iface, bool sync=false)
Definition: soft_register.hpp:469
 
virtual const std::string & get_name() const =0
 
soft_register_sync_t< uint64_t, true, false > soft_reg64_ro_sync_t
Definition: soft_register.hpp:390
 
virtual ~soft_regmap_t()
Definition: soft_register.hpp:456
 
soft_register_sync_t(wb_iface::wb_addr_type wr_addr, wb_iface::wb_addr_type rd_addr, soft_reg_flush_mode_t mode=ALWAYS_FLUSH)
Definition: soft_register.hpp:300
 
boost::shared_ptr< soft_regmap_accessor_t > sptr
Definition: soft_register.hpp:435
 
Definition: soft_register.hpp:433
 
UHD_INLINE bool is_readable()
Definition: soft_register.hpp:270
 
#define UHD_INLINE
Definition: config.h:53
 
UHD_INLINE void flush()
Definition: soft_register.hpp:331
 
UHD_INLINE reg_data_t read(const soft_reg_field_t field)
Definition: soft_register.hpp:252
 
soft_register_t(wb_iface::wb_addr_type wr_addr, wb_iface::wb_addr_type rd_addr, soft_reg_flush_mode_t mode=ALWAYS_FLUSH)
Definition: soft_register.hpp:142
 
soft_register_t< uint64_t, true, false > soft_reg64_ro_t
Definition: soft_register.hpp:387
 
boost::shared_ptr< soft_regmap_db_t > sptr
Definition: soft_register.hpp:564
 
Definition: soft_register.hpp:453
 
Definition: soft_register.hpp:99
 
soft_register_sync_t< uint32_t, true, false > soft_reg32_ro_sync_t
Definition: soft_register.hpp:383
 
Definition: exception.hpp:42
 
#define UHD_API
Definition: config.h:63
 
UHD_INLINE data_t mask(const soft_reg_field_t field)
Definition: soft_register.hpp:87
 
void add(soft_regmap_t ®map)
Definition: soft_register.hpp:584
 
UHD_INLINE reg_data_t read(const soft_reg_field_t field)
Definition: soft_register.hpp:349
 
const std::string & get_name() const
Definition: soft_register.hpp:579
 
UHD_INLINE void refresh()
Definition: soft_register.hpp:337
 
soft_register_t< uint64_t, true, true > soft_reg64_rw_t
Definition: soft_register.hpp:388
 
UHD_INLINE void write(const soft_reg_field_t field, const reg_data_t value)
Definition: soft_register.hpp:243
 
soft_register_t< uint16_t, true, true > soft_reg16_rw_t
Definition: soft_register.hpp:374
 
Definition: exception.hpp:70
 
void add(soft_regmap_db_t &db)
Definition: soft_register.hpp:592
 
virtual void initialize(wb_iface &iface, bool sync=false)=0
 
soft_register_base & lookup(const std::string &path) const
Definition: soft_register.hpp:611
 
soft_register_sync_t< uint16_t, true, true > soft_reg16_rw_sync_t
Definition: soft_register.hpp:377
 
soft_register_sync_t< uint64_t, false, true > soft_reg64_wo_sync_t
Definition: soft_register.hpp:389
 
UHD_INLINE void initialize(wb_iface &iface, bool sync=false)
Definition: soft_register.hpp:313
 
soft_register_t< uint16_t, false, true > soft_reg16_wo_t
Definition: soft_register.hpp:372
 
UHD_INLINE bool likely(bool expr)
hint for the branch prediction 
Definition: soft_register.hpp:49
 
soft_register_sync_t< uint32_t, true, true > soft_reg32_rw_sync_t
Definition: soft_register.hpp:384
 
virtual UHD_INLINE const std::string & get_name() const
Definition: soft_register.hpp:461
 
UHD_INLINE void add_to_map(soft_register_base ®, const std::string &name, const visibility_t visible=PRIVATE)
Definition: soft_register.hpp:534
 
UHD_INLINE size_t shift(const soft_reg_field_t field)
Definition: soft_register.hpp:82
 
Definition: soft_register.hpp:124
 
uint32_t wb_addr_type
Definition: wb_iface.hpp:23
 
static UHD_INLINE soft_reg_t & cast(soft_register_base ®)
Definition: soft_register.hpp:114
 
Definition: wb_iface.hpp:19
 
soft_register_t< uint16_t, true, false > soft_reg16_ro_t
Definition: soft_register.hpp:373
 
soft_register_sync_t< uint16_t, true, false > soft_reg16_ro_sync_t
Definition: soft_register.hpp:376
 
soft_register_t< uint32_t, true, true > soft_reg32_rw_t
Definition: soft_register.hpp:381