diff --git a/lib/include/prjxray/xilinx/xc7series/configuration_packet.h b/lib/include/prjxray/xilinx/xc7series/configuration_packet.h index 0816d93f..21baa646 100644 --- a/lib/include/prjxray/xilinx/xc7series/configuration_packet.h +++ b/lib/include/prjxray/xilinx/xc7series/configuration_packet.h @@ -24,9 +24,11 @@ class ConfigurationPacket { /* reserved = 3 */ }; - ConfigurationPacket(Opcode opcode, ConfigurationRegister address, + ConfigurationPacket(unsigned int header_type, Opcode opcode, + ConfigurationRegister address, const absl::Span &data) - : opcode_(opcode), address_(address), data_(std::move(data)) {} + : header_type_(header_type), opcode_(opcode), + address_(address), data_(std::move(data)) {} // Attempt to read a configuration packet from a sequence of // 32-bit, big-endian words. If successful, returns the packet read and @@ -39,11 +41,13 @@ class ConfigurationPacket { absl::Span words, const ConfigurationPacket *previous_packet = nullptr); + unsigned int header_type() const { return header_type_; } const Opcode opcode() const { return opcode_; } const ConfigurationRegister address() const { return address_; } const absl::Span &data() const { return data_; } private: + unsigned int header_type_; Opcode opcode_; ConfigurationRegister address_; absl::Span data_; diff --git a/lib/xilinx/xc7series/configuration_packet.cc b/lib/xilinx/xc7series/configuration_packet.cc index e3646ee7..82778220 100644 --- a/lib/xilinx/xc7series/configuration_packet.cc +++ b/lib/xilinx/xc7series/configuration_packet.cc @@ -32,7 +32,8 @@ ConfigurationPacket::InitWithWords(absl::Span words, } return {words.subspan(data_word_count+1), - {{opcode, address, words.subspan(1, data_word_count)}}}; + {{header_type, opcode, address, + words.subspan(1, data_word_count)}}}; } case 0b010: { absl::optional packet; @@ -48,7 +49,8 @@ ConfigurationPacket::InitWithWords(absl::Span words, if (previous_packet) { packet = ConfigurationPacket( - opcode, previous_packet->address(), + header_type, opcode, + previous_packet->address(), words.subspan(1, data_word_count)); } @@ -62,26 +64,48 @@ ConfigurationPacket::InitWithWords(absl::Span words, std::ostream& operator<<(std::ostream& o, const ConfigurationPacket &packet) { switch (packet.opcode()) { case ConfigurationPacket::Opcode::NOP: - return o << "[NOP]" << std::endl; + o << "[NOP]" << std::endl; + break; case ConfigurationPacket::Opcode::Read: - return o << "[Read Address=" - << std::setw(2) - << static_cast(packet.address()) - << " Length=" - << std::setw(10) << packet.data().size() - << " Reg=\"" << packet.address() << "\"" - << "]" << std::endl; + o << "[Read Type="; + o << packet.header_type(); + o << " Address="; + o << std::setw(2) << std::hex; + o << static_cast(packet.address()); + o << " Length="; + o << std::setw(10) << std::dec << packet.data().size(); + o << " Reg=\"" << packet.address() << "\""; + o << "]" << std::endl; + break; case ConfigurationPacket::Opcode::Write: - return o << "[Write Address=" - << std::setw(2) - << static_cast(packet.address()) - << " Length=" - << std::setw(10) << packet.data().size() - << " Reg=\"" << packet.address() << "\"" - << "]" << std::endl; + o << "[Write Type="; + o << packet.header_type(); + o << " Address="; + o << std::setw(2) << std::hex; + o << static_cast(packet.address()); + o << " Length="; + o << std::setw(10) << std::dec << packet.data().size(); + o << " Reg=\"" << packet.address() << "\""; + o << "]" << std::endl; + o << "Data in hex:" << std::endl; + + for (size_t ii = 0; ii < packet.data().size(); ++ii) { + o << std::setw(8) << std::hex; + o << packet.data()[ii] << " "; + + if ((ii+1) % 4 == 0) { + o << std::endl; + } + } + if (packet.data().size() % 4 != 0) { + o << std::endl; + } + break; default: - return o << "[Invalid Opcode]" << std::endl; + o << "[Invalid Opcode]" << std::endl; } + + return o; } } // namespace xc7series diff --git a/lib/xilinx/xc7series/configuration_packet_test.cc b/lib/xilinx/xc7series/configuration_packet_test.cc index 506557f1..fcf27d53 100644 --- a/lib/xilinx/xc7series/configuration_packet_test.cc +++ b/lib/xilinx/xc7series/configuration_packet_test.cc @@ -86,6 +86,7 @@ TEST(ConfigPacket, InitWithType2WithoutPreviousPacketFails) { TEST(ConfigPacket, InitWithType2WithPreviousPacket) { xc7series::ConfigurationPacket previous_packet( + static_cast(0x1), xc7series::ConfigurationPacket::Opcode::Read, xc7series::ConfigurationRegister::MFWR, absl::Span());