Skip to content

Commit 387aae3

Browse files
committed
added fixes for jeelabs#33 and jeelabs#34, also add new rf12_sendNow wrapper
1 parent bf843fc commit 387aae3

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

RF12.cpp

+18-7
Original file line numberDiff line numberDiff line change
@@ -398,14 +398,11 @@ uint8_t rf12_recvDone () {
398398
/// rf12_recvDone() periodically, because it keeps the RFM12B logic going. If
399399
/// you don't, rf12_canSend() will never return true.
400400
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
403403
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
409406
rxstate = TXIDLE;
410407
return 1;
411408
}
@@ -466,6 +463,20 @@ void rf12_sendStart (uint8_t hdr, const void* ptr, uint8_t len, uint8_t sync) {
466463
rf12_sendWait(sync);
467464
}
468465

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+
469480
/// @details
470481
/// Wait for completion of the preceding rf12_sendStart() call, using the
471482
/// specified low-power mode.

RF12.h

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ void rf12_sendStart(uint8_t hdr);
8989
void rf12_sendStart(uint8_t hdr, const void* ptr, uint8_t len);
9090
/// Deprecated: use rf12_sendStart(hdr,ptr,len) followed by rf12_sendWait(sync).
9191
void rf12_sendStart(uint8_t hdr, const void* ptr, uint8_t len, uint8_t sync);
92+
/// This variant loops on rf12_canSend() and then calls rf12_sendStart() asap.
93+
void rf12_sendNow(uint8_t hdr, const void* ptr, uint8_t len);
9294

9395
/// Wait for send to finish.
9496
/// @param mode sleep mode 0=none, 1=idle, 2=standby, 3=powerdown.

intro.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ These are the main classes:
2828
* Sleepy - code to put an ATmega or ATtiny into very low-power mode
2929

3030
The other major implementation in this library is the [RF12 wireless driver]
31-
(Md_intro_rf12.html) for the "RFM12" and RFM12B" wireless modules from HopeRF.
31+
(md_intro_rf12.html) for the "RFM12" and RFM12B" wireless modules from HopeRF.
3232

3333
Last but not least, there are about a hundred demo sketches in the "examples"
3434
folder, ready to try out all sorts of features and tricks, and to easily hook

intro_rf12.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ this can be useful while wriitng and testing your own code with this driver.
1616
rf12_initialize(),
1717
rf12_recvDone(),
1818
rf12_canSend(),
19-
rf12_sendStart()
19+
rf12_sendStart(),
20+
rf12_sendNow()
2021
* Easy transmit wrappers:
2122
rf12_easyInit(),
2223
rf12_easyPoll(),

0 commit comments

Comments
 (0)