Skip to content

Commit

Permalink
Merge pull request #9164 from maribu/cc110x
Browse files Browse the repository at this point in the history
drivers: Various minor improvments of the cc110x driver
  • Loading branch information
aabadie committed May 28, 2018
2 parents ea4aa1e + 2f3d811 commit d7585e3
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 22 deletions.
2 changes: 1 addition & 1 deletion drivers/cc110x/cc110x-netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
54 changes: 41 additions & 13 deletions drivers/cc110x/cc110x-rxtx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -61,15 +84,16 @@ 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);
}

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;
Expand Down Expand Up @@ -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);

Expand All @@ -133,14 +156,17 @@ 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);
}
}
}

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__);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion drivers/cc110x/cc110x.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion drivers/cc110x/gnrc_cc110x/gnrc_cc110x.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
36 changes: 36 additions & 0 deletions drivers/cc110x/include/cc110x-defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion drivers/cc110x/include/cc110x-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions drivers/cc110x/include/cc110x-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions drivers/include/cc110x.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down

0 comments on commit d7585e3

Please sign in to comment.