标签: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包)
标签:poke
原文地址:http://blog.csdn.net/yuan1164345228/article/details/46890103