2014-05-14 10:36:45 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 INRIA
|
|
|
|
*
|
2014-07-31 19:45:27 +02:00
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
2014-05-14 10:36:45 +02:00
|
|
|
*/
|
|
|
|
|
2013-12-16 17:54:58 +01:00
|
|
|
#include "at86rf231_spi.h"
|
|
|
|
#include "at86rf231_arch.h"
|
2014-02-11 17:15:03 +01:00
|
|
|
#include "at86rf231.h"
|
2013-07-12 12:31:16 +02:00
|
|
|
|
|
|
|
void at86rf231_reg_write(uint8_t addr, uint8_t value)
|
|
|
|
{
|
2013-08-15 19:13:00 +02:00
|
|
|
// Start the SPI transfer
|
|
|
|
at86rf231_spi_select();
|
2013-07-12 12:31:16 +02:00
|
|
|
|
2013-08-15 19:13:00 +02:00
|
|
|
// Send first byte being the command and address
|
|
|
|
at86rf231_spi_transfer_byte(AT86RF231_ACCESS_REG | AT86RF231_ACCESS_WRITE | addr);
|
2013-07-12 12:31:16 +02:00
|
|
|
|
2013-08-15 19:13:00 +02:00
|
|
|
// Send value
|
|
|
|
at86rf231_spi_transfer_byte(value);
|
2013-07-12 12:31:16 +02:00
|
|
|
|
2013-08-15 19:13:00 +02:00
|
|
|
// End the SPI transfer
|
|
|
|
at86rf231_spi_unselect();
|
2013-07-12 12:31:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t at86rf231_reg_read(uint8_t addr)
|
|
|
|
{
|
2013-08-15 19:13:00 +02:00
|
|
|
uint8_t value;
|
2013-07-12 12:31:16 +02:00
|
|
|
|
2013-08-15 19:13:00 +02:00
|
|
|
// Start the SPI transfer
|
|
|
|
at86rf231_spi_select();
|
2013-07-12 12:31:16 +02:00
|
|
|
|
2013-08-15 19:13:00 +02:00
|
|
|
// Send first byte being the command and address
|
|
|
|
at86rf231_spi_transfer_byte(AT86RF231_ACCESS_REG | AT86RF231_ACCESS_READ | addr);
|
2013-07-12 12:31:16 +02:00
|
|
|
|
2013-08-15 19:13:00 +02:00
|
|
|
// Send value
|
|
|
|
value = at86rf231_spi_transfer_byte(0);
|
2013-07-12 12:31:16 +02:00
|
|
|
|
2013-08-15 19:13:00 +02:00
|
|
|
// End the SPI transfer
|
|
|
|
at86rf231_spi_unselect();
|
2013-07-12 12:31:16 +02:00
|
|
|
|
2013-08-15 19:13:00 +02:00
|
|
|
return value;
|
2013-07-12 12:31:16 +02:00
|
|
|
}
|
|
|
|
|
2014-07-07 00:00:16 +02:00
|
|
|
void at86rf231_read_fifo(uint8_t *data, radio_packet_length_t length)
|
2013-07-12 12:31:16 +02:00
|
|
|
{
|
2013-08-15 19:13:00 +02:00
|
|
|
// Start the SPI transfer
|
|
|
|
at86rf231_spi_select();
|
2013-07-12 12:31:16 +02:00
|
|
|
|
2013-08-15 19:13:00 +02:00
|
|
|
// Send Frame Buffer Write access
|
|
|
|
at86rf231_spi_transfer_byte(AT86RF231_ACCESS_FRAMEBUFFER | AT86RF231_ACCESS_READ);
|
2013-07-12 12:31:16 +02:00
|
|
|
|
2013-08-15 19:13:00 +02:00
|
|
|
at86rf231_spi_transfer(0, data, length);
|
2013-07-12 12:31:16 +02:00
|
|
|
|
2013-08-15 19:13:00 +02:00
|
|
|
// End the SPI transfer
|
|
|
|
at86rf231_spi_unselect();
|
2013-07-12 12:31:16 +02:00
|
|
|
}
|
|
|
|
|
2014-07-07 00:00:16 +02:00
|
|
|
void at86rf231_write_fifo(const uint8_t *data, radio_packet_length_t length)
|
2013-07-12 12:31:16 +02:00
|
|
|
{
|
2013-08-15 19:13:00 +02:00
|
|
|
// Start the SPI transfer
|
|
|
|
at86rf231_spi_select();
|
2013-07-12 12:31:16 +02:00
|
|
|
|
2013-08-15 19:13:00 +02:00
|
|
|
// Send Frame Buffer Write access
|
|
|
|
at86rf231_spi_transfer_byte(AT86RF231_ACCESS_FRAMEBUFFER | AT86RF231_ACCESS_WRITE);
|
2013-07-12 12:31:16 +02:00
|
|
|
|
2013-08-15 19:13:00 +02:00
|
|
|
at86rf231_spi_transfer(data, 0, length);
|
2013-07-12 12:31:16 +02:00
|
|
|
|
2013-08-15 19:13:00 +02:00
|
|
|
// End the SPI transfer
|
|
|
|
at86rf231_spi_unselect();
|
2013-07-12 12:31:16 +02:00
|
|
|
}
|