Skip to content

Commit 082b052

Browse files
committed
[swt] Handle SWT timeout properly
1 parent 6b0ed8b commit 082b052

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/Swt/Swt.cxx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ void Swt::read(std::vector<SwtWord>& words, TimeOut msTimeOut, SwtWord::Size wor
8989

9090
// If we get the same counter as before it means the FIFO wasn't updated; drop the word
9191
if (tempWord.getSequence() != mWordSequence) {
92+
93+
if (std::chrono::steady_clock::now() < timeOut) {
94+
BOOST_THROW_EXCEPTION(SwtException() << ErrorInfo::Message("Timed out: not enough words in SWT READ FIFO"));
95+
}
96+
9297
getWarningLogger() << "SWT word sequence duplicate" << endm;
9398

9499
mWordSequence = tempWord.getSequence(); //roll mWordSequence back by one
@@ -139,13 +144,10 @@ std::string Swt::writeSequence(std::vector<std::pair<SwtData, Operation>> sequen
139144
try {
140145
timeOut = std::get<TimeOut>(data);
141146
} catch (...) { // no timeout was provided
142-
timeOut = -1;
143-
}
144-
if (timeOut >= 0) {
145-
read(results, timeOut);
146-
} else {
147-
read(results);
147+
data = DEFAULT_SWT_TIMEOUT_MS;
148+
timeOut = std::get<TimeOut>(data);
148149
}
150+
read(results, timeOut);
149151

150152
for (const auto& result : results) {
151153
resultBuffer << result << "\n";

src/Swt/Swt.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Swt
5151

5252
void reset();
5353
uint32_t write(const SwtWord& swtWord);
54-
void read(std::vector<SwtWord>& word, TimeOut msTimeOut = 10, SwtWord::Size wordSize = SwtWord::Size::High);
54+
void read(std::vector<SwtWord>& word, TimeOut msTimeOut, SwtWord::Size wordSize = SwtWord::Size::High);
5555

5656
enum Operation { Read,
5757
Write,
@@ -68,6 +68,7 @@ class Swt
6868

6969
AlfLink mLink;
7070
int mWordSequence = 0; //start from 0, as after the reset the counter starts at 1
71+
static constexpr int DEFAULT_SWT_TIMEOUT_MS = 10;
7172
};
7273

7374
} // namespace Alf

0 commit comments

Comments
 (0)