From 8e9ccd8b0d44b013a6bc27827bec767567ff045a Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Thu, 30 Jul 2015 16:07:39 -0700 Subject: stm32: spi: Add lock around spi_transaction Like the implementation for mec1322, add a lock around spi_transaction. It prevents 2 tasks from accessing a given bus at the same time. BRANCH=smaug TEST=Check the BMI160 FIFO corruption disappeared in SPI mode. BUG=None Change-Id: I9e8a9e39ca96ea56692e3125930ab05ae6ef143f Signed-off-by: Gwendal Grignou Reviewed-on: https://chromium-review.googlesource.com/289856 Reviewed-by: Vincent Palatin --- chip/stm32/spi_master.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'chip/stm32/spi_master.c') diff --git a/chip/stm32/spi_master.c b/chip/stm32/spi_master.c index 26d279f19c..f8cebc295d 100644 --- a/chip/stm32/spi_master.c +++ b/chip/stm32/spi_master.c @@ -11,6 +11,7 @@ #include "gpio.h" #include "shared_mem.h" #include "spi.h" +#include "task.h" #include "timer.h" #include "util.h" @@ -22,6 +23,8 @@ static stm32_spi_regs_t *SPI_REGS[] = { #endif }; +static struct mutex spi_mutex[ARRAY_SIZE(SPI_REGS)]; + #define SPI_TRANSACTION_TIMEOUT_USEC (800 * MSEC) /* Default DMA channel options */ @@ -245,9 +248,12 @@ int spi_transaction(const struct spi_device_t *spi_device, uint8_t *rxdata, int rxlen) { int rv; + int port = spi_device->port; + mutex_lock(spi_mutex + port); rv = spi_transaction_async(spi_device, txdata, txlen, rxdata, rxlen); rv |= spi_transaction_flush(spi_device); + mutex_unlock(spi_mutex + port); return rv; } -- cgit v1.2.1