Skip to content

Commit 96eb705

Browse files
committed
Reset RF module if we receive only 0xFF
1 parent 9ec34b1 commit 96eb705

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Sts1CobcSw/Outcome/Outcome.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ enum class ErrorCode : std::int8_t // NOLINT
105105
misaligned,
106106
eraseFailed,
107107
programFailed,
108+
// RF
109+
receivedInvalidData,
108110
};
109111

110112

Sts1CobcSw/Outcome/Outcome.ipp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ constexpr auto ToCZString(ErrorCode errorCode) -> char const *
183183
return "eraseFailed";
184184
case ErrorCode::programFailed:
185185
return "programFailed";
186+
// RF
187+
case ErrorCode::receivedInvalidData:
188+
return "receivedInvalidData";
186189
}
187190
return "unknown error code";
188191
}

Sts1CobcSw/Rf/Rf.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include <rodos_no_using_namespace.h>
3030

31+
#include <algorithm>
3132
#include <array>
3233
#include <bit>
3334
#include <compare>
@@ -345,7 +346,8 @@ auto ExecuteWithRecovery(Args... args)
345346
return result.value();
346347
}
347348
}
348-
// Reset COBC
349+
// If all attempts failed, reset the whole COBC
350+
DEBUG_PRINT("RF error recovery failed, resetting in %lld s\n", errorHandlingCobcResetDelay / s);
349351
SuspendFor(errorHandlingCobcResetDelay);
350352
RODOS::hwResetAndReboot();
351353
__builtin_unreachable(); // Tell the compiler that hwResetAndReboot() never returns
@@ -540,6 +542,17 @@ auto DoReceive(std::span<Byte> data, Duration timeout) -> Result<std::size_t>
540542
OUTCOME_TRY(ReadAndClearInterruptStatus());
541543
ReadFromFifo(data.subspan(dataIndex, rxFifoThreshold));
542544
dataIndex += rxFifoThreshold;
545+
if(dataIndex == rxFifoThreshold)
546+
{
547+
if(std::ranges::all_of(data.subspan(0, dataIndex),
548+
[](Byte byte) { return byte == 0xFF_b; })) // NOLINT
549+
{
550+
DEBUG_PRINT("Received bytes are all 0xFF\n");
551+
Reset();
552+
(void)DoInitialize();
553+
return ErrorCode::receivedInvalidData;
554+
}
555+
}
543556
}
544557
auto remainingData = data.subspan(dataIndex);
545558
OUTCOME_TRY(SetRxFifoThreshold(static_cast<Byte>(remainingData.size())));

0 commit comments

Comments
 (0)