From d50f43e9f5b3a56d2ac7f65af48fd18fcd7105d5 Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Thu, 17 Jul 2014 15:42:30 +0200 Subject: [PATCH] at86rf231: introduce variable to keep internal driver state The at86rf231 radio transceiver provides one IRQ (TRX_END) signaling end of transmission or reception but no way to distinguish between these. --- drivers/at86rf231/at86rf231.c | 16 +++++++++++++++- drivers/at86rf231/at86rf231_tx.c | 10 ++++++++++ drivers/include/at86rf231.h | 13 +++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/drivers/at86rf231/at86rf231.c b/drivers/at86rf231/at86rf231.c index 275ec6acc7..32eb5623e1 100644 --- a/drivers/at86rf231/at86rf231.c +++ b/drivers/at86rf231/at86rf231.c @@ -18,6 +18,7 @@ * @brief Driver implementation for at86rf231 chip * * @author Alaeddine Weslati + * @author Thomas Eichinger * * @} */ @@ -34,6 +35,8 @@ static uint8_t radio_channel; static uint16_t radio_address; static uint64_t radio_address_long; +uint8_t driver_state; + void at86rf231_init(kernel_pid_t tpid) { transceiver_pid = tpid; @@ -103,7 +106,18 @@ void at86rf231_switch_to_rx(void) void at86rf231_rx_irq(void) { - at86rf231_rx_handler(); + /* check if we are in sending state */ + if (driver_state == AT_DRIVER_STATE_SENDING) { + /* Read IRQ to clear it */ + at86rf231_reg_read(AT86RF231_REG__IRQ_STATUS); + /* clear internal state */ + driver_state = AT_DRIVER_STATE_DEFAULT; + return; + } + else { + /* handle receive */ + at86rf231_rx_handler(); + } } radio_address_t at86rf231_set_address(radio_address_t address) diff --git a/drivers/at86rf231/at86rf231_tx.c b/drivers/at86rf231/at86rf231_tx.c index 66053fd506..6976e8dcae 100644 --- a/drivers/at86rf231/at86rf231_tx.c +++ b/drivers/at86rf231/at86rf231_tx.c @@ -10,7 +10,11 @@ #include "at86rf231_arch.h" #include "at86rf231_spi.h" +#define ENABLE_DEBUG (0) +#include "debug.h" + static void at86rf231_xmit(uint8_t *data, radio_packet_length_t length); + static void at86rf231_gen_pkt(uint8_t *buf, at86rf231_packet_t *packet); static uint8_t sequenz_nr; @@ -87,11 +91,17 @@ static void at86rf231_xmit(uint8_t *data, radio_packet_length_t length) } while ((status & AT86RF231_TRX_STATUS_MASK__TRX_STATUS) != AT86RF231_TRX_STATUS__PLL_ON); + /* radio driver state: sending */ + /* will be freed in at86rf231_rx_irq when TRX_END interrupt occurs */ + driver_state = AT_DRIVER_STATE_SENDING; + // copy the packet to the radio FIFO at86rf231_write_fifo(data, length); + DEBUG("Wrote to FIFO\n"); // Start TX at86rf231_reg_write(AT86RF231_REG__TRX_STATE, AT86RF231_TRX_STATE__TX_START); + DEBUG("Started TX\n"); } /** diff --git a/drivers/include/at86rf231.h b/drivers/include/at86rf231.h index e019d6b73d..eab048373e 100644 --- a/drivers/include/at86rf231.h +++ b/drivers/include/at86rf231.h @@ -31,6 +31,19 @@ typedef struct __attribute__((packed)) } at86rf231_packet_t; +extern int transceiver_pid; + +#define AT_DRIVER_STATE_DEFAULT (0) +#define AT_DRIVER_STATE_SENDING (1) + +/** + * @brief To keep state inside of at86rf231 driver + * @details This variable is used to determine if a TRX_END IRQ from + * the radio transceiver has to be interpreted as end of + * sending or reception. + */ +extern uint8_t driver_state; + void at86rf231_init(kernel_pid_t tpid); //void at86rf231_reset(void); void at86rf231_rx(void);