i2s and digital microphones

Discussion and questions about programming with Ultibo.
pjde
Posts: 444
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: i2s and digital microphones

Postby pjde » Mon Apr 08, 2019 8:38 pm

Thanks Piotr

Clear as mud. I have a bit more research to do.

Regards

Paul
User avatar
Ultibo
Site Admin
Posts: 2303
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: i2s and digital microphones

Postby Ultibo » Mon Apr 08, 2019 11:40 pm

pjde wrote:Clear as mud. I have a bit more research to do.

There are two distinct processors in the BCM279x SoC, the ARM CPU (single or quad core) and the VC4 GPU.

From the perspective of the GPU the peripheral address range begins at 0x7E000000 but from the perspective of the CPU the peripherals are at 0x3F000000 (or 0x20000000 for the single core A/B/Zero etc).

When you want the DMA controller to address one of the peripherals you need to supply the address in the GPU range not in the CPU range, Ultibo contains a pair of functions to translate between the two without having to consider which model of Pi you have.

Look for PhysicalToIOAddress() and IOAddressToPhysical() in the Platform unit, you will also find the memory equivalents of these which are PhysicalToBusAddress() and BusAddressToPhysical() because you need to also translate any memory addresses passed to and from the GPU or DMA into something they can understand.

Of course we would recommend using the Ultibo DMA driver which handles all of these details plus channel allocation, cache cleaning and coherence, request completion and a whole lot more, the function DMATransfer() in the Platform unit gives a simplified interface whereas the DMA unit contains DMATransferRequest() and DMATransferRequestEx() that expose additional capabilities.
Ultibo.org | Make something amazing
https://ultibo.org
pjde
Posts: 444
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: i2s and digital microphones

Postby pjde » Tue Apr 09, 2019 7:02 am

Thanks Garry

Getting a little more translucent.

Do any of the examples use the Ultibo DMA functions? I did a quick text search but nothing came up.

Regards

Paul
pik33
Posts: 891
Joined: Fri Sep 30, 2016 6:30 pm
Location: Poland
Contact:

Re: i2s and digital microphones

Postby pik33 » Tue Apr 09, 2019 1:26 pm

Clear as mud. I have a bit more research to do.


It took me some time to learn this while coding SimpleAudio unit. Having one thing (PWM via DMA) working, there was easier to add control PWM and PCM/i2s related code to this.

I don't know how to use Ultibo DMA API so I used a pure hardware DMA programming.
pjde
Posts: 444
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: i2s and digital microphones

Postby pjde » Wed Apr 10, 2019 10:29 pm

Hi Garry

Have been looking through the DMA code.

The DMATransferRequestEx() requires a DMAHost value. Is there a default value we can use for all transfers or do we need to create our own for our specfic tasks.

Regards

Paul
User avatar
Ultibo
Site Admin
Posts: 2303
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: i2s and digital microphones

Postby Ultibo » Wed Apr 10, 2019 11:48 pm

Hi Paul,

pjde wrote:Do any of the examples use the Ultibo DMA functions? I did a quick text search but nothing came up.

None of the current examples deal with DMA (although it might be a candidate for an advanced example) but all of the functions above are used within the RTL.

The framebuffer API (in the Framebuffer unit) makes extensive use of the DMATransfer() function and is a good source to see how to setup a standard request and also how to do stride and chaining multiple requests etc.

The BCM270x SPI driver uses both the DMATransferRequest() and DMATransferRequestEx() functions in the BCM2710SPI0WriteRead() (or equivalent) function. This is a more complex case because it sets up both a read and a write to happen simultaneously but it does show how to create a request that performs a transfer to or from a peripheral.

One of the key things to remember is that most of the behavior of the transfer is governed by the parameters in the TDMAData structure which includes not only the source, dest and size of the transfer but also the flags which define exactly how to process that block. Multiple TDMAData structures can also be linked together to form a chain which the DMA controller will execute in order.

The one element that isn't complete in the DMA driver which might be useful (although not essential) for doing audio processing is cyclic transfers which are intended to allow a chain of requests that continuously repeat with a callback function that is called as each buffer is emptied in order to supply more data, designed for sending an uninterrupted stream of data to a peripheral using DMA.

pjde wrote:The DMATransferRequestEx() requires a DMAHost value. Is there a default value we can use for all transfers or do we need to create our own for our specfic tasks.

As per the usual Ultibo model there is prevision for multiple DMA hosts with standard functions to find one by name or description, there is also a DMAHostGetDefault function which returns the default (and often only) DMA host.

In the absence of a specific example if there are particular elements that don't make sense let us know and we'll provide more description.
Ultibo.org | Make something amazing
https://ultibo.org
pjde
Posts: 444
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: i2s and digital microphones

Postby pjde » Sun Apr 14, 2019 1:56 am

Quick question to Piotr.

Can RetAMP Player be configured to use I2S to output the audio?

Regards

Paul
pjde
Posts: 444
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: i2s and digital microphones

Postby pjde » Sun Apr 14, 2019 8:47 pm

2 more questions if I am not pushing my luck.

a) which clock is being used to generate the PCM_CLK
b) how is this connected to the actual GPIO output.

I have read the various sections of the Peripheral guide but can't find the relevant details.

Regards

Pauk
User avatar
Ultibo
Site Admin
Posts: 2303
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: i2s and digital microphones

Postby Ultibo » Mon Apr 15, 2019 12:29 am

pjde wrote:a) which clock is being used to generate the PCM_CLK
b) how is this connected to the actual GPIO output.

The clock manager is partly documented in section 6.3 of the BCM2835 Peripherals document, it only talks about the GP0/GP1/GP2 clocks but the control and divider information is actually the same for every clock.

You can find the Linux code for all the BCM2835 clocks here and the clock constants are all included in Ultibo in the BCM283X units, look for BCM2835_CM_* (or BCM2836, BCM2837 depending on your model).

For PCM you would need BCM2835_CM_PCMCTL and BCM2835_CM_PCMDIV.
Ultibo.org | Make something amazing
https://ultibo.org
pjde
Posts: 444
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: i2s and digital microphones

Postby pjde » Mon Apr 15, 2019 4:13 am

Thanks Garry

One step forward.

Regards

Paul

Return to “General”

Who is online

Users browsing this forum: No registered users and 41 guests