From 4d03d1535ca5181870864486a16d13d4e0f9de81 Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Sat, 15 Apr 2023 09:56:15 +0200 Subject: [PATCH] Added function to STM32F4 DMA stream driver returning its status (running or not). --- platform/mcu/STM32F4xx/drivers/DmaStream.hpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/platform/mcu/STM32F4xx/drivers/DmaStream.hpp b/platform/mcu/STM32F4xx/drivers/DmaStream.hpp index b7aceb56..eeb53372 100644 --- a/platform/mcu/STM32F4xx/drivers/DmaStream.hpp +++ b/platform/mcu/STM32F4xx/drivers/DmaStream.hpp @@ -154,7 +154,7 @@ public: * The stream does not stop immediately but only when it reaches the half * or the end of the transfer. */ - void stop() + inline void stop() { stopTransfer = true; } @@ -163,18 +163,28 @@ public: * Forcefully stop an ongoing DMA stream. * Calling this function causes the immediate stop of an ongoing stream. */ - void halt() + inline void halt() { stopTransfer = true; NVIC_SetPendingIRQ(IRQn); } + /** + * Query che the current status of the stream. + * + * @return true if the stream is active, false otherwise. + */ + inline bool running() + { + return (stream->CR & DMA_SxCR_EN) ? true : false; + } + /** * Register a function to be called on stream end. * * @param callback: std::function for the stream end callback. */ - void setEndTransferCallback(std::function&& callback) + inline void setEndTransferCallback(std::function&& callback) { streamEndCallback = callback; } @@ -267,7 +277,7 @@ public: /** * Low-level shutdown of a DMA stream. */ - static void terminate() + static inline void terminate() { NVIC_DisableIRQ(IRQn()); getStream()->CR = 0; @@ -279,7 +289,7 @@ public: * * @param hdl: pointer to the StreamHandler class managing the stream. */ - static void IRQhandleInterrupt(StreamHandler *hdl) + static inline void IRQhandleInterrupt(StreamHandler *hdl) { uint32_t flags = readIrqFlags(); hdl->IRQhandler(flags);