Merge pull request #978 from nvt/cc2420-rf-api

Implement set/get of the CCA threshold for CC2420
This commit is contained in:
George Oikonomou 2015-02-26 14:08:17 +00:00
commit 9fcb7f721f

View File

@ -152,6 +152,7 @@ static int cc2420_send(const void *data, unsigned short len);
static int cc2420_receiving_packet(void); static int cc2420_receiving_packet(void);
static int pending_packet(void); static int pending_packet(void);
static int get_cca_threshold(void);
static int cc2420_cca(void); static int cc2420_cca(void);
signed char cc2420_last_rssi; signed char cc2420_last_rssi;
@ -186,6 +187,9 @@ get_value(radio_param_t param, radio_value_t *value)
} }
} }
return RADIO_RESULT_OK; return RADIO_RESULT_OK;
case RADIO_PARAM_CCA_THRESHOLD:
*value = get_cca_threshold() + RSSI_OFFSET;
return RADIO_RESULT_OK;
case RADIO_PARAM_RSSI: case RADIO_PARAM_RSSI:
/* Return the RSSI value in dBm */ /* Return the RSSI value in dBm */
*value = cc2420_rssi(); *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); cc2420_set_txpower(output_power[i - 1].config);
return RADIO_RESULT_OK; return RADIO_RESULT_OK;
case RADIO_PARAM_CCA_THRESHOLD:
cc2420_set_cca_threshold(value - RSSI_OFFSET);
return RADIO_RESULT_OK;
default: default:
return RADIO_RESULT_NOT_SUPPORTED; return RADIO_RESULT_NOT_SUPPORTED;
} }
@ -1033,6 +1040,17 @@ pending_packet(void)
return CC2420_FIFOP_IS_1; 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 void
cc2420_set_cca_threshold(int value) cc2420_set_cca_threshold(int value)
{ {