samd21: Basic implementation of spi_acquire(), spi_release()
Signed-off-by: Joakim Gebart <joakim.gebart@eistec.se>
This commit is contained in:
parent
b20f21f2c5
commit
bec43f11d8
@ -14,12 +14,15 @@
|
|||||||
* @brief Low-level SPI driver implementation
|
* @brief Low-level SPI driver implementation
|
||||||
*
|
*
|
||||||
* @author Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
* @author Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
||||||
* Troels Hoffmeyer <troels.d.hoffmeyer@gmail.com>
|
* @author Troels Hoffmeyer <troels.d.hoffmeyer@gmail.com>
|
||||||
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||||
|
* @author Joakim Gebart <joakim.gebart@eistec.se>
|
||||||
*
|
*
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "cpu.h"
|
#include "cpu.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"
|
||||||
@ -28,6 +31,21 @@
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#if SPI_0_EN || SPI_1_EN
|
#if SPI_0_EN || SPI_1_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)
|
||||||
{
|
{
|
||||||
SercomSpi* spi_dev = 0;
|
SercomSpi* spi_dev = 0;
|
||||||
@ -177,6 +195,24 @@ void spi_transmission_begin(spi_t dev, char reset_val)
|
|||||||
/* TODO*/
|
/* TODO*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
SercomSpi* spi_dev = 0;
|
SercomSpi* spi_dev = 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user