Skip to content

Commit 51a8c39

Browse files
authored
Merge pull request #9245 from kjbracey-arm/lorawan_atomic_flag
LoRAWAN: volatile bool -> atomic_flag
2 parents 32c9c3a + 6f757a5 commit 51a8c39

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

UNITTESTS/features/lorawan/lorawanstack/unittest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ set(unittest-test-sources
3535
stubs/LoRaPHY_stub.cpp
3636
stubs/LoRaMac_stub.cpp
3737
stubs/mbed_assert_stub.c
38+
stubs/mbed_critical_stub.c
3839
stubs/LoRaMacCrypto_stub.cpp
3940
stubs/LoRaMacChannelPlan_stub.cpp
4041
stubs/LoRaWANTimer_stub.cpp

UNITTESTS/stubs/LoRaWANStack_stub.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ LoRaWANStack::LoRaWANStack()
3939
_app_port(12),
4040
_link_check_requested(false),
4141
_automatic_uplink_ongoing(false),
42-
_ready_for_rx(true),
4342
_queue(NULL)
4443
{
4544
}

UNITTESTS/stubs/mbed_critical_stub.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ void core_util_critical_section_exit(void)
4949
{
5050
}
5151

52+
bool core_util_atomic_flag_test_and_set(volatile core_util_atomic_flag *flagPtr)
53+
{
54+
return false;
55+
}
56+
57+
void core_util_atomic_flag_clear(volatile core_util_atomic_flag *flagPtr)
58+
{
59+
}
60+
5261
bool core_util_atomic_cas_u8(volatile uint8_t *ptr, uint8_t *expectedCurrentValue, uint8_t desiredValue)
5362
{
5463
return false;

features/lorawan/LoRaWANStack.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ LoRaWANStack::LoRaWANStack()
7373
_app_port(INVALID_PORT),
7474
_link_check_requested(false),
7575
_automatic_uplink_ongoing(false),
76-
_ready_for_rx(true),
7776
_queue(NULL)
7877
{
7978
_tx_metadata.stale = true;
8079
_rx_metadata.stale = true;
80+
core_util_atomic_flag_clear(&_rx_payload_in_use);
8181

8282
#ifdef MBED_CONF_LORA_APP_PORT
8383
if (is_port_valid(MBED_CONF_LORA_APP_PORT)) {
@@ -519,11 +519,10 @@ void LoRaWANStack::tx_interrupt_handler(void)
519519
void LoRaWANStack::rx_interrupt_handler(const uint8_t *payload, uint16_t size,
520520
int16_t rssi, int8_t snr)
521521
{
522-
if (!_ready_for_rx || size > sizeof _rx_payload) {
522+
if (size > sizeof _rx_payload || core_util_atomic_flag_test_and_set(&_rx_payload_in_use)) {
523523
return;
524524
}
525525

526-
_ready_for_rx = false;
527526
memcpy(_rx_payload, payload, size);
528527

529528
const uint8_t *ptr = _rx_payload;
@@ -709,13 +708,13 @@ void LoRaWANStack::process_reception(const uint8_t *const payload, uint16_t size
709708
mlme_confirm_handler();
710709

711710
if (_loramac.get_mlme_confirmation()->req_type == MLME_JOIN) {
712-
_ready_for_rx = true;
711+
core_util_atomic_flag_clear(&_rx_payload_in_use);
713712
return;
714713
}
715714
}
716715

717716
if (!_loramac.nwk_joined()) {
718-
_ready_for_rx = true;
717+
core_util_atomic_flag_clear(&_rx_payload_in_use);
719718
return;
720719
}
721720

@@ -744,7 +743,7 @@ void LoRaWANStack::process_reception(const uint8_t *const payload, uint16_t size
744743
mlme_indication_handler();
745744
}
746745

747-
_ready_for_rx = true;
746+
core_util_atomic_flag_clear(&_rx_payload_in_use);
748747
}
749748

750749
void LoRaWANStack::process_reception_timeout(bool is_timeout)

features/lorawan/LoRaWANStack.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
#include <stdint.h>
4444
#include "events/EventQueue.h"
45+
#include "platform/mbed_critical.h"
4546
#include "platform/Callback.h"
4647
#include "platform/NonCopyable.h"
4748
#include "platform/ScopedLock.h"
@@ -504,7 +505,7 @@ class LoRaWANStack: private mbed::NonCopyable<LoRaWANStack> {
504505
uint8_t _app_port;
505506
bool _link_check_requested;
506507
bool _automatic_uplink_ongoing;
507-
volatile bool _ready_for_rx;
508+
core_util_atomic_flag _rx_payload_in_use;
508509
uint8_t _rx_payload[LORAMAC_PHY_MAXPAYLOAD];
509510
events::EventQueue *_queue;
510511
lorawan_time_t _tx_timestamp;

0 commit comments

Comments
 (0)