Add configurable auto cca threshold and implement driver cca call.

Show smallest rssi in jackdaw menu.
This commit is contained in:
dak664 2011-03-21 11:10:30 -04:00
parent d8d94d0cd8
commit 5dd7500d0b
5 changed files with 53 additions and 11 deletions

View File

@ -73,6 +73,12 @@
#define RG_CSMA_BE CSMA_BE
#define RG_CSMA_SEED_0 CSMA_SEED_0
#define RG_PHY_RSSI PHY_RSSI
#define SR_CCA_MODE 0x08, 0x60, 5
//#define SR_CCA_CS_THRES 0x09, 0xf0, 4
#define SR_CCA_ED_THRES 0x09, 0x0f, 0
#define SR_CCA_REQUEST 0x08, 0x80, 7
#define SR_CCA_DONE 0x01, 0x80, 7
#define SR_CCA_STATUS 0x01, 0x40, 6
/* RF230 register assignments, for reference */

View File

@ -209,8 +209,7 @@ static int rf230_receiving_packet(void);
static int pending_packet(void);
static int rf230_cca(void);
signed char rf230_last_rssi;
uint8_t rf230_last_correlation;
uint8_t rf230_last_correlation,rf230_last_rssi,rf230_smallest_rssi;
const struct radio_driver rf230_driver =
{
@ -714,6 +713,24 @@ rf230_init(void)
hal_register_write(RG_CSMA_SEED_0,hal_register_read(RG_PHY_RSSI) );//upper two RSSI reg bits RND_VALUE are random in rf231
// hal_register_write(CSMA_SEED_1,42 );
/* CCA Mode Mode 1=Energy above threshold 2=Carrier sense only 3=Both 0=Either (RF231 only) */
//hal_subregister_write(SR_CCA_MODE,1); //1 is the power-on default
/* Carrier sense threshold (not implemented in RF230 or RF231) */
// hal_subregister_write(SR_CCA_CS_THRES,1);
/* CCA energy threshold = -91dB + 2*SR_CCA_ED_THRESH. Reset defaults to -77dB */
/* Use RF230 base of -91; RF231 base is -90 according to datasheet */
#if RF230_CONF_CCA_THRES < -91
#warning RF230_CONF_CCA_THRES below hardware limit, setting to -91dBm
hal_subregister_write(SR_CCA_ED_THRES,0);
#elif RF230_CONF_CCA_THRES > -61
#warning RF230_CONF_CCA_THRES above hardware limit, setting to -61dBm
hal_subregister_write(SR_CCA_ED_THRES,15);
#else
hal_subregister_write(SR_CCA_ED_THRES,(RF230_CONF_CCA_THRES+91)/2);
#endif
/* Use automatic CRC unless manual is specified */
#if RF230_CONF_CHECKSUM
hal_subregister_write(SR_TX_AUTO_CRC_ON, 0);
@ -883,7 +900,6 @@ rf230_transmit(unsigned short payload_len)
}
RELEASE_LOCK();
if (tx_result==1) { //success, data pending from adressee
tx_result=0; //Just show success?
} else if (tx_result==3) { //CSMA channel access failure
@ -1332,6 +1348,10 @@ if (RF230_receive_on) {
#endif
#endif /* speed vs. generality */
/* Save the smallest rssi. The display routine can reset by setting it to zero */
if ((rf230_smallest_rssi==0) || (rf230_last_rssi<rf230_smallest_rssi))
rf230_smallest_rssi=rf230_last_rssi;
// rf230_last_correlation = rxframe[rxframe_head].lqi;
packetbuf_set_attr(PACKETBUF_ATTR_RSSI, rf230_last_rssi);
packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, rf230_last_correlation);
@ -1451,10 +1471,18 @@ rf230_cca(void)
rf230_on();
}
// cca = CCA_IS_1;
DEBUGFLOW('c');
cca=1;
/* CCA Mode Mode 1=Energy above threshold 2=Carrier sense only 3=Both 0=Either (RF231 only) */
/* Use the current mode. Note triggering a manual CCA is not recommended in extended mode */
//hal_subregister_write(SR_CCA_MODE,1);
/* Start the CCA, wait till done, return result */
hal_subregister_write(SR_CCA_REQUEST,1);
delay_us(TIME_CCA);
//while ((hal_register_read(RG_TRX_STATUS) & 0x80) == 0 ) {continue;}
while (!hal_subregister_read(SR_CCA_DONE)) {continue;}
cca=hal_subregister_read(SR_CCA_STATUS);
if(radio_was_off) {
rf230_off();
}
@ -1481,4 +1509,3 @@ pending_packet(void)
return pending;
}
/*---------------------------------------------------------------------------*/

View File

@ -214,8 +214,7 @@ uint8_t rf230_get_txpower(void);
void rf230_set_promiscuous_mode(bool isPromiscuous);
bool rf230_is_ready_to_send();
extern signed char rf230_last_rssi;
extern uint8_t rf230_last_correlation;
extern uint8_t rf230_last_correlation,rf230_last_rssi,rf230_smallest_rssi;
uint8_t rf230_get_raw_rssi(void);
@ -223,4 +222,4 @@ uint8_t rf230_get_raw_rssi(void);
#endif
/** @} */
/*EOF*/
/*EOF*/

View File

@ -562,7 +562,12 @@ extern uip_ds6_netif_t uip_ds6_if;
PRINTF_P(PSTR(" * Operates on channel %d\n\r"), rf230_get_channel());
PRINTF_P(PSTR(" * TX Power(0=3dBm, 15=-17.2dBm): %d\n\r"), rf230_get_txpower());
#endif
PRINTF_P(PSTR(" * Current/Last RSSI: %d/%ddBm\n\r"), -91+(rf230_rssi()-1), -91+(rf230_last_rssi-1));
if (rf230_smallest_rssi) {
PRINTF_P(PSTR(" * Current/Last/Smallest RSSI: %d/%d/%ddBm\n\r"), -91+(rf230_rssi()-1), -91+(rf230_last_rssi-1),-91+(rf230_smallest_rssi-1));
rf230_smallest_rssi=0;
} else {
PRINTF_P(PSTR(" * Current/Last/Smallest RSSI: %d/%d/--dBm\n\r"), -91+(rf230_rssi()-1), -91+(rf230_last_rssi-1));
}
#else /* RF230BB */
PRINTF_P(PSTR(" * Operates on channel %d\n\r"), radio_get_operating_channel());

View File

@ -266,11 +266,16 @@ extern void mac_log_802_15_4_rx(const uint8_t* buffer, size_t total_len);
/* AUTOACK receive mode gives better rssi measurements, even if ACK is never requested */
#define RF230_CONF_AUTOACK 1
/* Request 802.15.4 ACK on all packets sent by sicslowpan.c (else autoretry) */
/* Broadcasts will be duplicated by the retry count! */
/* Broadcasts will be duplicated by the retry count, since no one will ACK them! */
#define SICSLOWPAN_CONF_ACK_ALL 0
/* Number of auto retry attempts 0-15 (0 implies don't use extended TX_ARET_ON mode with CCA) */
#define RF230_CONF_AUTORETRIES 1
/* CCA theshold energy -91 to -61 dBm (default -77). Set this smaller than the expected minimum rssi to avoid packet collisions */
/* The Jackdaw menu 'm' command is helpful for determining the smallest ever received rssi */
#define RF230_CONF_CCA_THRES -85
/* Allow 6loWPAN fragmentation (more efficient for large payloads over a reliable channel) */
#define SICSLOWPAN_CONF_FRAG 1
/* Timeout for fragment reassembly. A reissued browser GET will also cancel reassembly, typically in 2-3 seconds */
#define SICSLOWPAN_CONF_MAXAGE 3
#elif 0 /* Contiki-mac radio cycling */