128rfa1 cca fix, NETSTACK_RADIO.off now returns 0/1 if radio off/on
This commit is contained in:
parent
11efc33d2c
commit
09db159876
3 changed files with 36 additions and 32 deletions
|
@ -345,7 +345,8 @@
|
||||||
#define hal_set_rst_high( ) ( TRXPR |= ( 1 << TRXRST ) ) /**< This macro pulls the RST pin high. */
|
#define hal_set_rst_high( ) ( TRXPR |= ( 1 << TRXRST ) ) /**< This macro pulls the RST pin high. */
|
||||||
#define hal_set_slptr_high( ) ( TRXPR |= ( 1 << SLPTR ) ) /**< This macro pulls the SLP_TR pin high. */
|
#define hal_set_slptr_high( ) ( TRXPR |= ( 1 << SLPTR ) ) /**< This macro pulls the SLP_TR pin high. */
|
||||||
#define hal_set_slptr_low( ) ( TRXPR &= ~( 1 << SLPTR ) ) /**< This macro pulls the SLP_TR pin low. */
|
#define hal_set_slptr_low( ) ( TRXPR &= ~( 1 << SLPTR ) ) /**< This macro pulls the SLP_TR pin low. */
|
||||||
#define hal_get_slptr( ) ( ( TRXPR & ( 1 << SLPTR ) ) >> SLPTR ) /**< Read current state of the SLP_TR pin (High/Low). */
|
//#define hal_get_slptr( ) ( ( TRXPR & ( 1 << SLPTR ) ) >> SLPTR ) /**< Read current state of the SLP_TR pin (High/Low). */
|
||||||
|
#define hal_get_slptr( ) ( TRXPR & ( 1 << SLPTR ) ) /**< Read current state of the SLP_TR pin (High/Low). */
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#define SLP_TR SLPTRPIN /**< Pin number that corresponds to the SLP_TR pin. */
|
#define SLP_TR SLPTRPIN /**< Pin number that corresponds to the SLP_TR pin. */
|
||||||
|
@ -354,7 +355,8 @@
|
||||||
#define PIN_SLP_TR PIN( SLPTRPORT ) /**< Pin (Read Access) where SLP_TR is connected. */
|
#define PIN_SLP_TR PIN( SLPTRPORT ) /**< Pin (Read Access) where SLP_TR is connected. */
|
||||||
#define hal_set_slptr_high( ) ( PORT_SLP_TR |= ( 1 << SLP_TR ) ) /**< This macro pulls the SLP_TR pin high. */
|
#define hal_set_slptr_high( ) ( PORT_SLP_TR |= ( 1 << SLP_TR ) ) /**< This macro pulls the SLP_TR pin high. */
|
||||||
#define hal_set_slptr_low( ) ( PORT_SLP_TR &= ~( 1 << SLP_TR ) ) /**< This macro pulls the SLP_TR pin low. */
|
#define hal_set_slptr_low( ) ( PORT_SLP_TR &= ~( 1 << SLP_TR ) ) /**< This macro pulls the SLP_TR pin low. */
|
||||||
#define hal_get_slptr( ) ( ( PIN_SLP_TR & ( 1 << SLP_TR ) ) >> SLP_TR ) /**< Read current state of the SLP_TR pin (High/Low). */
|
//#define hal_get_slptr( ) ( ( PIN_SLP_TR & ( 1 << SLP_TR ) ) >> SLP_TR ) /**< Read current state of the SLP_TR pin (High/Low). */
|
||||||
|
#define hal_get_slptr( ) ( PIN_SLP_TR & ( 1 << SLP_TR ) ) /**< Read current state of the SLP_TR pin (High/Low). */
|
||||||
#define RST RSTPIN /**< Pin number that corresponds to the RST pin. */
|
#define RST RSTPIN /**< Pin number that corresponds to the RST pin. */
|
||||||
#define DDR_RST DDR( RSTPORT ) /**< Data Direction Register that corresponds to the port where RST is */
|
#define DDR_RST DDR( RSTPORT ) /**< Data Direction Register that corresponds to the port where RST is */
|
||||||
#define PORT_RST PORT( RSTPORT ) /**< Port (Write Access) where RST is connected. */
|
#define PORT_RST PORT( RSTPORT ) /**< Port (Write Access) where RST is connected. */
|
||||||
|
|
|
@ -833,7 +833,7 @@ ISR(TRX24_RX_END_vect)
|
||||||
|
|
||||||
/* Buffer the frame and call rf230_interrupt to schedule poll for rf230 receive process */
|
/* Buffer the frame and call rf230_interrupt to schedule poll for rf230 receive process */
|
||||||
/* Is a ram buffer available? */
|
/* Is a ram buffer available? */
|
||||||
if (rxframe[rxframe_tail].length) {DEBUGFLOW('0');} else DEBUGFLOW('1');
|
if (rxframe[rxframe_tail].length) {DEBUGFLOW('0');} else /*DEBUGFLOW('1')*/;
|
||||||
|
|
||||||
#ifdef RF230_MIN_RX_POWER
|
#ifdef RF230_MIN_RX_POWER
|
||||||
/* Discard packets weaker than the minimum if defined. This is for testing miniature meshes */
|
/* Discard packets weaker than the minimum if defined. This is for testing miniature meshes */
|
||||||
|
|
|
@ -502,17 +502,15 @@ on(void)
|
||||||
#if defined(__AVR_ATmega128RFA1__)
|
#if defined(__AVR_ATmega128RFA1__)
|
||||||
rf230_interruptwait=1;
|
rf230_interruptwait=1;
|
||||||
ENERGEST_ON(ENERGEST_TYPE_LED_RED);
|
ENERGEST_ON(ENERGEST_TYPE_LED_RED);
|
||||||
PORTE|=(1<<PE1); //ledon
|
// PORTE|=(1<<PE1); //ledon
|
||||||
hal_set_slptr_low();
|
hal_set_slptr_low();
|
||||||
while (rf230_interruptwait) {}
|
while (rf230_interruptwait) {}
|
||||||
// rf230_waitidle(); //?
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
uint8_t sreg = SREG;
|
uint8_t sreg = SREG;
|
||||||
cli();
|
cli();
|
||||||
// DEBUGFLOW('0');
|
// DEBUGFLOW('0');
|
||||||
hal_set_slptr_low();
|
hal_set_slptr_low();
|
||||||
delay_us(TIME_SLEEP_TO_TRX_OFF);
|
|
||||||
delay_us(TIME_SLEEP_TO_TRX_OFF);
|
delay_us(TIME_SLEEP_TO_TRX_OFF);
|
||||||
delay_us(TIME_SLEEP_TO_TRX_OFF);//extra delay for now, wake time depends on board capacitance
|
delay_us(TIME_SLEEP_TO_TRX_OFF);//extra delay for now, wake time depends on board capacitance
|
||||||
SREG=sreg;
|
SREG=sreg;
|
||||||
|
@ -529,21 +527,18 @@ on(void)
|
||||||
DEBUGFLOW('b');
|
DEBUGFLOW('b');
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// flushrx();
|
|
||||||
|
|
||||||
RF230_receive_on = 1;
|
RF230_receive_on = 1;
|
||||||
}
|
}
|
||||||
static void
|
static void
|
||||||
off(void)
|
off(void)
|
||||||
{
|
{
|
||||||
RF230_receive_on = 0;
|
|
||||||
#ifdef RF230BB_HOOK_RADIO_OFF
|
#ifdef RF230BB_HOOK_RADIO_OFF
|
||||||
RF230BB_HOOK_RADIO_OFF();
|
RF230BB_HOOK_RADIO_OFF();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Wait any transmission to end */
|
/* Wait any transmission to end */
|
||||||
rf230_waitidle();
|
rf230_waitidle();
|
||||||
|
RF230_receive_on = 0;
|
||||||
#if RADIOALWAYSON
|
#if RADIOALWAYSON
|
||||||
/* Do not transmit autoacks when stack thinks radio is off */
|
/* Do not transmit autoacks when stack thinks radio is off */
|
||||||
radio_set_trx_state(RX_ON);
|
radio_set_trx_state(RX_ON);
|
||||||
|
@ -553,11 +548,10 @@ off(void)
|
||||||
radio_reset_state_machine();
|
radio_reset_state_machine();
|
||||||
#if RADIOSLEEPSWHENOFF
|
#if RADIOSLEEPSWHENOFF
|
||||||
/* Sleep Radio */
|
/* Sleep Radio */
|
||||||
|
hal_set_slptr_high();
|
||||||
ENERGEST_OFF(ENERGEST_TYPE_LED_RED);
|
ENERGEST_OFF(ENERGEST_TYPE_LED_RED);
|
||||||
// PORTE&=~(1<<PE1); //ledoff
|
// PORTE&=~(1<<PE1); //ledoff
|
||||||
hal_set_slptr_high();
|
// DEBUGFLOW('d');
|
||||||
// DEBUGFLOW('d');
|
|
||||||
delay_us(TIME_SLEEP_TO_TRX_OFF); //?
|
|
||||||
#else
|
#else
|
||||||
// DEBUGFLOW('e');
|
// DEBUGFLOW('e');
|
||||||
#endif
|
#endif
|
||||||
|
@ -848,7 +842,7 @@ rf230_transmit(unsigned short payload_len)
|
||||||
hal_set_slptr_low();
|
hal_set_slptr_low();
|
||||||
DEBUGFLOW('j');
|
DEBUGFLOW('j');
|
||||||
delay_us(TIME_SLEEP_TO_TRX_OFF);
|
delay_us(TIME_SLEEP_TO_TRX_OFF);
|
||||||
delay_us(TIME_SLEEP_TO_TRX_OFF);
|
delay_us(TIME_SLEEP_TO_TRX_OFF); //extra delay depends on board capacitance
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -867,7 +861,9 @@ rf230_transmit(unsigned short payload_len)
|
||||||
|
|
||||||
/* Wait for any previous operation or state transition to finish */
|
/* Wait for any previous operation or state transition to finish */
|
||||||
rf230_waitidle();
|
rf230_waitidle();
|
||||||
|
if(RF230_receive_on) {
|
||||||
|
ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
|
||||||
|
}
|
||||||
/* Prepare to transmit */
|
/* Prepare to transmit */
|
||||||
#if RF230_CONF_AUTORETRIES
|
#if RF230_CONF_AUTORETRIES
|
||||||
radio_set_trx_state(TX_ARET_ON);
|
radio_set_trx_state(TX_ARET_ON);
|
||||||
|
@ -891,6 +887,9 @@ rf230_transmit(unsigned short payload_len)
|
||||||
#if RF230_CONF_TIMESTAMPS
|
#if RF230_CONF_TIMESTAMPS
|
||||||
rtimer_clock_t txtime = timesynch_time();
|
rtimer_clock_t txtime = timesynch_time();
|
||||||
#endif /* RF230_CONF_TIMESTAMPS */
|
#endif /* RF230_CONF_TIMESTAMPS */
|
||||||
|
|
||||||
|
ENERGEST_ON(ENERGEST_TYPE_TRANSMIT);
|
||||||
|
|
||||||
#if defined(__AVR_ATmega128RFA1__)
|
#if defined(__AVR_ATmega128RFA1__)
|
||||||
/* No interrupts across frame download! */
|
/* No interrupts across frame download! */
|
||||||
cli();
|
cli();
|
||||||
|
@ -917,11 +916,6 @@ rf230_transmit(unsigned short payload_len)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(RF230_receive_on) {
|
|
||||||
ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
|
|
||||||
}
|
|
||||||
ENERGEST_ON(ENERGEST_TYPE_TRANSMIT);
|
|
||||||
|
|
||||||
#if RADIOSTATS
|
#if RADIOSTATS
|
||||||
RF230_sendpackets++;
|
RF230_sendpackets++;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1097,7 +1091,7 @@ rf230_off(void)
|
||||||
{
|
{
|
||||||
/* Don't do anything if we are already turned off. */
|
/* Don't do anything if we are already turned off. */
|
||||||
if(RF230_receive_on == 0) {
|
if(RF230_receive_on == 0) {
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we are called when the driver is locked, we indicate that the
|
/* If we are called when the driver is locked, we indicate that the
|
||||||
|
@ -1112,13 +1106,12 @@ rf230_off(void)
|
||||||
driver should switch off the radio once the packet has been
|
driver should switch off the radio once the packet has been
|
||||||
received and processed, by setting the 'lock_off' variable. */
|
received and processed, by setting the 'lock_off' variable. */
|
||||||
if (!rf230_isidle()) {
|
if (!rf230_isidle()) {
|
||||||
// if (radio_get_trx_state()==BUSY_RX) {
|
|
||||||
lock_off = 1;
|
lock_off = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
off();
|
off();
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
int
|
int
|
||||||
|
@ -1563,9 +1556,8 @@ rf230_cca(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Don't allow interrupts! */
|
/* Don't allow interrupts! */
|
||||||
//#if !defined(__AVR_ATmega128RFA1__)
|
|
||||||
cli();
|
cli();
|
||||||
//#endif
|
|
||||||
/* Turn radio on if necessary. If radio is currently busy return busy channel */
|
/* Turn radio on if necessary. If radio is currently busy return busy channel */
|
||||||
/* This may happen when testing radio duty cycling with RADIOALWAYSON */
|
/* This may happen when testing radio duty cycling with RADIOALWAYSON */
|
||||||
|
|
||||||
|
@ -1588,20 +1580,30 @@ rf230_cca(void)
|
||||||
|
|
||||||
/* Start the CCA, wait till done, return result */
|
/* Start the CCA, wait till done, return result */
|
||||||
/* Note reading the TRX_STATUS register clears both CCA_STATUS and CCA_DONE bits */
|
/* Note reading the TRX_STATUS register clears both CCA_STATUS and CCA_DONE bits */
|
||||||
#if defined(__AVR_ATmega128RFA1__)&&0
|
#if defined(__AVR_ATmega128RFA1__)
|
||||||
|
/* Manual CCA gives no interrupt in extended mode, and testing cca done hangs the MCU */
|
||||||
|
#if 0
|
||||||
rf230_interruptwait=1;
|
rf230_interruptwait=1;
|
||||||
hal_subregister_write(SR_CCA_REQUEST,1);
|
|
||||||
sei();
|
sei();
|
||||||
|
hal_subregister_write(SR_CCA_REQUEST,1);
|
||||||
while (rf230_interruptwait) {}
|
while (rf230_interruptwait) {}
|
||||||
// while ((cca & 0x80) == 0 ) {//TODO:why does this hang the 128rfa1?
|
|
||||||
cca=hal_register_read(RG_TRX_STATUS);
|
cca=hal_register_read(RG_TRX_STATUS);
|
||||||
// }
|
#endif
|
||||||
|
/* So just read the current ED register without delay */
|
||||||
|
/* CCA energy threshold = -91dB + 2*SR_CCA_ED_THRESH. Reset defaults to -77dB */
|
||||||
|
#ifdef RF230_CONF_CCA_THRES
|
||||||
|
if (hal_register_read(RG_PHY_ED_LEVEL)<(91+RF230_CONF_CCA_THRES) cca=0xff;
|
||||||
#else
|
#else
|
||||||
|
if (hal_register_read(RG_PHY_ED_LEVEL)<(91-77)) cca=0xff;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#else /* RF230, RF231 */
|
||||||
hal_subregister_write(SR_CCA_REQUEST,1);
|
hal_subregister_write(SR_CCA_REQUEST,1);
|
||||||
delay_us(TIME_CCA);
|
delay_us(TIME_CCA);
|
||||||
// while ((cca & 0x80) == 0 ) { //hangs 128rfa1
|
while ((cca & 0x80) == 0 ) {
|
||||||
cca=hal_register_read(RG_TRX_STATUS);
|
cca=hal_register_read(RG_TRX_STATUS);
|
||||||
// }
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(radio_was_off) {
|
if(radio_was_off) {
|
||||||
|
|
Loading…
Reference in a new issue