|
14 | 14 | /// \author Pascal Boeschoten ([email protected]) |
15 | 15 | /// \author Kostas Alexopoulos ([email protected]) |
16 | 16 |
|
| 17 | +#include "Crorc/Constants.h" |
17 | 18 | #include "Crorc/CrorcBar.h" |
18 | 19 |
|
| 20 | +#include "boost/format.hpp" |
| 21 | + |
19 | 22 | namespace AliceO2 |
20 | 23 | { |
21 | 24 | namespace roc |
22 | 25 | { |
23 | 26 |
|
24 | 27 | CrorcBar::CrorcBar(const Parameters& parameters, std::unique_ptr<RocPciDevice> rocPciDevice) |
25 | | - : BarInterfaceBase(parameters, std::move(rocPciDevice)) |
| 28 | + : BarInterfaceBase(parameters, std::move(rocPciDevice)), |
| 29 | + mCrorcId(parameters.getCrorcId().get_value_or(0x0)), |
| 30 | + mDynamicOffset(parameters.getDynamicOffsetEnabled().get_value_or(false)) |
26 | 31 | { |
27 | 32 | } |
28 | 33 |
|
29 | 34 | CrorcBar::~CrorcBar() |
30 | 35 | { |
31 | 36 | } |
32 | 37 |
|
| 38 | +boost::optional<std::string> CrorcBar::getFirmwareInfo() |
| 39 | +{ |
| 40 | + uint32_t fwHash = readRegister(Crorc::Registers::FIRMWARE_HASH.index); |
| 41 | + return (boost::format("%x") % fwHash).str(); |
| 42 | +} |
| 43 | + |
33 | 44 | boost::optional<int32_t> CrorcBar::getSerial() |
34 | 45 | { |
35 | 46 | return Crorc::getSerial(*(mPdaBar.get())); |
36 | 47 | } |
37 | 48 |
|
38 | | -boost::optional<std::string> CrorcBar::getFirmwareInfo() |
| 49 | +void CrorcBar::setSerial(int serial) |
39 | 50 | { |
40 | | - uint32_t version = mPdaBar->readRegister(Rorc::RFID); |
41 | | - auto bits = [&](int lsb, int msb) { return Utilities::getBits(version, lsb, msb); }; |
42 | | - |
43 | | - uint32_t reserved = bits(24, 31); |
44 | | - uint32_t major = bits(20, 23); |
45 | | - uint32_t minor = bits(13, 19); |
46 | | - uint32_t year = bits(9, 12) + 2000; |
47 | | - uint32_t month = bits(5, 8); |
48 | | - uint32_t day = bits(0, 4); |
49 | | - |
50 | | - if (reserved != 0x2) { |
51 | | - BOOST_THROW_EXCEPTION(CrorcException() |
52 | | - << ErrorInfo::Message("Static field of version register did not equal 0x2")); |
53 | | - } |
54 | | - |
55 | | - std::ostringstream stream; |
56 | | - stream << major << '.' << minor << ':' << year << '-' << month << '-' << day; |
57 | | - return stream.str(); |
| 51 | + Crorc::setSerial(*(mPdaBar.get()), serial); |
58 | 52 | } |
59 | 53 |
|
60 | 54 | int CrorcBar::getEndpointNumber() |
61 | 55 | { |
62 | 56 | return 0; |
63 | 57 | } |
64 | 58 |
|
65 | | -void CrorcBar::setSerial(int serial) |
| 59 | +void CrorcBar::configure(bool /*force*/) |
66 | 60 | { |
67 | | - Crorc::setSerial(*(mPdaBar.get()), serial); |
| 61 | + // enable laser |
| 62 | + log("Enabling the laser"); |
| 63 | + setQsfpEnabled(); |
| 64 | + |
| 65 | + log("Configuring fixed/dynamic offset"); |
| 66 | + // choose between fixed and dynamic offset |
| 67 | + setDynamicOffsetEnabled(mDynamicOffset); |
| 68 | + |
| 69 | + // set crorc id |
| 70 | + log("Setting the CRORC ID"); |
| 71 | + setCrorcId(mCrorcId); |
| 72 | +} |
| 73 | + |
| 74 | +void CrorcBar::setQsfpEnabled() |
| 75 | +{ |
| 76 | + uint32_t qsfpStatus = (readRegister(Crorc::Registers::LINK_STATUS.index) >> 31) & 0x1; |
| 77 | + if (qsfpStatus == 0) { |
| 78 | + writeRegister(Crorc::Registers::I2C_CMD.index, 0x80); |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +bool CrorcBar::getQsfpEnabled() |
| 83 | +{ |
| 84 | + return (readRegister(Crorc::Registers::LINK_STATUS.index) >> 31) & 0x1; |
| 85 | +} |
| 86 | + |
| 87 | +void CrorcBar::setCrorcId(uint16_t crorcId) |
| 88 | +{ |
| 89 | + modifyRegister(Crorc::Registers::CFG_CONTROL.index, 4, 12, crorcId); |
| 90 | +} |
| 91 | + |
| 92 | +uint16_t CrorcBar::getCrorcId() |
| 93 | +{ |
| 94 | + return (readRegister(Crorc::Registers::CFG_CONTROL.index) >> 4) & 0x0fff; |
| 95 | +} |
| 96 | + |
| 97 | +void CrorcBar::setDynamicOffsetEnabled(bool enabled) |
| 98 | +{ |
| 99 | + modifyRegister(Crorc::Registers::CFG_CONTROL.index, 0, 1, enabled ? 0x1 : 0x0); |
| 100 | +} |
| 101 | + |
| 102 | +bool CrorcBar::getDynamicOffsetEnabled() |
| 103 | +{ |
| 104 | + return (readRegister(Crorc::Registers::CFG_CONTROL.index) & 0x1); |
68 | 105 | } |
69 | 106 |
|
70 | 107 | } // namespace roc |
|
0 commit comments