diff --git a/src/shared/drivers/WIZ5500/WIZ5500.cpp b/src/shared/drivers/WIZ5500/WIZ5500.cpp index 721d0fa13eae724c30769adc3eab193b8768196c..4f0159743bc43a917a714c73d498321b966bf7c4 100644 --- a/src/shared/drivers/WIZ5500/WIZ5500.cpp +++ b/src/shared/drivers/WIZ5500/WIZ5500.cpp @@ -407,7 +407,7 @@ void Wiz5500::close(int sock_n, int timeout) socket_infos[sock_n].mode = Wiz5500::SocketMode::CLOSED; } -void Wiz5500::waitForINTn(Lock<FastMutex>& l, long long until) +TimedWaitResult Wiz5500::waitForINTn(Lock<FastMutex>& l, long long until) { TimedWaitResult result = TimedWaitResult::NoTimeout; @@ -415,6 +415,7 @@ void Wiz5500::waitForINTn(Lock<FastMutex>& l, long long until) FastInterruptDisableLock il; while (intn.value() != 0 && result == TimedWaitResult::NoTimeout) result = Kernel::Thread::IRQenableIrqAndTimedWaitMs(il, until); + return result; } int Wiz5500::waitForSocketIrq(miosix::Lock<miosix::FastMutex>& l, int sock_n, @@ -533,14 +534,15 @@ TimedWaitResult Wiz5500::runInterruptServiceRoutine(Lock<FastMutex>& l, long long start = Kernel::getOldTick(); if (until == -1) { - waitForINTn(l, start + INTN_TIMEOUT); + // Wait for interrupts and check if we run out of time + if (waitForINTn(l, start + INTN_TIMEOUT) == TimedWaitResult::Timeout) + return TimedWaitResult::Timeout; } else { - waitForINTn(l, std::min(start + INTN_TIMEOUT, until)); - - // Did we run out of time? - if (Kernel::getOldTick() >= until) + // Wait for interrupts and check if we run out of time + if (waitForINTn(l, std::min(start + INTN_TIMEOUT, until)) == + TimedWaitResult::Timeout) return TimedWaitResult::Timeout; } diff --git a/src/shared/drivers/WIZ5500/WIZ5500.h b/src/shared/drivers/WIZ5500/WIZ5500.h index 11d627cc2488ce3039a60fef17fd13e2f10d2387..c28d1b005e23785bd76336ef5c63684535f9532a 100644 --- a/src/shared/drivers/WIZ5500/WIZ5500.h +++ b/src/shared/drivers/WIZ5500/WIZ5500.h @@ -252,7 +252,8 @@ private: static constexpr int NUM_THREAD_WAIT_INFOS = 16; static constexpr int NUM_SOCKETS = 8; - void waitForINTn(miosix::Lock<miosix::FastMutex>& l, long long until); + miosix::TimedWaitResult waitForINTn(miosix::Lock<miosix::FastMutex>& l, + long long until); int waitForSocketIrq(miosix::Lock<miosix::FastMutex>& l, int sock_n, uint8_t irq_mask, int timeout);