diff --git a/cpu/stm32f1/periph/spi.c b/cpu/stm32f1/periph/spi.c index 0944099a8f..8956191689 100644 --- a/cpu/stm32f1/periph/spi.c +++ b/cpu/stm32f1/periph/spi.c @@ -15,11 +15,14 @@ * * @author Thomas Eichinger * @author Fabian Nack + * @author Hauke Petersen + * @author Joakim Gebart * * @} */ #include "stm32f10x.h" +#include "mutex.h" #include "periph/gpio.h" #include "periph/spi.h" #include "periph_conf.h" @@ -31,6 +34,21 @@ /* guard file in case no SPI device is defined */ #if SPI_0_EN +/** + * @brief Array holding one pre-initialized mutex for each SPI device + */ +static mutex_t locks[] = { +#if SPI_0_EN + [SPI_0] = MUTEX_INIT, +#endif +#if SPI_1_EN + [SPI_1] = MUTEX_INIT, +#endif +#if SPI_2_EN + [SPI_2] = MUTEX_INIT +#endif +}; + int spi_init_master(spi_t dev, spi_conf_t conf, spi_speed_t speed) { SPI_TypeDef *spi; @@ -125,6 +143,24 @@ int spi_conf_pins(spi_t dev) return 0; } +int spi_acquire(spi_t dev) +{ + if (dev >= SPI_NUMOF) { + return -1; + } + mutex_lock(&locks[dev]); + return 0; +} + +int spi_release(spi_t dev) +{ + if (dev >= SPI_NUMOF) { + return -1; + } + mutex_unlock(&locks[dev]); + return 0; +} + int spi_transfer_byte(spi_t dev, char out, char *in) { SPI_TypeDef *spi;