[riot-notifications] [RIOT-OS/RIOT] stm32: get bytes left to transfer via DMA and set transfer complete callback (#16440)

benpicco notifications at github.com
Tue May 4 16:15:00 CEST 2021


@benpicco commented on this pull request.

The usual way would be to `dma_wait()` and then execute whatever is supposed to happen after the DMA completion following that.

Is this not possible due to timing constraints? 



> @@ -965,6 +965,15 @@ void dma_start(dma_t dma);
  */
 uint16_t dma_suspend(dma_t dma);
 
+/**
+ * @brief   Gets the number of bytes that have yet to be transferred
+ *
+ * @param[in] dma    logical DMA stream
+ *
+ * @return the remaining number of bytes to transfer.
+ */
+uint16_t dma_left(dma_t dma);

This is inherently racy - what's the use case for this? 

> @@ -445,6 +447,13 @@ int dma_configure(dma_t dma, int chan, const volatile void *src, volatile void *
     return 0;
 }
 
+void dma_transfer_complete(dma_t dma, void (*callback)(void*, dma_t), void *arg)

I'd go with something less ambigious

```suggestion
void dma_set_transfer_complete_cb(dma_t dma, void (*callback)(void*, dma_t), void *arg)
```

> +    ctx->callback = callback;
+    ctx->callback_arg = arg;

```suggestion
    unsigned state = irq_disable();
    ctx->callback = callback;
    ctx->callback_arg = arg;
    irq_restore(state);
```


> @@ -504,7 +521,11 @@ void dma_isr_handler(dma_t dma)
 {
     dma_clear_all_flags(dma);
 
-    mutex_unlock(&dma_ctx[dma].sync_lock);
+    struct dma_ctx *ctx = &dma_ctx[dma];
+    mutex_unlock(&ctx->sync_lock);

I guess we could replace this by setting `ctx->callback = mutex_unlock` now.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/16440#pullrequestreview-651277570
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210504/4f9d764d/attachment.htm>


More information about the notifications mailing list