|
| 1 | +// Copyright CERN and copyright holders of ALICE O2. This software is |
| 2 | +// distributed under the terms of the GNU General Public License v3 (GPL |
| 3 | +// Version 3), copied verbatim in the file "COPYING". |
| 4 | +// |
| 5 | +// See http://alice-o2.web.cern.ch/license for full licensing information. |
| 6 | +// |
| 7 | +// In applying this license CERN does not waive the privileges and immunities |
| 8 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 9 | +// or submit itself to any jurisdiction. |
| 10 | + |
| 11 | +/// \file FirmwareChecker.h |
| 12 | +/// \brief Helper functions to check a card's firmware compatibilty |
| 13 | +/// |
| 14 | +/// \author Kostas Alexopoulos ([email protected]) |
| 15 | + |
| 16 | +#include "unordered_map" |
| 17 | +#include "ReadoutCard/ChannelFactory.h" |
| 18 | +#include "ReadoutCard/Parameters.h" |
| 19 | + |
| 20 | +namespace AliceO2 |
| 21 | +{ |
| 22 | +namespace roc |
| 23 | +{ |
| 24 | + |
| 25 | +inline std::unordered_map<std::string, std::string> compatibleFirmwareList({ { "20190909-xxxxxx-3f5e11b3", "CRU v3.3.0" }, |
| 26 | + { "20190718-120712-4c8e6c48", "CRU v3.2.0" }, |
| 27 | + { "0.0:2000-0-0", "CRORC alpha" } }); |
| 28 | + |
| 29 | +inline std::string getFirmwareCompatibilityList() |
| 30 | +{ |
| 31 | + std::string fwStrings; |
| 32 | + for (auto fwString : compatibleFirmwareList) { |
| 33 | + fwStrings += "\n" + fwString.second + " - " + fwString.first; |
| 34 | + } |
| 35 | + return fwStrings; |
| 36 | +} |
| 37 | + |
| 38 | +inline void checkFirmwareCompatibilityWrapped(std::shared_ptr<BarInterface> bar2) |
| 39 | +{ |
| 40 | + auto firmware = bar2->getFirmwareInfo().value_or(""); |
| 41 | + auto serial = bar2->getSerial().value_or(-1); |
| 42 | + if (compatibleFirmwareList.find(firmware) == compatibleFirmwareList.end()) { |
| 43 | + BOOST_THROW_EXCEPTION(Exception() << ErrorInfo::Message( |
| 44 | + std::string("Firmware compatibility check failed.\n") + |
| 45 | + std::string("Serial: " + std::to_string(serial) + "\n") + |
| 46 | + std::string("Firmware: " + firmware + "\n") + |
| 47 | + std::string("\nCompatible firmwares:") + |
| 48 | + getFirmwareCompatibilityList())); |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +inline void checkFirmwareCompatibility(Parameters params) |
| 53 | +{ |
| 54 | + auto bar2 = ChannelFactory().getBar(params); |
| 55 | + checkFirmwareCompatibilityWrapped(bar2); |
| 56 | +} |
| 57 | + |
| 58 | +inline void checkFirmwareCompatibility(Parameters::CardIdType cardId) |
| 59 | +{ |
| 60 | + auto params = Parameters::makeParameters(cardId, 2); // access bar2 to check the firmware release |
| 61 | + auto bar2 = ChannelFactory().getBar(params); |
| 62 | + checkFirmwareCompatibilityWrapped(bar2); |
| 63 | +} |
| 64 | + |
| 65 | +} // namespace roc |
| 66 | +} // namespace AliceO2 |
0 commit comments