Skip to content

Commit

Permalink
Uncrustified files
Browse files Browse the repository at this point in the history
  • Loading branch information
jia200x committed Aug 1, 2016
1 parent 55c6c0d commit d525f20
Show file tree
Hide file tree
Showing 20 changed files with 728 additions and 544 deletions.
102 changes: 54 additions & 48 deletions drivers/at86rf2xx/at86rf2xx_getset.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,22 @@
#ifdef MODULE_AT86RF212B
/* See: Table 9-15. Recommended Mapping of TX Power, Frequency Band, and
* PHY_TX_PWR (register 0x05), AT86RF212B data sheet. */
static const uint8_t dbm_to_tx_pow_868[] = {0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18,
0x17, 0x15, 0x14, 0x13, 0x12, 0x11,
0x10, 0x0f, 0x31, 0x30, 0x2f, 0x94,
0x93, 0x91, 0x90, 0x29, 0x49, 0x48,
0x47, 0xad, 0xcd, 0xcc, 0xcb, 0xea,
0xe9, 0xe8, 0xe7, 0xe6, 0xe4, 0x80,
0xa0};
static const uint8_t dbm_to_tx_pow_915[] = {0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x17,
0x16, 0x15, 0x14, 0x13, 0x12, 0x11,
0x10, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b,
0x09, 0x91, 0x08, 0x07, 0x05, 0x27,
0x04, 0x03, 0x02, 0x01, 0x00, 0x86,
0x40, 0x84, 0x83, 0x82, 0x80, 0xc1,
0xc0};
static int16_t _tx_pow_to_dbm_212b(uint8_t channel, uint8_t page, uint8_t reg) {
static const uint8_t dbm_to_tx_pow_868[] = { 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18,
0x17, 0x15, 0x14, 0x13, 0x12, 0x11,
0x10, 0x0f, 0x31, 0x30, 0x2f, 0x94,
0x93, 0x91, 0x90, 0x29, 0x49, 0x48,
0x47, 0xad, 0xcd, 0xcc, 0xcb, 0xea,
0xe9, 0xe8, 0xe7, 0xe6, 0xe4, 0x80,
0xa0 };
static const uint8_t dbm_to_tx_pow_915[] = { 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x17,
0x16, 0x15, 0x14, 0x13, 0x12, 0x11,
0x10, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b,
0x09, 0x91, 0x08, 0x07, 0x05, 0x27,
0x04, 0x03, 0x02, 0x01, 0x00, 0x86,
0x40, 0x84, 0x83, 0x82, 0x80, 0xc1,
0xc0 };
static int16_t _tx_pow_to_dbm_212b(uint8_t channel, uint8_t page, uint8_t reg)
{
const uint8_t *dbm_to_tx_pow;
size_t nelem;

Expand All @@ -68,7 +69,7 @@ static int16_t _tx_pow_to_dbm_212b(uint8_t channel, uint8_t page, uint8_t reg) {
return 0;
}

for(size_t i = 0; i < nelem; i++){
for (size_t i = 0; i < nelem; i++) {
if (dbm_to_tx_pow[i] == reg) {
return i - 25;
}
Expand All @@ -77,19 +78,19 @@ static int16_t _tx_pow_to_dbm_212b(uint8_t channel, uint8_t page, uint8_t reg) {
}

#elif MODULE_AT86RF233
static const int16_t tx_pow_to_dbm[] = {4, 4, 3, 3, 2, 2, 1,
0, -1, -2, -3, -4, -6, -8, -12, -17};
static const uint8_t dbm_to_tx_pow[] = {0x0f, 0x0f, 0x0f, 0x0e, 0x0e, 0x0e,
0x0e, 0x0d, 0x0d, 0x0d, 0x0c, 0x0c,
0x0b, 0x0b, 0x0a, 0x09, 0x08, 0x07,
0x06, 0x05, 0x03,0x00};
static const int16_t tx_pow_to_dbm[] = { 4, 4, 3, 3, 2, 2, 1,
0, -1, -2, -3, -4, -6, -8, -12, -17 };
static const uint8_t dbm_to_tx_pow[] = { 0x0f, 0x0f, 0x0f, 0x0e, 0x0e, 0x0e,
0x0e, 0x0d, 0x0d, 0x0d, 0x0c, 0x0c,
0x0b, 0x0b, 0x0a, 0x09, 0x08, 0x07,
0x06, 0x05, 0x03, 0x00 };
#else
static const int16_t tx_pow_to_dbm[] = {3, 3, 2, 2, 1, 1, 0,
-1, -2, -3, -4, -5, -7, -9, -12, -17};
static const uint8_t dbm_to_tx_pow[] = {0x0f, 0x0f, 0x0f, 0x0e, 0x0e, 0x0e,
0x0e, 0x0d, 0x0d, 0x0c, 0x0c, 0x0b,
0x0b, 0x0a, 0x09, 0x08, 0x07, 0x06,
0x05, 0x03, 0x00};
static const int16_t tx_pow_to_dbm[] = { 3, 3, 2, 2, 1, 1, 0,
-1, -2, -3, -4, -5, -7, -9, -12, -17 };
static const uint8_t dbm_to_tx_pow[] = { 0x0f, 0x0f, 0x0f, 0x0e, 0x0e, 0x0e,
0x0e, 0x0d, 0x0d, 0x0c, 0x0c, 0x0b,
0x0b, 0x0a, 0x09, 0x08, 0x07, 0x06,
0x05, 0x03, 0x00 };
#endif

uint16_t at86rf2xx_get_addr_short(at86rf2xx_t *dev)
Expand All @@ -116,6 +117,7 @@ uint64_t at86rf2xx_get_addr_long(at86rf2xx_t *dev)
{
uint64_t addr;
uint8_t *ap = (uint8_t *)(&addr);

for (int i = 0; i < 8; i++) {
ap[i] = dev->netdev.long_addr[i];
}
Expand Down Expand Up @@ -178,6 +180,7 @@ uint16_t at86rf2xx_get_pan(at86rf2xx_t *dev)
void at86rf2xx_set_pan(at86rf2xx_t *dev, uint16_t pan)
{
le_uint16_t le_pan = byteorder_btols(byteorder_htons(pan));

dev->netdev.pan = pan;
DEBUG("pan0: %u, pan1: %u\n", le_pan.u8[0], le_pan.u8[1]);
at86rf2xx_reg_write(dev, AT86RF2XX_REG__PAN_ID_0, le_pan.u8[0]);
Expand All @@ -192,7 +195,7 @@ int16_t at86rf2xx_get_txpower(at86rf2xx_t *dev)
return _tx_pow_to_dbm_212b(dev->netdev.chan, dev->page, txpower);
#else
uint8_t txpower = at86rf2xx_reg_read(dev, AT86RF2XX_REG__PHY_TX_PWR)
& AT86RF2XX_PHY_TX_PWR_MASK__TX_PWR;
& AT86RF2XX_PHY_TX_PWR_MASK__TX_PWR;
return tx_pow_to_dbm[txpower];
#endif
}
Expand Down Expand Up @@ -252,6 +255,7 @@ void at86rf2xx_set_max_retries(at86rf2xx_t *dev, uint8_t max)
uint8_t at86rf2xx_get_csma_max_retries(at86rf2xx_t *dev)
{
uint8_t tmp;

tmp = at86rf2xx_reg_read(dev, AT86RF2XX_REG__XAH_CTRL_0);
tmp &= AT86RF2XX_XAH_CTRL_0__MAX_CSMA_RETRIES;
tmp >>= 1;
Expand All @@ -260,8 +264,8 @@ uint8_t at86rf2xx_get_csma_max_retries(at86rf2xx_t *dev)

void at86rf2xx_set_csma_max_retries(at86rf2xx_t *dev, int8_t retries)
{
retries = (retries > 5) ? 5 : retries; /* valid values: 0-5 */
retries = (retries < 0) ? 7 : retries; /* max < 0 => disable CSMA (set to 7) */
retries = (retries > 5) ? 5 : retries; /* valid values: 0-5 */
retries = (retries < 0) ? 7 : retries; /* max < 0 => disable CSMA (set to 7) */
DEBUG("[at86rf2xx] opt: Set CSMA retries to %u\n", retries);

uint8_t tmp = at86rf2xx_reg_read(dev, AT86RF2XX_REG__XAH_CTRL_0);
Expand All @@ -277,21 +281,21 @@ void at86rf2xx_set_csma_backoff_exp(at86rf2xx_t *dev, uint8_t min, uint8_t max)
DEBUG("[at86rf2xx] opt: Set min BE=%u, max BE=%u\n", min, max);

at86rf2xx_reg_write(dev,
AT86RF2XX_REG__CSMA_BE,
(max << 4) | (min));
AT86RF2XX_REG__CSMA_BE,
(max << 4) | (min));
}

void at86rf2xx_set_csma_seed(at86rf2xx_t *dev, uint8_t entropy[2])
{
if(entropy == NULL) {
if (entropy == NULL) {
DEBUG("[at86rf2xx] opt: CSMA seed entropy is nullpointer\n");
return;
}
DEBUG("[at86rf2xx] opt: Set CSMA seed to 0x%x 0x%x\n", entropy[0], entropy[1]);

at86rf2xx_reg_write(dev,
AT86RF2XX_REG__CSMA_SEED_0,
entropy[0]);
AT86RF2XX_REG__CSMA_SEED_0,
entropy[0]);

uint8_t tmp = at86rf2xx_reg_read(dev, AT86RF2XX_REG__CSMA_SEED_1);
tmp &= ~(AT86RF2XX_CSMA_SEED_1__CSMA_SEED_1);
Expand All @@ -302,6 +306,7 @@ void at86rf2xx_set_csma_seed(at86rf2xx_t *dev, uint8_t entropy[2])
int8_t at86rf2xx_get_cca_threshold(at86rf2xx_t *dev)
{
int8_t tmp = at86rf2xx_reg_read(dev, AT86RF2XX_REG__CCA_THRES);

tmp &= AT86RF2XX_CCA_THRES_MASK__CCA_ED_THRES;
tmp <<= 1;
return (RSSI_BASE_VAL + tmp);
Expand All @@ -327,7 +332,7 @@ void at86rf2xx_set_cca_threshold(at86rf2xx_t *dev, int8_t value)
#ifdef MODULE_OPENTHREAD
bool at86rf2xx_receiver_listening(at86rf2xx_t *dev)
{
return (at86rf2xx_reg_read(dev, AT86RF2XX_REG__RX_SYN) & 0x80) ? false : true;
return (at86rf2xx_reg_read(dev, AT86RF2XX_REG__RX_SYN) & 0x80) ? false : true;
}
#endif

Expand Down Expand Up @@ -374,12 +379,12 @@ void at86rf2xx_set_option(at86rf2xx_t *dev, uint16_t option, bool state)
at86rf2xx_reg_write(dev, AT86RF2XX_REG__IRQ_MASK, tmp);
break;
#ifdef MODULE_OPENTHREAD
case AT86RF2XX_OPT_RX_LISTENING:
case AT86RF2XX_OPT_RX_LISTENING:
DEBUG("[at86rf2xx] opt: enabling listening of pkt\n");
tmp = at86rf2xx_reg_read(dev, AT86RF2XX_REG__RX_SYN);
tmp &= ~(0x80);
at86rf2xx_reg_write(dev, AT86RF2XX_REG__RX_SYN, tmp);
break;
tmp &= ~(0x80);
at86rf2xx_reg_write(dev, AT86RF2XX_REG__RX_SYN, tmp);
break;
#endif
default:
/* do nothing */
Expand Down Expand Up @@ -423,12 +428,12 @@ void at86rf2xx_set_option(at86rf2xx_t *dev, uint16_t option, bool state)
at86rf2xx_reg_write(dev, AT86RF2XX_REG__IRQ_MASK, tmp);
break;
#ifdef MODULE_OPENTHREAD
case AT86RF2XX_OPT_RX_LISTENING:
case AT86RF2XX_OPT_RX_LISTENING:
DEBUG("[at86rf2xx] opt: disabling listening of pkt\n");
tmp = at86rf2xx_reg_read(dev, AT86RF2XX_REG__RX_SYN);
tmp |= 0x80;
at86rf2xx_reg_write(dev, AT86RF2XX_REG__RX_SYN, tmp);
break;
at86rf2xx_reg_write(dev, AT86RF2XX_REG__RX_SYN, tmp);
break;
#endif
default:
/* do nothing */
Expand All @@ -440,7 +445,7 @@ void at86rf2xx_set_option(at86rf2xx_t *dev, uint16_t option, bool state)
static inline void _set_state(at86rf2xx_t *dev, uint8_t state)
{
at86rf2xx_reg_write(dev, AT86RF2XX_REG__TRX_STATE, state);
while (at86rf2xx_get_status(dev) != state);
while (at86rf2xx_get_status(dev) != state) ;
dev->state = state;
}

Expand All @@ -461,9 +466,9 @@ void at86rf2xx_set_state(at86rf2xx_t *dev, uint8_t state)

/* we need to go via PLL_ON if we are moving between RX_AACK_ON <-> TX_ARET_ON */
if ((old_state == AT86RF2XX_STATE_RX_AACK_ON &&
state == AT86RF2XX_STATE_TX_ARET_ON) ||
state == AT86RF2XX_STATE_TX_ARET_ON) ||
(old_state == AT86RF2XX_STATE_TX_ARET_ON &&
state == AT86RF2XX_STATE_RX_AACK_ON)) {
state == AT86RF2XX_STATE_RX_AACK_ON)) {
_set_state(dev, AT86RF2XX_STATE_PLL_ON);
}
/* check if we need to wake up from sleep mode */
Expand All @@ -480,7 +485,8 @@ void at86rf2xx_set_state(at86rf2xx_t *dev, uint8_t state)
/* Go to SLEEP mode from TRX_OFF */
gpio_set(dev->params.sleep_pin);
dev->state = state;
} else {
}
else {
_set_state(dev, state);
}
}
Expand Down
17 changes: 9 additions & 8 deletions drivers/at86rf2xx/at86rf2xx_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,10 @@ netopt_state_t _get_state(at86rf2xx_t *dev)
return NETOPT_STATE_SLEEP;
case AT86RF2XX_STATE_BUSY_RX_AACK:
#ifdef MODULE_OPENTHREAD
/* Required for OpenThread abstraction */
if(at86rf2xx_receiver_listening(dev))
return NETOPT_STATE_IDLE;
/* Required for OpenThread abstraction */
if (at86rf2xx_receiver_listening(dev)) {
return NETOPT_STATE_IDLE;
}
#endif
return NETOPT_STATE_RX;
case AT86RF2XX_STATE_BUSY_TX_ARET:
Expand Down Expand Up @@ -373,10 +374,10 @@ static int _get(netdev2_t *netdev, netopt_t opt, void *val, size_t max_len)
break;

#ifdef MODULE_OPENTHREAD
case NETOPT_RX_LISTENING:
case NETOPT_RX_LISTENING:
*((bool *)val) = at86rf2xx_receiver_listening(dev) ? true : false;
res = sizeof(bool);
break;
break;
#endif
default:
res = -ENOTSUP;
Expand Down Expand Up @@ -577,12 +578,12 @@ static int _set(netdev2_t *netdev, netopt_t opt, void *val, size_t len)
}
break;

#ifdef MODULE_OPENTHREAD
case NETOPT_RX_LISTENING:
#ifdef MODULE_OPENTHREAD
case NETOPT_RX_LISTENING:
at86rf2xx_set_option(dev, AT86RF2XX_OPT_RX_LISTENING,
((bool *)val)[0]);
res = sizeof(netopt_enable_t);
break;
break;
#endif
default:
break;
Expand Down
26 changes: 13 additions & 13 deletions drivers/include/at86rf2xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,20 @@ extern "C" {
#define AT86RF2XX_OPT_RAWDUMP (NETDEV2_IEEE802154_RAW) /**< legacy define */
#define AT86RF2XX_OPT_AUTOACK (NETDEV2_IEEE802154_ACK_REQ) /**< legacy define */

#define AT86RF2XX_OPT_CSMA (0x0100) /**< CSMA active */
#define AT86RF2XX_OPT_PROMISCUOUS (0x0200) /**< promiscuous mode
* active */
#define AT86RF2XX_OPT_PRELOADING (0x0400) /**< preloading enabled */
#define AT86RF2XX_OPT_TELL_TX_START (0x0800) /**< notify MAC layer on TX
* start */
#define AT86RF2XX_OPT_TELL_TX_END (0x1000) /**< notify MAC layer on TX
* finished */
#define AT86RF2XX_OPT_TELL_RX_START (0x2000) /**< notify MAC layer on RX
* start */
#define AT86RF2XX_OPT_TELL_RX_END (0x4000) /**< notify MAC layer on RX
* finished */
#define AT86RF2XX_OPT_CSMA (0x0100) /**< CSMA active */
#define AT86RF2XX_OPT_PROMISCUOUS (0x0200) /**< promiscuous mode
* active */
#define AT86RF2XX_OPT_PRELOADING (0x0400) /**< preloading enabled */
#define AT86RF2XX_OPT_TELL_TX_START (0x0800) /**< notify MAC layer on TX
* start */
#define AT86RF2XX_OPT_TELL_TX_END (0x1000) /**< notify MAC layer on TX
* finished */
#define AT86RF2XX_OPT_TELL_RX_START (0x2000) /**< notify MAC layer on RX
* start */
#define AT86RF2XX_OPT_TELL_RX_END (0x4000) /**< notify MAC layer on RX
* finished */
#ifdef MODULE_OPENTHREAD
#define AT86RF2XX_OPT_RX_LISTENING (0x8000) /**< detection of reception active */
#define AT86RF2XX_OPT_RX_LISTENING (0x8000) /**< detection of reception active */
#endif
/** @} */

Expand Down
22 changes: 11 additions & 11 deletions drivers/include/net/netdev2.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ enum {
* upper layer
*/
typedef enum {
NETDEV2_EVENT_ISR, /**< driver needs it's ISR handled */
NETDEV2_EVENT_RX_STARTED, /**< started to receive a packet */
NETDEV2_EVENT_RX_COMPLETE, /**< finished receiving a packet */
NETDEV2_EVENT_TX_STARTED, /**< started to transfer a packet */
NETDEV2_EVENT_TX_COMPLETE, /**< finished transferring packet */
NETDEV2_EVENT_ISR, /**< driver needs it's ISR handled */
NETDEV2_EVENT_RX_STARTED, /**< started to receive a packet */
NETDEV2_EVENT_RX_COMPLETE, /**< finished receiving a packet */
NETDEV2_EVENT_TX_STARTED, /**< started to transfer a packet */
NETDEV2_EVENT_TX_COMPLETE, /**< finished transferring packet */
#ifdef MODULE_OPENTHREAD
NETDEV2_EVENT_TX_COMPLETE_DATA_PENDING, /**< finished transferring packet and has data pending flag **/
NETDEV2_EVENT_TX_COMPLETE_DATA_PENDING, /**< finished transferring packet and has data pending flag **/
#endif
NETDEV2_EVENT_TX_NOACK, /**< ACK requested but not received */
NETDEV2_EVENT_TX_MEDIUM_BUSY, /**< couldn't transfer packet */
NETDEV2_EVENT_LINK_UP, /**< link established */
NETDEV2_EVENT_LINK_DOWN, /**< link gone */
NETDEV2_EVENT_TX_NOACK, /**< ACK requested but not received */
NETDEV2_EVENT_TX_MEDIUM_BUSY, /**< couldn't transfer packet */
NETDEV2_EVENT_LINK_UP, /**< link established */
NETDEV2_EVENT_LINK_DOWN, /**< link gone */
/* expand this list if needed */
} netdev2_event_t;

Expand Down Expand Up @@ -118,7 +118,7 @@ typedef void (*netdev2_event_cb_t)(netdev2_t *dev, netdev2_event_t event);
struct netdev2 {
const struct netdev2_driver *driver; /**< ptr to that driver's interface. */
netdev2_event_cb_t event_callback; /**< callback for device events */
void* context; /**< ptr to network stack context */
void *context; /**< ptr to network stack context */
#ifdef MODULE_NETSTATS_L2
netstats_t stats; /**< transceiver's statistics */
#endif
Expand Down
Loading

0 comments on commit d525f20

Please sign in to comment.