From d8617c7879e166e141d862cacf6a640717b13d3a Mon Sep 17 00:00:00 2001 From: adamdunkels Date: Wed, 5 Dec 2007 13:21:05 +0000 Subject: [PATCH] Added API for setting 802.15.4 channel and for measuring RSSI --- core/dev/simple-cc2420.c | 38 +++++++++++++++++++++++++++++++++++++- core/dev/simple-cc2420.h | 6 +++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/core/dev/simple-cc2420.c b/core/dev/simple-cc2420.c index 5baa600b9..91fa65fd3 100644 --- a/core/dev/simple-cc2420.c +++ b/core/dev/simple-cc2420.c @@ -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; +} +/*---------------------------------------------------------------------------*/ diff --git a/core/dev/simple-cc2420.h b/core/dev/simple-cc2420.h index 057e2667e..a8f087bba 100644 --- a/core/dev/simple-cc2420.h +++ b/core/dev/simple-cc2420.h @@ -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; /**