How does the PCM stream operate?

In order to make the PCM device work, you need to define the callback functions in the ado_pcm_hw_t structures for the capture and playback portions of the PCM device.

Before we look at them in detail, let's first review how a PCM stream operates in hardware. The model used in this architecture is a DMA buffer in memory that's divided into two or more buffer fragments. When instructed to do so, the hardware acts on a fragment using DMA, and then generates an interrupt on completing the fragment.

So, if we consider the simplified case of playback with a 50K buffer, composed of two fragments, here's what happens when the client application sends data:

From a programming perspective, if the hardware can be set up to do a looping DMA buffer playback with an interrupt every x bytes, implementing this model is very straightforward. A variation on this theme is to reprogram the DMA engine after every fragment in the interrupt routine. In the general case, the client suggests the fragment size and number of fragments, but the driver has the ultimate authority on these parameters.