mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #9164 from maribu/cc110x
drivers: Various minor improvments of the cc110x driver
This commit is contained in:
commit
d7585e379c
@ -201,7 +201,7 @@ static int _init(netdev_t *dev)
|
||||
cc110x_t *cc110x = &((netdev_cc110x_t*) dev)->cc110x;
|
||||
|
||||
gpio_init_int(cc110x->params.gdo2, GPIO_IN, GPIO_BOTH,
|
||||
&_netdev_cc110x_isr, (void*)dev);
|
||||
&_netdev_cc110x_isr, (void*)dev);
|
||||
|
||||
gpio_set(cc110x->params.gdo2);
|
||||
gpio_irq_disable(cc110x->params.gdo2);
|
||||
|
@ -38,11 +38,34 @@
|
||||
#include "cpu_conf.h"
|
||||
#include "cpu.h"
|
||||
|
||||
#ifdef MODULE_OD
|
||||
#include "od.h"
|
||||
#endif
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#define ENABLE_DEBUG (0)
|
||||
#include "debug.h"
|
||||
|
||||
const char *cc110x_state_to_text(uint8_t state)
|
||||
{
|
||||
switch (state){
|
||||
case RADIO_IDLE:
|
||||
return "idle";
|
||||
case RADIO_TX_BUSY:
|
||||
return "tx busy";
|
||||
case RADIO_RX:
|
||||
return "rx";
|
||||
case RADIO_RX_BUSY:
|
||||
return "rx busy";
|
||||
case RADIO_PWD:
|
||||
return "pwd";
|
||||
case RADIO_UNKNOWN:
|
||||
return "unknown";
|
||||
}
|
||||
return "invalid";
|
||||
}
|
||||
|
||||
static void _rx_abort(cc110x_t *dev)
|
||||
{
|
||||
gpio_irq_disable(dev->params.gdo2);
|
||||
@ -61,7 +84,8 @@ static void _rx_start(cc110x_t *dev)
|
||||
pkt_buf->pos = 0;
|
||||
|
||||
gpio_irq_disable(dev->params.gdo2);
|
||||
cc110x_write_reg(dev, CC110X_IOCFG2, 0x01);
|
||||
cc110x_write_reg(dev, CC110X_IOCFG2,
|
||||
CC110X_GDO_HIGH_ON_RX_FIFO_FILLED_OR_PKT_END);
|
||||
gpio_irq_enable(dev->params.gdo2);
|
||||
}
|
||||
|
||||
@ -69,7 +93,7 @@ static void _rx_read_data(cc110x_t *dev, void(*callback)(void*), void*arg)
|
||||
{
|
||||
int fifo = cc110x_get_reg_robust(dev, 0xfb);
|
||||
|
||||
if (fifo & 0x80) {
|
||||
if (fifo & RXFIFO_OVERFLOW) {
|
||||
DEBUG("%s:%s:%u rx overflow\n", RIOT_FILE_RELATIVE, __func__, __LINE__);
|
||||
_rx_abort(dev);
|
||||
return;
|
||||
@ -120,11 +144,10 @@ static void _rx_read_data(cc110x_t *dev, void(*callback)(void*), void*arg)
|
||||
int crc_ok = (status[I_LQI] & CRC_OK) >> 7;
|
||||
|
||||
if (crc_ok) {
|
||||
LOG_DEBUG("cc110x: received packet from=%u to=%u payload "
|
||||
"len=%u\n",
|
||||
(unsigned)pkt_buf->packet.phy_src,
|
||||
(unsigned)pkt_buf->packet.address,
|
||||
pkt_buf->packet.length-3);
|
||||
LOG_DEBUG("cc110x: received packet from=%u to=%u payload len=%u\n",
|
||||
(unsigned)pkt_buf->packet.phy_src,
|
||||
(unsigned)pkt_buf->packet.address,
|
||||
pkt_buf->packet.length - 3);
|
||||
/* let someone know that we've got a packet */
|
||||
callback(arg);
|
||||
|
||||
@ -133,6 +156,10 @@ static void _rx_read_data(cc110x_t *dev, void(*callback)(void*), void*arg)
|
||||
else {
|
||||
DEBUG("%s:%s:%u crc-error\n", RIOT_FILE_RELATIVE, __func__, __LINE__);
|
||||
dev->cc110x_statistic.packets_in_crc_fail++;
|
||||
#if defined(MODULE_OD) && ENABLE_DEBUG
|
||||
od_hex_dump(pkt_buf->packet.data, pkt_buf->packet.length - 3,
|
||||
OD_WIDTH_DEFAULT);
|
||||
#endif
|
||||
_rx_abort(dev);
|
||||
}
|
||||
}
|
||||
@ -140,7 +167,6 @@ static void _rx_read_data(cc110x_t *dev, void(*callback)(void*), void*arg)
|
||||
|
||||
static void _rx_continue(cc110x_t *dev, void(*callback)(void*), void*arg)
|
||||
{
|
||||
|
||||
if (dev->radio_state != RADIO_RX_BUSY) {
|
||||
DEBUG("%s:%s:%u _rx_continue in invalid state\n", RIOT_FILE_RELATIVE,
|
||||
__func__, __LINE__);
|
||||
@ -177,9 +203,9 @@ static void _tx_continue(cc110x_t *dev)
|
||||
return;
|
||||
}
|
||||
|
||||
int fifo = 64 - cc110x_get_reg_robust(dev, 0xfa);
|
||||
int fifo = CC110X_FIFO_LENGTH - cc110x_get_reg_robust(dev, 0xfa);
|
||||
|
||||
if (fifo & 0x80) {
|
||||
if (fifo & TXFIFO_UNDERFLOW) {
|
||||
DEBUG("%s:%s:%u tx underflow!\n", RIOT_FILE_RELATIVE, __func__, __LINE__);
|
||||
_tx_abort(dev);
|
||||
return;
|
||||
@ -205,11 +231,12 @@ static void _tx_continue(cc110x_t *dev)
|
||||
if (to_send < left) {
|
||||
/* set GDO2 to 0x2 -> will deassert at TX FIFO below threshold */
|
||||
gpio_irq_enable(dev->params.gdo2);
|
||||
cc110x_write_reg(dev, CC110X_IOCFG2, 0x02);
|
||||
cc110x_write_reg(dev, CC110X_IOCFG2,
|
||||
CC110X_GDO_LOW_ON_TX_FIFO_BELOW_THRESHOLD);
|
||||
}
|
||||
else {
|
||||
/* set GDO2 to 0x6 -> will deassert at packet end */
|
||||
cc110x_write_reg(dev, CC110X_IOCFG2, 0x06);
|
||||
cc110x_write_reg(dev, CC110X_IOCFG2, CC110X_GDO_HIGH_ON_SYNC_WORD);
|
||||
gpio_irq_enable(dev->params.gdo2);
|
||||
}
|
||||
}
|
||||
@ -281,7 +308,8 @@ int cc110x_send(cc110x_t *dev, cc110x_pkt_t *packet)
|
||||
cc110x_hook_tx();
|
||||
#endif
|
||||
|
||||
cc110x_write_reg(dev, CC110X_IOCFG2, 0x02);
|
||||
cc110x_write_reg(dev, CC110X_IOCFG2,
|
||||
CC110X_GDO_LOW_ON_TX_FIFO_BELOW_THRESHOLD);
|
||||
|
||||
/* Put CC110x in IDLE mode to flush the FIFO */
|
||||
cc110x_strobe(dev, CC110X_SIDLE);
|
||||
|
@ -151,7 +151,7 @@ void cc110x_switch_to_rx(cc110x_t *dev)
|
||||
|
||||
dev->radio_state = RADIO_RX;
|
||||
|
||||
cc110x_write_reg(dev, CC110X_IOCFG2, 0x6);
|
||||
cc110x_write_reg(dev, CC110X_IOCFG2, CC110X_GDO_HIGH_ON_SYNC_WORD);
|
||||
cc110x_strobe(dev, CC110X_SRX);
|
||||
|
||||
gpio_irq_enable(dev->params.gdo2);
|
||||
|
@ -103,7 +103,10 @@ static int _send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt)
|
||||
"length %u\n",
|
||||
(unsigned)cc110x_pkt.phy_src,
|
||||
(unsigned)cc110x_pkt.address,
|
||||
(unsigned)cc110x_pkt.length);
|
||||
(unsigned)payload_len);
|
||||
#if defined(MODULE_OD) && ENABLE_DEBUG
|
||||
od_hex_dump(cc110x_pkt.data, payload_len, OD_WIDTH_DEFAULT);
|
||||
#endif
|
||||
|
||||
return dev->driver->send(dev, &iolist);
|
||||
}
|
||||
|
@ -208,6 +208,42 @@ extern "C" {
|
||||
#define CC110X_RXFIFO (0x3F) /**< RX FIFO: Read operations read from the RX FIFO (SB: +0x80; BURST: +0xC0) */
|
||||
/** @} */
|
||||
|
||||
|
||||
/**
|
||||
* @name GDO configuration values
|
||||
*
|
||||
* Values that can be written to the GDO0, GDO1 and GDO2 configuration registers
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @brief GDO goes high when RX FIFO is filled at or above threshold */
|
||||
#define CC110X_GDO_HIGH_ON_RX_FIFO_ABOVE_THRESHOLD (0x00)
|
||||
/**
|
||||
* @brief GDO goes high when RX FIFO is filled at or above threshold or when
|
||||
* packet is fully received
|
||||
*/
|
||||
#define CC110X_GDO_HIGH_ON_RX_FIFO_FILLED_OR_PKT_END (0x01)
|
||||
/** @brief GDO goes low when TX FIFO is filled less than threshold */
|
||||
#define CC110X_GDO_LOW_ON_TX_FIFO_BELOW_THRESHOLD (0x02)
|
||||
/** @brief GDO goes low when TX FIFO becomes empty */
|
||||
#define CC110X_GDO_LOW_ON_TX_FIFO_EMPTY (0x03)
|
||||
/** @brief GDO goes high when RX FIFO overflows */
|
||||
#define CC110X_GDO_HIGH_ON_RX_FIFO_OVERFLOW (0x04)
|
||||
/** @brief GDO goes high when TX FIFO underflows */
|
||||
#define CC110X_GDO_HIGH_ON_TX_FIFO_UNDERFLOW (0x05)
|
||||
/**
|
||||
* @brief GDO goes high when sync word was just received until the packet is
|
||||
* fully received, or when sync word has been send until packet is fully
|
||||
* send
|
||||
*/
|
||||
#define CC110X_GDO_HIGH_ON_SYNC_WORD (0x06)
|
||||
/**
|
||||
* @brief GDO goes high when a packet is received and CRC is correct.
|
||||
* Goes back to low when first byte of RX fifo has been read
|
||||
*/
|
||||
#define CC110X_GDO_HIGH_ON_PACKET_RECEIVED (0x07)
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -35,7 +35,7 @@ extern "C" {
|
||||
* @{
|
||||
*/
|
||||
char *cc110x_get_marc_state(cc110x_t *dev);
|
||||
char *cc110x_state_to_text(uint8_t state);
|
||||
const char *cc110x_state_to_text(uint8_t state);
|
||||
int cc110x_rd_set_mode(cc110x_t *dev, int mode);
|
||||
uint8_t cc110x_get_buffer_pos(cc110x_t *dev);
|
||||
void cc110x_isr_handler(cc110x_t *dev, void(*callback)(void*), void*arg);
|
||||
|
@ -29,6 +29,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#define CC110X_RXBUF_SIZE (2)
|
||||
#define CC110X_FIFO_LENGTH (64)
|
||||
#define CC110X_MAX_DATA_LENGTH (58+64)
|
||||
|
||||
#define CC110X_HEADER_LENGTH (3) /**< Header covers SRC, DST and
|
||||
|
@ -33,11 +33,11 @@ extern "C" {
|
||||
* @brief Struct for holding cc110x IO parameters
|
||||
*/
|
||||
typedef struct cc110x_params {
|
||||
spi_t spi; /**< what */
|
||||
gpio_t cs; /**< does */
|
||||
gpio_t gdo0; /**< this */
|
||||
gpio_t gdo1; /**< look */
|
||||
gpio_t gdo2; /**< like */
|
||||
spi_t spi; /**< SPI bus the CC110x is connected to */
|
||||
gpio_t cs; /**< GPIO connected to the chip select pin of the CC110x */
|
||||
gpio_t gdo0; /**< GPIO connected to the GDO0 pin of the CC110x */
|
||||
gpio_t gdo1; /**< GPIO connected to the GDO1 pin of the CC110x */
|
||||
gpio_t gdo2; /**< GPIO connected to the GDO2 pin of the CC110x */
|
||||
} cc110x_params_t;
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user