From 577215deca868267f77f63ccc4b0de5c0c9e20a8 Mon Sep 17 00:00:00 2001 From: David Kopf Date: Mon, 15 Aug 2011 15:06:38 -0400 Subject: [PATCH] Use 128rfa1 interrupts instead of timing. Generalize DEBUGFLOW macro for use in multiple routines. --- cpu/avr/radio/rf230bb/halbb.c | 158 ++++++++++++++------------------ cpu/avr/radio/rf230bb/rf230bb.c | 99 +++++++++++++++----- cpu/avr/radio/rf230bb/rf230bb.h | 4 + cpu/avr/rtimer-arch.c | 14 ++- 4 files changed, 158 insertions(+), 117 deletions(-) diff --git a/cpu/avr/radio/rf230bb/halbb.c b/cpu/avr/radio/rf230bb/halbb.c index c377db10e..8f6dd6d04 100644 --- a/cpu/avr/radio/rf230bb/halbb.c +++ b/cpu/avr/radio/rf230bb/halbb.c @@ -58,7 +58,13 @@ * which communicates directly with the contiki core MAC layer. * It is optimized for speed at the expense of generality. */ - +#include "contiki-conf.h" +#if DEBUGFLOWSIZE +extern uint8_t debugflowsize,debugflow[DEBUGFLOWSIZE]; +#define DEBUGFLOW(c) if (debugflowsize<(DEBUGFLOWSIZE-1)) debugflow[debugflowsize++]=c +#else +#define DEBUGFLOW(c) +#endif /*============================ INCLUDE =======================================*/ @@ -814,118 +820,88 @@ volatile char rf230interruptflag; #endif #if defined(__AVR_ATmega128RFA1__) -/* The atmega128rfa1 has individual interrupts for the integrated radio */ -/* Whichever are enabled by the RF230 driver must be present even if not used! */ +/* The atmega128rfa1 has individual interrupts for the integrated radio' + * Whichever are enabled by the RF230 driver must be present even if not used! + */ +/* Received packet interrupt */ ISR(TRX24_RX_END_vect) { - INTERRUPTDEBUG(11); - /* Received packet interrupt */ - /* 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[rxframe_tail].length) INTERRUPTDEBUG(42); else INTERRUPTDEBUG(12); +/* Get the rssi from ED if extended mode */ +#if RF230_CONF_AUTOACK + rf230_last_rssi=hal_register_read(RG_PHY_ED_LEVEL); +#endif + +/* Buffer the frame and call rf230_interrupt to schedule poll for rf230 receive process */ +/* Is a ram buffer available? */ + if (rxframe[rxframe_tail].length) {DEBUGFLOW('0');} else DEBUGFLOW('1'); #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 */ -#if RF230_CONF_AUTOACK - // rf230_last_rssi=hal_subregister_read(SR_ED_LEVEL); - rf230_last_rssi=hal_register_read(RG_PHY_ED_LEVEL); -#endif -// if (rf230_last_rssi >= RF230_MIN_RX_POWER) { - if (1) { -#endif - hal_frame_read(&rxframe[rxframe_tail]); - rxframe_tail++;if (rxframe_tail >= RF230_CONF_RX_BUFFERS) rxframe_tail=0; - rf230_interrupt(); -#ifdef RF230_MIN_RX_POWER - } +/* Discard packets weaker than the minimum if defined. This is for testing miniature meshes */ +/* This does not prevent an autoack. TODO:rfa1 radio can be set up to not autoack weak packets */ + if (rf230_last_rssi >= RF230_MIN_RX_POWER) { +#else + if (1) { #endif +// DEBUGFLOW('2'); + hal_frame_read(&rxframe[rxframe_tail]); + rxframe_tail++;if (rxframe_tail >= RF230_CONF_RX_BUFFERS) rxframe_tail=0; + rf230_interrupt(); + } } +/* Preamble detected, starting frame reception */ ISR(TRX24_RX_START_vect) { - INTERRUPTDEBUG(10); - /* Save RSSI for this packet if not in extended mode, scaling to 1dB resolution */ +// DEBUGFLOW('3'); +/* Save RSSI for this packet if not in extended mode, scaling to 1dB resolution */ #if !RF230_CONF_AUTOACK rf230_last_rssi = 3 * hal_subregister_read(SR_RSSI); #endif } + +/* PLL has locked, either from a transition out of TRX_OFF or a channel change while on */ ISR(TRX24_PLL_LOCK_vect) { +// DEBUGFLOW('4'); } + +/* PLL has unexpectedly unlocked */ ISR(TRX24_PLL_UNLOCK_vect) { + DEBUGFLOW('5'); } +/* Flag is set by the following interrupts */ +extern volatile uint8_t rf230_interruptwait; -#if 0 -HAL_RF230_ISR() //for reference, for now +/* Wake has finished */ +ISR(TRX24_AWAKE_vect) { - /*The following code reads the current system time. This is done by first - reading the hal_system_time and then adding the 16 LSB directly from the - hardware counter. - */ -// uint32_t isr_timestamp = hal_system_time; -// isr_timestamp <<= 16; -// isr_timestamp |= HAL_TICK_UPCNT(); // TODO: what if this wraps after reading hal_system_time? -// isr_timestamp /= HAL_US_PER_SYMBOL; /* Divide so that we get time in 16us resolution. */ -// isr_timestamp &= HAL_SYMBOL_MASK; - - uint8_t interrupt_source; - - INTERRUPTDEBUG(1); - - /*Read Interrupt source.*/ - interrupt_source = IRQ_STATUS; - - /*Handle the incomming interrupt. Prioritized.*/ - if (interrupt_source & (1>>RX_START)){ - INTERRUPTDEBUG(10); - /* Save RSSI for this packet if not in extended mode, scaling to 1dB resolution */ -#if !RF230_CONF_AUTOACK - rf230_last_rssi = 3 * hal_subregister_read(SR_RSSI); -#endif - - } else if (interrupt_source & (1<= RF230_MIN_RX_POWER) { - if (1) { -#endif - hal_frame_read(&rxframe[rxframe_tail]); - rxframe_tail++;if (rxframe_tail >= RF230_CONF_RX_BUFFERS) rxframe_tail=0; - rf230_interrupt(); -// trx_end_callback(isr_timestamp); -#ifdef RF230_MIN_RX_POWER - } -#endif - - } else if (interrupt_source & (1<