diff --git a/cpu/avr/radio/rf230bb/atmega128rfa1_registermap.h b/cpu/avr/radio/rf230bb/atmega128rfa1_registermap.h index 01444ffbd..986001f6d 100644 --- a/cpu/avr/radio/rf230bb/atmega128rfa1_registermap.h +++ b/cpu/avr/radio/rf230bb/atmega128rfa1_registermap.h @@ -67,6 +67,7 @@ #define RG_IEEE_ADDR_7 IEEE_ADDR_7 //#define SR_ED_LEVEL 0x147, 0xff, 0 #define RG_PHY_ED_LEVEL PHY_ED_LEVEL +#define RG_RX_SYN RX_SYN #define SR_RSSI 0x146, 0x1f, 0 #define SR_PLL_CF_START 0x1a, 0x80, 7 #define SR_PLL_DCU_START 0x1b, 0x80, 7 diff --git a/cpu/avr/radio/rf230bb/halbb.c b/cpu/avr/radio/rf230bb/halbb.c index 67fe835fe..20b236aba 100644 --- a/cpu/avr/radio/rf230bb/halbb.c +++ b/cpu/avr/radio/rf230bb/halbb.c @@ -871,7 +871,7 @@ ISR(TRX24_PLL_UNLOCK_vect) DEBUGFLOW('5'); } /* Flag is set by the following interrupts */ -extern volatile uint8_t rf230_interruptwait; +extern volatile uint8_t rf230_interruptwait,rf230_ccawait; /* Wake has finished */ ISR(TRX24_AWAKE_vect) @@ -899,7 +899,7 @@ ISR(TRX24_XAH_AMI_vect) ISR(TRX24_CCA_ED_DONE_vect) { DEBUGFLOW('4'); - rf230_interruptwait=0; + rf230_ccawait=0; } #else /* defined(__AVR_ATmega128RFA1__) */ diff --git a/cpu/avr/radio/rf230bb/rf230bb.c b/cpu/avr/radio/rf230bb/rf230bb.c index 0ac1f91d8..27d75a779 100644 --- a/cpu/avr/radio/rf230bb/rf230bb.c +++ b/cpu/avr/radio/rf230bb/rf230bb.c @@ -28,7 +28,6 @@ * * This file is part of the Contiki operating system. * - * @(#)$Id: rf230bb.c,v 1.24 2010/12/22 20:10:00 dak664 Exp $ */ /* * This code is almost device independent and should be easy to port. @@ -98,6 +97,19 @@ static bool is_promiscuous; #define RF230_CONF_AUTORETRIES 3 #endif +/* In extended mode (AUTORETRIES>0) the tx routine waits for hardware + * processing of an expected ACK and returns RADIO_TX_OK/NOACK result. + * In non-extended mode the ACK is treated as a normal rx packet. + * If the caller needs the ACK to be returned as an rx packet, + * RF230_INSERTACK will generate one based on the hardware result. + * This is triggered when the read routine is called with a buffer + * length of three (the ack length). + */ +#if RF320_CONF_INSERTACK && RF230_CONF_AUTORETRIES +#define RF230_INSERTACK 1 +uint8_t ack_pending,ack_seqnum; +#endif + /* RF230_CONF_CSMARETRIES is number of random-backoff/CCA retries. */ /* The hardware will accept 0-7, but 802.15.4-2003 only allows 5 maximum */ #ifndef RF230_CONF_CSMARETRIES @@ -186,7 +198,7 @@ static int num_transmissions; #endif #if defined(__AVR_ATmega128RFA1__) -volatile uint8_t rf230_interruptwait; +volatile uint8_t rf230_interruptwait,rf230_ccawait; #endif uint8_t volatile rf230_pending; @@ -355,9 +367,12 @@ rf230_isidle(void) static void rf230_waitidle(void) { - while (1) { +int i; + for (i=0;i<10000;i++) { //to avoid potential hangs + // while (1) { if (rf230_isidle()) break; } + if (i>=10000) {DEBUGFLOW('H');DEBUGFLOW('R');} } /*----------------------------------------------------------------------------*/ @@ -492,59 +507,59 @@ static uint8_t locked, lock_on, lock_off; static void on(void) { +// ENERGEST_OFF(ENERGEST_TYPE_LISTEN);//testing ENERGEST_ON(ENERGEST_TYPE_LISTEN); - + RF230_receive_on = 1; #ifdef RF230BB_HOOK_RADIO_ON RF230BB_HOOK_RADIO_ON(); #endif +/* If radio is off (slptr high), turn it on */ if (hal_get_slptr()) { -#if defined(__AVR_ATmega128RFA1__) - rf230_interruptwait=1; - ENERGEST_ON(ENERGEST_TYPE_LED_RED); + ENERGEST_ON(ENERGEST_TYPE_LED_RED); #if RF230BB_CONF_LEDONPORTE1 -// PORTE|=(1< 84 +#warning rf231 power threshold clipped to -48dBm by hardware register + hal_register_write(RG_RX_SYN, 0xf); +#elif RF230_MIN_RX_POWER < 0 +#error RF230_MIN_RX_POWER can not be negative! +#endif + hal_register_write(RG_RX_SYN, RF230_MIN_RX_POWER/6 + 1); //1-15 -> -90 to -48dBm +#endif + /* 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 */ #ifdef RF230_CONF_CCA_THRES @@ -839,23 +860,29 @@ rf230_transmit(unsigned short payload_len) // DEBUGFLOW('j'); ENERGEST_ON(ENERGEST_TYPE_LED_RED); #if RF230BB_CONF_LEDONPORTE1 -// PORTE|=(1<