上位機的poke()、peek()、寫SPI函數實現以及控制資訊的發送(VRT Context包)

來源:互聯網
上載者:User

標籤:poke

lib/usrp/common/fifo_ctrl_excelsior.cpp

 /*******************************************************************     * Peek and poke 32 bit implementation     ******************************************************************/    void poke32(wb_addr_type addr, boost::uint32_t data){        boost::mutex::scoped_lock lock(_mutex);        this->send_pkt(addr, data, POKE32_CMD);//調用send_pkt,打包成VRT  context包        this->wait_for_ack(_seq_out-MAX_SEQS_OUT);    }    boost::uint32_t peek32(wb_addr_type addr){        boost::mutex::scoped_lock lock(_mutex);        this->send_pkt(addr, 0, PEEK32_CMD);        return this->wait_for_ack(_seq_out);    }

/*******************************************************************     * FIFO controlled SPI implementation     ******************************************************************/    void init_spi(void){        boost::mutex::scoped_lock lock(_mutex);        this->send_pkt(SPI_DIV, SPI_DIVIDER, POKE32_CMD);        this->wait_for_ack(_seq_out-MAX_SEQS_OUT);        _ctrl_word_cache = 0; // force update first time around    }    boost::uint32_t transact_spi(        int which_slave,        const spi_config_t &config,        boost::uint32_t data,        size_t num_bits,        bool readback    ){        boost::mutex::scoped_lock lock(_mutex);        //load control word        boost::uint32_t ctrl_word = 0;        ctrl_word |= ((which_slave & 0xffffff) << 0);        ctrl_word |= ((num_bits & 0x3ff) << 24);        if (config.mosi_edge == spi_config_t::EDGE_FALL) ctrl_word |= (1 << 31);        if (config.miso_edge == spi_config_t::EDGE_RISE) ctrl_word |= (1 << 30);        //load data word (must be in upper bits)        const boost::uint32_t data_out = data << (32 - num_bits);        //conditionally send control word        if (_ctrl_word_cache != ctrl_word){            this->send_pkt(SPI_CTRL, ctrl_word, POKE32_CMD);            this->wait_for_ack(_seq_out-MAX_SEQS_OUT);            _ctrl_word_cache = ctrl_word;        }        //send data word        this->send_pkt(SPI_DATA, data_out, POKE32_CMD);        this->wait_for_ack(_seq_out-MAX_SEQS_OUT);        //conditional readback        if (readback){            this->send_pkt(_config.spi_rb, 0, PEEK32_CMD);            return this->wait_for_ack(_seq_out);        }        return 0;    }

/*******************************************************************     * Primary control and interaction private methods     ******************************************************************/    UHD_INLINE void send_pkt(wb_addr_type addr, boost::uint32_t data, int cmd){        managed_send_buffer::sptr buff = _xport->get_send_buff();        if (not buff){            throw uhd::runtime_error("fifo ctrl timed out getting a send buffer");        }        boost::uint32_t *pkt = buff->cast<boost::uint32_t *>();        //load packet info,打包成VRT協議包        vrt::if_packet_info_t packet_info;        packet_info.packet_type = vrt::if_packet_info_t::PACKET_TYPE_CONTEXT;        packet_info.num_payload_words32 = 2;        packet_info.num_payload_bytes = packet_info.num_payload_words32*sizeof(boost::uint32_t);        packet_info.packet_count = ++_seq_out;        packet_info.tsf = _time.to_ticks(_tick_rate);        packet_info.sob = false;        packet_info.eob = false;        packet_info.has_sid = false;        packet_info.has_cid = false;        packet_info.has_tsi = false;        packet_info.has_tsf = _use_time;        packet_info.has_tlr = false;        //load header        vrt::if_hdr_pack_le(pkt, packet_info);        //load payload        const boost::uint32_t ctrl_word = (addr/4 & 0xff) | cmd | (_seq_out << 16);        pkt[packet_info.num_header_words32+0] = uhd::htowx(ctrl_word);        pkt[packet_info.num_header_words32+1] = uhd::htowx(data);        //send the buffer over the interface        buff->commit(sizeof(boost::uint32_t)*(packet_info.num_packet_words32));    }


著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

上位機的poke()、peek()、寫SPI函數實現以及控制資訊的發送(VRT Context包)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.