@@ -398,14 +398,11 @@ uint8_t rf12_recvDone () {
398
398
// / rf12_recvDone() periodically, because it keeps the RFM12B logic going. If
399
399
// / you don't, rf12_canSend() will never return true.
400
400
uint8_t rf12_canSend () {
401
- // no need to test with interrupts disabled: state TXRECV is only reached
402
- // outside of ISR and we don't care if rxfill jumps from 0 to 1 here
401
+ // need interrupts off to avoid a race (and enable the RFM12B, thx Jorg!)
402
+ // see http://openenergymonitor.org/emon/node/1051?page=3
403
403
if (rxstate == TXRECV && rxfill == 0 &&
404
- (rf12_byte (0x00 ) & (RF_RSSI_BIT >> 8 )) == 0 ) {
405
- rf12_xfer (RF_IDLE_MODE); // stop receiver
406
- // XXX just in case, don't know whether these RF12 reads are needed!
407
- // rf12_xfer(0x0000); // status register
408
- // rf12_xfer(RF_RX_FIFO_READ); // fifo read
404
+ (rf12_control (0x0000 ) & RF_RSSI_BIT) == 0 ) {
405
+ rf12_control (RF_IDLE_MODE); // stop receiver
409
406
rxstate = TXIDLE;
410
407
return 1 ;
411
408
}
@@ -466,6 +463,20 @@ void rf12_sendStart (uint8_t hdr, const void* ptr, uint8_t len, uint8_t sync) {
466
463
rf12_sendWait (sync );
467
464
}
468
465
466
+ // / @details
467
+ // / Wait until transmission is possible, then start it as soon as possible.
468
+ // / @note This uses a (brief) busy loop and will discard any incoming packets.
469
+ // / @param hdr The header contains information about the destination of the
470
+ // / packet to send, and flags such as whether this should be
471
+ // / acknowledged - or if it actually is an acknowledgement.
472
+ // / @param ptr Pointer to the data to send as packet.
473
+ // / @param len Number of data bytes to send. Must be in the range 0 .. 65.
474
+ void rf12_sendNow (uint8_t hdr, const void * ptr, uint8_t len) {
475
+ while (!rf12_canSend ())
476
+ rf12_recvDone (); // keep the driver state machine going, ignore incoming
477
+ rf12_sendStart (hdr, ptr, len);
478
+ }
479
+
469
480
// / @details
470
481
// / Wait for completion of the preceding rf12_sendStart() call, using the
471
482
// / specified low-power mode.
0 commit comments