Skip to content

Commit

Permalink
Merge pull request #14422 from pan-/lora-cancellation
Browse files Browse the repository at this point in the history
Fix Lora timer cancellation
  • Loading branch information
0xc0170 authored Mar 12, 2021
2 parents 09eac13 + 70920d4 commit b4abfe6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 9 deletions.
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

0 comments on commit b4abfe6

Please sign in to comment.