Skip to content

Commit 3f742c9

Browse files
author
Cruz Monrreal
authored
Merge pull request #7430 from kivaisan/user_constructed_phy_v2
Lora: Add support for runtime PHY selection
2 parents c038419 + 0397b0b commit 3f742c9

28 files changed

+159
-128
lines changed

features/lorawan/LoRaWANInterface.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,28 @@
2020
*/
2121

2222
#include "LoRaWANInterface.h"
23+
#include "lorastack/phy/loraphy_target.h"
2324

2425
using namespace events;
2526

2627
LoRaWANInterface::LoRaWANInterface(LoRaRadio &radio)
28+
: _default_phy(NULL)
2729
{
28-
_lw_stack.bind_radio_driver(radio);
30+
_default_phy = new LoRaPHY_region;
31+
MBED_ASSERT(_default_phy);
32+
_lw_stack.bind_phy_and_radio_driver(radio, *_default_phy);
33+
}
34+
35+
LoRaWANInterface::LoRaWANInterface(LoRaRadio &radio, LoRaPHY &phy)
36+
: _default_phy(NULL)
37+
{
38+
_lw_stack.bind_phy_and_radio_driver(radio, phy);
2939
}
3040

3141
LoRaWANInterface::~LoRaWANInterface()
3242
{
43+
delete _default_phy;
44+
_default_phy = NULL;
3345
}
3446

3547
lorawan_status_t LoRaWANInterface::initialize(EventQueue *queue)

features/lorawan/LoRaWANInterface.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "LoRaRadio.h"
2525
#include "LoRaWANBase.h"
2626

27+
class LoRaPHY;
28+
2729
class LoRaWANInterface: public LoRaWANBase {
2830

2931
public:
@@ -33,9 +35,19 @@ class LoRaWANInterface: public LoRaWANBase {
3335
* Currently, LoRaWANStack is a singleton and you should only
3436
* construct a single instance of LoRaWANInterface.
3537
*
38+
* LoRaWANInterface will construct PHY based on "lora.phy" setting in mbed_app.json.
39+
*
40+
* @param radio A reference to radio object
3641
*/
3742
LoRaWANInterface(LoRaRadio &radio);
3843

44+
/** Constructs a LoRaWANInterface using the user provided PHY object.
45+
46+
* @param radio A reference to radio object
47+
* @param phy A reference to PHY object
48+
*/
49+
LoRaWANInterface(LoRaRadio &radio, LoRaPHY &phy);
50+
3951
virtual ~LoRaWANInterface();
4052

4153
/** Initialize the LoRa stack.
@@ -508,6 +520,13 @@ class LoRaWANInterface: public LoRaWANBase {
508520
typedef mbed::ScopedLock<LoRaWANInterface> Lock;
509521

510522
LoRaWANStack _lw_stack;
523+
524+
/** PHY object if created by LoRaWANInterface
525+
*
526+
* PHY object if LoRaWANInterface has created it.
527+
* If PHY object is provided by the application, this pointer is NULL.
528+
*/
529+
LoRaPHY *_default_phy;
511530
};
512531

513532
#endif /* LORAWANINTERFACE_H_ */

features/lorawan/LoRaWANStack.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,16 @@ LoRaWANStack::LoRaWANStack()
9898
/*****************************************************************************
9999
* Public Methods *
100100
****************************************************************************/
101-
void LoRaWANStack::bind_radio_driver(LoRaRadio &radio)
101+
void LoRaWANStack::bind_phy_and_radio_driver(LoRaRadio &radio, LoRaPHY &phy)
102102
{
103103
radio_events.tx_done = mbed::callback(this, &LoRaWANStack::tx_interrupt_handler);
104104
radio_events.rx_done = mbed::callback(this, &LoRaWANStack::rx_interrupt_handler);
105105
radio_events.rx_error = mbed::callback(this, &LoRaWANStack::rx_error_interrupt_handler);
106106
radio_events.tx_timeout = mbed::callback(this, &LoRaWANStack::tx_timeout_interrupt_handler);
107107
radio_events.rx_timeout = mbed::callback(this, &LoRaWANStack::rx_timeout_interrupt_handler);
108108

109-
_loramac.bind_radio_driver(radio);
109+
phy.set_radio_instance(radio);
110+
_loramac.bind_phy(phy);
110111

111112
radio.lock();
112113
radio.init_radio(&radio_events);

features/lorawan/LoRaWANStack.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,27 @@
5151
#include "system/lorawan_data_structures.h"
5252
#include "LoRaRadio.h"
5353

54+
class LoRaPHY;
55+
5456
class LoRaWANStack: private mbed::NonCopyable<LoRaWANStack> {
5557

5658
public:
5759
LoRaWANStack();
5860

59-
/** Binds radio driver to PHY layer.
61+
/** Binds PHY layer and radio driver to stack.
6062
*
6163
* MAC layer is totally detached from the PHY layer so the stack layer
62-
* needs to play the role of an arbitrator. This API gets a radio driver
63-
* object from the application (via LoRaWANInterface), binds it to the PHY
64-
* layer and initialises radio callback handles which the radio driver will
64+
* needs to play the role of an arbitrator.
65+
* This API sets the PHY layer object to stack and bind the radio driver
66+
* object from the application to the PHY layer.
67+
* Also initialises radio callback handles which the radio driver will
6568
* use in order to report events.
6669
*
6770
* @param radio LoRaRadio object, i.e., the radio driver
71+
* @param phy LoRaPHY object.
6872
*
6973
*/
70-
void bind_radio_driver(LoRaRadio &radio);
74+
void bind_phy_and_radio_driver(LoRaRadio &radio, LoRaPHY &phy);
7175

7276
/** End device initialization.
7377
* @param queue A pointer to an EventQueue passed from the application.

0 commit comments

Comments
 (0)