예제 #1
0
    void write_i2c(boost::uint8_t addr, const byte_vector_t &bytes){
        //allocate some memory for this transaction
        UHD_ASSERT_THROW(bytes.size() <= max_i2c_data_bytes);
        boost::uint8_t mem[sizeof(usrp_e_i2c) + max_i2c_data_bytes];

        //load the data struct
        usrp_e_i2c *data = reinterpret_cast<usrp_e_i2c*>(mem);
        data->addr = addr;
        data->len = bytes.size();
        std::copy(bytes.begin(), bytes.end(), data->data);

        //call the spi ioctl
        this->ioctl(USRP_E_I2C_WRITE, data);
    }
예제 #2
0
//negative sum of bytes excluding checksum byte
static uint8_t checksum(const byte_vector_t &bytes){
    int sum = 0;
    for (size_t i = 0; i < std::min(bytes.size(), size_t(DB_EEPROM_CHKSUM)); i++){
        sum -= int(bytes.at(i));
    }
    UHD_LOG_TRACE("DB_EEPROM", boost::format("byte sum: 0x%02x") % sum)
    return uint8_t(sum);
}
예제 #3
0
//negative sum of bytes excluding checksum byte
static boost::uint8_t checksum(const byte_vector_t &bytes){
    int sum = 0;
    for (size_t i = 0; i < std::min(bytes.size(), size_t(DB_EEPROM_CHKSUM)); i++){
        sum -= int(bytes.at(i));
    }
    UHD_LOGV(often) << boost::format("sum: 0x%02x") % sum << std::endl;
    return boost::uint8_t(sum);
}
예제 #4
0
    void write_i2c(boost::uint8_t addr, const byte_vector_t &bytes){
        byte_vector_t rw_bytes(bytes);

        //setup the message
        i2c_msg msg;
        msg.addr = addr;
        msg.flags = 0;
        msg.len = bytes.size();
        msg.buf = &rw_bytes.front();

        //setup the data
        i2c_rdwr_ioctl_data data;
        data.msgs = &msg;
        data.nmsgs = 1;

        //call the ioctl
        UHD_ASSERT_THROW(::ioctl(_node_fd, I2C_RDWR, &data) >= 0);
    }