Skip to content
Snippets Groups Projects
Unverified Commit 30c79a66 authored by Marian Buschsieweke's avatar Marian Buschsieweke
Browse files

drivers: Replaced magic numbers in cc110x

Replaced magic undocumented numbers in the code by human readable preprocessor
macros.
parent cbff3e6d
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -80,7 +80,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);
}
......@@ -88,7 +89,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;
......@@ -196,9 +197,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;
......@@ -224,11 +225,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);
}
}
......@@ -300,7 +302,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);
......
......@@ -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
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment