Skip to content

Commit 3efd238

Browse files
committed
[sc] Add SC base class
1 parent 052027a commit 3efd238

File tree

12 files changed

+230
-277
lines changed

12 files changed

+230
-277
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ add_library(ALF SHARED
7777
src/Ic.cxx
7878
src/Lla.cxx
7979
src/Sca.cxx
80+
src/ScBase.cxx
8081
src/Swt.cxx
8182
src/SwtWord.cxx
8283
)

apps/Alf.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ class Alf : public AliceO2::Common::Program
105105

106106
Logger::get() << "CRU " << card.serialId << " registered" << LogInfoDevel << endm;
107107
bar = roc::ChannelFactory().getBar(card.serialId, 2);
108-
for (int linkId = 0; linkId < CRU_NUM_LINKS; linkId++) {
108+
for (int linkId = 0; linkId < kCruNumLinks; linkId++) {
109109
links.push_back({ alfId, card.serialId, linkId, card.serialId.getEndpoint() * 12 + linkId, bar, roc::CardType::Cru });
110110
}
111111

112112
} else if (card.cardType == roc::CardType::Crorc) {
113113
Logger::get() << "CRORC " << card.serialId << " registered" << LogInfoDevel << endm;
114-
for (int linkId = 0; linkId < CRORC_NUM_LINKS; linkId++) {
114+
for (int linkId = 0; linkId < kCrorcNumLinks; linkId++) {
115115
bar = roc::ChannelFactory().getBar(card.serialId, linkId);
116116
links.push_back({ alfId, card.serialId, linkId, -1, bar, roc::CardType::Crorc });
117117
}

include/Alf/Common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ namespace alf
2828

2929
namespace roc = AliceO2::roc;
3030

31-
static constexpr int CRU_NUM_LINKS(12);
32-
static constexpr int CRORC_NUM_LINKS(6);
31+
static constexpr int kCruNumLinks(12);
32+
static constexpr int kCrorcNumLinks(6);
3333

3434
static constexpr auto BUSY_TIMEOUT = std::chrono::milliseconds(10);
3535
static constexpr auto CHANNEL_BUSY_TIMEOUT = std::chrono::milliseconds(10);

include/Alf/Exception.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ namespace alf
2525

2626
struct AlfException : AliceO2::Common::Exception {
2727
};
28+
struct ScException : AliceO2::Common::Exception {
29+
};
2830
struct ScaException : AliceO2::Common::Exception {
2931
};
3032
struct SwtException : AliceO2::Common::Exception {

include/Alf/Ic.h

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include "Common.h"
3535
#include "Alf/Lla.h"
36+
#include "Alf/ScBase.h"
3637

3738
namespace roc = AliceO2::roc;
3839

@@ -42,7 +43,7 @@ namespace alf
4243
{
4344

4445
/// Class for IC Transactions with the CRU
45-
class Ic
46+
class Ic : public ScBase
4647
{
4748
public:
4849
/// Struct holding the IC address and data pair; useful to AlfServer
@@ -70,13 +71,6 @@ class Ic
7071
/// \param linkId The link ID for which to get the IC handle.
7172
Ic(std::string cardId, int linkId = -1);
7273

73-
/// Sets the IC channel
74-
/// \param gbtChannel The IC channel to set.
75-
void setChannel(int gbtChannel);
76-
77-
/// Executes an SC reset
78-
void scReset();
79-
8074
/// Performs an IC read
8175
/// \param address IC address to read from
8276
/// \return IC data requested
@@ -131,21 +125,6 @@ class Ic
131125

132126
static std::string IcOperationToString(Operation op);
133127
static Ic::Operation StringToIcOperation(std::string op);
134-
135-
private:
136-
void init(const roc::Parameters::CardIdType& cardId, int linkId);
137-
138-
/// Checks if an IC channel is selected
139-
/// \throws o2::alf::IcException if no IC channel selected
140-
void checkChannelSet();
141-
142-
void barWrite(uint32_t offset, uint32_t data);
143-
uint32_t barRead(uint32_t index);
144-
145-
std::shared_ptr<roc::BarInterface> mBar2;
146-
147-
AlfLink mLink;
148-
std::unique_ptr<LlaSession> mLlaSession;
149128
};
150129

151130
} // namespace alf

include/Alf/ScBase.h

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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 ScBase.h
12+
/// \brief Definition of ALICE Lowlevel Frontend (ALF) SC base class
13+
///
14+
/// \author Kostas Alexopoulos ([email protected])
15+
16+
#ifndef O2_ALF_INC_SCBASE_H
17+
#define O2_ALF_INC_SCBASE_H
18+
19+
#include "ReadoutCard/BarInterface.h"
20+
#include "ReadoutCard/Parameters.h"
21+
22+
#include "Common.h"
23+
#include "Alf/Lla.h"
24+
25+
namespace roc = AliceO2::roc;
26+
27+
namespace o2
28+
{
29+
namespace alf
30+
{
31+
32+
/// Class for interfacing with the C-RORC's(?) and CRU's Slow-Control Adapter (SCA)
33+
class ScBase
34+
{
35+
public:
36+
/// Internal constructor for the AlfServer
37+
/// \param link AlfLink holding useful information coming from the AlfServer class
38+
ScBase(AlfLink link, std::shared_ptr<lla::Session> llaSession);
39+
40+
/// External constructor
41+
/// \param cardId The card ID for which to get the SC handle.
42+
/// \param linkId The link ID to set the channel to (optional).
43+
ScBase(const roc::Parameters::CardIdType& cardId, int linkId = -1);
44+
45+
/// External constructor
46+
/// \param cardId The card ID for which to get the SC handle.
47+
/// \param linkId The link ID to set the channel to (optional).
48+
ScBase(std::string cardId, int linkId = -1);
49+
50+
/// Sets the SC channel
51+
/// \param gbtChannel The channel to set
52+
void setChannel(int gbtChannel);
53+
54+
/// Executes a global SC reset
55+
void scReset();
56+
57+
/// Checks if an SCA channel has been selected
58+
/// \throws o2::alf::ScaException if no SCA channel selected
59+
void checkChannelSet();
60+
61+
protected:
62+
uint32_t barRead(uint32_t index);
63+
void barWrite(uint32_t index, uint32_t data);
64+
65+
AlfLink mLink;
66+
std::unique_ptr<LlaSession> mLlaSession;
67+
68+
private:
69+
/// Does the necessary initializations after an object creating
70+
void init(const roc::Parameters::CardIdType& cardId, int linkId);
71+
72+
/// Interface for BAR 2
73+
std::shared_ptr<roc::BarInterface> mBar2;
74+
};
75+
76+
} // namespace alf
77+
} // namespace o2
78+
79+
#endif // O2_ALF_INC_SCBASE_H

include/Alf/Sca.h

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "Common.h"
2828
#include "Alf/Lla.h"
29+
#include "Alf/ScBase.h"
2930

3031
namespace roc = AliceO2::roc;
3132

@@ -35,7 +36,7 @@ namespace alf
3536
{
3637

3738
/// Class for interfacing with the C-RORC's(?) and CRU's Slow-Control Adapter (SCA)
38-
class Sca
39+
class Sca : public ScBase
3940
{
4041
public:
4142
/// Struct holding the command and data pair of an SCA command
@@ -72,13 +73,6 @@ class Sca
7273
/// \param linkId The link ID to set the channel to (optional).
7374
Sca(std::string cardId, int linkId = -1);
7475

75-
/// Sets the SCA channel
76-
/// \param gbtChannel The channel to set
77-
void setChannel(int gbtChannel);
78-
79-
/// Executes a global SC reset
80-
void scReset();
81-
8276
/// Executes an SCA reset
8377
void svlReset();
8478

@@ -124,15 +118,6 @@ class Sca
124118
static Sca::Operation StringToScaOperation(std::string op);
125119

126120
private:
127-
void init(const roc::Parameters::CardIdType& cardId, int linkId);
128-
129-
/// Checks if an SCA channel has been selected
130-
/// \throws o2::alf::ScaException if no SCA channel selected
131-
void checkChannelSet();
132-
133-
uint32_t barRead(uint32_t index);
134-
void barWrite(uint32_t index, uint32_t data);
135-
136121
/// Performs an SCA read
137122
/// \return CommandData An SCA command, data pair
138123
/// \throws o2::alf::ScaException on SCA error
@@ -156,11 +141,6 @@ class Sca
156141
bool isChannelBusy(uint32_t command);
157142
void waitOnBusyClear();
158143

159-
/// Interface for BAR 2
160-
std::shared_ptr<roc::BarInterface> mBar2;
161-
AlfLink mLink;
162-
std::unique_ptr<LlaSession> mLlaSession;
163-
164144
static constexpr int DEFAULT_SCA_WAIT_TIME_MS = 3;
165145
};
166146

include/Alf/Swt.h

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@
3333
#include "ReadoutCard/BarInterface.h"
3434
#include "ReadoutCard/Parameters.h"
3535

36-
#include "Alf/SwtWord.h"
3736
#include "Common.h"
3837
#include "Alf/Lla.h"
38+
#include "Alf/ScBase.h"
39+
#include "Alf/SwtWord.h"
3940

4041
namespace roc = AliceO2::roc;
4142

@@ -45,7 +46,7 @@ namespace alf
4546
{
4647

4748
/// Class for Single Word Transactions with the CRU
48-
class Swt
49+
class Swt : public ScBase
4950
{
5051
public:
5152
typedef int TimeOut, WaitTime;
@@ -76,13 +77,6 @@ class Swt
7677
/// \param linkId The link ID to set the channel to (optional).
7778
Swt(std::string cardId, int linkId = -1);
7879

79-
/// Sets the SWT channel
80-
/// \param gbtChannel The channel to set
81-
void setChannel(int gbtChannel);
82-
83-
/// Executes an SC reset
84-
void scReset();
85-
8680
/// Writes an SWT word
8781
/// \param swtWord The SWT word to write
8882
/// \param wordSize The size of the SWT word to be written
@@ -118,20 +112,6 @@ class Swt
118112
static constexpr int DEFAULT_SWT_TIMEOUT_MS = 10;
119113

120114
private:
121-
void init(const roc::Parameters::CardIdType& cardId, int linkId);
122-
123-
/// Checks if an SWT channel has been selected
124-
/// \throws o2::alf::SwtException if no SWT channel selected
125-
void checkChannelSet();
126-
127-
void barWrite(uint32_t offset, uint32_t data);
128-
uint32_t barRead(uint32_t index);
129-
130-
std::shared_ptr<roc::BarInterface> mBar2;
131-
132-
AlfLink mLink;
133-
std::unique_ptr<LlaSession> mLlaSession;
134-
135115
static constexpr int DEFAULT_SWT_WAIT_TIME_MS = 3;
136116
};
137117

0 commit comments

Comments
 (0)