From 7c6333989c37d1f623b02e71988edeb4fdea43aa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nicol=C3=B2=20Caruso?= <niccolo.caruso@skywarder.eu>
Date: Sat, 8 Feb 2025 11:19:18 +0100
Subject: [PATCH] [Wiz5500] Wiz5500 fixes to ISR selection

The Interrupt Service Routine thread was not properly chosen.
It was not put to null in case no thread could act as ISR and in a while loop it was always reassinging to itself the ISR routine.
---
 src/shared/drivers/WIZ5500/WIZ5500.cpp | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/shared/drivers/WIZ5500/WIZ5500.cpp b/src/shared/drivers/WIZ5500/WIZ5500.cpp
index 43dc983de..9af411fdd 100644
--- a/src/shared/drivers/WIZ5500/WIZ5500.cpp
+++ b/src/shared/drivers/WIZ5500/WIZ5500.cpp
@@ -494,19 +494,25 @@ int Wiz5500::waitForSocketIrq(miosix::Lock<miosix::FastMutex>& l, int sock_n,
         // service thread
         if (wait_infos[i].irq != 0)
         {
+            Thread* new_interrupt_service_thread = nullptr;
+
             for (int j = 0; j < NUM_THREAD_WAIT_INFOS; j++)
             {
-                if (wait_infos[j].irq == 0)
+                if (wait_infos[j].irq == 0 && wait_infos[j].sock_n != -1 &&
+                    j != i)
                 {
-                    {
-                        FastInterruptDisableLock il;
-                        interrupt_service_thread = wait_infos[j].thread;
-                    }
-
-                    wait_infos[j].thread->wakeup();
+                    new_interrupt_service_thread = wait_infos[j].thread;
                     break;
                 }
             }
+
+            {
+                FastInterruptDisableLock il;
+                interrupt_service_thread = new_interrupt_service_thread;
+            }
+
+            if (new_interrupt_service_thread)
+                new_interrupt_service_thread->wakeup();
         }
     }
 
-- 
GitLab