Skip to content

Commit c11934d

Browse files
softwareckikv2019i
authored andcommitted
zephyr: host: Add support for xrun notifications in host
Add support to the host for sending ipc4 notifications when dma reports an underrun/overrun occurrence. Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
1 parent 7815e31 commit c11934d

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/audio/copier/host_copier.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ struct host_data {
9898
/* stream info */
9999
struct sof_ipc_stream_posn posn; /* TODO: update this */
100100
struct ipc_msg *msg; /**< host notification */
101+
#if CONFIG_XRUN_NOTIFICATIONS_ENABLE
102+
bool xrun_notification_sent;
103+
#endif
101104
uint32_t dma_buffer_size; /* dma buffer size */
102105
#if CONFIG_HOST_DMA_STREAM_SYNCHRONIZATION
103106
bool is_grouped;

src/audio/host-zephyr.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
#include <stddef.h>
3333
#include <stdint.h>
3434

35+
#if CONFIG_XRUN_NOTIFICATIONS_ENABLE
36+
#include <sof/ipc/notification_pool.h>
37+
#include <ipc4/notification.h>
38+
#endif
39+
3540
#include "copier/copier.h"
3641
#include "copier/host_copier.h"
3742

@@ -359,6 +364,32 @@ static void host_dma_cb(struct comp_dev *dev, size_t bytes)
359364
host_common_one_shot(hd, bytes);
360365
}
361366

367+
/* get status from dma and check for xrun */
368+
static int host_get_status(struct comp_dev *dev, struct host_data *hd, struct dma_status *stat)
369+
{
370+
int ret = dma_get_status(hd->chan->dma->z_dev, hd->chan->index, stat);
371+
#if CONFIG_XRUN_NOTIFICATIONS_ENABLE
372+
if (ret == -EPIPE && !hd->xrun_notification_sent) {
373+
struct ipc_msg *notify = ipc_notification_pool_get(IPC4_RESOURCE_EVENT_SIZE);
374+
375+
if (notify) {
376+
if (dev->direction == SOF_IPC_STREAM_PLAYBACK)
377+
copier_gateway_underrun_notif_msg_init(notify,
378+
dev->pipeline->pipeline_id);
379+
else
380+
copier_gateway_overrun_notif_msg_init(notify,
381+
dev->pipeline->pipeline_id);
382+
383+
ipc_msg_send(notify, notify->tx_data, false);
384+
hd->xrun_notification_sent = true;
385+
}
386+
} else if (!ret) {
387+
hd->xrun_notification_sent = false;
388+
}
389+
#endif
390+
return ret;
391+
}
392+
362393
/* Minimum time between 2 consecutive "no bytes to copy" messages in milliseconds */
363394
#define SOF_MIN_NO_BYTES_INTERVAL_MS 20
364395

@@ -378,7 +409,7 @@ static uint32_t host_get_copy_bytes_normal(struct host_data *hd, struct comp_dev
378409
int ret;
379410

380411
/* get data sizes from DMA */
381-
ret = dma_get_status(hd->chan->dma->z_dev, hd->chan->index, &dma_stat);
412+
ret = host_get_status(dev, hd, &dma_stat);
382413
if (ret < 0) {
383414
comp_err(dev, "dma_get_status() failed, ret = %u",
384415
ret);

0 commit comments

Comments
 (0)