From 9d01fbf7359990549d719569c572232a5cf62c7c Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Tue, 1 Apr 2014 15:42:35 +0200 Subject: [PATCH] Added stub for extended radio API for CC2520 --- dev/cc2520/cc2520.c | 72 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 4 deletions(-) diff --git a/dev/cc2520/cc2520.c b/dev/cc2520/cc2520.c index 561236b08..249bc6ad6 100644 --- a/dev/cc2520/cc2520.c +++ b/dev/cc2520/cc2520.c @@ -115,6 +115,70 @@ static int cc2520_cca(void); signed char cc2520_last_rssi; uint8_t cc2520_last_correlation; +static uint8_t receive_on; +static int channel; + +static radio_result_t +get_value(radio_param_t param, radio_value_t *value) +{ + if(!value) { + return RADIO_RESULT_INVALID_VALUE; + } + switch(param) { + case RADIO_PARAM_POWER_MODE: + *value = receive_on ? RADIO_POWER_MODE_ON : RADIO_POWER_MODE_OFF; + return RADIO_RESULT_OK; + case RADIO_PARAM_CHANNEL: + *value = cc2520_get_channel(); + return RADIO_RESULT_OK; + case RADIO_CONST_CHANNEL_MIN: + *value = 11; + return RADIO_RESULT_OK; + case RADIO_CONST_CHANNEL_MAX: + *value = 26; + return RADIO_RESULT_OK; + default: + return RADIO_RESULT_NOT_SUPPORTED; + } +} + +static radio_result_t +set_value(radio_param_t param, radio_value_t value) +{ + switch(param) { + case RADIO_PARAM_POWER_MODE: + if(value == RADIO_POWER_MODE_ON) { + cc2520_on(); + return RADIO_RESULT_OK; + } + if(value == RADIO_POWER_MODE_OFF) { + cc2520_off(); + return RADIO_RESULT_OK; + } + return RADIO_RESULT_INVALID_VALUE; + case RADIO_PARAM_CHANNEL: + if(value < 11 || value > 26) { + return RADIO_RESULT_INVALID_VALUE; + } + cc2520_set_channel(value); + return RADIO_RESULT_OK; + default: + return RADIO_RESULT_NOT_SUPPORTED; + } +} + +static radio_result_t +get_object(radio_param_t param, void *dest, size_t size) +{ + return RADIO_RESULT_NOT_SUPPORTED; +} + +static radio_result_t +set_object(radio_param_t param, const void *src, size_t size) +{ + return RADIO_RESULT_NOT_SUPPORTED; +} + const struct radio_driver cc2520_driver = { cc2520_init, @@ -129,12 +193,12 @@ const struct radio_driver cc2520_driver = pending_packet, cc2520_on, cc2520_off, + get_value, + set_value, + get_object, + set_object }; -static uint8_t receive_on; - -static int channel; - /*---------------------------------------------------------------------------*/ static void