Skip to content
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
14 changes: 13 additions & 1 deletion features/lorawan/LoRaWANInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,28 @@
*/

#include "LoRaWANInterface.h"
#include "lorastack/phy/loraphy_target.h"

using namespace events;

LoRaWANInterface::LoRaWANInterface(LoRaRadio &radio)
: _default_phy(NULL)
{
_lw_stack.bind_radio_driver(radio);
_default_phy = new LoRaPHY_region;
MBED_ASSERT(_default_phy);
_lw_stack.bind_phy_and_radio_driver(radio, *_default_phy);
}

LoRaWANInterface::LoRaWANInterface(LoRaRadio &radio, LoRaPHY &phy)
: _default_phy(NULL)
{
_lw_stack.bind_phy_and_radio_driver(radio, phy);
}

LoRaWANInterface::~LoRaWANInterface()
{
delete _default_phy;
_default_phy = NULL;
}

lorawan_status_t LoRaWANInterface::initialize(EventQueue *queue)
Expand Down
19 changes: 19 additions & 0 deletions features/lorawan/LoRaWANInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "LoRaRadio.h"
#include "LoRaWANBase.h"

class LoRaPHY;

class LoRaWANInterface: public LoRaWANBase {

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

/** Constructs a LoRaWANInterface using the user provided PHY object.

* @param radio A reference to radio object
* @param phy A reference to PHY object
*/
LoRaWANInterface(LoRaRadio &radio, LoRaPHY &phy);

virtual ~LoRaWANInterface();

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

LoRaWANStack _lw_stack;

/** PHY object if created by LoRaWANInterface
*
* PHY object if LoRaWANInterface has created it.
* If PHY object is provided by the application, this pointer is NULL.
*/
LoRaPHY *_default_phy;
};

#endif /* LORAWANINTERFACE_H_ */
5 changes: 3 additions & 2 deletions features/lorawan/LoRaWANStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,16 @@ LoRaWANStack::LoRaWANStack()
/*****************************************************************************
* Public Methods *
****************************************************************************/
void LoRaWANStack::bind_radio_driver(LoRaRadio &radio)
void LoRaWANStack::bind_phy_and_radio_driver(LoRaRadio &radio, LoRaPHY &phy)
{
radio_events.tx_done = mbed::callback(this, &LoRaWANStack::tx_interrupt_handler);
radio_events.rx_done = mbed::callback(this, &LoRaWANStack::rx_interrupt_handler);
radio_events.rx_error = mbed::callback(this, &LoRaWANStack::rx_error_interrupt_handler);
radio_events.tx_timeout = mbed::callback(this, &LoRaWANStack::tx_timeout_interrupt_handler);
radio_events.rx_timeout = mbed::callback(this, &LoRaWANStack::rx_timeout_interrupt_handler);

_loramac.bind_radio_driver(radio);
phy.set_radio_instance(radio);
_loramac.bind_phy(phy);

radio.lock();
radio.init_radio(&radio_events);
Expand Down
14 changes: 9 additions & 5 deletions features/lorawan/LoRaWANStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,27 @@
#include "system/lorawan_data_structures.h"
#include "LoRaRadio.h"

class LoRaPHY;

class LoRaWANStack: private mbed::NonCopyable<LoRaWANStack> {

public:
LoRaWANStack();

/** Binds radio driver to PHY layer.
/** Binds PHY layer and radio driver to stack.
*
* MAC layer is totally detached from the PHY layer so the stack layer
* needs to play the role of an arbitrator. This API gets a radio driver
* object from the application (via LoRaWANInterface), binds it to the PHY
* layer and initialises radio callback handles which the radio driver will
* needs to play the role of an arbitrator.
* This API sets the PHY layer object to stack and bind the radio driver
* object from the application to the PHY layer.
* Also initialises radio callback handles which the radio driver will
* use in order to report events.
*
* @param radio LoRaRadio object, i.e., the radio driver
* @param phy LoRaPHY object.
*
*/
void bind_radio_driver(LoRaRadio &radio);
void bind_phy_and_radio_driver(LoRaRadio &radio, LoRaPHY &phy);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style fix LoRaRadio &radio

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is good already but I fixed some other radio style bugs.


/** End device initialization.
* @param queue A pointer to an EventQueue passed from the application.
Expand Down
Loading