1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #6895 from bergzand/drivers/radio-rssi-conv

drivers/radios Apply register to rssi dBm conversion to all radios
This commit is contained in:
Martine Lenders 2017-11-27 23:52:15 +01:00 committed by GitHub
commit a63bb6d47b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 90 additions and 45 deletions

View File

@ -164,15 +164,17 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
(void)tmp;
if (info != NULL) {
uint8_t rssi = 0;
netdev_ieee802154_rx_info_t *radio_info = info;
at86rf2xx_fb_read(dev, &(radio_info->lqi), 1);
#ifndef MODULE_AT86RF231
at86rf2xx_fb_read(dev, &(radio_info->rssi), 1);
at86rf2xx_fb_read(dev, &(rssi), 1);
at86rf2xx_fb_stop(dev);
#else
at86rf2xx_fb_stop(dev);
radio_info->rssi = at86rf2xx_reg_read(dev, AT86RF2XX_REG__PHY_ED_LEVEL);
rssi = at86rf2xx_reg_read(dev, AT86RF2XX_REG__PHY_ED_LEVEL);
#endif
radio_info->rssi = RSSI_BASE_VAL + rssi;
}
else {
at86rf2xx_fb_stop(dev);

View File

@ -27,6 +27,7 @@
#include "cc110x-netdev.h"
#include "cc110x-internal.h"
#include "cc110x-interface.h"
#include "cc110x-defines.h"
#include "net/eui64.h"
#include "periph/gpio.h"
@ -61,7 +62,7 @@ static int _recv(netdev_t *dev, void *buf, size_t len, void *info)
if (info != NULL) {
netdev_cc110x_rx_info_t *cc110x_info = info;
cc110x_info->rssi = cc110x->pkt_buf.rssi;
cc110x_info->rssi = (int16_t)cc110x->pkt_buf.rssi/2 - CC110X_RSSI_OFFSET;
cc110x_info->lqi = cc110x->pkt_buf.lqi;
}
return cc110x_pkt->length;

View File

@ -34,6 +34,15 @@ extern "C" {
*/
#define VARIABLE_PKTLEN (0x01)
/**
* @brief RSSI calculation offset.
*
* The cc1101 has 74 as a RSSI offset. The CC1100E has a
* slightly larger offset of 75 to 79 (not implemented here).
* With those devices we thus get a slightly optimistic result.
*/
#define CC110X_RSSI_OFFSET (74)
/**
* @name Bitmasks for reading out status register values
* @{

View File

@ -197,8 +197,8 @@ int cc2420_rx(cc2420_t *dev, uint8_t *buf, size_t max_len, void *info)
DEBUG("cc2420: recv: reading %i byte of the packet\n", (int)len);
cc2420_fifo_read(dev, buf, len);
uint8_t rssi;
cc2420_fifo_read(dev, &rssi, 1);
int8_t rssi;
cc2420_fifo_read(dev, (uint8_t*)&rssi, 1);
DEBUG("cc2420: recv: RSSI is %i\n", (int)rssi);
/* fetch and check if CRC_OK bit (MSB) is set */
@ -208,6 +208,11 @@ int cc2420_rx(cc2420_t *dev, uint8_t *buf, size_t max_len, void *info)
/* drop the corrupted frame from the RXFIFO */
len = 0;
}
if (info != NULL) {
netdev_ieee802154_rx_info_t *radio_info = info;
radio_info->rssi = CC2420_RSSI_OFFSET + rssi;
radio_info->lqi = crc_corr & CC2420_CRCCOR_COR_MASK;
}
/* finally flush the FIFO */
cc2420_strobe(dev, CC2420_STROBE_FLUSHRX);

View File

@ -190,6 +190,14 @@ enum {
#define CC2420_MDMCTRL0_PREAMBLE_3B (0x0002)
/** @} */
/**
* @brief CRC/Correlation bit masks
* @{
*/
#define CC2420_CRCCOR_CRC_MASK (0x80)
#define CC2420_CRCCOR_COR_MASK (0x7F)
/** @} */
/**
* @name Transmit control register bitfields
* @{

View File

@ -61,6 +61,11 @@ extern "C" {
#define CC2420_TXPOWER_DEFAULT (IEEE802154_DEFAULT_TXPOWER)
/** @} */
/**
* @brief RSSI offset
*/
#define CC2420_RSSI_OFFSET (-45)
/**
* @brief A couple of return values used in this driver
*/

View File

@ -368,6 +368,14 @@ void mrf24j40_reset_state_machine(mrf24j40_t *dev);
*/
void mrf24j40_software_reset(mrf24j40_t *dev);
/**
* @brief Convert scalar from mrf24j40 RSSI to dBm
*
* @param[in] value value to convert to dBm
* @return converted value in dBm
*/
int8_t mrf24j40_dbm_from_reg(uint8_t value);
/**
* @brief Prepare for sending of data
*

View File

@ -246,7 +246,7 @@ typedef enum {
* May be different for certain radios.
*/
struct netdev_radio_rx_info {
uint8_t rssi; /**< RSSI of a received packet */
int16_t rssi; /**< RSSI of a received packet in dBm */
uint8_t lqi; /**< LQI of a received packet */
};

View File

@ -160,7 +160,7 @@ uint8_t kw2xrf_get_cca_mode(kw2xrf_t *dev);
*
* @return deduced RSSI in dBm
*/
uint32_t kw2xrf_get_rssi(uint32_t value);
int16_t kw2xrf_get_rssi(uint32_t value);
/**
* @brief Get state of a given device

View File

@ -346,7 +346,7 @@ uint8_t kw2xrf_get_cca_mode(kw2xrf_t *dev)
return (tmp & MKW2XDM_PHY_CTRL4_CCATYPE_MASK) >> MKW2XDM_PHY_CTRL4_CCATYPE_SHIFT;
}
uint32_t kw2xrf_get_rssi(uint32_t value)
int16_t kw2xrf_get_rssi(uint32_t value)
{
/* Get rssi (Received Signal Strength Indicator, unit is dBm)
* from lqi (Link Quality Indicator) value.
@ -361,7 +361,7 @@ uint32_t kw2xrf_get_rssi(uint32_t value)
*/
uint32_t a = (uint32_t)(295.4 * 65536 / 2.84);
uint32_t b = (uint32_t)(65536 / 2.84);
return (a - (b * value)) >> 16;
return ((b * value) - a) >> 16;
}
void kw2xrf_set_option(kw2xrf_t *dev, uint16_t option, bool state)

View File

@ -169,7 +169,7 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
if (info != NULL) {
netdev_ieee802154_rx_info_t *radio_info = info;
radio_info->lqi = ((uint8_t*)buf)[pkt_len];
radio_info->rssi = (uint8_t)kw2xrf_get_rssi(radio_info->lqi);
radio_info->rssi = kw2xrf_get_rssi(radio_info->lqi);
}
/* skip FCS and LQI */

View File

@ -74,38 +74,38 @@ static const uint8_t dbm_to_tx_pow[] = { 0x00, 0x10, 0x18, 0x20, 0x28, 0x30, 0x3
0xc0, 0xd0, 0xd8, 0xe0, 0xe8, 0xf0, 0xf8 };
/* take a look onto datasheet table 3-8 */
static const int8_t dBm_value[] = { 95, 89, 88, 88, 87, 87, 87, 87, \
86, 86, 86, 86, 85, 85, 85, 85, \
84, 84, 84, 84, 84, 84, 83, 83, \
83, 83, 82, 82, 82, 82, 81, 81, \
81, 81, 81, 80, 80, 80, 80, 80, \
80, 79, 79, 79, 79, 79, 78, 78, \
78, 78, 78, 77, 77, 77, 77, 77, \
76, 76, 76, 76, 76, 75, 75, 75, \
75, 75, 75, 74, 74, 74, 74, 73, \
73, 73, 73, 73, 72, 72, 72, 72, \
72, 71, 71, 71, 71, 71, 70, 70, \
70, 70, 70, 70, 70, 69, 69, 69, \
69, 69, 68, 68, 68, 68, 68, 68, \
68, 67, 67, 67, 67, 66, 66, 66, \
66, 66, 66, 65, 65, 65, 65, 65, \
64, 64, 64, 64, 63, 63, 63, 63, \
62, 62, 62, 62, 61, 61, 61, 61, \
60, 60, 60, 60, 60, 59, 59, 59, \
59, 59, 58, 58, 58, 58, 58, 57, \
57, 57, 57, 57, 57, 56, 56, 56, \
56, 56, 56, 56, 55, 55, 55, 55, \
54, 54, 54, 54, 54, 54, 53, 53, \
53, 53, 53, 53, 53, 52, 52, 52, \
52, 52, 52, 51, 51, 51, 51, 51, \
50, 50, 50, 50, 50, 49, 49, 49, \
49, 49, 48, 48, 48, 48, 47, 47, \
47, 47, 47, 46, 46, 46, 46, 45, \
45, 45, 45, 44, 44, 44, 44, 44, \
43, 43, 43, 42, 42, 42, 42, 41, \
41, 41, 41, 41, 41, 40, 40, 40, \
40, 40, 39, 39, 39, 39, 39, 38, \
38, 38, 38, 37, 37, 37, 36, 30 };
static const int8_t dBm_value[] = { -90, -89, -88, -88, -87, -87, -87, -87, \
-86, -86, -86, -86, -85, -85, -85, -85, \
-84, -84, -84, -84, -84, -84, -83, -83, \
-83, -83, -82, -82, -82, -82, -81, -81, \
-81, -81, -81, -80, -80, -80, -80, -80, \
-80, -79, -79, -79, -79, -79, -78, -78, \
-78, -78, -78, -77, -77, -77, -77, -77, \
-76, -76, -76, -76, -76, -75, -75, -75, \
-75, -75, -75, -74, -74, -74, -74, -73, \
-73, -73, -73, -73, -72, -72, -72, -72, \
-72, -71, -71, -71, -71, -71, -70, -70, \
-70, -70, -70, -70, -70, -69, -69, -69, \
-69, -69, -68, -68, -68, -68, -68, -68, \
-68, -67, -67, -67, -67, -66, -66, -66, \
-66, -66, -66, -65, -65, -65, -65, -65, \
-64, -64, -64, -64, -63, -63, -63, -63, \
-62, -62, -62, -62, -61, -61, -61, -61, \
-60, -60, -60, -60, -60, -59, -59, -59, \
-59, -59, -58, -58, -58, -58, -58, -57, \
-57, -57, -57, -57, -57, -56, -56, -56, \
-56, -56, -56, -56, -55, -55, -55, -55, \
-54, -54, -54, -54, -54, -54, -53, -53, \
-53, -53, -53, -53, -53, -52, -52, -52, \
-52, -52, -52, -51, -51, -51, -51, -51, \
-50, -50, -50, -50, -50, -49, -49, -49, \
-49, -49, -48, -48, -48, -48, -47, -47, \
-47, -47, -47, -46, -46, -46, -46, -45, \
-45, -45, -45, -44, -44, -44, -44, -44, \
-43, -43, -43, -42, -42, -42, -42, -41, \
-41, -41, -41, -41, -41, -40, -40, -40, \
-40, -40, -39, -39, -39, -39, -39, -38, \
-38, -38, -38, -37, -37, -37, -36, -35 };
/* take a look onto datasheet table 3-8 */
static const uint8_t RSSI_value[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
@ -488,3 +488,8 @@ void mrf24j40_software_reset(mrf24j40_t *dev)
softrst = mrf24j40_reg_read_short(dev, MRF24J40_REG_SOFTRST);
} while (softrst != 0); /* wait until soft-reset has finished */
}
int8_t mrf24j40_dbm_from_reg(uint8_t value)
{
return dBm_value[value];
}

View File

@ -156,9 +156,11 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
if (info != NULL) {
netdev_ieee802154_rx_info_t *radio_info = info;
uint8_t rssi_scalar = 0;
/* Read LQI and RSSI values from the RX fifo */
mrf24j40_rx_fifo_read(dev, phr + 1, &(radio_info->lqi), 1);
mrf24j40_rx_fifo_read(dev, phr + 2, &(radio_info->rssi), 1);
mrf24j40_rx_fifo_read(dev, phr + 2, &(rssi_scalar), 1);
radio_info->rssi = mrf24j40_dbm_from_reg(rssi_scalar);
}
/* Turn on reception of packets off the air */

View File

@ -85,7 +85,7 @@ typedef struct {
uint8_t dst_l2addr_len; /**< length of l2 destination address in byte */
kernel_pid_t if_pid; /**< PID of network interface */
uint8_t flags; /**< flags as defined above */
uint8_t rssi; /**< rssi of received packet (optional) */
int16_t rssi; /**< rssi of received packet in dBm (optional) */
uint8_t lqi; /**< lqi of received packet (optional) */
} gnrc_netif_hdr_t;

View File

@ -23,7 +23,7 @@ void gnrc_netif_hdr_print(gnrc_netif_hdr_t *hdr)
char addr_str[GNRC_NETIF_HDR_L2ADDR_PRINT_LEN];
printf("if_pid: %u ", (unsigned) hdr->if_pid);
printf("rssi: %u ", (unsigned) hdr->rssi);
printf("rssi: %d ", (signed) hdr->rssi);
printf("lqi: %u\n", (unsigned) hdr->lqi);
printf("flags: ");