Skip to content

Commit

Permalink
Enable buffered writes/transmissions
Browse files Browse the repository at this point in the history
- Add optional startTx to startFastWrite() function:
a: Allows software to fully utilize FIFO buffers for buffering payloads
to the TX FIFO, while remaining in RX mode, instead of storing data in
RAM etc.
b: Default is still to start sending immediately unless startTx is
included and set to 0

Note: This will not work correctly if using ack-payloads. Tx FIFO is
flushed when switching between RX/TX modes to prevent data corruption.

- Added optional startTx to txStandBy(timeout,startTx)
a: Allows automated sending of buffered data, with indication of success
or failure for the bulk data transfer.
b: Default is still to not initiate sending, and not leave RX mode.
c: Calling this with startTx set to true will automatically call
radio.stopListening() to begin transmission.

Example:
radio.startFastWrite( &time, sizeof(unsigned long), false );
radio.startFastWrite( &time, sizeof(unsigned long), false );

if (!radio.txStandBy(100, true) ){  printf("failed.\n\r");  }
radio.startListening()
  • Loading branch information
TMRh20 committed Jan 19, 2015
1 parent 1e05097 commit 08480a3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
14 changes: 11 additions & 3 deletions RF24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -958,11 +958,13 @@ bool RF24::writeFast( const void* buf, uint8_t len ){
//Otherwise we enter Standby-II mode, which is still faster than standby mode
//Also, we remove the need to keep writing the config register over and over and delaying for 150 us each time if sending a stream of data

void RF24::startFastWrite( const void* buf, uint8_t len, const bool multicast){ //TMRh20
void RF24::startFastWrite( const void* buf, uint8_t len, const bool multicast, bool startTx){ //TMRh20

//write_payload( buf,len);
write_payload( buf, len,multicast ? W_TX_PAYLOAD_NO_ACK : W_TX_PAYLOAD ) ;
ce(HIGH);
if(startTx){
ce(HIGH);
}

}

Expand Down Expand Up @@ -993,6 +995,7 @@ bool RF24::rxFifoFull(){
/****************************************************************************/

bool RF24::txStandBy(){

#if defined (FAILURE_HANDLING) || defined (RF24_LINUX)
uint32_t timeout = millis();
#endif
Expand All @@ -1019,8 +1022,12 @@ bool RF24::txStandBy(){

/****************************************************************************/

bool RF24::txStandBy(uint32_t timeout){
bool RF24::txStandBy(uint32_t timeout, bool startTx){

if(startTx){
stopListening();
ce(HIGH);
}
uint32_t start = millis();

while( ! (read_register(FIFO_STATUS) & _BV(TX_EMPTY)) ){
Expand All @@ -1047,6 +1054,7 @@ bool RF24::txStandBy(uint32_t timeout){
return 1;

}

/****************************************************************************/

void RF24::maskIRQ(bool tx, bool fail, bool rx){
Expand Down
6 changes: 3 additions & 3 deletions RF24.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ s *
* @return True if transmission is successful
*
*/
bool txStandBy(uint32_t timeout);
bool txStandBy(uint32_t timeout, bool startTx = 0);

/**
* Write an ack payload for the specified pipe
Expand Down Expand Up @@ -545,7 +545,7 @@ s *
* @param multicast Request ACK (0) or NOACK (1)
* @return True if the payload was delivered successfully false if not
*/
void startFastWrite( const void* buf, uint8_t len, const bool multicast );
void startFastWrite( const void* buf, uint8_t len, const bool multicast, bool startTx = 1 );

/**
* Non-blocking write to the open writing pipe
Expand All @@ -568,7 +568,7 @@ s *
*
*/
void startWrite( const void* buf, uint8_t len, const bool multicast );

/**
* This function is mainly used internally to take advantage of the auto payload
* re-use functionality of the chip, but can be beneficial to users as well.
Expand Down

1 comment on commit 08480a3

@wilmsn
Copy link

@wilmsn wilmsn commented on 08480a3 Jan 20, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sync with TMRh20 sources

Please sign in to comment.