Skip to content

Commit 02fd4fa

Browse files
committed
[swt] Introduce wait operation
1 parent 5347bc5 commit 02fd4fa

File tree

7 files changed

+37
-6
lines changed

7 files changed

+37
-6
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ The services are DIM RPC services. Every RPC is called with a string and expects
7979
* Sequence of SCA operations as follows:
8080
* Operations may be:
8181
* An SCA command and data pair (e.g. `0x0000f00d,0x0000cafe`)
82-
* A wait operation (e.g. `30,wait`)
82+
* A wait operation (e.g. `30,wait`) in ms, defaults to 3
8383
* An instruction to execute the sequence atomically (`lock` - needs to lead the sequence)
8484
* Returns:
8585
* Sequence of SCA command and SCA read pairs, and wait confirmations
@@ -97,12 +97,14 @@ The services are DIM RPC services. Every RPC is called with a string and expects
9797
* `write` with SWT prefix (e.g. `0x0000f00d,write`)
9898
* `reset` (without SWT word)
9999
* `read` with optional TimeOut prefix (e.g. `2,read`)
100+
* `wait` with optional WaitTime prefix in ms (e.g. `5,wait`), defaults to 3
100101
* `lock` which instructs ALF to execute the sequence atomically (needs to lead the sequence)
101102
* Returns:
102103
* Sequence of SWT output as follows:
103104
* `write` always retuns `0`
104105
* `read` returns the SWT words present in the CRU SWT FIFO
105106
* `reset` returns nothing
107+
* `wait` returns time waited
106108
* `lock` returns nothing
107109

108110
* Example:
@@ -218,7 +220,7 @@ All the above offer **no implicit locking** and should be manually locked throug
218220
### Sequences of operations
219221
All SC classes offer a function to execute a sequence of their respective operations. This function receives an `std::vector`, consisting of an `std::pair` made up of the compatible SC operation and SC data, as these are defined in their headers.
220222

221-
For example, `SWT` offers `Read, Write and Reset` operations which expect a `TimeOut`, an `SwtWord` and no argument, respectively.
223+
For example, `SWT` offers `Read, Write, Wait, and Reset` operations which expect a `TimeOut`, an `SwtWord`, a `WaitTime`, and no argument, respectively.
222224

223225
```
224226
typedef int TimeOut;
@@ -230,6 +232,7 @@ typedef boost::variant<boost::blank, TimeOut, SwtWord, std::string> Data;
230232
/// Enum for the different SWT operation types
231233
enum Operation { Read,
232234
Write,
235+
WaitTime,
233236
Reset,
234237
Error };
235238

apps/AlfClient.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class AlfClient : public AliceO2::Common::Program
161161
std::make_pair("0x0000000000000000000", "write"),
162162
std::make_pair("0x000000001234", "write"),
163163
std::make_pair("", "read"),
164+
std::make_pair("200", "wait"),
164165
std::make_pair("0xdeadbeef", "write"),
165166
std::make_pair("1", "read"),
166167
std::make_pair("0xbadc0ffee", "write"),

apps/AlfLibClient.cxx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class AlfLibClient : public AliceO2::Common::Program
8888
if (out.first == Sca::Operation::Command) {
8989
std::cout << "Command: " << boost::get<Sca::CommandData>(out.second) << std::endl;
9090
} else if (out.first == Sca::Operation::Wait) {
91-
std::cout << "Wait: " << boost::get<Sca::WaitTime>(out.second) << std::endl;
91+
std::cout << "Wait: " << std::dec << boost::get<Sca::WaitTime>(out.second) << std::endl;
9292
} else if (out.first == Sca::Operation::Error) {
9393
std::cout << "Error: " << boost::get<std::string>(out.second) << std::endl;
9494
} else {
@@ -126,6 +126,7 @@ class AlfLibClient : public AliceO2::Common::Program
126126
ops.push_back({ Swt::Operation::Write, SwtWord{ 0xb00f, 0x42, 0x88, SwtWord::Size::High } });
127127
ops.push_back({ Swt::Operation::Write, SwtWord{ 0xb00f, 0x42, 0x88 } });
128128
ops.push_back({ Swt::Operation::Read, {} });
129+
ops.push_back({ Swt::Operation::Wait, 100 });
129130
ops.push_back({ Swt::Operation::Write, SwtWord{ 0x1, 0x0, 0x0, SwtWord::Size::Low } });
130131
ops.push_back({ Swt::Operation::Write, SwtWord{ 0xb00f, 0x42, 0x88, SwtWord::Size::Low } });
131132
ops.push_back({ Swt::Operation::Write, SwtWord{ 0xcafe, 0x41d, 0x0 } });
@@ -143,6 +144,8 @@ class AlfLibClient : public AliceO2::Common::Program
143144
std::cout << "Read | " << boost::get<SwtWord>(out.second) << std::endl;
144145
} else if (out.first == Swt::Operation::Reset) {
145146
std::cout << "Reset |" /* boost::blank here */ << std::endl;
147+
} else if (out.first == Swt::Operation::Wait) {
148+
std::cout << "Wait | " << std::dec << boost::get<int>(out.second) << std::endl;
146149
} else if (out.first == Swt::Operation::Error) {
147150
std::cout << "Error | " << boost::get<std::string>(out.second) << std::endl;
148151
} else {

include/Alf/Swt.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,17 @@ namespace alf
4848
class Swt
4949
{
5050
public:
51-
typedef int TimeOut;
51+
typedef int TimeOut, WaitTime;
5252

5353
/// Typedef for the Data type of an SWT sequence operation.
5454
/// Variant of TimeOut for reads, SwtWord for writes, std::string for Errors
55-
typedef boost::variant<boost::blank, TimeOut, SwtWord, std::string> Data;
55+
typedef boost::variant<boost::blank, TimeOut, WaitTime, SwtWord, std::string> Data;
5656

5757
/// Enum for the different SWT operation types
5858
enum Operation { Read,
5959
Write,
6060
Reset,
61+
Wait,
6162
Error,
6263
Lock };
6364

@@ -125,6 +126,7 @@ class Swt
125126
AlfLink mLink;
126127
std::unique_ptr<LlaSession> mLlaSession;
127128

129+
static constexpr int DEFAULT_SWT_WAIT_TIME_MS = 3;
128130
static constexpr int DEFAULT_SWT_TIMEOUT_MS = 10;
129131
};
130132

src/AlfServer.cxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ std::pair<Swt::Operation, Swt::Data> AlfServer::stringToSwtPair(const std::strin
342342
BOOST_THROW_EXCEPTION(
343343
AlfException() << ErrorInfo::Message("Too many arguments for RESET operation"));
344344
}
345+
} else if (swtPair[swtPair.size() - 1] == "wait") {
346+
operation = Swt::Operation::Wait;
345347
} else {
346348
BOOST_THROW_EXCEPTION(std::out_of_range("Parameter for SWT operation unkown"));
347349
}
@@ -376,6 +378,12 @@ std::pair<Swt::Operation, Swt::Data> AlfServer::stringToSwtPair(const std::strin
376378
} catch (const std::exception& e) {
377379
BOOST_THROW_EXCEPTION(SwtException() << ErrorInfo::Message("SWT Read Timeout provided cannot be converted to int"));
378380
}
381+
} else if (operation == Swt::Operation::Wait && swtPair.size() == 2) {
382+
try {
383+
data = std::stoi(swtPair[0]);
384+
} catch (const std::exception& e) {
385+
BOOST_THROW_EXCEPTION(SwtException() << ErrorInfo::Message("SWT WaitTime provided cannot be converted to int"));
386+
}
379387
}
380388

381389
return std::make_pair(operation, data);

src/Sca.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ std::string Sca::writeSequence(const std::vector<std::pair<Operation, Data>>& op
324324
if (operation == Operation::Command) {
325325
resultBuffer << data << "\n"; // "[cmd],[data]\n"
326326
} else if (operation == Operation::Wait) {
327-
resultBuffer << data << "\n"; // "[time]\n"
327+
resultBuffer << std::dec << data << "\n"; // "[time]\n"
328328
} else if (operation == Operation::Error) {
329329
resultBuffer << data; // "[error_msg]"
330330
Logger::get().err() << data << endm;

src/Swt.cxx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,16 @@ std::vector<std::pair<Swt::Operation, Swt::Data>> Swt::executeSequence(std::vect
210210
} else if (operation == Operation::Reset) {
211211
reset();
212212
ret.push_back({ Operation::Reset, {} });
213+
} else if (operation == Operation::Wait) {
214+
int waitTime;
215+
try {
216+
waitTime = boost::get<WaitTime>(data);
217+
} catch (...) { // no timeout was provided
218+
data = DEFAULT_SWT_WAIT_TIME_MS;
219+
waitTime = boost::get<WaitTime>(data);
220+
}
221+
std::this_thread::sleep_for(std::chrono::milliseconds(waitTime));
222+
ret.push_back({ operation, waitTime });
213223
} else {
214224
BOOST_THROW_EXCEPTION(SwtException() << ErrorInfo::Message("SWT operation type unknown"));
215225
}
@@ -221,6 +231,8 @@ std::vector<std::pair<Swt::Operation, Swt::Data>> Swt::executeSequence(std::vect
221231
meaningfulMessage = (boost::format("SWT_SEQUENCE WRITE data=%s serialId=%s link=%d, error='%s'") % boost::get<SwtWord>(data) % mLink.serialId % mLink.linkId % e.what()).str();
222232
} else if (operation == Operation::Reset) {
223233
meaningfulMessage = (boost::format("SWT_SEQUENCE RESET serialId=%d link=%s, error='%s'") % mLink.serialId % mLink.linkId % e.what()).str();
234+
} else if (operation == Operation::Wait) {
235+
meaningfulMessage = (boost::format("SWT_SEQUENCE WAIT waitTime=%d serialId=%s link=%d error='%s'") % boost::get<WaitTime>(data) % mLink.serialId % mLink.linkId % e.what()).str();
224236
} else {
225237
meaningfulMessage = (boost::format("SWT_SEQUENCE UNKNOWN serialId=%d link=%s, error='%s'") % mLink.serialId % mLink.linkId % e.what()).str();
226238
}
@@ -251,6 +263,8 @@ std::string Swt::writeSequence(std::vector<std::pair<Operation, Data>> sequence,
251263
resultBuffer << "0\n";
252264
} else if (operation == Operation::Reset) {
253265
/* DO NOTHING */
266+
} else if (operation == Operation::Wait) {
267+
resultBuffer << std::dec << data << "\n";
254268
} else if (operation == Operation::Error) {
255269
resultBuffer << data;
256270
Logger::get().err() << data << endm;

0 commit comments

Comments
 (0)