nvl32: Fix expected handling on i2c read
Uses the correct logic for post not being complete. Previously
this ran into an exception, since we were trying to return an error
from a std::expected that potentially had a value instead.
Tested-by: loading onto an nvl32-obmc and Ac cycling
Change-Id: Ie299380361319970fb82a132782dc9ea30f9befc
Signed-off-by: Marc Olberding <molberding@nvidia.com>
diff --git a/nvidia/nvl32.cpp b/nvidia/nvl32.cpp
index ddd5871..b2779cc 100644
--- a/nvidia/nvl32.cpp
+++ b/nvidia/nvl32.cpp
@@ -57,16 +57,13 @@
i2c::RawDevice cpld{4, 0x17};
auto now = steady_clock::now();
auto end = now + 20min;
+
while (steady_clock::now() < end)
{
static constexpr uint8_t i2c_ready = 0xf2;
const auto result = cpld.read_byte(i2c_ready);
- if (result.has_value() && *result == 1)
- {
- return;
- }
- else if (result.error())
+ if (!result.has_value())
{
std::string err =
std::format("Unable to communicate with cpld. rc: {}\n",
@@ -75,6 +72,11 @@
throw std::runtime_error(err);
}
+ if (*result == 1)
+ {
+ return;
+ }
+
std::this_thread::sleep_for(std::chrono::seconds{10});
}