Skip to content

Commit c283955

Browse files
committed
[alf] Share LLA session objects internally
1 parent acc0901 commit c283955

File tree

10 files changed

+37
-29
lines changed

10 files changed

+37
-29
lines changed

include/Alf/Ic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Ic
5858

5959
/// Internal constructor for the ALF server
6060
/// \param link AlfLink holding useful information coming from the AlfServer class
61-
Ic(AlfLink link);
61+
Ic(AlfLink link, std::shared_ptr<lla::Session> llaSession);
6262

6363
/// External constructor
6464
/// \param cardId The card ID for which to get the IC handle.

include/Alf/Lla.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@ namespace alf
2828
class LlaSession
2929
{
3030
public:
31+
LlaSession(std::shared_ptr<lla::Session> llaSession);
3132
LlaSession(std::string sessionName, roc::SerialId serialId);
3233
void start();
3334
void stop();
3435

3536
private:
3637
lla::SessionParameters mParams;
37-
std::unique_ptr<lla::Session> mSession;
38+
std::shared_ptr<lla::Session> mSession;
3839
std::string mSessionName;
39-
roc::SerialId mSerialId;
40+
roc::SerialId mSerialId = -1;
4041
};
4142

4243
} // namespace alf

include/Alf/Sca.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Sca
6060

6161
/// Internal constructor for the AlfServer
6262
/// \param link AlfLink holding useful information coming from the AlfServer class
63-
Sca(AlfLink link);
63+
Sca(AlfLink link, std::shared_ptr<lla::Session> llaSession);
6464

6565
/// External constructor
6666
/// \param cardId The card ID for which to get the SCA handle.

include/Alf/Swt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Swt
6464

6565
/// Internal constructor for the ALF server
6666
/// \param link AlfLink holding useful information coming from the AlfServer class
67-
Swt(AlfLink link);
67+
Swt(AlfLink link, std::shared_ptr<lla::Session> llaSession);
6868

6969
/// External constructor
7070
/// \param cardId The card ID for which to get the SWT handle.

src/AlfServer.cxx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ std::string AlfServer::scaBlobWrite(const std::string& parameter, AlfLink link)
8383
{
8484
std::vector<std::string> stringPairs = Util::split(parameter, argumentSeparator());
8585
std::vector<std::pair<Sca::Operation, Sca::Data>> scaPairs = parseStringToScaPairs(stringPairs);
86-
Sca sca = Sca(link);
86+
Sca sca = Sca(link, mSessions[link.serialId]);
8787

8888
bool lock = false;
8989
// Check if the operation should be locked
@@ -99,7 +99,7 @@ std::string AlfServer::swtBlobWrite(const std::string& parameter, AlfLink link)
9999

100100
std::vector<std::string> stringPairs = Util::split(parameter, argumentSeparator());
101101
std::vector<std::pair<Swt::Operation, Swt::Data>> swtPairs = parseStringToSwtPairs(stringPairs);
102-
Swt swt = Swt(link);
102+
Swt swt = Swt(link, mSessions[link.serialId]);
103103

104104
bool lock = false;
105105
// Check if the operation should be locked
@@ -115,7 +115,7 @@ std::string AlfServer::icBlobWrite(const std::string& parameter, AlfLink link)
115115

116116
std::vector<std::string> stringPairs = Util::split(parameter, argumentSeparator());
117117
std::vector<std::pair<Ic::Operation, Ic::Data>> icPairs = parseStringToIcPairs(stringPairs);
118-
Ic ic = Ic(link);
118+
Ic ic = Ic(link, mSessions[link.serialId]);
119119

120120
bool lock = false;
121121
// Check if the operation should be locked
@@ -136,7 +136,7 @@ std::string AlfServer::icGbtI2cWrite(const std::string& parameter, AlfLink link)
136136

137137
uint32_t value = Util::stringToHex(params[0]);
138138

139-
Ic ic = Ic(link);
139+
Ic ic = Ic(link, mSessions[link.serialId]);
140140
ic.writeGbtI2c(value);
141141
return "";
142142
}
@@ -163,10 +163,7 @@ std::string AlfServer::llaSessionStart(const std::string& parameter, roc::Serial
163163
}
164164

165165
if (mSessions.find(serialId) == mSessions.end()) {
166-
lla::SessionParameters params = lla::SessionParameters::makeParameters()
167-
.setSessionName(parameters[0])
168-
.setCardId(serialId);
169-
mSessions[serialId] = std::make_unique<lla::Session>(params);
166+
BOOST_THROW_EXCEPTION(AlfException() << ErrorInfo::Message("Session not initialized for serial " + serialId.toString()));
170167
} /*else {
171168
// TODO: Update session name?
172169
}*/
@@ -572,19 +569,24 @@ void AlfServer::makeRpcServers(std::vector<AlfLink> links)
572569
[link, this](auto parameter) { return llaSessionStop(parameter, link.serialId); }));
573570
}
574571

572+
lla::SessionParameters params = lla::SessionParameters::makeParameters()
573+
.setSessionName("ALF")
574+
.setCardId(link.serialId);
575+
mSessions[link.serialId] = std::make_shared<lla::Session>(params);
576+
575577
// SCA Sequence
576578
servers.push_back(makeServer(names.scaSequence(),
577-
[link](auto parameter) { return scaBlobWrite(parameter, link); }));
579+
[link, this](auto parameter) { return scaBlobWrite(parameter, link); }));
578580
// SWT Sequence
579581
servers.push_back(makeServer(names.swtSequence(),
580-
[link](auto parameter) { return swtBlobWrite(parameter, link); }));
582+
[link, this](auto parameter) { return swtBlobWrite(parameter, link); }));
581583
// IC Sequence
582584
servers.push_back(makeServer(names.icSequence(),
583-
[link](auto parameter) { return icBlobWrite(parameter, link); }));
585+
[link, this](auto parameter) { return icBlobWrite(parameter, link); }));
584586

585587
// IC GBT I2C write
586588
servers.push_back(makeServer(names.icGbtI2cWrite(),
587-
[link](auto parameter) { return icGbtI2cWrite(parameter, link); }));
589+
[link, this](auto parameter) { return icGbtI2cWrite(parameter, link); }));
588590

589591
} else if (link.cardType == roc::CardType::Crorc) {
590592
// Register Sequence

src/AlfServer.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ class AlfServer
4949
private:
5050
static std::string registerRead(const std::string& parameter, std::shared_ptr<roc::BarInterface>);
5151
static std::string registerWrite(const std::string& parameter, std::shared_ptr<roc::BarInterface>);
52-
static std::string scaBlobWrite(const std::string& parameter, AlfLink link);
53-
static std::string swtBlobWrite(const std::string& parameter, AlfLink link);
54-
static std::string icBlobWrite(const std::string& parameter, AlfLink link);
55-
static std::string icGbtI2cWrite(const std::string& parameter, AlfLink link);
52+
std::string scaBlobWrite(const std::string& parameter, AlfLink link);
53+
std::string swtBlobWrite(const std::string& parameter, AlfLink link);
54+
std::string icBlobWrite(const std::string& parameter, AlfLink link);
55+
std::string icGbtI2cWrite(const std::string& parameter, AlfLink link);
5656
static std::string patternPlayer(const std::string& parameter, std::shared_ptr<roc::BarInterface>);
5757
static std::string registerBlobWrite(const std::string& parameter, AlfLink link);
5858
std::string llaSessionStart(const std::string& parameter, roc::SerialId serialId);
@@ -75,7 +75,7 @@ class AlfServer
7575

7676
/// serialId -> link -> vector of RPC servers
7777
std::map<roc::SerialId, std::map<int, std::vector<std::unique_ptr<StringRpcServer>>>, serialIdComparator> mRpcServers;
78-
std::map<roc::SerialId, std::unique_ptr<lla::Session>, serialIdComparator> mSessions;
78+
std::map<roc::SerialId, std::shared_ptr<lla::Session>, serialIdComparator> mSessions;
7979
};
8080

8181
} // namespace alf

src/Ic.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ static constexpr roc::Register IC_WR_CMD(IC_BASE.address + 0x28);
5252
static constexpr roc::Register IC_RD_DATA(IC_BASE.address + 0x30);
5353
} // namespace ic_regs
5454

55-
Ic::Ic(AlfLink link) : mBar2(link.bar), mLink(link)
55+
Ic::Ic(AlfLink link, std::shared_ptr<lla::Session> llaSession) : mBar2(link.bar), mLink(link)
5656
{
5757
scReset();
5858

5959
// Set CFG to 0x3 by default
6060
barWrite(ic_regs::IC_WR_CFG.index, 0x3);
6161

62-
mLlaSession = std::make_unique<LlaSession>("DDT", link.serialId);
62+
mLlaSession = std::make_unique<LlaSession>(llaSession);
6363
}
6464

6565
Ic::Ic(const roc::Parameters::CardIdType& cardId, int linkId)

src/Lla.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ namespace o2
2020
namespace alf
2121
{
2222

23+
LlaSession::LlaSession(std::shared_ptr<lla::Session> llaSession)
24+
: mSession(llaSession)
25+
{
26+
}
27+
2328
LlaSession::LlaSession(std::string sessionName, roc::SerialId serialId)
2429
: mSessionName(sessionName),
2530
mSerialId(serialId)
@@ -30,7 +35,7 @@ void LlaSession::start()
3035
{
3136
if (!mSession) {
3237
mParams = lla::SessionParameters::makeParameters(mSessionName, mSerialId);
33-
mSession = std::make_unique<lla::Session>(mParams);
38+
mSession = std::make_shared<lla::Session>(mParams);
3439
}
3540

3641
if (!mSession->isStarted()) {

src/Sca.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ namespace o2
3838
namespace alf
3939
{
4040

41-
Sca::Sca(AlfLink link)
41+
Sca::Sca(AlfLink link, std::shared_ptr<lla::Session> llaSession)
4242
: mBar2(link.bar), mLink(link)
4343
{
44-
mLlaSession = std::make_unique<LlaSession>("DDT", link.serialId);
44+
mLlaSession = std::make_unique<LlaSession>(llaSession);
4545
}
4646

4747
Sca::Sca(const roc::Parameters::CardIdType& cardId, int linkId)

src/Swt.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ namespace alf
4242

4343
namespace sc_regs = AliceO2::roc::Cru::ScRegisters;
4444

45-
Swt::Swt(AlfLink link) : mBar2(link.bar), mLink(link)
45+
Swt::Swt(AlfLink link, std::shared_ptr<lla::Session> llaSession) : mBar2(link.bar), mLink(link)
4646
{
47-
mLlaSession = std::make_unique<LlaSession>("DDT", link.serialId);
47+
mLlaSession = std::make_unique<LlaSession>(llaSession);
4848
}
4949

5050
Swt::Swt(const roc::Parameters::CardIdType& cardId, int linkId)

0 commit comments

Comments
 (0)