From a785405b368050210b6de6c998b66da15ac1297d Mon Sep 17 00:00:00 2001 From: Nicolas Tsiftes Date: Thu, 19 Feb 2015 11:26:43 +0100 Subject: [PATCH] Make it possible to set and get the CC2420's CCA threshold through the extended radio API. --- dev/cc2420/cc2420.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/dev/cc2420/cc2420.c b/dev/cc2420/cc2420.c index 1e0ce8c75..970f9dca7 100644 --- a/dev/cc2420/cc2420.c +++ b/dev/cc2420/cc2420.c @@ -152,6 +152,7 @@ static int cc2420_send(const void *data, unsigned short len); static int cc2420_receiving_packet(void); static int pending_packet(void); +static int get_cca_threshold(void); static int cc2420_cca(void); signed char cc2420_last_rssi; @@ -186,6 +187,9 @@ get_value(radio_param_t param, radio_value_t *value) } } return RADIO_RESULT_OK; + case RADIO_PARAM_CCA_THRESHOLD: + *value = get_cca_threshold() + RSSI_OFFSET; + return RADIO_RESULT_OK; case RADIO_PARAM_RSSI: /* Return the RSSI value in dBm */ *value = cc2420_rssi(); @@ -241,6 +245,9 @@ set_value(radio_param_t param, radio_value_t value) } cc2420_set_txpower(output_power[i - 1].config); return RADIO_RESULT_OK; + case RADIO_PARAM_CCA_THRESHOLD: + cc2420_set_cca_threshold(value - RSSI_OFFSET); + return RADIO_RESULT_OK; default: return RADIO_RESULT_NOT_SUPPORTED; } @@ -1033,6 +1040,17 @@ pending_packet(void) return CC2420_FIFOP_IS_1; } /*---------------------------------------------------------------------------*/ +static int +get_cca_threshold(void) +{ + int value; + + GET_LOCK(); + value = (int8_t)(getreg(CC2420_RSSI) >> 8); + RELEASE_LOCK(); + return value; +} +/*---------------------------------------------------------------------------*/ void cc2420_set_cca_threshold(int value) {