CC2520: Added offset to calculate correct RSSI value
This commit is contained in:
parent
6947fc7381
commit
25dea7264a
|
@ -55,6 +55,13 @@
|
||||||
#define FOOTER1_CRC_OK 0x80
|
#define FOOTER1_CRC_OK 0x80
|
||||||
#define FOOTER1_CORRELATION 0x7f
|
#define FOOTER1_CORRELATION 0x7f
|
||||||
|
|
||||||
|
#ifdef CC2520_CONF_RSSI_OFFSET
|
||||||
|
#define RSSI_OFFSET CC2520_CONF_RSSI_OFFSET
|
||||||
|
#else /* CC2520_CONF_RSSI_OFFSET */
|
||||||
|
/* The RSSI_OFFSET is approximate 76 (see CC2520 specification) */
|
||||||
|
#define RSSI_OFFSET 76
|
||||||
|
#endif /* CC2520_CONF_RSSI_OFFSET */
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
@ -97,7 +104,6 @@ static volatile uint16_t last_packet_timestamp;
|
||||||
PROCESS(cc2520_process, "CC2520 driver");
|
PROCESS(cc2520_process, "CC2520 driver");
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
int cc2520_on(void);
|
int cc2520_on(void);
|
||||||
int cc2520_off(void);
|
int cc2520_off(void);
|
||||||
|
|
||||||
|
@ -141,7 +147,6 @@ get_value(radio_param_t param, radio_value_t *value)
|
||||||
return RADIO_RESULT_NOT_SUPPORTED;
|
return RADIO_RESULT_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static radio_result_t
|
static radio_result_t
|
||||||
set_value(radio_param_t param, radio_value_t value)
|
set_value(radio_param_t param, radio_value_t value)
|
||||||
{
|
{
|
||||||
|
@ -166,19 +171,16 @@ set_value(radio_param_t param, radio_value_t value)
|
||||||
return RADIO_RESULT_NOT_SUPPORTED;
|
return RADIO_RESULT_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static radio_result_t
|
static radio_result_t
|
||||||
get_object(radio_param_t param, void *dest, size_t size)
|
get_object(radio_param_t param, void *dest, size_t size)
|
||||||
{
|
{
|
||||||
return RADIO_RESULT_NOT_SUPPORTED;
|
return RADIO_RESULT_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
static radio_result_t
|
static radio_result_t
|
||||||
set_object(radio_param_t param, const void *src, size_t size)
|
set_object(radio_param_t param, const void *src, size_t size)
|
||||||
{
|
{
|
||||||
return RADIO_RESULT_NOT_SUPPORTED;
|
return RADIO_RESULT_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct radio_driver cc2520_driver =
|
const struct radio_driver cc2520_driver =
|
||||||
{
|
{
|
||||||
cc2520_init,
|
cc2520_init,
|
||||||
|
@ -269,7 +271,9 @@ off(void)
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
#define GET_LOCK() locked++
|
#define GET_LOCK() locked++
|
||||||
static void RELEASE_LOCK(void) {
|
static void
|
||||||
|
RELEASE_LOCK(void)
|
||||||
|
{
|
||||||
if(locked == 1) {
|
if(locked == 1) {
|
||||||
if(lock_on) {
|
if(lock_on) {
|
||||||
on();
|
on();
|
||||||
|
@ -340,7 +344,7 @@ cc2520_init(void)
|
||||||
/* correlation threshold = 20, RX bandpass filter = 1.3uA.*/
|
/* correlation threshold = 20, RX bandpass filter = 1.3uA.*/
|
||||||
|
|
||||||
setreg(CC2520_TXCTRL, 0x94);
|
setreg(CC2520_TXCTRL, 0x94);
|
||||||
setreg(CC2520_TXPOWER, 0x13); // Output power 1 dBm
|
setreg(CC2520_TXPOWER, 0x13); /* Output power 1 dBm */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
@ -357,21 +361,21 @@ cc2520_init(void)
|
||||||
0xF2 -> 3 dBm
|
0xF2 -> 3 dBm
|
||||||
0xF7 -> 5 dBm
|
0xF7 -> 5 dBm
|
||||||
*/
|
*/
|
||||||
setreg(CC2520_CCACTRL0, 0xF8); // CCA treshold -80dBm
|
setreg(CC2520_CCACTRL0, 0xF8); /* CCA treshold -80dBm */
|
||||||
|
|
||||||
// Recommended RX settings
|
/* Recommended RX settings */
|
||||||
setreg(CC2520_MDMCTRL0, 0x84); // Controls modem
|
setreg(CC2520_MDMCTRL0, 0x84); /* Controls modem */
|
||||||
setreg(CC2520_MDMCTRL1, 0x14); // Controls modem
|
setreg(CC2520_MDMCTRL1, 0x14); /* Controls modem */
|
||||||
setreg(CC2520_RXCTRL, 0x3F); // Adjust currents in RX related analog modules
|
setreg(CC2520_RXCTRL, 0x3F); /* Adjust currents in RX related analog modules */
|
||||||
setreg(CC2520_FSCTRL, 0x5A); // Adjust currents in synthesizer.
|
setreg(CC2520_FSCTRL, 0x5A); /* Adjust currents in synthesizer. */
|
||||||
setreg(CC2520_FSCAL1, 0x2B); // Adjust currents in VCO
|
setreg(CC2520_FSCAL1, 0x2B); /* Adjust currents in VCO */
|
||||||
setreg(CC2520_AGCCTRL1, 0x11); // Adjust target value for AGC control loop
|
setreg(CC2520_AGCCTRL1, 0x11); /* Adjust target value for AGC control loop */
|
||||||
setreg(CC2520_AGCCTRL2, 0xEB);
|
setreg(CC2520_AGCCTRL2, 0xEB);
|
||||||
|
|
||||||
// Disable external clock
|
/* Disable external clock */
|
||||||
setreg(CC2520_EXTCLOCK, 0x00);
|
setreg(CC2520_EXTCLOCK, 0x00);
|
||||||
|
|
||||||
// Tune ADC performance
|
/* Tune ADC performance */
|
||||||
setreg(CC2520_ADCTEST0, 0x10);
|
setreg(CC2520_ADCTEST0, 0x10);
|
||||||
setreg(CC2520_ADCTEST1, 0x0E);
|
setreg(CC2520_ADCTEST1, 0x0E);
|
||||||
setreg(CC2520_ADCTEST2, 0x03);
|
setreg(CC2520_ADCTEST2, 0x03);
|
||||||
|
@ -462,7 +466,7 @@ cc2520_transmit(unsigned short payload_len)
|
||||||
ENERGEST_ON(ENERGEST_TYPE_TRANSMIT);
|
ENERGEST_ON(ENERGEST_TYPE_TRANSMIT);
|
||||||
/* We wait until transmission has ended so that we get an
|
/* We wait until transmission has ended so that we get an
|
||||||
accurate measurement of the transmission time.*/
|
accurate measurement of the transmission time.*/
|
||||||
//BUSYWAIT_UNTIL(getreg(CC2520_EXCFLAG0) & TX_FRM_DONE , RTIMER_SECOND / 100);
|
/* BUSYWAIT_UNTIL(getreg(CC2520_EXCFLAG0) & TX_FRM_DONE , RTIMER_SECOND / 100); */
|
||||||
BUSYWAIT_UNTIL(!(status() & BV(CC2520_TX_ACTIVE)), RTIMER_SECOND / 10);
|
BUSYWAIT_UNTIL(!(status() & BV(CC2520_TX_ACTIVE)), RTIMER_SECOND / 10);
|
||||||
|
|
||||||
#ifdef ENERGEST_CONF_LEVELDEVICE_LEVELS
|
#ifdef ENERGEST_CONF_LEVELDEVICE_LEVELS
|
||||||
|
@ -641,14 +645,13 @@ cc2520_set_pan_addr(unsigned pan,
|
||||||
tmp[1] = pan >> 8;
|
tmp[1] = pan >> 8;
|
||||||
CC2520_WRITE_RAM(&tmp, CC2520RAM_PANID, 2);
|
CC2520_WRITE_RAM(&tmp, CC2520RAM_PANID, 2);
|
||||||
|
|
||||||
|
|
||||||
tmp[0] = addr & 0xff;
|
tmp[0] = addr & 0xff;
|
||||||
tmp[1] = addr >> 8;
|
tmp[1] = addr >> 8;
|
||||||
CC2520_WRITE_RAM(&tmp, CC2520RAM_SHORTADDR, 2);
|
CC2520_WRITE_RAM(&tmp, CC2520RAM_SHORTADDR, 2);
|
||||||
if(ieee_addr != NULL) {
|
if(ieee_addr != NULL) {
|
||||||
int f;
|
int f;
|
||||||
uint8_t tmp_addr[8];
|
uint8_t tmp_addr[8];
|
||||||
// LSB first, MSB last for 802.15.4 addresses in CC2520
|
/* LSB first, MSB last for 802.15.4 addresses in CC2520 */
|
||||||
for(f = 0; f < 8; f++) {
|
for(f = 0; f < 8; f++) {
|
||||||
tmp_addr[7 - f] = ieee_addr[f];
|
tmp_addr[7 - f] = ieee_addr[f];
|
||||||
}
|
}
|
||||||
|
@ -737,15 +740,13 @@ cc2520_read(void *buf, unsigned short bufsize)
|
||||||
getrxdata(footer, FOOTER_LEN);
|
getrxdata(footer, FOOTER_LEN);
|
||||||
|
|
||||||
if(footer[1] & FOOTER1_CRC_OK) {
|
if(footer[1] & FOOTER1_CRC_OK) {
|
||||||
cc2520_last_rssi = footer[0];
|
cc2520_last_rssi = footer[0] - RSSI_OFFSET;
|
||||||
cc2520_last_correlation = footer[1] & FOOTER1_CORRELATION;
|
cc2520_last_correlation = footer[1] & FOOTER1_CORRELATION;
|
||||||
|
|
||||||
|
|
||||||
packetbuf_set_attr(PACKETBUF_ATTR_RSSI, cc2520_last_rssi);
|
packetbuf_set_attr(PACKETBUF_ATTR_RSSI, cc2520_last_rssi);
|
||||||
packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, cc2520_last_correlation);
|
packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, cc2520_last_correlation);
|
||||||
|
|
||||||
RIMESTATS_ADD(llrx);
|
RIMESTATS_ADD(llrx);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
RIMESTATS_ADD(badcrc);
|
RIMESTATS_ADD(badcrc);
|
||||||
len = FOOTER_LEN;
|
len = FOOTER_LEN;
|
||||||
|
@ -809,6 +810,7 @@ cc2520_rssi(void)
|
||||||
BUSYWAIT_UNTIL(status() & BV(CC2520_RSSI_VALID), RTIMER_SECOND / 100);
|
BUSYWAIT_UNTIL(status() & BV(CC2520_RSSI_VALID), RTIMER_SECOND / 100);
|
||||||
|
|
||||||
rssi = (int)((signed char)getreg(CC2520_RSSI));
|
rssi = (int)((signed char)getreg(CC2520_RSSI));
|
||||||
|
rssi -= RSSI_OFFSET;
|
||||||
|
|
||||||
if(radio_was_off) {
|
if(radio_was_off) {
|
||||||
cc2520_off();
|
cc2520_off();
|
||||||
|
|
Loading…
Reference in a new issue