Skip to content

Commit f7c0ce6

Browse files
Hasnain Virktheotherjimmy
authored andcommitted
Making static objects SingletonPtr
We had a lot of static objects which would get constructed and hence pull in some of the LoRaWAN code into the builds for other technologies. Such objects have been now lazily initialized using utility class SingletonPtr.
1 parent 7872b6a commit f7c0ce6

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

features/lorawan/LoRaWANStack.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,34 +44,34 @@ SPDX-License-Identifier: BSD-3-Clause
4444
#ifdef MBED_CONF_LORA_PHY
4545
#if MBED_CONF_LORA_PHY == 0
4646
#include "lorawan/lorastack/phy/LoRaPHYEU868.h"
47-
static LoRaPHYEU868 lora_phy;
47+
static SingletonPtr<LoRaPHYEU868> lora_phy;
4848
#elif MBED_CONF_LORA_PHY == 1
4949
#include "lorawan/lorastack/phy/LoRaPHYAS923.h"
50-
static LoRaPHYAS923 lora_phy;
50+
static SingletonPtr<LoRaPHYAS923> lora_phy;
5151
#elif MBED_CONF_LORA_PHY == 2
5252
#include "lorawan/lorastack/phy/LoRaPHYAU915.h"
53-
static LoRaPHYAU915 lora_phy;
53+
static SingletonPtr<LoRaPHYAU915> lora_phy;
5454
#elif MBED_CONF_LORA_PHY == 3
5555
#include "lorawan/lorastack/phy/LoRaPHYCN470.h"
56-
static LoRaPHYCN470 lora_phy;
56+
static SingletonPtr<LoRaPHYCN470> lora_phy;
5757
#elif MBED_CONF_LORA_PHY == 4
5858
#include "lorawan/lorastack/phy/LoRaPHYCN779.h"
59-
static LoRaPHYCN779 lora_phy;
59+
static SingletonPtr<LoRaPHYCN779> lora_phy;
6060
#elif MBED_CONF_LORA_PHY == 5
6161
#include "lorawan/lorastack/phy/LoRaPHYEU433.h"
62-
static LoRaPHYEU433 lora_phy;
62+
static SingletonPtr<LoRaPHYEU433> lora_phy;
6363
#elif MBED_CONF_LORA_PHY == 6
6464
#include "lorawan/lorastack/phy/LoRaPHYIN865.h"
65-
static LoRaPHYIN865 lora_phy;
65+
static SingletonPtr<LoRaPHYIN865> lora_phy;
6666
#elif MBED_CONF_LORA_PHY == 7
6767
#include "lorawan/lorastack/phy/LoRaPHYKR920.h"
68-
static LoRaPHYKR920 lora_phy;
68+
static SingletonPtr<LoRaPHYKR920> lora_phy;
6969
#elif MBED_CONF_LORA_PHY == 8
7070
#include "lorawan/lorastack/phy/LoRaPHYUS915.h"
71-
static LoRaPHYUS915 lora_phy;
71+
static SingletonPtr<LoRaPHYUS915> lora_phy;
7272
#elif MBED_CONF_LORA_PHY == 9
7373
#include "lorawan/lorastack/phy/LoRaPHYUS915Hybrid.h"
74-
static LoRaPHYUS915Hybrid lora_phy;
74+
static SingletonPtr<LoRaPHYUS915Hybrid> lora_phy;
7575
#endif //MBED_CONF_LORA_PHY == VALUE
7676
#else
7777
#error "Must set LoRa PHY layer parameters."
@@ -170,9 +170,10 @@ radio_events_t *LoRaWANStack::bind_radio_driver(LoRaRadio& radio)
170170
// Store pointer to callback routines inside MAC layer (non-IRQ safe)
171171
_mac_handlers = GetPhyEventHandlers();
172172
// passes the reference to radio driver down to PHY layer
173-
lora_phy.set_radio_instance(radio);
173+
lora_phy.get()->set_radio_instance(radio);
174174
return _mac_handlers;
175175
}
176+
176177
lora_mac_status_t LoRaWANStack::initialize_mac_layer(EventQueue *queue)
177178
{
178179
if (DEVICE_STATE_NOT_INITIALIZED != _device_current_state)
@@ -203,7 +204,7 @@ lora_mac_status_t LoRaWANStack::initialize_mac_layer(EventQueue *queue)
203204
LoRaMacPrimitives.MacMcpsConfirm = callback(this, &LoRaWANStack::mcps_confirm);
204205
LoRaMacPrimitives.MacMcpsIndication = callback(this, &LoRaWANStack::mcps_indication);
205206
LoRaMacPrimitives.MacMlmeConfirm = callback(this, &LoRaWANStack::mlme_confirm);
206-
LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, &lora_phy, queue);
207+
LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, lora_phy.get(), queue);
207208

208209
mib_req.type = LORA_MIB_ADR;
209210
mib_req.param.adr_enable = LORAWAN_ADR_ON;
@@ -336,7 +337,7 @@ lora_mac_status_t LoRaWANStack::send_frame_to_mac()
336337
GetPhyParams_t phy_params;
337338
PhyParam_t default_datarate;
338339
phy_params.Attribute = PHY_DEF_TX_DR;
339-
default_datarate = lora_phy.get_phy_params(&phy_params);
340+
default_datarate = lora_phy.get()->get_phy_params(&phy_params);
340341

341342
mcps_req.type = _tx_msg.type;
342343

@@ -484,7 +485,7 @@ lora_mac_status_t LoRaWANStack::add_channels(const lora_channelplan_t &channel_p
484485

485486
// Check first how many channels the selected PHY layer supports
486487
get_phy.Attribute = PHY_MAX_NB_CHANNELS;
487-
phy_param = lora_phy.get_phy_params(&get_phy);
488+
phy_param = lora_phy.get()->get_phy_params(&get_phy);
488489
max_num_channels = (uint8_t) phy_param.Value;
489490

490491
// check if user is setting more channels than supported
@@ -528,17 +529,17 @@ lora_mac_status_t LoRaWANStack::drop_channel_list()
528529

529530
// Check first how many channels the selected PHY layer supports
530531
get_phy.Attribute = PHY_MAX_NB_CHANNELS;
531-
phy_param = lora_phy.get_phy_params(&get_phy);
532+
phy_param = lora_phy.get()->get_phy_params(&get_phy);
532533
max_num_channels = (uint8_t) phy_param.Value;
533534

534535
// Now check the channel mask for enabled channels
535536
get_phy.Attribute = PHY_CHANNELS_MASK;
536-
phy_param = lora_phy.get_phy_params(&get_phy);
537+
phy_param = lora_phy.get()->get_phy_params(&get_phy);
537538
channel_masks = phy_param.ChannelsMask;
538539

539540
// Now check the channel mask for default channels
540541
get_phy.Attribute = PHY_CHANNELS_DEFAULT_MASK;
541-
phy_param = lora_phy.get_phy_params(&get_phy);
542+
phy_param = lora_phy.get()->get_phy_params(&get_phy);
542543
default_channel_masks = phy_param.ChannelsMask;
543544

544545
for (uint8_t i = 0; i < max_num_channels; i++) {
@@ -577,7 +578,7 @@ lora_mac_status_t LoRaWANStack::remove_a_channel(uint8_t channel_id)
577578

578579
// Check first how many channels the selected PHY layer supports
579580
get_phy.Attribute = PHY_MAX_NB_CHANNELS;
580-
phy_param = lora_phy.get_phy_params(&get_phy);
581+
phy_param = lora_phy.get()->get_phy_params(&get_phy);
581582
max_num_channels = (uint8_t) phy_param.Value;
582583

583584
// According to specification channel IDs start from 0 and last valid
@@ -589,7 +590,7 @@ lora_mac_status_t LoRaWANStack::remove_a_channel(uint8_t channel_id)
589590

590591
// Now check the Default channel mask
591592
get_phy.Attribute = PHY_CHANNELS_DEFAULT_MASK;
592-
phy_param = lora_phy.get_phy_params(&get_phy);
593+
phy_param = lora_phy.get()->get_phy_params(&get_phy);
593594
channel_masks = phy_param.ChannelsMask;
594595

595596
// check if the channel ID give belongs to a default channel
@@ -624,12 +625,12 @@ lora_mac_status_t LoRaWANStack::get_enabled_channels(lora_channelplan_t& channel
624625

625626
// Check first how many channels the selected PHY layer supports
626627
get_phy.Attribute = PHY_MAX_NB_CHANNELS;
627-
phy_param = lora_phy.get_phy_params(&get_phy);
628+
phy_param = lora_phy.get()->get_phy_params(&get_phy);
628629
max_num_channels = (uint8_t) phy_param.Value;
629630

630631
// Now check the Default channel mask
631632
get_phy.Attribute = PHY_CHANNELS_MASK;
632-
phy_param = lora_phy.get_phy_params(&get_phy);
633+
phy_param = lora_phy.get()->get_phy_params(&get_phy);
633634
channel_masks = phy_param.ChannelsMask;
634635

635636
// Request Mib to get channels

features/lorawan/system/LoRaWANTimer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ void TimerInit( TimerEvent_t *obj, void ( *callback )( void ) )
4646

4747
void TimerStart( TimerEvent_t *obj )
4848
{
49-
obj->Timer.attach_us( mbed::callback( obj->Callback ), obj->value * 1000 );
49+
obj->Timer.get()->attach_us( mbed::callback( obj->Callback ), obj->value * 1000 );
5050
}
5151

5252
void TimerStop( TimerEvent_t *obj )
5353
{
54-
obj->Timer.detach( );
54+
obj->Timer.get()->detach( );
5555
}
5656

5757
void TimerSetValue( TimerEvent_t *obj, uint32_t value )

features/lorawan/system/LoRaWANTimer.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ SPDX-License-Identifier: BSD-3-Clause
2020

2121
#ifndef MBED_LORAWAN_SYS_TIMER_H__
2222
#define MBED_LORAWAN_SYS_TIMER_H__
23+
2324
#include "drivers/Timer.h"
2425
#include "drivers/Ticker.h"
2526
#include "lorawan/system/lorawan_data_structures.h"
2627
#include "events/EventQueue.h"
28+
#include "platform/SingletonPtr.h"
2729

2830
/*!
2931
* \brief Timer object description
@@ -32,7 +34,7 @@ typedef struct TimerEvent_s
3234
{
3335
uint32_t value;
3436
void ( *Callback )( void );
35-
mbed::Ticker Timer;
37+
SingletonPtr<mbed::Ticker> Timer;
3638
}TimerEvent_t;
3739

3840
/*!

0 commit comments

Comments
 (0)