stm32f1: Basic implementation of spi_acquire(), spi_release()

Signed-off-by: Joakim Gebart <joakim.gebart@eistec.se>
This commit is contained in:
Joakim Gebart 2015-01-16 13:38:02 +01:00
parent 98c88b0549
commit f64c54bf66

View File

@ -15,11 +15,14 @@
* *
* @author Thomas Eichinger <thomas.eichinger@fu-berlin.de> * @author Thomas Eichinger <thomas.eichinger@fu-berlin.de>
* @author Fabian Nack <nack@inf.fu-berlin.de> * @author Fabian Nack <nack@inf.fu-berlin.de>
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Joakim Gebart <joakim.gebart@eistec.se>
* *
* @} * @}
*/ */
#include "stm32f10x.h" #include "stm32f10x.h"
#include "mutex.h"
#include "periph/gpio.h" #include "periph/gpio.h"
#include "periph/spi.h" #include "periph/spi.h"
#include "periph_conf.h" #include "periph_conf.h"
@ -31,6 +34,21 @@
/* guard file in case no SPI device is defined */ /* guard file in case no SPI device is defined */
#if SPI_0_EN #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) int spi_init_master(spi_t dev, spi_conf_t conf, spi_speed_t speed)
{ {
SPI_TypeDef *spi; SPI_TypeDef *spi;
@ -125,6 +143,24 @@ int spi_conf_pins(spi_t dev)
return 0; 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) int spi_transfer_byte(spi_t dev, char out, char *in)
{ {
SPI_TypeDef *spi; SPI_TypeDef *spi;