at86rf231: Acquire exclusive access to SPI bus.

Signed-off-by: Joakim Gebart <joakim.gebart@eistec.se>
This commit is contained in:
Joakim Gebart 2015-01-16 13:46:58 +01:00
parent d68b4ef6c2
commit 1f577b4fee
2 changed files with 19 additions and 0 deletions

View File

@ -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 */

View File

@ -15,6 +15,7 @@
*
* @author Alaeddine Weslati <alaeddine.weslati@inria.fr>
* @author Thomas Eichinger <thomas.eichinger@fu-berlin.de>
* @author Joakim Gebart <joakim.gebart@eistec.se>
*
* @}
*/
@ -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)