Skip to content

Commit

Permalink
Changed timeout calculation from ms to us as usual math resulted in
Browse files Browse the repository at this point in the history
loss of resolution and the possibility of a premature timeout. The
write monitoring loop now uses us rather than ms to be more compatible
with the us result returned from getMaxTimeout.
  • Loading branch information
gcopeland committed Mar 16, 2013
1 parent 65a291e commit e9788cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions RF24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,16 +467,16 @@ bool RF24::write( const void* buf, uint8_t len, bool multicast )
// Generally much faster.
uint8_t observe_tx;
uint8_t status;
uint32_t sent_at = millis();
const uint16_t timeout = getMaxTimeout() ; //ms to wait for timeout
uint32_t sent_at = micros();
const uint16_t timeout = getMaxTimeout() ; //us to wait for timeout

// Monitor the send
do
{
status = read_register(OBSERVE_TX,&observe_tx,1);
IF_SERIAL_DEBUG(Serial.print(observe_tx,HEX));
}
while( ! ( status & ( _BV(TX_DS) | _BV(MAX_RT) ) ) && ( millis() - sent_at < timeout ) );
while( ! ( status & ( _BV(TX_DS) | _BV(MAX_RT) ) ) && ( micros() - sent_at < timeout ) );

// The part above is what you could recreate with your own interrupt handler,
// and then call this when you got an interrupt
Expand Down Expand Up @@ -1015,8 +1015,8 @@ uint8_t RF24::getRetries( void )
uint16_t RF24::getMaxTimeout( void )
{
uint8_t retries = getRetries() ;
uint16_t to = ((250 + (250 * ((retries & 0xf0) >> 4))) * (retries & 0x0f)) / 1000 ;

uint16_t to = ((250 + (250 * ((retries & 0xf0) >> 4))) * (retries & 0x0f)) ;
return to ;
}

Expand Down
4 changes: 2 additions & 2 deletions RF24.h
Original file line number Diff line number Diff line change
Expand Up @@ -659,10 +659,10 @@ class RF24


/**
* Calculate the maximum timeout in ms based on current hardware
* Calculate the maximum timeout in us based on current hardware
* configuration.
*
* @return ms of maximum timeout; accounting for retries
* @return us of maximum timeout; accounting for retries
*/
uint16_t getMaxTimeout(void) ;

Expand Down

0 comments on commit e9788cc

Please sign in to comment.