Misleading names/documentation in DMAChannel.h

AaronD

Well-known member
In reading the DMA code and tracking it in the datasheet, I noticed that the trigger setup is misleading. Specifically, triggerAtTransfersOf and triggerAtCompletionOf.

Normally, a class function is assumed to work primarily within its own object, so a function that says to trigger on another channel's activity or completion suggests that I can have a wide fan-out of multiple other transfers triggered from that same activity or completion, simply by passing the same DMA management object to all of them:
C++:
channel_B.triggerAtCompletionOf(TCD_A);
channel_C.triggerAtCompletionOf(TCD_A);
channel_D.triggerAtCompletionOf(TCD_A);
//etc.
Effectively, "I should watch this other channel, while it has no idea." And in fact I did design a complex structure around that ability before I noticed that it wouldn't work.

But the hardware actually has the trigger going the opposite direction: a minor or major loop completion triggers one other channel. And indeed the trigger setup functions work primarily on the object that is passed to them instead of on their own. Effectively, "Hey you, trigger me."

So what I think should exist is simply a swap between the passed objects and their own. Effectively, "I should trigger this other channel." And possibly a note against calling it multiple times to create a fan-out:
C++:
TCD_A.triggerOneChannelAtCompletion(channel_B);
TCD_A.triggerOneChannelAtCompletion(channel_C);
TCD_A.triggerOneChannelAtCompletion(channel_D);
//etc.

What's the difference beyond semantics? The assumption that only the function's this object is affected. In the first example, the possibility of a large fan-out feels far more contractual than in the second. Especially since the second can explicitly say OneChannel with a double-singular.

I can see why the existing functions are how they are - the HardwareEvents and Continuous triggers have that same mentality and the hardware does seem to work that way for them - and it doesn't add anything technical to have both - it's just swapping two pointers and then un-swapping them by how the function is called - but I think it would reduce some confusion to encourage the second and eventually deprecate the first.
 
I just now noticed on page 86 (section 5.6.1.2.2) of the reference manual, that the hardware trigger has the same limitation. Not really sure what to do with that, as there isn't a class associated with that source, just a number.

It still has a clear mindset of, "Hey you, trigger me exclusively," but without creating a class for each possible source, or perhaps one for the DMA MUX (which is separate from the DMA controller for reasons I don't yet understand), I don't know what else to do.

So the existing functions do all have a consistent mindset, which is good as far as that goes. But the problem is, it's a confusing mindset because it doesn't match what C/C++ wants to do.

---

For my present project, I don't think I need the hardware triggers, and I don't think the mindset really matters for the continuous trigger, so I think I can just do this and move on:
C++:
#define triggerOneChannelAtTransfersOf(ch, tcd)     (ch).triggerAtTransfersOf(tcd)
#define triggerOneChannelAtCompletionOf(ch, tcd)    (ch).triggerAtCompletionOf(tcd)
but it still feels like there ought to be a less-confusing and still-coherent way to make the overall library, that both adheres to the expectations of C/C++ and self-documents how the hardware actually works.
 
Back
Top