Skip to content

Commit 6687896

Browse files
committed
[sca] Add reset & connect commands
1 parent 02fd4fa commit 6687896

File tree

6 files changed

+65
-9
lines changed

6 files changed

+65
-9
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,16 @@ The services are DIM RPC services. Every RPC is called with a string and expects
8080
* Operations may be:
8181
* An SCA command and data pair (e.g. `0x0000f00d,0x0000cafe`)
8282
* A wait operation (e.g. `30,wait`) in ms, defaults to 3
83+
* An SCA connect operation (e.g. `connect`)
84+
* An SCA reset operation (e.g. `reset`)
8385
* An instruction to execute the sequence atomically (`lock` - needs to lead the sequence)
8486
* Returns:
85-
* Sequence of SCA command and SCA read pairs, and wait confirmations
86-
* No entries for `lock` directives
87+
* Sequence of SCA output as follows:
88+
* SCA command and SCA read pairs
89+
* Wait confirmations with time waited
90+
* Connect confirmations made up of a "connect" string
91+
* No entries for `reset` directives
92+
* No entries for `lock` directives
8793

8894
* Example:
8995
* DIM input: `0x00000010,0x00000011\n3\n0x000000020,0x00000021`
@@ -227,12 +233,12 @@ typedef int TimeOut;
227233
228234
/// Typedef for the Data type of an SWT sequence operation.
229235
/// Variant of TimeOut for reads, SwtWord for writes, std::string for Errors
230-
typedef boost::variant<boost::blank, TimeOut, SwtWord, std::string> Data;
236+
typedef boost::variant<boost::blank, TimeOut, WaitTime, SwtWord, std::string> Data;
231237
232238
/// Enum for the different SWT operation types
233239
enum Operation { Read,
234240
Write,
235-
WaitTime,
241+
Wait,
236242
Reset,
237243
Error };
238244

apps/AlfClient.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ class AlfClient : public AliceO2::Common::Program
189189
}
190190

191191
if (mOptions.sca) {
192-
auto scaOut = scaSequence.write({ std::make_pair("1000", "wait"),
192+
auto scaOut = scaSequence.write({ std::make_pair("", "reset"),
193+
std::make_pair("", "connect"),
194+
std::make_pair("1000", "wait"),
193195
std::make_pair("0x00010002", "0xff000000"),
194196
std::make_pair("0x00020004", "0xff000000"),
195197
std::make_pair("0x00030006", "0xff000000"),

apps/AlfLibClient.cxx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ class AlfLibClient : public AliceO2::Common::Program
6868
auto sca = Sca(roc::SerialId{ mOptions.serial, mOptions.endpoint }, mOptions.link);
6969
sca.reset();
7070

71-
std::cout << "Running simple SCA operation" << std::endl;
71+
std::cout << "Running simple SCA operations" << std::endl;
7272
try {
73+
sca.connect();
7374
auto scaOut = sca.executeCommand({ 0x00010002, 0xff000000 });
7475
std::cout << scaOut.command << " " << scaOut.data << std::endl;
7576
} catch (const ScaException& e) {
@@ -79,6 +80,8 @@ class AlfLibClient : public AliceO2::Common::Program
7980
std::cout << "Running an SCA sequence" << std::endl;
8081
std::vector<std::pair<Sca::Operation, Sca::Data>> ops;
8182
sca.setChannel(1);
83+
ops.push_back({ Sca::Operation::Reset , {} });
84+
ops.push_back({ Sca::Operation::Connect, {} });
8285
ops.push_back({ Sca::Operation::Command, Sca::CommandData{ 0x00100002, 0xff000000 } });
8386
ops.push_back({ Sca::Operation::Command, Sca::CommandData{ 0x00100003, 0xff000000 } });
8487
ops.push_back({ Sca::Operation::Wait, 100 });
@@ -89,6 +92,10 @@ class AlfLibClient : public AliceO2::Common::Program
8992
std::cout << "Command: " << boost::get<Sca::CommandData>(out.second) << std::endl;
9093
} else if (out.first == Sca::Operation::Wait) {
9194
std::cout << "Wait: " << std::dec << boost::get<Sca::WaitTime>(out.second) << std::endl;
95+
} else if (out.first == Sca::Operation::Reset) {
96+
std::cout << "Reset" << std::endl;
97+
} else if (out.first == Sca::Operation::Connect) {
98+
std::cout << "Connect " << std::endl;
9299
} else if (out.first == Sca::Operation::Error) {
93100
std::cout << "Error: " << boost::get<std::string>(out.second) << std::endl;
94101
} else {

include/Alf/Sca.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class Sca
5252
/// Enum for the different SCA operation types as seen from DIM RPCs
5353
enum Operation { Command,
5454
Wait,
55+
Reset,
56+
Connect,
5557
Error,
5658
Lock };
5759

@@ -77,9 +79,12 @@ class Sca
7779
/// \throws o2::alf::ScaException if no SCA channel selected
7880
void checkChannelSet();
7981

80-
/// Executes an SC reset
82+
/// Executes an SCA reset
8183
void reset();
8284

85+
/// Executes an SCA connect
86+
void connect();
87+
8388
/// Executes an SCA command
8489
/// \param commandData SCA command, data pair
8590
/// \param lock Boolean enabling implicit locking

src/AlfServer.cxx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,18 @@ std::pair<Sca::Operation, Sca::Data> AlfServer::stringToScaPair(const std::strin
296296
} catch (const std::exception& e) {
297297
BOOST_THROW_EXCEPTION(SwtException() << ErrorInfo::Message("SCA Wait Time provided cannot be converted to int"));
298298
}
299+
} else if (scaPair[scaPair.size() - 1] == "reset") {
300+
operation = Sca::Operation::Reset;
301+
if (scaPair.size() != 1) {
302+
BOOST_THROW_EXCEPTION(
303+
AlfException() << ErrorInfo::Message("Too many arguments for RESET operation"));
304+
}
305+
} else if (scaPair[scaPair.size() - 1] == "connect") {
306+
operation = Sca::Operation::Connect;
307+
if (scaPair.size() != 1) {
308+
BOOST_THROW_EXCEPTION(
309+
AlfException() << ErrorInfo::Message("Too many arguments for CONNECT operation"));
310+
}
299311
} else { // regular sca command
300312
operation = Sca::Operation::Command;
301313
if (scaPair.size() != 2) {

src/Sca.cxx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,18 @@ void Sca::checkChannelSet()
9898

9999
void Sca::reset()
100100
{
101-
barWrite(sc_regs::SC_RESET.index, 0x1);
102-
barWrite(sc_regs::SC_RESET.index, 0x0);
101+
barWrite(sc_regs::SCA_WR_CTRL.index, 0x1);
102+
barWrite(sc_regs::SCA_WR_CTRL.index, 0x0);
103+
/* DO I NEED THIS?
104+
waitOnBusyClear(); */
105+
}
106+
107+
void Sca::connect()
108+
{
109+
barWrite(sc_regs::SCA_WR_CTRL.index, 0x2);
110+
barWrite(sc_regs::SCA_WR_CTRL.index, 0x0);
111+
/* DO I NEED THIS?
112+
waitOnBusyClear(); */
103113
}
104114

105115
Sca::CommandData Sca::executeCommand(uint32_t command, uint32_t data, bool lock)
@@ -286,6 +296,12 @@ std::vector<std::pair<Sca::Operation, Sca::Data>> Sca::executeSequence(const std
286296
}
287297
std::this_thread::sleep_for(std::chrono::milliseconds(waitTime));
288298
ret.push_back({ operation, waitTime });
299+
} else if (operation == Operation::Reset) {
300+
reset();
301+
ret.push_back({ Operation::Reset, {} });
302+
} else if (operation == Operation::Connect) {
303+
connect();
304+
ret.push_back({ Operation::Connect, {} });
289305
} else {
290306
BOOST_THROW_EXCEPTION(ScaException() << ErrorInfo::Message("SCA operation type unknown"));
291307
}
@@ -297,6 +313,10 @@ std::vector<std::pair<Sca::Operation, Sca::Data>> Sca::executeSequence(const std
297313
meaningfulMessage = (boost::format("SCA_SEQUENCE cmd=0x%08x data=0x%08x serialId=%s link=%d error='%s'") % boost::get<CommandData>(data).command % boost::get<CommandData>(data).data % mLink.serialId % mLink.linkId % e.what()).str();
298314
} else if (operation == Operation::Wait) {
299315
meaningfulMessage = (boost::format("SCA_SEQUENCE WAIT waitTime=%d serialId=%s link=%d error='%s'") % boost::get<WaitTime>(data) % mLink.serialId % mLink.linkId % e.what()).str();
316+
} else if (operation == Operation::Reset) {
317+
meaningfulMessage = (boost::format("SCA_SEQUENCE RESET serialId=%s link=%d error='%s'") % mLink.serialId % mLink.linkId % e.what()).str();
318+
} else if (operation == Operation::Connect) {
319+
meaningfulMessage = (boost::format("SCA_SEQUENCE CONNECT serialId=%s link=%d error='%s'") % mLink.serialId % mLink.linkId % e.what()).str();
300320
} else {
301321
meaningfulMessage = (boost::format("SCA_SEQUENCE UNKNOWN serialId=%s link=%d error='%s'") % mLink.serialId % mLink.linkId % e.what()).str();
302322
}
@@ -325,6 +345,10 @@ std::string Sca::writeSequence(const std::vector<std::pair<Operation, Data>>& op
325345
resultBuffer << data << "\n"; // "[cmd],[data]\n"
326346
} else if (operation == Operation::Wait) {
327347
resultBuffer << std::dec << data << "\n"; // "[time]\n"
348+
} else if (operation == Operation::Reset) {
349+
/* DO NOTHING */
350+
} else if (operation == Operation::Connect) {
351+
resultBuffer << "connect\n"; // echo
328352
} else if (operation == Operation::Error) {
329353
resultBuffer << data; // "[error_msg]"
330354
Logger::get().err() << data << endm;

0 commit comments

Comments
 (0)