From b650f355c7ae38594a66f55cf56073bc5d016537 Mon Sep 17 00:00:00 2001 From: Koen Zandberg Date: Thu, 7 Mar 2019 17:12:15 +0100 Subject: [PATCH] nrf802154: Add rssi/lqi to received frames LQI calculation following the instructions from the datasheet. RSSI calculation appears to only require the offset and not the scaling factor --- cpu/nrf52/radio/nrf802154/nrf802154.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cpu/nrf52/radio/nrf802154/nrf802154.c b/cpu/nrf52/radio/nrf802154/nrf802154.c index 1a57a87997..4a6a7d080f 100644 --- a/cpu/nrf52/radio/nrf802154/nrf802154.c +++ b/cpu/nrf52/radio/nrf802154/nrf802154.c @@ -60,6 +60,9 @@ netdev_ieee802154_t nrf802154_dev = { static uint8_t rxbuf[IEEE802154_FRAME_LEN_MAX + 3]; /* len PHR + PSDU + LQI */ static uint8_t txbuf[IEEE802154_FRAME_LEN_MAX + 3]; /* len PHR + PSDU + LQI */ +#define ED_RSSISCALE (4U) +#define ED_RSSIOFFS (92U) + #define RX_COMPLETE (0x1) #define TX_COMPLETE (0x2) #define LIFS (40U) @@ -317,6 +320,20 @@ static int _recv(netdev_t *dev, void *buf, size_t len, void *info) else { DEBUG("[nrf802154] recv: reading packet of length %i\n", pktlen); memcpy(buf, &rxbuf[1], pktlen); + if (info != NULL) { + netdev_ieee802154_rx_info_t *radio_info = info; + /* Hardware link quality indicator */ + uint8_t hwlqi = rxbuf[pktlen + 1]; + /* Convert to 802.15.4 LQI (page 319 of product spec v1.1) */ + radio_info->lqi = (uint8_t)(hwlqi > UINT8_MAX/ED_RSSISCALE + ? UINT8_MAX + : hwlqi * ED_RSSISCALE); + /* Calculate RSSI by substracting the offset from the datasheet. + * Intentionally using a different calculation than the one from + * figure 122 of the v1.1 product specification. This appears to + * match real world performance better */ + radio_info->rssi = (int16_t)hwlqi - ED_RSSIOFFS; + } } _reset_rx();