From b44c11e480505f754d0f7b4ac3067e4ebf5adcc2 Mon Sep 17 00:00:00 2001 From: batt Date: Fri, 9 Jul 2010 10:43:19 +0000 Subject: [PATCH] Flush the transfer before exiting from write function. Since the buffer is used by the DMA, if we return early we run the risk of having the buffer overwritten before the transfer will be completed. Waiting for the flush could be theorically a pessimization, but from tests, since the typical use involves mixed reads/writes, we already wait for the transfers to be completed, and performance are almost the same. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4017 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/cpu/arm/drv/spi_dma_at91.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bertos/cpu/arm/drv/spi_dma_at91.c b/bertos/cpu/arm/drv/spi_dma_at91.c index 03b98d85..25a10410 100644 --- a/bertos/cpu/arm/drv/spi_dma_at91.c +++ b/bertos/cpu/arm/drv/spi_dma_at91.c @@ -76,11 +76,11 @@ static int spi_dma_flush(UNUSED_ARG(struct KFile *, fd)) static size_t spi_dma_write(struct KFile *fd, const void *_buf, size_t size) { - spi_dma_flush(fd); SPI0_PTCR = BV(PDC_TXTDIS); SPI0_TPR = (reg32_t)_buf; SPI0_TCR = size; SPI0_PTCR = BV(PDC_TXTEN); + spi_dma_flush(fd); return size; } @@ -97,8 +97,6 @@ static size_t spi_dma_read(struct KFile *fd, void *_buf, size_t size) size_t count, total_rx = 0; uint8_t *buf = (uint8_t *)_buf; - spi_dma_flush(fd); - while (size) { count = MIN(size, (size_t)CONFIG_SPI_DMA_MAX_RX); -- 2.25.1