Skip to content

Commit

Permalink
squash kw41zrf get ED level
Browse files Browse the repository at this point in the history
  • Loading branch information
Joakim Nohlgård committed Aug 2, 2017
1 parent cd33649 commit e95005e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions drivers/kw41zrf/include/kw41zrf_getset.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
8 changes: 7 additions & 1 deletion drivers/kw41zrf/kw41zrf_getset.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions drivers/kw41zrf/kw41zrf_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e95005e

Please sign in to comment.