Algorithm to handle DMA

Thread Starter

JerryNa

Joined Feb 15, 2010
32
Hi,
I'd love to consult on my ongoing project.

So far, I programmed the uC to write logs Cyclically to a 10KB Buffer of fast memory.

About the logs' writing statistics, the max pace of writing into the 10KB buffer is 1KB / 0.47ms.

Now I'd like to use a 1MB buffer of slower memory, to be able to increase the amount of logs I capture.

The problem is the due to real-time, I can't afford the delay of having the uC writing logs directly to the 1MB buffer.

Therefore I'd use a DMA to transfer data from the 10KB buffer to the 1MB buffer, in background.

What algorithm would you use for that transfer?

the difficulties are:
I can't instruct the DMA to transfer the 10KB data to the 1MB buffer, because then I'd have to wait for it to finish until I can log messages again to the 10KB buffer.

On the other hand, I can't tell the DMA to transfer data to the 1MB buffer after each message the uC writes to the 10KB buffer, that would be waste of time due to overhead.

Therefore, when should I tell the DMA to start transferring data?

Thank you very much.
 
Last edited:

Thread Starter

JerryNa

Joined Feb 15, 2010
32
Hi MrChips.

It's an internal uC which the company developed, therefore I can't specify it here and its datasheet.

However, I can provide any needed data.

I added to the thread an input about the logs' writing statistics, the max pace of writing into the 10KB buffer is 1KB / 0.47ms.
 

ErnieM

Joined Apr 24, 2011
8,415
How much data are you willing to lose in this process?

If it takes X to load the fast data and Y to copy to slow data then you cannot put more then the fraction of X/Y into slow data, even assuming you can read and write to fast data simutaneously.

There's just no way to insert process Y into process X when Y>X.
 

Thread Starter

JerryNa

Joined Feb 15, 2010
32
Hi Ernie,

Why must I accept losing data in the process?

The DMA could transfer data from the 10KB buffer to the 1MB buffer faster than the logging to the 10KB buffer, therefore nothing should be lost.

What algorithm would you recommend for:
1. when to trigger the DMA to start a transfer of bytes from 10KB buffer to 1MB buffer?
2. how to not waste too many cycles on calculating when to decide on triggering a transfer?
 

ErnieM

Joined Apr 24, 2011
8,415
I dunno, I give up.

Just seems curious you have "slow" memory that is faster then the data rate why you would write to "fast" memory and then copy over? Why not just use the slow large memory for the initial writes.
 

Thread Starter

JerryNa

Joined Feb 15, 2010
32
The uC does not always write to the fast memory.
While the DMA, once it starts transferring data to the slow memory, it does that the whole time until it finishes.
That's why the DMA would transfer data faster.

If the uC writes all logs directly to the slow memory, it'd cause large delay, than if it writes to the fast memory.
That delay would harm the system operation.
 
Top