Skip to content
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

Fix Lora timer cancellation #14422

Merged
merged 4 commits into from
Mar 12, 2021
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
5 changes: 5 additions & 0 deletions UNITTESTS/stubs/LoRaWANTimer_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,8 @@ void LoRaWANTimeHandler::stop(timer_event_t &obj)
{
obj.timer_id = 0;
}

void LoRaWANTimeHandler::clear(timer_event_t &obj)
{
obj.timer_id = 0;
}
44 changes: 35 additions & 9 deletions connectivity/lorawan/lorastack/mac/LoRaMac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,13 @@ void LoRaMac::set_device_class(const device_class_t &device_class,
_device_class = device_class;
_rx2_would_be_closure_for_class_c = rx2_would_be_closure_handler;

_lora_time.init(_rx2_closure_timer_for_class_c, _rx2_would_be_closure_for_class_c);
_lora_time.init(_rx2_closure_timer_for_class_c, [this] {
{
Lock lock(*this);
_lora_time.clear(_rx2_closure_timer_for_class_c);
}
_rx2_would_be_closure_for_class_c();
});

if (CLASS_A == _device_class) {
tr_debug("Changing device class to -> CLASS_A");
Expand Down Expand Up @@ -1805,14 +1811,34 @@ lorawan_status_t LoRaMac::initialize(EventQueue *queue,
_lora_phy->setup_public_network_mode(_params.is_nwk_public);
_lora_phy->put_radio_to_sleep();

_lora_time.init(_params.timers.backoff_timer,
mbed::callback(this, &LoRaMac::on_backoff_timer_expiry));
_lora_time.init(_params.timers.rx_window1_timer,
mbed::callback(this, &LoRaMac::open_rx1_window));
_lora_time.init(_params.timers.rx_window2_timer,
mbed::callback(this, &LoRaMac::open_rx2_window));
_lora_time.init(_params.timers.ack_timeout_timer,
mbed::callback(this, &LoRaMac::on_ack_timeout_timer_event));
_lora_time.init(_params.timers.backoff_timer, [this] {
{
Lock lock(*this);
_lora_time.clear(_params.timers.backoff_timer);
}
on_backoff_timer_expiry();
});
_lora_time.init(_params.timers.rx_window1_timer, [this] {
{
Lock lock(*this);
_lora_time.clear(_params.timers.rx_window1_timer);
}
open_rx1_window();
});
_lora_time.init(_params.timers.rx_window2_timer, [this] {
{
Lock lock(*this);
_lora_time.clear(_params.timers.rx_window2_timer);
}
open_rx2_window();
});
_lora_time.init(_params.timers.ack_timeout_timer, [this] {
{
Lock lock(*this);
_lora_time.clear(_params.timers.ack_timeout_timer);
}
on_ack_timeout_timer_event();
});

_params.timers.mac_init_time = _lora_time.get_current_time();

Expand Down
5 changes: 5 additions & 0 deletions connectivity/lorawan/system/LoRaWANTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,8 @@ void LoRaWANTimeHandler::stop(timer_event_t &obj)
_queue->cancel(obj.timer_id);
obj.timer_id = 0;
}

void LoRaWANTimeHandler::clear(timer_event_t &obj)
{
obj.timer_id = 0;
}
7 changes: 7 additions & 0 deletions connectivity/lorawan/system/LoRaWANTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ class LoRaWANTimeHandler {
*/
void stop(timer_event_t &obj);

/** Clear timer state so it is not inadvertently canceled. This function
* must be called by the callback registered in init.
*
* @param [in] obj The structure containing the timer object parameters.
*/
void clear(timer_event_t &obj);

private:
events::EventQueue *_queue;
};
Expand Down