Added API for setting 802.15.4 channel and for measuring RSSI

This commit is contained in:
adamdunkels 2007-12-05 13:21:05 +00:00
parent 6a84562e5a
commit d8617c7879
2 changed files with 42 additions and 2 deletions

View file

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: simple-cc2420.c,v 1.15 2007/11/17 10:12:19 adamdunkels Exp $
* @(#)$Id: simple-cc2420.c,v 1.16 2007/12/05 13:21:05 adamdunkels Exp $
*/
/*
* This code is almost device independent and should be easy to port.
@ -356,6 +356,20 @@ simple_cc2420_on(void)
}
/*---------------------------------------------------------------------------*/
void
simple_cc2420_set_channel(int channel)
{
u16_t f = channel;
f = 5 * (f - 11) + 357 + 0x4000;
/*
* Writing RAM requires crystal oscillator to be stable.
*/
while(!(status() & (BV(CC2420_XOSC16M_STABLE))));
setreg(CC2420_FSCTRL, f);
}
/*---------------------------------------------------------------------------*/
void
simple_cc2420_set_chan_pan_addr(unsigned channel, /* 11 - 26 */
unsigned pan,
unsigned addr,
@ -525,3 +539,25 @@ simple_cc2420_set_txpower(u8_t power)
RELEASE_LOCK();
}
/*---------------------------------------------------------------------------*/
int
simple_cc2420_rssi(void)
{
int rssi;
int radio_was_off = 0;
if(!receive_on) {
radio_was_off = 1;
simple_cc2420_on();
}
while(!(status() & BV(CC2420_RSSI_VALID))) {
/* printf("simple_cc2420_rssi: RSSI not valid.\n");*/
}
rssi = (int)((signed char)getreg(CC2420_RSSI));
if(radio_was_off) {
simple_cc2420_off();
}
return rssi;
}
/*---------------------------------------------------------------------------*/

View file

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: simple-cc2420.h,v 1.4 2007/05/25 08:06:15 adamdunkels Exp $
* $Id: simple-cc2420.h,v 1.5 2007/12/05 13:21:05 adamdunkels Exp $
*/
/**
@ -48,6 +48,8 @@ void simple_cc2420_init(void);
#define SIMPLE_CC2420_MAX_PACKET_LEN 127
void simple_cc2420_set_channel(int channel);
void simple_cc2420_set_chan_pan_addr(unsigned channel, /* 11 - 26 */
unsigned pan,
unsigned addr,
@ -56,6 +58,8 @@ void simple_cc2420_set_chan_pan_addr(unsigned channel, /* 11 - 26 */
extern signed char simple_cc2420_last_rssi;
extern u8_t simple_cc2420_last_correlation;
int simple_cc2420_rssi(void);
extern const struct radio_driver simple_cc2420_driver;
/**