|
| 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 ScaMftPsu.h |
| 12 | +/// \brief Definition of ALICE Lowlevel Frontend (ALF) SCA operations for the MFT PSU |
| 13 | +/// |
| 14 | +/// \author Kostas Alexopoulos ([email protected]) |
| 15 | + |
| 16 | +#ifndef O2_ALF_INC_SCA_MFT_PSU_H |
| 17 | +#define O2_ALF_INC_SCA_MFT_PSU_H |
| 18 | + |
| 19 | +#include <string> |
| 20 | +#include <map> |
| 21 | +#include <boost/variant.hpp> |
| 22 | + |
| 23 | +#include "ReadoutCard/BarInterface.h" |
| 24 | +#include "ReadoutCard/Parameters.h" |
| 25 | + |
| 26 | +#include "Common.h" |
| 27 | +#include "Alf/Lla.h" |
| 28 | +#include "Alf/Sca.h" |
| 29 | +#include "Alf/ScaMftPsu.h" |
| 30 | + |
| 31 | +namespace roc = AliceO2::roc; |
| 32 | + |
| 33 | +namespace o2 |
| 34 | +{ |
| 35 | +namespace alf |
| 36 | +{ |
| 37 | + |
| 38 | +/// Class for interfacing with the MFT PSU Slow-Control Adapter (SCA) |
| 39 | +class ScaMftPsu |
| 40 | +{ |
| 41 | + public: |
| 42 | + // Pull these from Sca to simplify things a bit |
| 43 | + typedef Sca::CommandData CommandData; |
| 44 | + typedef Sca::WaitTime WaitTime; |
| 45 | + typedef Sca::Data Data; |
| 46 | + typedef Sca::Operation Operation; |
| 47 | + |
| 48 | + /// Internal constructor for the AlfServer |
| 49 | + /// \param link AlfLink holding useful information coming from the AlfServer class |
| 50 | + ScaMftPsu(AlfLink link, std::shared_ptr<lla::Session> llaSession); |
| 51 | + |
| 52 | + /// Executes a global SC reset |
| 53 | + void scReset(); |
| 54 | + |
| 55 | + /// Executes an SCA reset |
| 56 | + void svlReset(); |
| 57 | + |
| 58 | + /// Executes an SCA connect |
| 59 | + void svlConnect(); |
| 60 | + |
| 61 | + /// Changes to master |
| 62 | + void setMaster(); |
| 63 | + |
| 64 | + /// Changes to slave |
| 65 | + void setSlave(); |
| 66 | + |
| 67 | + /// Executes an SCA command |
| 68 | + /// \param commandData SCA command, data pair |
| 69 | + /// \param lock Boolean enabling implicit locking |
| 70 | + /// \throws o2::lla::LlaException on lock fail, |
| 71 | + /// o2::alf::ScaMftPsuException on SCA error |
| 72 | + CommandData executeCommand(CommandData commandData, bool lock = false) |
| 73 | + { |
| 74 | + return executeCommand(commandData.command, commandData.data, lock); |
| 75 | + } |
| 76 | + /// Executes an SCA command |
| 77 | + /// \param command SCA command |
| 78 | + /// \param data SCA data |
| 79 | + /// \param lock Boolean enabling implicit locking |
| 80 | + /// \throws o2::lla::LlaException on lock fail |
| 81 | + /// o2::alf::ScaMftPsuException on SCA error |
| 82 | + CommandData executeCommand(uint32_t command, uint32_t data, bool lock = false); |
| 83 | + |
| 84 | + /// Executes an SCA sequence |
| 85 | + /// \param operations A vector of Operation and Data pairs |
| 86 | + /// \param lock Boolean enabling implicit locking |
| 87 | + /// \return A vector of Operation and Data pairs |
| 88 | + /// CommandData for Commands |
| 89 | + /// WaitTime for Waits |
| 90 | + /// std::string for Errors |
| 91 | + /// \throws o2::lla::LlaException on lock fail |
| 92 | + std::vector<std::pair<Operation, Data>> executeSequence(const std::vector<std::pair<Operation, Data>>& operations, bool lock = false); |
| 93 | + |
| 94 | + /// Executes an SCA sequence for the ALF Server |
| 95 | + /// \param operations A vector of Data and Operation pairs |
| 96 | + /// \param lock Boolean enabling implicit locking |
| 97 | + /// \return A string of newline separated results; |
| 98 | + /// \throws o2::lla::LlaException on lock fail |
| 99 | + /// o2::alf::ScaMftPsuException on invalid operation or error |
| 100 | + std::string writeSequence(const std::vector<std::pair<Operation, Data>>& operations, bool lock = false); |
| 101 | + |
| 102 | + private: |
| 103 | + uint32_t barRead(uint32_t index); |
| 104 | + void barWrite(uint32_t index, uint32_t data); |
| 105 | + |
| 106 | + /// Performs an SCA read |
| 107 | + /// \return CommandData An SCA command, data pair |
| 108 | + /// \throws o2::alf::ScaMftPsuException on SCA error |
| 109 | + CommandData read(); |
| 110 | + |
| 111 | + /// Performs an SCA write |
| 112 | + /// \param command SCA command |
| 113 | + /// \param data SCA data |
| 114 | + /// \throws o2::alf::ScaMftPsuException on SCA error |
| 115 | + void write(uint32_t command, uint32_t data); |
| 116 | + |
| 117 | + /// Performs an SCA write |
| 118 | + /// \param commandData SCA command, data pair |
| 119 | + /// \throws o2::alf::ScaMftPsuException on SCA error |
| 120 | + void write(CommandData commandData) |
| 121 | + { |
| 122 | + write(commandData.command, commandData.data); |
| 123 | + }; |
| 124 | + void execute(); |
| 125 | + void checkError(uint32_t command); |
| 126 | + bool isChannelBusy(uint32_t command); |
| 127 | + void waitOnBusyClear(); |
| 128 | + |
| 129 | + /// Interface for BAR 2 |
| 130 | + std::shared_ptr<roc::BarInterface> mBar2; |
| 131 | + AlfLink mLink; |
| 132 | + std::unique_ptr<LlaSession> mLlaSession; |
| 133 | + |
| 134 | + static constexpr int DEFAULT_SCA_WAIT_TIME_MS = 3; |
| 135 | +}; |
| 136 | + |
| 137 | +} // namespace alf |
| 138 | +} // namespace o2 |
| 139 | + |
| 140 | +#endif // O2_ALF_INC_SCA_H |
0 commit comments