From 9e0178230ff14aa012e7e55217ba408941fafba4 Mon Sep 17 00:00:00 2001 From: Tomasz Michalak Date: Thu, 10 Oct 2019 12:31:56 +0200 Subject: [PATCH] bitstream_tools: Move ECC related functions to ECC header Signed-off-by: Tomasz Michalak --- lib/include/prjxray/xilinx/xc7series/ecc.h | 5 ++++- lib/xilinx/frames.cc | 22 ++++------------------ lib/xilinx/xc7series/ecc.cc | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/lib/include/prjxray/xilinx/xc7series/ecc.h b/lib/include/prjxray/xilinx/xc7series/ecc.h index 40e131b3..63513fd9 100644 --- a/lib/include/prjxray/xilinx/xc7series/ecc.h +++ b/lib/include/prjxray/xilinx/xc7series/ecc.h @@ -2,6 +2,7 @@ #define PRJXRAY_LIB_XILINX_XC7SERIES_ECC_H_ #include +#include namespace prjxray { namespace xilinx { @@ -9,9 +10,11 @@ namespace xc7series { // Extend the current ECC code with one data word (32 bit) at a given // word index in the configuration frame and return the new ECC code. - uint32_t icap_ecc(uint32_t idx, uint32_t data, uint32_t ecc); +// Updates the ECC information in the frame. +void updateECC(std::vector& data); + } // namespace xc7series } // namespace xilinx } // namespace prjxray diff --git a/lib/xilinx/frames.cc b/lib/xilinx/frames.cc index 9ffd50cd..c2586c01 100644 --- a/lib/xilinx/frames.cc +++ b/lib/xilinx/frames.cc @@ -55,7 +55,10 @@ int Frames::readFrames(const std::string& frm_file_str) { return std::stoul(val, nullptr, 16); }); - updateECC(frame_data); + // Spartan6 doesn't have ECC + if (std::is_same::value) { + xc7series::updateECC(frame_data); + } // Insert the frame address and corresponding frame data to the // map @@ -87,27 +90,10 @@ void Frames::addMissingFrames( } while (current_frame_address); } -static uint32_t calculateECC(const typename Frames::FrameData& data) { - uint32_t ecc = 0; - for (size_t ii = 0; ii < data.size(); ++ii) { - ecc = xc7series::icap_ecc(ii, data[ii], ecc); - } - return ecc; -} - -template <> -void Frames::updateECC(FrameData& data) { - assert(data.size() != 0); - // Replace the old ECC with the new. - data[0x32] &= 0xFFFFE000; - data[0x32] |= (calculateECC(data) & 0x1FFF); -} - template Frames::Frames2Data& Frames::getFrames(); template void Frames::addMissingFrames( const absl::optional& part); template int Frames::readFrames(const std::string&); -template void Frames::updateECC(Frames::FrameData&); } // namespace xilinx } // namespace prjxray diff --git a/lib/xilinx/xc7series/ecc.cc b/lib/xilinx/xc7series/ecc.cc index 7c56cb8e..a3a5cb22 100644 --- a/lib/xilinx/xc7series/ecc.cc +++ b/lib/xilinx/xc7series/ecc.cc @@ -1,9 +1,13 @@ #include +#include +#include namespace prjxray { namespace xilinx { namespace xc7series { +constexpr size_t kECCFrameNumber = 0x32; + uint32_t icap_ecc(uint32_t idx, uint32_t data, uint32_t ecc) { uint32_t val = idx * 32; // bit offset @@ -36,6 +40,21 @@ uint32_t icap_ecc(uint32_t idx, uint32_t data, uint32_t ecc) { return ecc; } +static uint32_t calculateECC(const std::vector& data) { + uint32_t ecc = 0; + for (size_t ii = 0; ii < data.size(); ++ii) { + ecc = xc7series::icap_ecc(ii, data[ii], ecc); + } + return ecc; +} + +void updateECC(std::vector& data) { + assert(data.size() >= kECCFrameNumber); + // Replace the old ECC with the new. + data[kECCFrameNumber] &= 0xFFFFE000; + data[kECCFrameNumber] |= (calculateECC(data) & 0x1FFF); +} + } // namespace xc7series } // namespace xilinx } // namespace prjxray