Skip to content

Commit

Permalink
audio: dai-zephyr: reset DMA buffer cursors on TRIGGER_RELEASE
Browse files Browse the repository at this point in the history
On NXP platforms, stopping the DMAC and then re-configuring it
leads to the internal DMA buffer cursors being reset. Leaving the
SOF DMA buffer cursors in the same state means the DMA driver
and SOF may potentially end up with two different views of the
same buffer (from the cursors' point of view). This in, turn,
may lead to the DAI consuming stale data because of the values of
"free" and "pending" queried from dma_reload() stopping
dai_common_copy() from copying new data. To fix this, reset the
read and write cursors of the DMA buffer from SOF side. This
way, both SOF and the DMA driver will have the same initial
view of the DMA buffer cursors.

Signed-off-by: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>
  • Loading branch information
LaurentiuM1234 authored and dbaluta committed Feb 23, 2024
1 parent 3ab82dc commit 9831a9d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/audio/dai-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,16 @@ static int dai_comp_trigger_internal(struct dai_data *dd, struct comp_dev *dev,
buffer_zero(dd->dma_buffer);
}

/* DMA driver and SOF's view of the DMA buffer's
* read and write cursors must be the same to
* avoid scenarios in which the DMA driver
* reports false "free" and "pending" values, thus
* leading to the DMA copying stale data due to
* dma_status() stopping dai_common_copy() from
* updating the data.
*/
audio_stream_reset(&dd->dma_buffer->stream);

/* only start the DAI if we are not XRUN handling */
if (dd->xrun == 0) {
/* recover valid start position */
Expand Down

0 comments on commit 9831a9d

Please sign in to comment.