DSPRelated.com
Forums

Sample code for working with DMA in C5509

Started by mehdi hosseini September 2, 2009
Hi every body
I have been working on DSP implementation of Sound Source Localization. I'm
going to use C5509 for this task.
I decided to use the DMA to improve the performance and real time processing
but I am a beginner.
I wonder if anyone has some source codes and hint which could share with me.

Thanks
--
Seyed Mehdi Hosseini
I don't have any source code available, but I'll give you the overview of
how we did it. Hopefully it may get you started. Though the hard part was to
set up the DMA with the MCBSP...
My apologies if this is already known or obvious information.

We used a double-buffer system for both reading (RB1, RB2) and writing (WB1,
WB2).
We set up the DMA in a two channel system with MCBSP, one channel for read
and one channel for write.
While the DMA is writing to WB1, the application will read from WB2 (which
was written in the previous round). When the DMA is done, we will switch
buffers (switch pointers). Vice versa with the reading. So you need to have
a buffer size to balance the read and write: the application should be able
to read what the DMA wrote, and the DMA should be able to write without
losing data.

We set up the DMA/MCBSP to trigger an interrupt when it was done writing so
that we knew when to switch buffers.

The hard part was to find the correct settings to get the timing between the
DMA and the MCBSP channels, but when we got them everything worked
perfectly, no problems.

Good luck, if I find any source, I'll post it.

-Sima

On Sat, Aug 29, 2009 at 9:58 PM, mehdi hosseini wrote:

>
> Hi every body
> I have been working on DSP implementation of Sound Source Localization. I'm
> going to use C5509 for this task.
> I decided to use the DMA to improve the performance and real time
> processing but I am a beginner.
> I wonder if anyone has some source codes and hint which could share with
> me.
>
> Thanks
> --
> Seyed Mehdi Hosseini
>
>
Thank you very much for this really good information - (Sima)
It is the same way that I am going to use, but in my case there are three
channels for receive the A/Ds output (which comes from microphones output ),
and of course we need 2 WBs (Write Buffer) for each channel. more details
come in following steps:

1. First of all we read the each A/Ds output and write the get data to the
certain block of memory. so we have 3 blocks of memory with 3 pointers. we
call this blocks with the names WB11, WB12, WB13 and pointers with P1, P2,
P3.
after a read and write process we must to increase each pointers (P1, P2,
P3) and doing this task while each blocks (WB11, WB12, WB13) will be full.
This task doing by using the DMA. In same time the CPU process the data
which stored in next 3 blocks (WB21, WB22, WB23).So in this step we write
the data to WB11, WB12 and WB13 by using the DMA and read the stored data
from WB21, WB22, WB23 and process them using CPU.
2. After step1, the pointers (P1, P2, P3) will point the start of next
3 blocks (WB21, WB22, WB23) and so the obtained data will be stored in these
blocks. In this step the CPU use the data which stored on WB11, WB12 and
WB13 for processing.
By using above steps we can get data from A/Ds and process them in the same
time. This is my algorithm but I have no idea for doing it.
Can I read the data from parallel port (not MCBSP) by using DMA? If so, have
I do this?
Have every body any better idea to perform this task?

Thanks for your guidance

On Wed, Sep 2, 2009 at 4:48 PM, Sima Baymani wrote:

> I don't have any source code available, but I'll give you the overview of
> how we did it. Hopefully it may get you started. Though the hard part was to
> set up the DMA with the MCBSP...
> My apologies if this is already known or obvious information.
>
> We used a double-buffer system for both reading (RB1, RB2) and writing
> (WB1, WB2).
> We set up the DMA in a two channel system with MCBSP, one channel for read
> and one channel for write.
> While the DMA is writing to WB1, the application will read from WB2 (which
> was written in the previous round). When the DMA is done, we will switch
> buffers (switch pointers). Vice versa with the reading. So you need to have
> a buffer size to balance the read and write: the application should be able
> to read what the DMA wrote, and the DMA should be able to write without
> losing data.
>
> We set up the DMA/MCBSP to trigger an interrupt when it was done writing so
> that we knew when to switch buffers.
>
> The hard part was to find the correct settings to get the timing between
> the DMA and the MCBSP channels, but when we got them everything worked
> perfectly, no problems.
>
> Good luck, if I find any source, I'll post it.
>
> -Sima
> On Sat, Aug 29, 2009 at 9:58 PM, mehdi hosseini wrote:
>
>>
>> Hi every body
>> I have been working on DSP implementation of Sound Source Localization.
>> I'm going to use C5509 for this task.
>> I decided to use the DMA to improve the performance and real time
>> processing but I am a beginner.
>> I wonder if anyone has some source codes and hint which could share with
>> me.
>>
>> Thanks
>> --
>> Seyed Mehdi Hosseini
>>
>

--
Seyed Mehdi Hosseini
Don't forget that the c55x DMA has the ability to interrupt half way
through the buffer as well as at the end of the buffer. Thus you can
use a single DMA buffer and process it as two consecutive buffers in
memory. This allows dual buffering (I think that's a better term
than double buffering, which can be confused with a second stage of
buffering which is used in some setups).

The DMA has many modes, including McBSP and EXIF as well as several
others. Source and/or destination addresses can stay constant or be
incremented per transfer, allowing parallel port access, too.

Brian Willoughby
Sound Consulting