Skip to content

LoRAWAN: volatile bool -> atomic_flag #9245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions UNITTESTS/features/lorawan/lorawanstack/unittest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ set(unittest-test-sources
stubs/LoRaPHY_stub.cpp
stubs/LoRaMac_stub.cpp
stubs/mbed_assert_stub.c
stubs/mbed_critical_stub.c
stubs/LoRaMacCrypto_stub.cpp
stubs/LoRaMacChannelPlan_stub.cpp
stubs/LoRaWANTimer_stub.cpp
Expand Down
1 change: 0 additions & 1 deletion UNITTESTS/stubs/LoRaWANStack_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ LoRaWANStack::LoRaWANStack()
_app_port(12),
_link_check_requested(false),
_automatic_uplink_ongoing(false),
_ready_for_rx(true),
_queue(NULL)
{
}
Expand Down
9 changes: 9 additions & 0 deletions UNITTESTS/stubs/mbed_critical_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ void core_util_critical_section_exit(void)
{
}

bool core_util_atomic_flag_test_and_set(volatile core_util_atomic_flag *flagPtr)
{
return false;
}

void core_util_atomic_flag_clear(volatile core_util_atomic_flag *flagPtr)
{
}

bool core_util_atomic_cas_u8(volatile uint8_t *ptr, uint8_t *expectedCurrentValue, uint8_t desiredValue)
{
return false;
Expand Down
11 changes: 5 additions & 6 deletions features/lorawan/LoRaWANStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ LoRaWANStack::LoRaWANStack()
_app_port(INVALID_PORT),
_link_check_requested(false),
_automatic_uplink_ongoing(false),
_ready_for_rx(true),
_queue(NULL)
{
_tx_metadata.stale = true;
_rx_metadata.stale = true;
core_util_atomic_flag_clear(&_rx_payload_in_use);

#ifdef MBED_CONF_LORA_APP_PORT
if (is_port_valid(MBED_CONF_LORA_APP_PORT)) {
Expand Down Expand Up @@ -519,11 +519,10 @@ void LoRaWANStack::tx_interrupt_handler(void)
void LoRaWANStack::rx_interrupt_handler(const uint8_t *payload, uint16_t size,
int16_t rssi, int8_t snr)
{
if (!_ready_for_rx || size > sizeof _rx_payload) {
if (size > sizeof _rx_payload || core_util_atomic_flag_test_and_set(&_rx_payload_in_use)) {
return;
}

_ready_for_rx = false;
memcpy(_rx_payload, payload, size);

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

if (_loramac.get_mlme_confirmation()->req_type == MLME_JOIN) {
_ready_for_rx = true;
core_util_atomic_flag_clear(&_rx_payload_in_use);
return;
}
}

if (!_loramac.nwk_joined()) {
_ready_for_rx = true;
core_util_atomic_flag_clear(&_rx_payload_in_use);
return;
}

Expand Down Expand Up @@ -744,7 +743,7 @@ void LoRaWANStack::process_reception(const uint8_t *const payload, uint16_t size
mlme_indication_handler();
}

_ready_for_rx = true;
core_util_atomic_flag_clear(&_rx_payload_in_use);
}

void LoRaWANStack::process_reception_timeout(bool is_timeout)
Expand Down
3 changes: 2 additions & 1 deletion features/lorawan/LoRaWANStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

#include <stdint.h>
#include "events/EventQueue.h"
#include "platform/mbed_critical.h"
#include "platform/Callback.h"
#include "platform/NonCopyable.h"
#include "platform/ScopedLock.h"
Expand Down Expand Up @@ -504,7 +505,7 @@ class LoRaWANStack: private mbed::NonCopyable<LoRaWANStack> {
uint8_t _app_port;
bool _link_check_requested;
bool _automatic_uplink_ongoing;
volatile bool _ready_for_rx;
core_util_atomic_flag _rx_payload_in_use;
uint8_t _rx_payload[LORAMAC_PHY_MAXPAYLOAD];
events::EventQueue *_queue;
lorawan_time_t _tx_timestamp;
Expand Down