From 1f577b4fee6e3bfe6c5369f30fd9c3a2fea7e5db Mon Sep 17 00:00:00 2001 From: Joakim Gebart Date: Fri, 16 Jan 2015 13:46:58 +0100 Subject: [PATCH] at86rf231: Acquire exclusive access to SPI bus. Signed-off-by: Joakim Gebart --- drivers/at86rf231/at86rf231.c | 2 ++ drivers/at86rf231/at86rf231_spi.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/drivers/at86rf231/at86rf231.c b/drivers/at86rf231/at86rf231.c index 55e3013729..b26aea18b0 100644 --- a/drivers/at86rf231/at86rf231.c +++ b/drivers/at86rf231/at86rf231.c @@ -411,7 +411,9 @@ int at86rf231_get_monitor(void) void at86rf231_gpio_spi_interrupts_init(void) { /* SPI init */ + spi_acquire(AT86RF231_SPI); spi_init_master(AT86RF231_SPI, SPI_CONF_FIRST_RISING, SPI_SPEED); + spi_release(AT86RF231_SPI); /* IRQ0 */ gpio_init_int(AT86RF231_INT, GPIO_NOPULL, GPIO_RISING, (gpio_cb_t)at86rf231_rx_irq, NULL); /* CS */ diff --git a/drivers/at86rf231/at86rf231_spi.c b/drivers/at86rf231/at86rf231_spi.c index 72fb0ff987..8dc7b9d413 100644 --- a/drivers/at86rf231/at86rf231_spi.c +++ b/drivers/at86rf231/at86rf231_spi.c @@ -15,6 +15,7 @@ * * @author Alaeddine Weslati * @author Thomas Eichinger + * @author Joakim Gebart * * @} */ @@ -27,29 +28,39 @@ void at86rf231_reg_write(uint8_t addr, uint8_t value) { + /* Acquire exclusive access to the bus. */ + spi_acquire(AT86RF231_SPI); /* Start the SPI transfer */ gpio_clear(AT86RF231_CS); /* write to register */ spi_transfer_reg(AT86RF231_SPI, AT86RF231_ACCESS_REG | AT86RF231_ACCESS_WRITE | addr, value, 0); /* End the SPI transfer */ gpio_set(AT86RF231_CS); + /* Release the bus for other threads. */ + spi_release(AT86RF231_SPI); } uint8_t at86rf231_reg_read(uint8_t addr) { char value; + /* Acquire exclusive access to the bus. */ + spi_acquire(AT86RF231_SPI); /* Start the SPI transfer */ gpio_clear(AT86RF231_CS); /* read from register */ spi_transfer_reg(AT86RF231_SPI, AT86RF231_ACCESS_REG | AT86RF231_ACCESS_READ | addr, 0, &value); /* End the SPI transfer */ gpio_set(AT86RF231_CS); + /* Release the bus for other threads. */ + spi_release(AT86RF231_SPI); return (uint8_t)value; } void at86rf231_read_fifo(uint8_t *data, radio_packet_length_t length) { + /* Acquire exclusive access to the bus. */ + spi_acquire(AT86RF231_SPI); /* Start the SPI transfer */ gpio_clear(AT86RF231_CS); /* Read a number of bytes from the devices frame buffer */ @@ -57,10 +68,14 @@ void at86rf231_read_fifo(uint8_t *data, radio_packet_length_t length) 0, (char*)data, length); /* End the SPI transfer */ gpio_set(AT86RF231_CS); + /* Release the bus for other threads. */ + spi_release(AT86RF231_SPI); } void at86rf231_write_fifo(const uint8_t *data, radio_packet_length_t length) { + /* Acquire exclusive access to the bus. */ + spi_acquire(AT86RF231_SPI); /* Start the SPI transfer */ gpio_clear(AT86RF231_CS); /* Send Frame Buffer Write access */ @@ -68,6 +83,8 @@ void at86rf231_write_fifo(const uint8_t *data, radio_packet_length_t length) (char*)data, 0, length); /* End the SPI transfer */ gpio_set(AT86RF231_CS); + /* Release the bus for other threads. */ + spi_release(AT86RF231_SPI); } uint8_t at86rf231_get_status(void)