at86rf231: Acquire exclusive access to SPI bus.
Signed-off-by: Joakim Gebart <joakim.gebart@eistec.se>
This commit is contained in:
parent
d68b4ef6c2
commit
1f577b4fee
@ -411,7 +411,9 @@ int at86rf231_get_monitor(void)
|
|||||||
void at86rf231_gpio_spi_interrupts_init(void)
|
void at86rf231_gpio_spi_interrupts_init(void)
|
||||||
{
|
{
|
||||||
/* SPI init */
|
/* SPI init */
|
||||||
|
spi_acquire(AT86RF231_SPI);
|
||||||
spi_init_master(AT86RF231_SPI, SPI_CONF_FIRST_RISING, SPI_SPEED);
|
spi_init_master(AT86RF231_SPI, SPI_CONF_FIRST_RISING, SPI_SPEED);
|
||||||
|
spi_release(AT86RF231_SPI);
|
||||||
/* IRQ0 */
|
/* IRQ0 */
|
||||||
gpio_init_int(AT86RF231_INT, GPIO_NOPULL, GPIO_RISING, (gpio_cb_t)at86rf231_rx_irq, NULL);
|
gpio_init_int(AT86RF231_INT, GPIO_NOPULL, GPIO_RISING, (gpio_cb_t)at86rf231_rx_irq, NULL);
|
||||||
/* CS */
|
/* CS */
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
*
|
*
|
||||||
* @author Alaeddine Weslati <alaeddine.weslati@inria.fr>
|
* @author Alaeddine Weslati <alaeddine.weslati@inria.fr>
|
||||||
* @author Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
* @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)
|
void at86rf231_reg_write(uint8_t addr, uint8_t value)
|
||||||
{
|
{
|
||||||
|
/* Acquire exclusive access to the bus. */
|
||||||
|
spi_acquire(AT86RF231_SPI);
|
||||||
/* Start the SPI transfer */
|
/* Start the SPI transfer */
|
||||||
gpio_clear(AT86RF231_CS);
|
gpio_clear(AT86RF231_CS);
|
||||||
/* write to register */
|
/* write to register */
|
||||||
spi_transfer_reg(AT86RF231_SPI, AT86RF231_ACCESS_REG | AT86RF231_ACCESS_WRITE | addr, value, 0);
|
spi_transfer_reg(AT86RF231_SPI, AT86RF231_ACCESS_REG | AT86RF231_ACCESS_WRITE | addr, value, 0);
|
||||||
/* End the SPI transfer */
|
/* End the SPI transfer */
|
||||||
gpio_set(AT86RF231_CS);
|
gpio_set(AT86RF231_CS);
|
||||||
|
/* Release the bus for other threads. */
|
||||||
|
spi_release(AT86RF231_SPI);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t at86rf231_reg_read(uint8_t addr)
|
uint8_t at86rf231_reg_read(uint8_t addr)
|
||||||
{
|
{
|
||||||
char value;
|
char value;
|
||||||
|
|
||||||
|
/* Acquire exclusive access to the bus. */
|
||||||
|
spi_acquire(AT86RF231_SPI);
|
||||||
/* Start the SPI transfer */
|
/* Start the SPI transfer */
|
||||||
gpio_clear(AT86RF231_CS);
|
gpio_clear(AT86RF231_CS);
|
||||||
/* read from register */
|
/* read from register */
|
||||||
spi_transfer_reg(AT86RF231_SPI, AT86RF231_ACCESS_REG | AT86RF231_ACCESS_READ | addr, 0, &value);
|
spi_transfer_reg(AT86RF231_SPI, AT86RF231_ACCESS_REG | AT86RF231_ACCESS_READ | addr, 0, &value);
|
||||||
/* End the SPI transfer */
|
/* End the SPI transfer */
|
||||||
gpio_set(AT86RF231_CS);
|
gpio_set(AT86RF231_CS);
|
||||||
|
/* Release the bus for other threads. */
|
||||||
|
spi_release(AT86RF231_SPI);
|
||||||
return (uint8_t)value;
|
return (uint8_t)value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void at86rf231_read_fifo(uint8_t *data, radio_packet_length_t length)
|
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 */
|
/* Start the SPI transfer */
|
||||||
gpio_clear(AT86RF231_CS);
|
gpio_clear(AT86RF231_CS);
|
||||||
/* Read a number of bytes from the devices frame buffer */
|
/* 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);
|
0, (char*)data, length);
|
||||||
/* End the SPI transfer */
|
/* End the SPI transfer */
|
||||||
gpio_set(AT86RF231_CS);
|
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)
|
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 */
|
/* Start the SPI transfer */
|
||||||
gpio_clear(AT86RF231_CS);
|
gpio_clear(AT86RF231_CS);
|
||||||
/* Send Frame Buffer Write access */
|
/* 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);
|
(char*)data, 0, length);
|
||||||
/* End the SPI transfer */
|
/* End the SPI transfer */
|
||||||
gpio_set(AT86RF231_CS);
|
gpio_set(AT86RF231_CS);
|
||||||
|
/* Release the bus for other threads. */
|
||||||
|
spi_release(AT86RF231_SPI);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t at86rf231_get_status(void)
|
uint8_t at86rf231_get_status(void)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user