From 8c16506277c4819c8ed28451e2d10aaff4c1d2e7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 10 Nov 2013 15:02:51 -0600 Subject: [PATCH] SAMA5 I2S: Need to update the count of valid bytes at the conclusion of the read DMA --- arch/arm/src/sama5/sam_ssc.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/arch/arm/src/sama5/sam_ssc.c b/arch/arm/src/sama5/sam_ssc.c index 9490e7c151..6e42d5ea23 100644 --- a/arch/arm/src/sama5/sam_ssc.c +++ b/arch/arm/src/sama5/sam_ssc.c @@ -1053,6 +1053,10 @@ static int ssc_rxdma_setup(struct sam_ssc_s *priv) apb = bfcontainer->apb; DEBUGASSERT(((uintptr_t)apb->samp & 3) == 0); + /* No data received yet */ + + apb->nbytes = 0; + /* Physical address of the SSC RHR register and of the buffer location * in RAM. */ @@ -1203,13 +1207,25 @@ static void ssc_rx_worker(void *arg) bfcontainer = (struct sam_buffer_s *)sq_remfirst(&priv->rxdone); irqrestore(flags); - /* Perform the TX transfer done callback */ - DEBUGASSERT(bfcontainer && bfcontainer->callback); + + /* If the DMA was successful, then update the number of valid bytes in + * the audio buffer. + */ + + if (bfcontainer->result == OK) + { + bfcontainer->apb->nbytes = bfcontainer->apb->nmaxbytes; + } + + /* Perform the RX transfer done callback */ + bfcontainer->callback(&priv->dev, bfcontainer->apb, bfcontainer->arg, bfcontainer->result); - /* Release our reference on the audio buffer */ + /* Release our reference on the audio buffer. This may very likely + * cause the audio buffer to be freed. + */ apb_free(bfcontainer->apb); @@ -1585,7 +1601,9 @@ static void ssc_tx_worker(void *arg) bfcontainer->callback(&priv->dev, bfcontainer->apb, bfcontainer->arg, bfcontainer->result); - /* Release our reference on the audio buffer */ + /* Release our reference on the audio buffer. This may very likely + * cause the audio buffer to be freed. + */ apb_free(bfcontainer->apb);