From 6e92ee11682870f60d69b8c606b97efb3ff79b1a Mon Sep 17 00:00:00 2001
From: Fabrizio Monti <fabrizio.monti@skywarder.eu>
Date: Thu, 6 Mar 2025 17:04:35 +0100
Subject: [PATCH] [DMA] Fixed timed polling: flags were not updated during
 polling.

---
 src/shared/drivers/dma/DMA.h | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/shared/drivers/dma/DMA.h b/src/shared/drivers/dma/DMA.h
index 4234aa342..b1276864a 100644
--- a/src/shared/drivers/dma/DMA.h
+++ b/src/shared/drivers/dma/DMA.h
@@ -24,7 +24,6 @@
 
 #include <kernel/scheduler/scheduler.h>
 #include <kernel/sync.h>
-#include <utils/TimedPollingFlag.h>
 
 #include <chrono>
 #include <functional>
@@ -405,13 +404,15 @@ private:
             // Pool the flag if the user did not enable the interrupt
             if (timeout_ns >= 0)
             {
-                // TODO: this doesn't work, because the methods passed as
-                // getEventStatus do not update the flags (reading them
-                // by calling readFlags()).
-                // This means that it always polls a value that will
-                // never become true, then exit when the timeout is
-                // reached.
-                result = timedPollingFlag(getEventStatus, timeout_ns);
+                const long long start = miosix::getTime();
+
+                do
+                {
+                    readFlags();
+                } while (!getEventStatus() &&
+                         miosix::getTime() - start < timeout_ns);
+
+                result = getEventStatus();
             }
             else
             {
-- 
GitLab