Skip to content

Commit 9398f3c

Browse files
committed
RadioLibWrappers: Add blockTaskUntilRXEvent()
This adds a new method blockTaskUntilRXEvent() which uses a FreeRTOS semaphore to stall the calling task until a packet has been received. Signed-off-by: Frieder Schrempf <frieder@fris.de>
1 parent e5a3efc commit 9398f3c

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/helpers/radiolib/RadioLibWrappers.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define SAMPLING_THRESHOLD 14
1313

1414
static volatile uint8_t state = STATE_IDLE;
15+
static SemaphoreHandle_t rx_wait_sem;
1516

1617
// this function is called when a complete packet
1718
// is transmitted by the module
@@ -22,6 +23,8 @@ static
2223
void setFlag(void) {
2324
// we sent a packet, set the flag
2425
state |= STATE_INT_READY;
26+
27+
if (state & STATE_RX) xSemaphoreGive(rx_wait_sem);
2528
}
2629

2730
void RadioLibWrapper::begin() {
@@ -38,13 +41,21 @@ void RadioLibWrapper::begin() {
3841
// start average out some samples
3942
_num_floor_samples = 0;
4043
_floor_sample_sum = 0;
44+
45+
rx_wait_sem = xSemaphoreCreateBinary();
46+
xSemaphoreGive(rx_wait_sem);
47+
xSemaphoreTake(rx_wait_sem, portMAX_DELAY);
4148
}
4249

4350
void RadioLibWrapper::idle() {
4451
_radio->standby();
4552
state = STATE_IDLE; // need another startReceive()
4653
}
4754

55+
int RadioLibWrapper::blockTaskUntilRXEvent(unsigned int timeout = 5000) {
56+
return xSemaphoreTake(rx_wait_sem, pdMS_TO_TICKS(timeout));
57+
}
58+
4859
void RadioLibWrapper::triggerNoiseFloorCalibrate(int threshold) {
4960
_threshold = threshold;
5061
if (_num_floor_samples >= NUM_NOISE_FLOOR_SAMPLES) { // ignore trigger if currently sampling

src/helpers/radiolib/RadioLibWrappers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class RadioLibWrapper : public mesh::Radio {
3636
return isChannelActive();
3737
}
3838

39+
int blockTaskUntilRXEvent(unsigned int timeout);
40+
3941
virtual float getCurrentRSSI() =0;
4042

4143
int getNoiseFloor() const override { return _noise_floor; }

0 commit comments

Comments
 (0)