Enable RX_START interrupt and read rssi at end of preamble when not using energy detect register

This commit is contained in:
dak664 2010-12-14 22:34:18 +00:00
parent 0a4a0ffb32
commit c784e8bc46
3 changed files with 30 additions and 13 deletions

View File

@ -98,6 +98,7 @@
* \see hal_get_system_time
*/
static uint16_t hal_system_time = 0;
volatile extern signed char rf230_last_rssi;
/*Flag section.*/
//static uint8_t volatile hal_bat_low_flag; /**< BAT_LOW flag. */
@ -751,6 +752,11 @@ HAL_RF230_ISR()
/*Handle the incomming interrupt. Prioritized.*/
if ((interrupt_source & HAL_RX_START_MASK)){
INTERRUPTDEBUG(10);
/* Save RSSI for this packet if not in extended mode, scaling to 1dB resolution (avoiding multiply) */
#if !RF230_CONF_AUTOACK
rf230_last_rssi = hal_subregister_read(SR_RSSI);
rf230_last_rssi = (rf230_last_rssi <<1) + rf230_last_rssi;
#endif
// if(rx_start_callback != NULL){
// /* Read Frame length and call rx_start callback. */
// HAL_SPI_TRANSFER_OPEN();
@ -775,18 +781,14 @@ HAL_RF230_ISR()
/* Buffer the frame and call rf230_interrupt to schedule poll for rf230 receive process */
// if (rxframe.length) break; //toss packet if last one not processed yet
if (rxframe.length) INTERRUPTDEBUG(42); else INTERRUPTDEBUG(12);
#ifdef RF230_MIN_RX_POWER
/* Discard packets weaker than the minimum if defined. This is for testing miniature meshes.*/
/* Save the rssi for printing in the main loop */
volatile extern signed char rf230_last_rssi;
#if RF230_CONF_AUTOACK
rf230_last_rssi=hal_subregister_read(SR_ED_LEVEL);
#endif
if (rf230_last_rssi >= RF230_MIN_RX_POWER) {
#else
rf230_last_rssi=hal_subregister_read(SR_RSSI);
if (rf230_last_rssi >= RF230_MIN_RX_POWER/3) {
#endif
#endif
// hal_frame_read(&rxframe, NULL);
hal_frame_read(&rxframe);

View File

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: rf230bb.c,v 1.17 2010/12/05 17:28:29 dak664 Exp $
* @(#)$Id: rf230bb.c,v 1.18 2010/12/14 22:34:18 dak664 Exp $
*/
/*
* This code is almost device independent and should be easy to port.
@ -106,7 +106,7 @@ struct timestamp {
#if JACKDAW
#define RADIOALWAYSON 1
#else
#define RADIOALWAYSON 1
//#define RADIOALWAYSON 1
#endif
#define DEBUG 0
@ -415,7 +415,10 @@ rf230_set_promiscuous_mode(bool isPromiscuous) {
if(isPromiscuous) {
is_promiscuous = true;
#if RF230_CONF_AUTOACK
/* For now only do promiscuous in Macintosh build */
#if USB_CONF_MACINTOSH
radio_set_trx_state(RX_ON);
#endif
#endif
} else {
is_promiscuous = false;
@ -463,7 +466,12 @@ on(void)
rf230_waitidle();
#if RF230_CONF_AUTOACK
/* For now only do promiscuous on Mac build */
#if USB_CONF_MACINTOSH
radio_set_trx_state(is_promiscuous?RX_ON:RX_AACK_ON);
#else
radio_set_trx_state(RX_AACK_ON);
#endif
#else
radio_set_trx_state(RX_ON);
#endif
@ -563,7 +571,7 @@ rf230_init(void)
PRINTF("rf230: Version %u, ID %u\n",tvers,tmanu);
hal_register_write(RG_IRQ_MASK, RF230_SUPPORTED_INTERRUPT_MASK);
/* Set up number of automatic retries */
/* Set up number of automatic retries 0-15 (0 implies PLL_ON sends instead of the extended TX_ARET mode */
hal_subregister_write(SR_MAX_FRAME_RETRIES, RF230_CONF_AUTORETRIES );
/* Use automatic CRC unless manual is specified */
@ -1124,7 +1132,8 @@ if (RF230_receive_on) {
#if RF230_CONF_AUTOACK
rf230_last_rssi = hal_subregister_read(SR_ED_LEVEL); //0-84 resolution 1 dB
#else
rf230_last_rssi = 3*hal_subregister_read(SR_RSSI); //0-28 resolution 3 dB
/* last_rssi will have been set at RX_START interrupt */
// rf230_last_rssi = 3*hal_subregister_read(SR_RSSI); //0-28 resolution 3 dB
#endif
#endif /* speed vs. generality */
@ -1202,6 +1211,7 @@ rf230_get_txpower(void)
}
return power;
}
/*---------------------------------------------------------------------------*/
uint8_t
rf230_get_raw_rssi(void)
@ -1221,7 +1231,8 @@ rf230_get_raw_rssi(void)
if ((state==RX_AACK_ON) || (state==BUSY_RX_AACK)) {
rssi = hal_subregister_read(SR_ED_LEVEL); //0-84, resolution 1 dB
} else {
rssi = 3*hal_subregister_read(SR_RSSI); //0-28, resolution 3 dB
rssi = hal_subregister_read(SR_RSSI); //0-28, resolution 3 dB
rssi = (rssi << 1) + rssi; //fast multiply by 3
}
if(radio_was_off) {
@ -1229,6 +1240,7 @@ rf230_get_raw_rssi(void)
}
return rssi;
}
/*---------------------------------------------------------------------------*/
static int
rf230_cca(void)

View File

@ -45,7 +45,7 @@
* \file
* \brief This file contains radio driver code.
*
* $Id: rf230bb.h,v 1.4 2010/12/03 20:42:01 dak664 Exp $
* $Id: rf230bb.h,v 1.5 2010/12/14 22:34:18 dak664 Exp $
*/
#ifndef RADIO_H
@ -61,7 +61,10 @@
#define RF230_REVA ( 1 )
#define RF230_REVB ( 2 )
#define SUPPORTED_MANUFACTURER_ID ( 31 )
#define RF230_SUPPORTED_INTERRUPT_MASK ( 0x0C )
/* RF230 does not support RX_START interrupts in extended mode, but it seems harmless to always enable it. */
/* In non-extended mode this allows RX_START to sample the RF rssi at the end of the preamble */
//#define RF230_SUPPORTED_INTERRUPT_MASK ( 0x0C ) //disable RX_START
#define RF230_SUPPORTED_INTERRUPT_MASK ( 0x0F )
#define RF230_MIN_CHANNEL ( 11 )
#define RF230_MAX_CHANNEL ( 26 )