From e95005eeb0f02b2664db577266a4be581a79d955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Sat, 3 Jun 2017 06:40:06 +0200 Subject: [PATCH] squash kw41zrf get ED level --- drivers/kw41zrf/include/kw41zrf_getset.h | 8 ++++++++ drivers/kw41zrf/kw41zrf_getset.c | 8 +++++++- drivers/kw41zrf/kw41zrf_netdev.c | 8 ++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/kw41zrf/include/kw41zrf_getset.h b/drivers/kw41zrf/include/kw41zrf_getset.h index b820073460f5f..29ad66b055f71 100644 --- a/drivers/kw41zrf/include/kw41zrf_getset.h +++ b/drivers/kw41zrf/include/kw41zrf_getset.h @@ -158,6 +158,14 @@ void kw41zrf_set_cca_mode(kw41zrf_t *dev, uint8_t mode); */ uint8_t kw41zrf_get_cca_mode(kw41zrf_t *dev); +/** + * @brief Get latest ED measurement from the device + * + * @param[in] dev kw41zrf device descriptor + * @return most recent ED level + */ +int8_t kw41zrf_get_ed_level(kw41zrf_t *dev); + /** * @brief Get state of a given device * diff --git a/drivers/kw41zrf/kw41zrf_getset.c b/drivers/kw41zrf/kw41zrf_getset.c index 8643ba91d8694..ce7b52da13c07 100644 --- a/drivers/kw41zrf/kw41zrf_getset.c +++ b/drivers/kw41zrf/kw41zrf_getset.c @@ -204,6 +204,12 @@ uint8_t kw41zrf_get_cca_mode(kw41zrf_t *dev) return (ZLL->PHY_CTRL & ZLL_PHY_CTRL_CCATYPE_MASK) >> ZLL_PHY_CTRL_CCATYPE_SHIFT; } +int8_t kw41zrf_get_ed_level(kw41zrf_t *dev) +{ + (void) dev; + return (ZLL->LQI_AND_RSSI & ZLL_LQI_AND_RSSI_CCA1_ED_FNL_MASK) >> ZLL_LQI_AND_RSSI_CCA1_ED_FNL_SHIFT; +} + void kw41zrf_set_option(kw41zrf_t *dev, uint16_t option, bool state) { DEBUG("[kw41zrf] set option 0x%04x to %x\n", option, state); @@ -340,7 +346,7 @@ int kw41zrf_cca(kw41zrf_t *dev) * short enough to just spin */ while ((((ZLL->PHY_CTRL & ZLL_PHY_CTRL_XCVSEQ_MASK) >> ZLL_PHY_CTRL_XCVSEQ_SHIFT) == XCVSEQ_CCA) && ((ZLL->SEQ_CTRL_STS & ZLL_SEQ_CTRL_STS_SEQ_IDLE_MASK) == 0)) {} - DEBUG("[kw41zrf] kw41zrf_cca done, RSSI: %d\n", (int8_t)((ZLL->LQI_AND_RSSI & ZLL_LQI_AND_RSSI_CCA1_ED_FNL_MASK) >> ZLL_LQI_AND_RSSI_CCA1_ED_FNL_SHIFT)); + DEBUG("[kw41zrf] kw41zrf_cca done, RSSI: %d\n", kw41zrf_get_ed_level(dev)); if (ZLL->IRQSTS & ZLL_IRQSTS_CCA_MASK) { DEBUG("[kw41zrf] Channel busy\n"); return 1; diff --git a/drivers/kw41zrf/kw41zrf_netdev.c b/drivers/kw41zrf/kw41zrf_netdev.c index 60d8d56cd161f..bb4556ef7eb7e 100644 --- a/drivers/kw41zrf/kw41zrf_netdev.c +++ b/drivers/kw41zrf/kw41zrf_netdev.c @@ -341,6 +341,14 @@ int kw41zrf_netdev_get(netdev_t *netdev, netopt_t opt, void *value, size_t len) } break; + case NETOPT_LAST_ED_LEVEL: + if (len < sizeof(int8_t)) { + return -EOVERFLOW; + } + else { + *(int8_t *)value = kw41zrf_get_ed_level(dev); + } + return sizeof(int8_t); case NETOPT_CHANNEL_PAGE: default: break;