1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 05:12:57 +01:00

drivers: Replaced magic numbers in cc110x

Replaced magic undocumented numbers in the code by human readable preprocessor
macros.
This commit is contained in:
Marian Buschsieweke 2018-05-24 19:28:46 +02:00
parent cbff3e6d3a
commit 30c79a66d0
No known key found for this signature in database
GPG Key ID: 61F64C6599B1539F
5 changed files with 49 additions and 9 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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