Commit 9dd9b231 authored by Georg Auzinger's avatar Georg Auzinger
Browse files

adding features for Cta Fpga FW download from SD that went missing during latest merge

parent 5691b829
......@@ -9,6 +9,7 @@ Data/*
*.bin
*.raw
Results/*
Results/
settings/connections_slc6.xml
# just for G. Auzingers sanity
Calibrations
......
......@@ -388,6 +388,12 @@ void CtaFWInterface::JumpToFpgaConfig( const std::string& strConfig)
fpgaConfig->jumpToImage( strConfig);
}
void CtaFWInterface::DownloadFpgaConfig( const std::string& strConfig, const std::string& strDest)
{
checkIfUploading();
fpgaConfig->runDownload( strConfig, strDest.c_str());
}
std::vector<std::string> CtaFWInterface::getFpgaConfigList()
{
checkIfUploading();
......
......@@ -190,6 +190,8 @@ public:
void FlashProm( const std::string& strConfig, const char* pstrFile );
/*! \brief Jump to an FPGA configuration */
void JumpToFpgaConfig( const std::string& strConfig);
void DownloadFpgaConfig( const std::string& strConfig, const std::string& strDest );
/*! \brief Is the FPGA being configured ?
* \return FPGA configuring process or NULL if configuration occurs */
const FpgaConfig* getConfiguringFpga()
......
......@@ -10,12 +10,12 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
FileName : CtaFpgaConfig.cc
Content : FPGA configuration
Programmer : Christian Bonnin
Version :
FileName : CtaFpgaConfig.cc
Content : FPGA configuration
Programmer : Christian Bonnin
Version :
Date of creation : 2014-07-10
Support : mail to : christian.bonnin@iphc.cnrs.fr
Support : mail to : christian.bonnin@iphc.cnrs.fr
*/
#include <sys/stat.h>//file size
#include <time.h>
......@@ -27,93 +27,108 @@
using namespace std;
#define SECURE_MODE_PASSWORD "RuleBritannia"
#define SECURE_MODE_PASSWORD "RuleBritannia"
namespace Ph2_HwInterface
{
CtaFpgaConfig::CtaFpgaConfig(BeBoardFWInterface* pbbi):
FpgaConfig(pbbi),
lNode(dynamic_cast< const fc7::MmcPipeInterface & > (fwManager->getUhalNode( "buf_cta" )))
FpgaConfig(pbbi),
lNode(dynamic_cast< const fc7::MmcPipeInterface & > (fwManager->getUhalNode( "buf_cta" )))
{
}
void CtaFpgaConfig::runUpload(const std::string& strImage, const char* szFile) throw (std::string){
vector<string> lstNames=lNode.ListFilesOnSD();
for (int iName=0; iName<lstNames.size(); iName++){
if (!strImage.compare(lstNames[iName]))
numUploadingFpga=iName+1;
break;
}
progressValue=0;
progressString="Starting upload";
boost::thread(&CtaFpgaConfig::dumpFromFileIntoSD, this, strImage, szFile);
void CtaFpgaConfig::runUpload(const std::string& strImage, const char* szFile) throw (std::string)
{
vector<string> lstNames = lNode.ListFilesOnSD();
for (int iName = 0; iName < lstNames.size(); iName++)
{
if (!strImage.compare(lstNames[iName]))
numUploadingFpga = iName + 1;
break;
}
progressValue = 0;
progressString = "Starting upload";
boost::thread(&CtaFpgaConfig::dumpFromFileIntoSD, this, strImage, szFile);
}
void CtaFpgaConfig::dumpFromFileIntoSD(const std::string& strImage, const char* pstrFile){
if (string(pstrFile).compare(string(pstrFile).length()-4,4,".bit")==0){
fc7::XilinxBitFile bitFile(pstrFile);
lNode.FileToSD(strImage, bitFile, &progressValue, &progressString);
} else {
fc7::XilinxBinFile binFile(pstrFile);
lNode.FileToSD(strImage, binFile, &progressValue, &progressString);
}
progressValue=100;
lNode.RebootFPGA(strImage, SECURE_MODE_PASSWORD);
void CtaFpgaConfig::dumpFromFileIntoSD(const std::string& strImage, const char* pstrFile)
{
if (string(pstrFile).compare(string(pstrFile).length() - 4, 4, ".bit") == 0)
{
fc7::XilinxBitFile bitFile(pstrFile);
lNode.FileToSD(strImage, bitFile, &progressValue, &progressString);
}
void CtaFpgaConfig::jumpToImage( const std::string& strImage){
lNode.RebootFPGA(strImage, SECURE_MODE_PASSWORD);
else
{
fc7::XilinxBinFile binFile(pstrFile);
lNode.FileToSD(strImage, binFile, &progressValue, &progressString);
}
progressValue = 100;
lNode.RebootFPGA(strImage, SECURE_MODE_PASSWORD);
}
void CtaFpgaConfig::runDownload(const std::string& strImage, const char* szFile) throw (std::string){
vector<string> lstNames=lNode.ListFilesOnSD();
for (int iName=0; iName<lstNames.size(); iName++){
if (!strImage.compare(lstNames[iName]))
numUploadingFpga=iName+1;
break;
}
progressValue=0;
progressString="Downloading configuration";
boost::thread(&CtaFpgaConfig::downloadImage, this, strImage, szFile);
void CtaFpgaConfig::jumpToImage( const std::string& strImage)
{
lNode.RebootFPGA(strImage, SECURE_MODE_PASSWORD);
}
void CtaFpgaConfig::runDownload(const std::string& strImage, const char* szFile) throw (std::string)
{
vector<string> lstNames = lNode.ListFilesOnSD();
for (int iName = 0; iName < lstNames.size(); iName++)
{
if (!strImage.compare(lstNames[iName]))
numUploadingFpga = iName + 1;
break;
}
progressValue = 0;
progressString = "Downloading configuration";
boost::thread(&CtaFpgaConfig::downloadImage, this, strImage, szFile);
}
void CtaFpgaConfig::downloadImage( const std::string& strImage, const std::string& strDestFile){
fc7::Firmware bitStream1 = lNode.FileFromSD(strImage, &progressValue, 0);
progressString="Checking download";
fc7::Firmware bitStream2 = lNode.FileFromSD(strImage, &progressValue, 33);
fc7::Firmware bitStream3("empty");
ofstream oFile;
oFile.open(strDestFile, ios::out | ios::binary);
void CtaFpgaConfig::downloadImage( const std::string& strImage, const std::string& strDestFile)
{
fc7::Firmware bitStream1 = lNode.FileFromSD(strImage, &progressValue, 0);
progressString = "Checking download";
fc7::Firmware bitStream2 = lNode.FileFromSD(strImage, &progressValue, 33);
fc7::Firmware bitStream3("empty");
ofstream oFile;
oFile.open(strDestFile, ios::out | ios::binary);
//for (const auto& uVal:bitStream.Bitstream())
for (size_t idx = 0 ; idx<bitStream1.Bitstream().size(); idx++){
if (bitStream1.Bitstream()[idx]!=bitStream2.Bitstream()[idx]){
if (bitStream3.Bitstream().empty()){
progressString="Errors found, checking again";
bitStream3 = lNode.FileFromSD(strImage, &progressValue, 66);
}
if (bitStream1.Bitstream()[idx]==bitStream3.Bitstream()[idx])
oFile<<(char)bitStream1.Bitstream()[idx];
else if (bitStream2.Bitstream()[idx]==bitStream3.Bitstream()[idx])
oFile<<(char)bitStream2.Bitstream()[idx];
else
throw fc7::CorruptedFile();
} else
oFile<<(char)bitStream1.Bitstream()[idx];
}
oFile.close();
progressValue=100;
//for (const auto& uVal:bitStream.Bitstream())
for (size_t idx = 0 ; idx < bitStream1.Bitstream().size(); idx++)
{
if (bitStream1.Bitstream()[idx] != bitStream2.Bitstream()[idx])
{
if (bitStream3.Bitstream().empty())
{
progressString = "Errors found, checking again";
bitStream3 = lNode.FileFromSD(strImage, &progressValue, 66);
}
if (bitStream1.Bitstream()[idx] == bitStream3.Bitstream()[idx])
oFile << (char)bitStream1.Bitstream()[idx];
else if (bitStream2.Bitstream()[idx] == bitStream3.Bitstream()[idx])
oFile << (char)bitStream2.Bitstream()[idx];
else
throw fc7::CorruptedFile();
}
else
oFile << (char)bitStream1.Bitstream()[idx];
}
oFile.close();
progressValue = 100;
}
std::vector<std::string> CtaFpgaConfig::getFirmwareImageNames(){
return lNode.ListFilesOnSD ();
}
std::vector<std::string> CtaFpgaConfig::getFirmwareImageNames()
{
return lNode.ListFilesOnSD ();
void CtaFpgaConfig::deleteFirmwareImage(const std::string& strId){
lNode.DeleteFromSD(strId, SECURE_MODE_PASSWORD);
}
}
void CtaFpgaConfig::deleteFirmwareImage(const std::string& strId)
{
lNode.DeleteFromSD(strId, SECURE_MODE_PASSWORD);
}
}
/*!
\file CtaFpgaConfig.h
\brief FPGA configuration by uploading the firware in MCS file format into a GLIB board
/*!
\file CtaFpgaConfig.h
\brief FPGA configuration by uploading the firware in MCS file format into a GLIB board
\version 1.0
\author Christian Bonnin
\date 02/03/2015
Support : mail to : christian.bonnin@iphc.cnrs.fr
\author Christian Bonnin
\date 02/03/2015
Support : mail to : christian.bonnin@iphc.cnrs.fr
*/
#ifndef _CTAFPGACONFIG_H_
#define _CTAFPGACONFIG_H_
......@@ -21,46 +21,47 @@ namespace Ph2_HwInterface
* \brief Upload MCS files into Flash EPROM as FPGA configuration
* @author cbonnin
*/
class CtaFpgaConfig : public FpgaConfig{
private:
fc7::MmcPipeInterface lNode;
class CtaFpgaConfig : public FpgaConfig
{
private:
fc7::MmcPipeInterface lNode;
public:
CtaFpgaConfig(BeBoardFWInterface* pbbi);
/*! \brief Launch the firmware upload in a separate thread
* \param strConfig FPGA configuration name
* \param pstrFile absolute path to the .bit or .bin file
*/
void runUpload(const std::string& strConfig, const char* pstrFile) throw (std::string);
/*! \brief Launch the firmware download in a separate thread
* \param strConfig FPGA configuration name
* \param pstrFile absolute path to the .bin file
*/
void runDownload(const std::string& strConfig, const char* pstrFile) throw (std::string);
/*! \brief Jump to an FPGA configuration
* \param strConfig FPGA configuration name
*/
void jumpToImage( const std::string& strImage);
public:
CtaFpgaConfig(BeBoardFWInterface* pbbi);
/*! \brief Launch the firmware upload in a separate thread
* \param strConfig FPGA configuration name
* \param pstrFile absolute path to the .bit or .bin file
*/
void runUpload(const std::string& strConfig, const char* pstrFile) throw (std::string);
/*! \brief Launch the firmware download in a separate thread
* \param strConfig FPGA configuration name
* \param pstrFile absolute path to the .bin file
*/
void runDownload(const std::string& strConfig, const char* pstrFile) throw (std::string);
/*! \brief Jump to an FPGA configuration
* \param strConfig FPGA configuration name
*/
void jumpToImage( const std::string& strImage);
void downloadImage( const std::string& strImage, const std::string& strDestFile);
/*! \brief Get the list of available FPGA configuration (or firmware images)*/
std::vector<std::string> getFirmwareImageNames();
/*! \brief Delete one Fpga configuration (or firmware image)*/
void deleteFirmwareImage(const std::string& strId);
private:
void downloadImage( const std::string& strImage, const std::string& strDestFile);
/*! \brief Get the list of available FPGA configuration (or firmware images)*/
std::vector<std::string> getFirmwareImageNames();
/*! \brief Delete one Fpga configuration (or firmware image)*/
void deleteFirmwareImage(const std::string& strId);
private:
///Sets the read mode as asynchronous.
void confAsyncRead() throw (std::string);
///Locks or unlocks a block of the flash (Xilinx DS617(v3.0.1) page 75, figure 43).
void blockLockOrUnlock(uint32_t block_number, char operation) throw (std::string);
///Erases a block of the flash (Xilinx DS617(v3.0.1) page 73, figure 41).
void blockErase(uint32_t block_number) throw (std::string);
///Writes up to 32 words to the flash (Xilinx DS617(v3.0.1) page 71, figure 39).
void bufferProgram(uint32_t block_number, uint32_t data_address, std::vector<uint32_t>& write_buffer, uint32_t words) throw (std::string);
/*! \brief Main uploading loop
* \param pstrFile Absolute path the .bit configuration file
*/
void dumpFromFileIntoSD(const std::string& strImage, const char* pstrFile);
void confAsyncRead() throw (std::string);
///Locks or unlocks a block of the flash (Xilinx DS617(v3.0.1) page 75, figure 43).
void blockLockOrUnlock(uint32_t block_number, char operation) throw (std::string);
///Erases a block of the flash (Xilinx DS617(v3.0.1) page 73, figure 41).
void blockErase(uint32_t block_number) throw (std::string);
///Writes up to 32 words to the flash (Xilinx DS617(v3.0.1) page 71, figure 39).
void bufferProgram(uint32_t block_number, uint32_t data_address, std::vector<uint32_t>& write_buffer, uint32_t words) throw (std::string);
/*! \brief Main uploading loop
* \param pstrFile Absolute path the .bit configuration file
*/
void dumpFromFileIntoSD(const std::string& strImage, const char* pstrFile);
};
};
}
#endif
/*!
\file FpgaConfig.h
\brief FPGA configuration by uploading the firware in MCS file format
/*!
\file FpgaConfig.h
\brief FPGA configuration by uploading the firware in MCS file format
\version 1.0
\author Christian Bonnin
\date 02/03/2015
Support : mail to : christian.bonnin@iphc.cnrs.fr
\author Christian Bonnin
\date 02/03/2015
Support : mail to : christian.bonnin@iphc.cnrs.fr
*/
#ifndef _FPGACONFIG_H_
#define _FPGACONFIG_H_
......@@ -13,51 +13,61 @@
using namespace Ph2_HwDescription;
namespace Ph2_HwInterface
{
class BeBoardFWInterface;
class BeBoardFWInterface;
/*!
* \brief Upload MCS files into Flash EPROM as FPGA configuration
* @author cbonnin
*/
class FpgaConfig{
public:
/*! \brief Constructor from a BeBoardFWInterface
* \param pbbi Reference to the BeBoardFWInterface
*/
FpgaConfig(BeBoardFWInterface* pbbi);
/*! \brief Launch the firmware download in a separate thread
* \param strConfig FPGA configuration number or name
* \param pstrFile absolute path to the configuration file
*/
virtual void runDownload(const std::string& strConfig, const char* pstrFile) throw (std::string){};
/*! \brief Launch the firmware upload in a separate thread
* \param strConfig FPGA configuration number or name
* \param pstrFile absolute path to the configuration file
*/
virtual void runUpload(const std::string& strConfig, const char* pstrFile) throw (std::string)=0;
/*! \brief Tells if a configuration is currently been uploaded
* \return Configuration number or 0 if no upload is been processed
*/
uint32_t getUploadingFpga() const {return numUploadingFpga;}
/*! \brief Percentage of the upload already done
* \return 0 to 100 percentage value
*/
uint32_t getProgressValue() const {return progressValue;}
/*! \brief Description of the upload current status
* \return String describing the upload status containing the block number and the estimated remaining time
*/
const std::string& getProgressString() const {return progressString;}
class FpgaConfig
{
public:
/*! \brief Constructor from a BeBoardFWInterface
* \param pbbi Reference to the BeBoardFWInterface
*/
FpgaConfig(BeBoardFWInterface* pbbi);
/*! \brief Launch the firmware download in a separate thread
* \param strConfig FPGA configuration number or name
* \param pstrFile absolute path to the configuration file
*/
virtual void runDownload(const std::string& strConfig, const char* pstrFile) throw (std::string) {};
/*! \brief Launch the firmware upload in a separate thread
* \param strConfig FPGA configuration number or name
* \param pstrFile absolute path to the configuration file
*/
virtual void runUpload(const std::string& strConfig, const char* pstrFile) throw (std::string) = 0;
/*! \brief Tells if a configuration is currently been uploaded
* \return Configuration number or 0 if no upload is been processed
*/
uint32_t getUploadingFpga() const
{
return numUploadingFpga;
}
/*! \brief Percentage of the upload already done
* \return 0 to 100 percentage value
*/
uint32_t getProgressValue() const
{
return progressValue;
}
/*! \brief Description of the upload current status
* \return String describing the upload status containing the block number and the estimated remaining time
*/
const std::string& getProgressString() const
{
return progressString;
}
/*! \brief Jump to an FPGA configuration
* \param strConfig FPGA configuration number or name
*/
virtual void jumpToImage( const std::string& strImage)=0;
/*! \brief Jump to an FPGA configuration
* \param strConfig FPGA configuration number or name
*/
virtual void jumpToImage( const std::string& strImage) = 0;
protected:
protected:
timeval timStart, timEnd;
uint32_t progressValue, numUploadingFpga;
std::string progressString;
BeBoardFWInterface* fwManager;
};
timeval timStart, timEnd;
uint32_t progressValue, numUploadingFpga;
std::string progressString;
BeBoardFWInterface* fwManager;
};
}
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment