Algorithm to handle DMA

Discussion in 'Programmer's Corner' started by JerryNa, May 16, 2014.

  1. JerryNa

    Thread Starter Member

    Feb 15, 2010
    32
    0
    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: May 16, 2014
  2. MrChips

    Moderator

    Oct 2, 2009
    12,414
    3,353
    We cannot help you without knowing which MCU you are using.
     
    JerryNa likes this.
  3. JerryNa

    Thread Starter Member

    Feb 15, 2010
    32
    0
    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.
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    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.
     
    JerryNa likes this.
  5. JerryNa

    Thread Starter Member

    Feb 15, 2010
    32
    0
    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?
     
  6. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    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.
     
  7. JerryNa

    Thread Starter Member

    Feb 15, 2010
    32
    0
    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.
     
Loading...