diff --git a/src/shared/drivers/dma/DMA.cpp b/src/shared/drivers/dma/DMA.cpp index ecd2589789d64a374b3d942b4af95b8e99000e49..c23edfe8479af7871091b9192b088c5bd8cb5a4b 100644 --- a/src/shared/drivers/dma/DMA.cpp +++ b/src/shared/drivers/dma/DMA.cpp @@ -507,6 +507,8 @@ void DMAStream::setup(DMATransaction& transaction) enableInterrupt = true; } + // Select the interrupt number + IRQn_Type irqNumber = DMADefs::irqNumberMapping[static_cast<uint8_t>(id)]; if (enableInterrupt) { NVIC_SetPriority(irqNumber, 8); @@ -674,9 +676,6 @@ DMAStream::DMAStream(DMADefs::DMAStreamId id, DMADefs::Channel channel) // Refer to reference manual for the register bits structure int offset = static_cast<uint8_t>(id) % 4; IFindex = (offset % 2) * 6 + (offset / 2) * 16; - - // Select the interrupt - irqNumber = DMADefs::irqNumberMapping[static_cast<uint8_t>(id)]; } DMAStream* DMAStreamGuard::operator->() diff --git a/src/shared/drivers/dma/DMA.h b/src/shared/drivers/dma/DMA.h index 1d78927b71c60092239d4eeec2d67eb4b4a7f5ca..4234aa34292175643ad4aee7f295c4e3250d4e8b 100644 --- a/src/shared/drivers/dma/DMA.h +++ b/src/shared/drivers/dma/DMA.h @@ -89,6 +89,9 @@ public: static DMADriver& instance(); + /** + * @return True if the stream is not already in use. + */ bool tryChannel(DMADefs::DMAStreamId id); /** @@ -123,6 +126,9 @@ public: private: DMADriver(); + /** + * @brief Wakeup the sleeping thread associated to the stream. + */ void IRQwakeupThread(DMAStream& stream); miosix::FastMutex mutex; @@ -146,18 +152,44 @@ public: /** * @brief Activate the stream. As soon as the stream is enabled, it - * can serve any DMA request from the peripheral connected to the stream. + * serves any DMA request from/to the peripheral connected to the stream. */ void enable(); void disable(); + /** + * @brief Wait for the half transfer complete signal. + * The caller waits for the corresponding interrupt, if enabled. + * Otherwise it goes to polling mode on the flag. + */ void waitForHalfTransfer(); + /** + * @brief Wait for the transfer complete signal. + * The caller waits for the corresponding interrupt, if enabled. + * Otherwise it goes to polling mode on the flag. + */ void waitForTransferComplete(); + /** + * @brief Wait for the half transfer complete signal. + * The caller waits for the corresponding interrupt, if enabled. + * Otherwise it goes to polling mode on the flag. + * @param timeout_ns The maximum time that will be waited. + * @return True if the event is reached, false if the + * timeout expired. + */ bool timedWaitForHalfTransfer(std::chrono::nanoseconds timeout_ns); + /** + * @brief Wait for the transfer complete signal. + * The caller waits for the corresponding interrupt, if enabled. + * Otherwise it goes to polling mode on the flag. + * @param timeout_ns The maximum time that will be waited. + * @return True if the event is reached, false if the + * timeout expired. + */ bool timedWaitForTransferComplete(std::chrono::nanoseconds timeout_ns); void setHalfTransferCallback(std::function<void()> callback); @@ -278,7 +310,7 @@ private: /** * @brief Used to determine if the user thread is - * waiting to be awaked by an interrupt. + * waiting to be awakened by an interrupt. */ miosix::Thread* waitingThread = nullptr; @@ -294,9 +326,8 @@ private: std::function<void()> transferCompleteCallback; std::function<void()> errorCallback; - DMADefs::DMAStreamId id; + const DMADefs::DMAStreamId id; DMADefs::Channel currentChannel; - IRQn_Type irqNumber; DMA_Stream_TypeDef* registers; volatile uint32_t* ISR; ///< Interrupt status register