Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Nucleo_IOT1 wireless
Revision 5:bb28775120e7, committed 2016-09-13
- Comitter:
- ianmcc
- Date:
- Tue Sep 13 13:21:59 2016 +0000
- Parent:
- 4:8f612189af31
- Child:
- 6:952996e3abdb
- Commit message:
- Support for non-blocking transmit (untested)
Changed in this revision
| nRF24L01P_PTX.cpp | Show annotated file Show diff for this revision Revisions of this file |
| nRF24L01P_PTX.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/nRF24L01P_PTX.cpp Sat Sep 03 12:24:04 2016 +0000
+++ b/nRF24L01P_PTX.cpp Tue Sep 13 13:21:59 2016 +0000
@@ -35,7 +35,7 @@
Device.reset();
Device.set_ptx_mode();
Status = STATUS_POWER_DOWN;
- Int.fall(this, &nRF24L01P_PTX::IntHandler);
+ Int.fall(NULL);
}
void
@@ -106,11 +106,13 @@
{
error("nRF24L01P_PTX::TransmitPacket(): error: device power must be on!");
}
- // Wait until the device is ready to transmit
- while (Status != STATUS_STANDBY)
+
+ // if we're not ready to send, then bug out
+ if (Status != STATUS_STANDBY)
{
- wait_us(1);
+ return -1;
}
+
Device.write_tx_payload(Buf, Size);
Status = STATUS_TRANSMITTING;
CE = 1;
@@ -151,9 +153,80 @@
return -1;
}
+int
+nRF24L01P_PTX::TransmitPacketNonBlocking(char* Buf, int Size)
+{
+ // If the device isn't powered up then there is a logic error
+ if (Status == STATUS_UNDEFINED || Status == STATUS_READY_INIT || Status == STATUS_POWER_DOWN)
+ {
+ error("nRF24L01P_PTX::TransmitPacketNonBlocking(): error: device power must be on!");
+ }
+
+ // if we're not ready to send, then bug out
+ if (Status != STATUS_STANDBY)
+ {
+ return -1;
+ }
+
+ // Set up the interrupt handler
+ Int.fall(this, &nRF24L01P_PTX::IntHandler);
+
+ // write the payload
+ Device.write_tx_payload(Buf, Size);
+ Status = STATUS_TRANSMITTING;
+ CE = 1;
+ wait_us(Thce_us);
+ CE = 0;
+
+ return 0;
+}
+
+bool
+nRF24L01P_PTX::IsTransmitFinished()
+{
+ return Status != STATUS_TRANSMITTING;
+}
+
+int
+nRF24L01P_PTX::TransmitComplete()
+{
+ // wait until the packet is transmitted (or some error)
+ while (Status == STATUS_TRANSMITTING)
+ {
+ wait_us(1);
+ }
+
+ if (Status == STATUS_PACKET_OK)
+ {
+ Status = STATUS_STANDBY;
+ return 0;
+ }
+ else if (Status == STATUS_PACKET_MAX_RT)
+ {
+ Status = STATUS_STANDBY;
+ Device.flush_tx_fifo();
+ return -1;
+ }
+ // this shouldn't happen
+ return -2;
+}
+
void
nRF24L01P_PTX::IntHandler()
{
+ Int.fall(NULL);
+ if (Device.is_tx_sent())
+ {
+ // we successfully sent a packet
+ Status = STATUS_PACKET_OK;
+ Device.clear_tx_sent();
+ }
+ else if (Device.is_max_rt())
+ {
+ // we failed to send the packet
+ Status = STATUS_PACKET_MAX_RT;
+ Device.clear_max_rt();
+ }
}
void
--- a/nRF24L01P_PTX.h Sat Sep 03 12:24:04 2016 +0000
+++ b/nRF24L01P_PTX.h Tue Sep 13 13:21:59 2016 +0000
@@ -45,6 +45,21 @@
// Returns -1 if the packet wasn't successfully acknowledged.
int TransmitPacket(char* Buf, int Size);
+ // Transmits a packet in non-blocking mode.
+ // returns 0 if the packet was successful, -1 on some error (eg
+ // if the device isn't ready to transmit).
+ int TransmitPacketNonBlocking(char* Buf, int Size);
+
+ // For nonblocking mode, returns false if there is still a pending
+ // packet waiting to send. Returns true if the packet has been
+ // sent or there was some error (eg max retries was hit).
+ bool IsTransmitFinished();
+
+ // For nonblocking mode, complete the transmission process. If
+ // IsTransmitFinished() is false, then this call is blocking.
+ // returns 0 if the packet was sent successfully, -1 if it wasn't.
+ int TransmitComplete();
+
private:
void IntHandler();
void ReadyInitialize();