Changeset 9657

Show
Ignore:
Timestamp:
09/24/08 13:43:13
Author:
eb
Message:

work-in-progress on usrp2

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gnuradio/branches/developers/eb/u2-wip/usrp2/host/include/usrp2/usrp2.h

    r9647 r9657  
    3030 
    3131 
     32/* 
     33 * N.B., The interfaces described here are still in flux. 
     34 * 
     35 * We will keep all the code in the tree up-to-date with regard to changes 
     36 * here, but reserve the right to change this on a whim. 
     37 */ 
     38 
    3239namespace usrp2 { 
    3340 
     
    9097    std::string mac_addr(); 
    9198 
    92     /*! 
    93      * Burn new mac address into EEPROM on USRP2 
    94      * 
    95      * \param new_addr  Network mac address, e.g., "01:23:45:67:89:ab" or "89:ab". 
    96      *                  If \p addr is HH:HH, it's treated as if it were 00:50:c2:85:HH:HH 
    97      */ 
    98     bool burn_mac_addr(const std::string &new_addr); 
    99  
    10099    /* 
    101100     * ---------------------------------------------------------------- 
     
    254253                const tx_metadata *metadata); 
    255254 
    256     // ---------------------------------------------------------------- 
     255    /* 
     256     * ---------------------------------------------------------------- 
     257     *  miscellaneous methods 
     258     * ---------------------------------------------------------------- 
     259     */ 
    257260 
    258261    /*! 
     
    274277     */ 
    275278    bool config_mimo(int flags); 
     279 
     280 
     281    //! Get frequency of master oscillator in Hz 
     282    bool fpga_master_clock_freq(long *freq); 
     283 
     284    // Get Sampling rate of A/D converter in Hz 
     285    bool adc_rate(long *rate); 
     286 
     287    // Get Sampling rate of D/A converter in Hz 
     288    bool dac_rate(long *rate); 
     289 
     290    /*! 
     291     * \brief Get Tx daughterboard ID 
     292     * 
     293     * \param[out] dbid returns the daughterboard id. 
     294     * 
     295     * daughterboard id >= 0 if successful, -1 if no daugherboard installed, 
     296     * -2 if invalid EEPROM on daughterboard. 
     297     */ 
     298    bool tx_daughterboard_id(int *dbid); 
     299 
     300    /*! 
     301     * \brief Get Rx daughterboard ID 
     302     * 
     303     * \param[out] dbid returns the daughterboard id. 
     304     * 
     305     * daughterboard id >= 0 if successful, -1 if no daugherboard installed, 
     306     * -2 if invalid EEPROM on daughterboard. 
     307     */ 
     308    bool rx_daughterboard_id(int *dbid); 
     309 
     310    /* 
     311     * ---------------------------------------------------------------- 
     312     *  Low level methods 
     313     * ---------------------------------------------------------------- 
     314     */ 
     315 
     316    /*! 
     317     * Burn new mac address into EEPROM on USRP2 
     318     * 
     319     * \param new_addr  Network mac address, e.g., "01:23:45:67:89:ab" or "89:ab". 
     320     *                  If \p addr is HH:HH, it's treated as if it were 00:50:c2:85:HH:HH 
     321     */ 
     322    bool burn_mac_addr(const std::string &new_addr); 
     323 
     324 
     325#if 0   // not yet implemented 
     326    /*! 
     327     * \brief Write EEPROM on motherboard or any daughterboard. 
     328     * \param i2c_addr          I2C bus address of EEPROM 
     329     * \param eeprom_offset     byte offset in EEPROM to begin writing 
     330     * \param buf               the data to write 
     331     * \returns true iff sucessful 
     332     */ 
     333    bool write_eeprom (int i2c_addr, int eeprom_offset, const std::string &buf); 
     334 
     335    /*! 
     336     * \brief Read EEPROM on motherboard or any daughterboard. 
     337     * \param i2c_addr          I2C bus address of EEPROM 
     338     * \param eeprom_offset     byte offset in EEPROM to begin reading 
     339     * \param len               number of bytes to read 
     340     * \returns the data read if successful, else a zero length string. 
     341     */ 
     342    std::string read_eeprom (int i2c_addr, int eeprom_offset, int len); 
     343 
     344    /*! 
     345     * \brief Write to I2C peripheral 
     346     * \param i2c_addr          I2C bus address (7-bits) 
     347     * \param buf               the data to write 
     348     * \returns true iff successful 
     349     * Writes are limited to a maximum of of 64 bytes. 
     350     */ 
     351    bool write_i2c (int i2c_addr, const std::string &buf); 
     352 
     353    /*! 
     354     * \brief Read from I2C peripheral 
     355     * \param i2c_addr          I2C bus address (7-bits) 
     356     * \param len               number of bytes to read 
     357     * \returns the data read if successful, else a zero length string. 
     358     * Reads are limited to a maximum of 64 bytes. 
     359     */ 
     360    std::string read_i2c (int i2c_addr, int len); 
     361 
     362    /*! 
     363     * \brief Write data to SPI bus peripheral. 
     364     * 
     365     * \param optional_header   0,1 or 2 bytes to write before buf. 
     366     * \param enables           bitmask of peripherals to write. See usrp_spi_defs.h 
     367     * \param format            transaction format.  See usrp_spi_defs.h SPI_FMT_* 
     368     * \param buf               the data to write 
     369     * \returns true iff successful 
     370     * Writes are limited to a maximum of 64 bytes. 
     371     * 
     372     * If \p format specifies that optional_header bytes are present, they are 
     373     * written to the peripheral immediately prior to writing \p buf. 
     374     */ 
     375    bool write_spi (int optional_header, int enables, int format, const std::string &buf); 
     376 
     377    /* 
     378     * \brief Read data from SPI bus peripheral. 
     379     * 
     380     * \param optional_header   0,1 or 2 bytes to write before buf. 
     381     * \param enables           bitmask of peripheral to read. See usrp_spi_defs.h 
     382     * \param format            transaction format.  See usrp_spi_defs.h SPI_FMT_* 
     383     * \param len               number of bytes to read.  Must be in [0,64]. 
     384     * \returns the data read if sucessful, else a zero length string. 
     385     * 
     386     * Reads are limited to a maximum of 64 bytes. 
     387     * 
     388     * If \p format specifies that optional_header bytes are present, they 
     389     * are written to the peripheral first.  Then \p len bytes are read from 
     390     * the peripheral and returned. 
     391     */ 
     392    std::string read_spi (int optional_header, int enables, int format, int len); 
     393#endif 
     394 
    276395 
    277396    class impl;         // implementation details 
  • gnuradio/branches/developers/eb/u2-wip/usrp2/host/lib/usrp2.cc

    r9647 r9657  
    161161  } 
    162162 
    163   bool 
    164   usrp2::burn_mac_addr(const std::string &new_addr) 
    165   { 
    166     return d_impl->burn_mac_addr(new_addr); 
    167   } 
    168  
    169  
    170163  // Receive 
    171164 
     
    277270  } 
    278271 
     272  // miscellaneous methods 
     273 
     274  bool 
     275  usrp2::config_mimo(int flags) 
     276  { 
     277    return d_impl->config_mimo(flags); 
     278  } 
     279 
     280  bool 
     281  usrp2::fpga_master_clock_freq(long *freq) 
     282  { 
     283    return d_impl->fpga_master_clock_freq(freq); 
     284  } 
     285 
     286  bool 
     287  usrp2::adc_rate(long *rate) 
     288  { 
     289    return d_impl->adc_rate(rate); 
     290  } 
     291 
     292  bool 
     293  usrp2::dac_rate(long *rate) 
     294  { 
     295    return d_impl->dac_rate(rate); 
     296  } 
     297 
     298  bool 
     299  usrp2::tx_daughterboard_id(int *dbid) 
     300  { 
     301    return d_impl->tx_daughterboard_id(dbid); 
     302  } 
     303 
     304  bool 
     305  usrp2::rx_daughterboard_id(int *dbid) 
     306  { 
     307    return d_impl->rx_daughterboard_id(dbid); 
     308  } 
     309   
     310 
     311  // low level methods 
     312 
     313  bool 
     314  usrp2::burn_mac_addr(const std::string &new_addr) 
     315  { 
     316    return d_impl->burn_mac_addr(new_addr); 
     317  } 
     318 
     319 
    279320} // namespace usrp2 
    280321 
  • gnuradio/branches/developers/eb/u2-wip/usrp2/host/lib/usrp2_impl.cc

    r9647 r9657  
    413413 
    414414  // ---------------------------------------------------------------- 
    415   //                       misc commands 
    416   // ---------------------------------------------------------------- 
    417  
    418   bool 
    419   usrp2::impl::burn_mac_addr(const std::string &new_addr) 
    420   { 
    421     op_burn_mac_addr_cmd cmd; 
    422     op_generic_t reply; 
    423  
    424     memset(&cmd, 0, sizeof(cmd)); 
    425     init_etf_hdrs(&cmd.h, d_addr, 0, CONTROL_CHAN, -1); 
    426     cmd.op.opcode = OP_BURN_MAC_ADDR; 
    427     cmd.op.len = sizeof(cmd.op); 
    428     cmd.op.rid = d_next_rid++; 
    429     if (!parse_mac_addr(new_addr, &cmd.op.addr)) 
    430       return false; 
    431  
    432     pending_reply p(cmd.op.rid, &reply, sizeof(reply)); 
    433     if (!transmit_cmd(&cmd, sizeof(cmd), &p, 4*DEF_CMD_TIMEOUT)) 
    434       return false; 
    435  
    436     bool success = (ntohx(reply.ok) == 1); 
    437     return success; 
    438   } 
    439  
    440  
    441   // ---------------------------------------------------------------- 
    442415  //                           Receive 
    443416  // ---------------------------------------------------------------- 
     
    871844  } 
    872845 
     846  // ---------------------------------------------------------------- 
     847  //                       misc commands 
     848  // ---------------------------------------------------------------- 
     849 
     850  bool 
     851  usrp2::impl::config_mimo(int flags) 
     852  { 
     853    return false;       // FIXME implement 
     854  } 
     855 
     856  bool 
     857  usrp2::impl::fpga_master_clock_freq(long *freq) 
     858  { 
     859    *freq = 100000000L; 
     860    return true; 
     861  } 
     862 
     863  bool 
     864  usrp2::impl::adc_rate(long *rate) 
     865  { 
     866    return fpga_master_clock_freq(rate); 
     867  } 
     868 
     869  bool 
     870  usrp2::impl::dac_rate(long *rate) 
     871  { 
     872    return fpga_master_clock_freq(rate); 
     873  } 
     874 
     875  bool 
     876  usrp2::impl::tx_daughterboard_id(int *dbid) 
     877  { 
     878    *dbid = -1;         // FIXME implement 
     879    return true; 
     880  } 
     881 
     882  bool 
     883  usrp2::impl::rx_daughterboard_id(int *dbid) 
     884  { 
     885    *dbid = -1;         // FIXME implement 
     886    return true; 
     887  } 
     888 
     889 
     890  // ---------------------------------------------------------------- 
     891  //                    low-level commands 
     892  // ---------------------------------------------------------------- 
     893 
     894  bool 
     895  usrp2::impl::burn_mac_addr(const std::string &new_addr) 
     896  { 
     897    op_burn_mac_addr_cmd cmd; 
     898    op_generic_t reply; 
     899 
     900    memset(&cmd, 0, sizeof(cmd)); 
     901    init_etf_hdrs(&cmd.h, d_addr, 0, CONTROL_CHAN, -1); 
     902    cmd.op.opcode = OP_BURN_MAC_ADDR; 
     903    cmd.op.len = sizeof(cmd.op); 
     904    cmd.op.rid = d_next_rid++; 
     905    if (!parse_mac_addr(new_addr, &cmd.op.addr)) 
     906      return false; 
     907 
     908    pending_reply p(cmd.op.rid, &reply, sizeof(reply)); 
     909    if (!transmit_cmd(&cmd, sizeof(cmd), &p, 4*DEF_CMD_TIMEOUT)) 
     910      return false; 
     911 
     912    bool success = (ntohx(reply.ok) == 1); 
     913    return success; 
     914  } 
     915 
    873916 
    874917} // namespace usrp2 
  • gnuradio/branches/developers/eb/u2-wip/usrp2/host/lib/usrp2_impl.h

    r9647 r9657  
    9696 
    9797    std::string mac_addr() const { return d_addr; } // FIXME: convert from u2_mac_addr_t 
    98     bool burn_mac_addr(const std::string &new_addr); 
     98 
     99    // Rx 
    99100 
    100101    bool set_rx_gain(double gain); 
     
    107108    unsigned int rx_overruns() const { return d_num_rx_overruns; } 
    108109    unsigned int rx_missing() const { return d_num_rx_missing; } 
     110 
     111    // Tx 
    109112 
    110113    bool set_tx_gain(double gain); 
     
    127130                size_t nitems, 
    128131                const tx_metadata *metadata); 
     132 
     133    // misc 
     134 
     135    bool config_mimo(int flags); 
     136    bool fpga_master_clock_freq(long *freq); 
     137    bool adc_rate(long *rate); 
     138    bool dac_rate(long *rate); 
     139    bool tx_daughterboard_id(int *dbid); 
     140    bool rx_daughterboard_id(int *dbid); 
     141 
     142    // low level 
     143 
     144    bool burn_mac_addr(const std::string &new_addr); 
    129145  }; 
    130146