From 260c4a2be7379487b2cca033732f84d217493b52 Mon Sep 17 00:00:00 2001 From: Georg Auzinger Date: Fri, 8 Jan 2016 11:13:47 +0100 Subject: [PATCH] final touches --- Utils/Utilities.cc | 3 +- src/fpgaconfig.cc | 146 +++++++++++++++++++++++---------------------- 2 files changed, 77 insertions(+), 72 deletions(-) diff --git a/Utils/Utilities.cc b/Utils/Utilities.cc index 340fcaf..8592b1b 100755 --- a/Utils/Utilities.cc +++ b/Utils/Utilities.cc @@ -99,9 +99,10 @@ void verifyImageName( const std::string& strImage, const std::vector lstNames = cSystemController.fFEDInterface->getFpgaConfigList(pBoard); + std::string cFWFile; + std::string strImage("1"); + if (cmd.foundOption("list")) + { + std::cout << lstNames.size() << " firmware images on SD card:" << std::endl; + for (auto &name : lstNames) + std::cout << " - " << name << std::endl; - exit(0); - } - else if (cmd.foundOption("file")) - { - cFWFile = cmd.optionValue("file"); - if (lstNames.size() == 0 && cFWFile.find(".mcs") == std::string::npos) + exit(0); + } + else if (cmd.foundOption("file")) { - std::cout << "Error, the specified file is not a .mcs file" << std::endl; - exit(1); + cFWFile = cmd.optionValue("file"); + if (lstNames.size() == 0 && cFWFile.find(".mcs") == std::string::npos) + { + std::cout << "Error, the specified file is not a .mcs file" << std::endl; + exit(1); + } + else if (lstNames.size() > 0 && cFWFile.compare(cFWFile.length() - 4, 4, ".bit") && cFWFile.compare(cFWFile.length() - 4, 4, ".bin")) + { + std::cout << "Error, the specified file is neither a .bit nor a .bin file" << std::endl; + exit(1); + } + } + else if (cmd.foundOption("delete") && !lstNames.empty()) + { + strImage = cmd.optionValue("delete"); + verifyImageName(strImage, lstNames); + cSystemController.fFEDInterface->DeleteFpgaConfig(pBoard, strImage); + std::cout << "Firmware image: " << strImage << " deleted from SD card" << std::endl; + exit(0); } - else if (lstNames.size() > 0 && cFWFile.compare(cFWFile.length() - 4, 4, ".bit") && cFWFile.compare(cFWFile.length() - 4, 4, ".bin")) + else if (!cmd.foundOption("image")) { - std::cout << "Error, the specified file is neither a .bit nor a .bin file" << std::endl; + cFWFile = ""; + std::cout << "Error, no FW image specified" << std::endl; exit(1); } - } - else if (cmd.foundOption("delete") && !lstNames.empty()) - { - strImage = cmd.optionValue("delete"); - verifyImageName(strImage, lstNames); - cSystemController.fFEDInterface->DeleteFpgaConfig(pBoard, strImage); - std::cout << "Firmware image: " << strImage << " deleted from SD card" << std::endl; - exit(0); - } - else if (!cmd.foundOption("image")) - { - cFWFile = ""; - std::cout << "Error, no FW image specified" << std::endl; - exit(1); - } - if (cmd.foundOption("image")) - { - strImage = cmd.optionValue("image"); - if (!cmd.foundOption("file")) - verifyImageName(strImage, lstNames); - } - else if (!lstNames.empty()) - strImage = "GoldenImage.bin"; + if (cmd.foundOption("image")) + { + strImage = cmd.optionValue("image"); + if (!cmd.foundOption("file")) + verifyImageName(strImage, lstNames); + } + else if (!lstNames.empty()) + strImage = "GoldenImage.bin"; - Timer t; - t.start(); + Timer t; + t.start(); - t.stop(); - t.show( "Time to Initialize/configure the system: " ); + t.stop(); + t.show( "Time to Initialize/configure the system: " ); - if (!cmd.foundOption("file") && !cmd.foundOption("download")) - { - cSystemController.fFEDInterface->JumpToFpgaConfig(pBoard, strImage); - exit(0); - } + if (!cmd.foundOption("file") && !cmd.foundOption("download")) + { + cSystemController.fFEDInterface->JumpToFpgaConfig(pBoard, strImage); + exit(0); + } - bool cDone = 0; + bool cDone = 0; - if (cmd.foundOption("download")) - cSystemController.fFEDInterface->DownloadFpgaConfig(pBoard, strImage, cmd.optionValue("download")); - else - cSystemController.fFEDInterface->FlashProm(pBoard, strImage, cFWFile.c_str()); + if (cmd.foundOption("download")) + cSystemController.fFEDInterface->DownloadFpgaConfig(pBoard, strImage, cmd.optionValue("download")); + else + cSystemController.fFEDInterface->FlashProm(pBoard, strImage, cFWFile.c_str()); - uint32_t progress; + uint32_t progress; - while (cDone == 0) - { - progress = cSystemController.fFEDInterface->getConfiguringFpga(pBoard)->getProgressValue(); - - if (progress == 100) - { - cDone = 1; - std::cout << "\n 100% Done" << std::endl; - } - else + while (cDone == 0) { - std::cout << progress << "% " << cSystemController.fFEDInterface->getConfiguringFpga(pBoard)->getProgressString() << " \r" << flush; - sleep(1); + progress = cSystemController.fFEDInterface->getConfiguringFpga(pBoard)->getProgressValue(); + + if (progress == 100) + { + cDone = 1; + std::cout << "\n 100% Done" << std::endl; + } + else + { + std::cout << progress << "% " << cSystemController.fFEDInterface->getConfiguringFpga(pBoard)->getProgressString() << " \r" << flush; + sleep(1); + } } - } - t.stop(); - t.show( "Time elapsed:" ); + t.stop(); + t.show( "Time elapsed:" ); + + } }