Hi,
a customer has used other e2e posts successfully to implement a circular buffer with DMA and a dummy channel
The customer is trying to use the DMA on the RM57 to fill a circular buffer with data received from the SCI. The E2E site was very helpful, and answers there got him most of the way; now just down to one problem that if solved should allow everything to work.
Here is the setup:
- Set up 3 DMA channels:
- RX channel that fills a large (1KiB) buffer, with auto-initiation and BTC enabled. Frame transfer mode is used, with frames of 1 byte triggered by the SCI DMA HW request. Port B read, Port A write.
- "dummy" channel that is software-triggered and makes a transfer of one word from an arbitrary peripheral register (I picked the DMA PTCRL register, but the result isn't used). This channel is used to force arbitration. Port B read, Port A write.
- "sentinel" channel that is hardware-triggered by the same request as the RX channel. Transfers 1 byte between arbitrary locations. The enable bit of this channel is manipulated in such a way that it on the first frame of the RX block, and then is not triggered until the buffer wraps around.
- Set up BTC interrupts for each channel:
- The RX channel BTC clears the "transfer in progress" flag, and checks for overflows.
- The dummy BTC reads the Working Control Packet for the RX channel and stores the CFTCOUNT field so the application knows how far it can safely read. It also does additional overflow checking.
- The sentinel BTC sets the "transfer in progress" flag so the dummy BTC can tell whether an arbitration was triggered; it is possible that the buffer has filled, in which case no arbitration will be triggered and the CFTCOUNT will not be written back to the WCP. In this case the application needs to know it cannot read past the end of the buffer.
Tested the setup by sending a sequence of bytes from my PC and checking that the sequence received matched the sequence sent. It works perfectly, except in one condition: When the dummy channel transfer occurs at a byte boundary on the SCI (so that the last byte ends and the next one starts while the dummy transfer is in progress), the DMA stops updating the WCP. Thereafter, CFTCOUNT is frozen and no longer updated, so the application can no longer tell how much data is in the buffer.
The customer is not sure what causes this behavior, but they assume it has something to do with the DMA state machine. Any suggestions are greatly appreciated!
Regards,
--Gunter