Timer SingletonPtr & mac protocol data structure

Ticker objects embeded in TimerEvent_t data structure were getting constructed
even for the non LORAWAN builds. And that's what was bloating the builds.
We now lazy initialize them using Mbed-OS utility clas SingletonPtr.

A central data structure has been created that carries all the protocol level
variables for the Mac layer. This is important as we are going to break down
MAC services into subsystems and we will pass around common data using that data structure.
pull/6059/head
Hasnain Virk 2018-01-08 18:06:40 +02:00
parent f62253ca0e
commit a3106d2fe6
4 changed files with 703 additions and 669 deletions

File diff suppressed because it is too large Load Diff

View File

@ -613,138 +613,18 @@ private:
LoRaWANTimeHandler &_lora_time;
lora_mac_protocol_params _params;
/**
* Radio event callback handlers for MAC
*/
radio_events_t RadioEvents;
/*!
* Device IEEE EUI
*/
uint8_t *LoRaMacDevEui;
/*!
* Application IEEE EUI
*/
uint8_t *LoRaMacAppEui;
/*!
* AES encryption/decryption cipher application key
*/
uint8_t *LoRaMacAppKey;
/*!
* AES encryption/decryption cipher network session key
*/
uint8_t LoRaMacNwkSKey[16];
/*!
* AES encryption/decryption cipher application session key
*/
uint8_t LoRaMacAppSKey[16];
/*!
* Device nonce is a random value extracted by issuing a sequence of RSSI
* measurements
*/
uint16_t LoRaMacDevNonce;
/*!
* Network ID ( 3 bytes )
*/
uint32_t LoRaMacNetID;
/*!
* Mote Address
*/
uint32_t LoRaMacDevAddr;
/*!
* Multicast channels linked list
*/
MulticastParams_t *MulticastChannels;
/*!
* Actual device class
*/
DeviceClass_t LoRaMacDeviceClass;
/*!
* Indicates if the node is connected to a private or public network
*/
bool PublicNetwork;
/*!
* Indicates if the node supports repeaters
*/
bool RepeaterSupport;
/*!
* Buffer containing the data to be sent or received.
*/
uint8_t LoRaMacBuffer[LORAMAC_PHY_MAXPAYLOAD];
/*!
* Length of packet in LoRaMacBuffer
*/
uint16_t LoRaMacBufferPktLen;
/*!
* Length of the payload in LoRaMacBuffer
*/
uint8_t LoRaMacTxPayloadLen;
/*!
* Buffer containing the upper layer data.
*/
uint8_t LoRaMacRxPayload[LORAMAC_PHY_MAXPAYLOAD];
/*!
* LoRaMAC frame counter. Each time a packet is sent the counter is incremented.
* Only the 16 LSB bits are sent
*/
uint32_t UpLinkCounter;
/*!
* LoRaMAC frame counter. Each time a packet is received the counter is incremented.
* Only the 16 LSB bits are received
*/
uint32_t DownLinkCounter;
/*!
* IsPacketCounterFixed enables the MIC field tests by fixing the
* UpLinkCounter value
*/
bool IsUpLinkCounterFixed;
/*!
* Used for test purposes. Disables the opening of the reception windows.
*/
bool IsRxWindowsEnabled;
/*!
* Indicates if the MAC layer has already joined a network.
*/
bool IsLoRaMacNetworkJoined;
/*!
* Counts the number of missed ADR acknowledgements
*/
uint32_t AdrAckCounter;
/*!
* If the node has sent a FRAME_TYPE_DATA_CONFIRMED_UP this variable indicates
* if the nodes needs to manage the server acknowledgement.
*/
bool NodeAckRequested;
/*!
* If the server has sent a FRAME_TYPE_DATA_CONFIRMED_DOWN this variable indicates
* if the ACK bit must be set for the next transmission
*/
bool SrvAckRequested;
/*!
* LoRaMac parameters
@ -756,69 +636,6 @@ private:
*/
LoRaMacParams_t LoRaMacParamsDefaults;
/*!
* Uplink messages repetitions counter
*/
uint8_t ChannelsNbRepCounter;
/*!
* Aggregated duty cycle management
*/
TimerTime_t AggregatedLastTxDoneTime;
TimerTime_t AggregatedTimeOff;
/*!
* Enables/Disables duty cycle management (Test only)
*/
bool DutyCycleOn;
/*!
* Current channel index
*/
uint8_t Channel;
/*!
* Current channel index
*/
uint8_t LastTxChannel;
/*!
* Set to true, if the last uplink was a join request
*/
bool LastTxIsJoinRequest;
/*!
* Stores the time at LoRaMac initialization.
*
* \remark Used for the BACKOFF_DC computation.
*/
TimerTime_t LoRaMacInitializationTime;
/*!
* LoRaMac internal states
*/
enum eLoRaMacState
{
LORAMAC_IDLE = 0x00000000,
LORAMAC_TX_RUNNING = 0x00000001,
LORAMAC_RX = 0x00000002,
LORAMAC_ACK_REQ = 0x00000004,
LORAMAC_ACK_RETRY = 0x00000008,
LORAMAC_TX_DELAYED = 0x00000010,
LORAMAC_TX_CONFIG = 0x00000020,
LORAMAC_RX_ABORT = 0x00000040,
};
/*!
* LoRaMac internal state
*/
uint32_t LoRaMacState;
/*!
* LoRaMac timer used to check the LoRaMacState (runs every second)
*/
TimerEvent_t MacStateCheckTimer;
/*!
* LoRaMac upper layer event functions
*/
@ -829,16 +646,7 @@ private:
*/
LoRaMacCallback_t *LoRaMacCallbacks;
/*!
* LoRaMac duty cycle delayed Tx timer
*/
TimerEvent_t TxDelayedTimer;
/*!
* LoRaMac reception windows timers
*/
TimerEvent_t RxWindowTimer1;
TimerEvent_t RxWindowTimer2;
/*!
* LoRaMac reception windows delay
@ -854,40 +662,6 @@ private:
RxConfigParams_t RxWindow1Config;
RxConfigParams_t RxWindow2Config;
/*!
* Acknowledge timeout timer. Used for packet retransmissions.
*/
TimerEvent_t AckTimeoutTimer;
/*!
* Number of trials to get a frame acknowledged
*/
uint8_t AckTimeoutRetries;
/*!
* Number of trials to get a frame acknowledged
*/
uint8_t AckTimeoutRetriesCounter;
/*!
* Indicates if the AckTimeout timer has expired or not
*/
bool AckTimeoutRetry;
/*!
* Last transmission time on air
*/
TimerTime_t TxTimeOnAir;
/*!
* Number of trials for the Join Request
*/
uint8_t JoinRequestTrials;
/*!
* Maximum number of trials for the Join Request
*/
uint8_t MaxJoinRequestTrials;
/*!
* Structure to hold MCPS indication data.
@ -914,11 +688,6 @@ private:
*/
LoRaMacRxSlot_t RxSlot;
/*!
* LoRaMac tx/rx operation state
*/
LoRaMacFlags_t LoRaMacFlags;
};
#endif // __LORAMAC_H__

View File

@ -22,20 +22,8 @@ SPDX-License-Identifier: BSD-3-Clause
#define MBED_LORAWAN_SYS_TIMER_H__
#include <stdint.h>
#include "drivers/Ticker.h"
#include "lorawan/system/lorawan_data_structures.h"
#include "events/EventQueue.h"
#include "platform/SingletonPtr.h"
/*!
* \brief Timer object description
*/
typedef struct TimerEvent_s
{
uint32_t value;
mbed::Callback<void()> Callback;
SingletonPtr<mbed::Ticker> Timer;
}TimerEvent_t;
class LoRaWANTimeHandler
{

View File

@ -24,7 +24,9 @@
#define LORAWAN_SYSTEM_LORAWAN_DATA_STRUCTURES_H_
#include <inttypes.h>
#include "drivers/Ticker.h"
#include "platform/Callback.h"
#include "platform/SingletonPtr.h"
/*!
* \brief Timer time variable definition
@ -2939,6 +2941,269 @@ typedef struct loramac_downlink_status {
uint8_t buffer_size;
} loramac_downlink_status_t;
/*!
* \brief Timer object description
*/
typedef struct TimerEvent_s
{
uint32_t value;
mbed::Callback<void()> Callback;
SingletonPtr<mbed::Ticker> Timer;
} TimerEvent_t;
/*!
* LoRaMac internal states
*/
enum eLoRaMacState
{
LORAMAC_IDLE = 0x00000000,
LORAMAC_TX_RUNNING = 0x00000001,
LORAMAC_RX = 0x00000002,
LORAMAC_ACK_REQ = 0x00000004,
LORAMAC_ACK_RETRY = 0x00000008,
LORAMAC_TX_DELAYED = 0x00000010,
LORAMAC_TX_CONFIG = 0x00000020,
LORAMAC_RX_ABORT = 0x00000040,
};
typedef struct {
/*!
* Device IEEE EUI
*/
uint8_t *LoRaMacDevEui;
/*!
* Application IEEE EUI
*/
uint8_t *LoRaMacAppEui;
/*!
* AES encryption/decryption cipher application key
*/
uint8_t *LoRaMacAppKey;
/*!
* AES encryption/decryption cipher network session key
*/
uint8_t LoRaMacNwkSKey[16];
/*!
* AES encryption/decryption cipher application session key
*/
uint8_t LoRaMacAppSKey[16];
} lora_mac_keys;
typedef struct {
/*!
* Aggregated duty cycle management
*/
TimerTime_t AggregatedLastTxDoneTime;
TimerTime_t AggregatedTimeOff;
/*!
* Stores the time at LoRaMac initialization.
*
* \remark Used for the BACKOFF_DC computation.
*/
TimerTime_t LoRaMacInitializationTime;
/*!
* Last transmission time on air
*/
TimerTime_t TxTimeOnAir;
/*!
* LoRaMac timer used to check the LoRaMacState (runs every second)
*/
TimerEvent_t MacStateCheckTimer;
/*!
* LoRaMac duty cycle delayed Tx timer
*/
TimerEvent_t TxDelayedTimer;
/*!
* LoRaMac reception windows timers
*/
TimerEvent_t RxWindowTimer1;
TimerEvent_t RxWindowTimer2;
/*!
* Acknowledge timeout timer. Used for packet retransmissions.
*/
TimerEvent_t AckTimeoutTimer;
} lora_mac_timers;
typedef struct {
/*!
* Actual device class
*/
DeviceClass_t LoRaMacDeviceClass;
/*!
* Indicates if the node is connected to a private or public network
*/
bool PublicNetwork;
/*!
* Indicates if the node supports repeaters
*/
bool RepeaterSupport;
/*!
* IsPacketCounterFixed enables the MIC field tests by fixing the
* UpLinkCounter value
*/
bool IsUpLinkCounterFixed;
/*!
* Used for test purposes. Disables the opening of the reception windows.
*/
bool IsRxWindowsEnabled;
/*!
* Indicates if the MAC layer has already joined a network.
*/
bool IsLoRaMacNetworkJoined;
/*!
* If the node has sent a FRAME_TYPE_DATA_CONFIRMED_UP this variable indicates
* if the nodes needs to manage the server acknowledgement.
*/
bool NodeAckRequested;
/*!
* If the server has sent a FRAME_TYPE_DATA_CONFIRMED_DOWN this variable indicates
* if the ACK bit must be set for the next transmission
*/
bool SrvAckRequested;
/*!
* Enables/Disables duty cycle management (Test only)
*/
bool DutyCycleOn;
/*!
* Set to true, if the last uplink was a join request
*/
bool LastTxIsJoinRequest;
/*!
* Indicates if the AckTimeout timer has expired or not
*/
bool AckTimeoutRetry;
/*!
* Current channel index
*/
uint8_t Channel;
/*!
* Current channel index
*/
uint8_t LastTxChannel;
/*!
* Uplink messages repetitions counter
*/
uint8_t ChannelsNbRepCounter;
/*!
* Buffer containing the data to be sent or received.
*/
uint8_t LoRaMacBuffer[LORAMAC_PHY_MAXPAYLOAD];
/*!
* Length of the payload in LoRaMacBuffer
*/
uint8_t LoRaMacTxPayloadLen;
/*!
* Buffer containing the upper layer data.
*/
uint8_t LoRaMacRxPayload[LORAMAC_PHY_MAXPAYLOAD];
/*!
* Number of trials to get a frame acknowledged
*/
uint8_t AckTimeoutRetries;
/*!
* Number of trials to get a frame acknowledged
*/
uint8_t AckTimeoutRetriesCounter;
/*!
* Number of trials for the Join Request
*/
uint8_t JoinRequestTrials;
/*!
* Maximum number of trials for the Join Request
*/
uint8_t MaxJoinRequestTrials;
/*!
* Mac keys
*/
lora_mac_keys keys;
/*!
* LoRaMac tx/rx operation state
*/
LoRaMacFlags_t LoRaMacFlags;
/*!
* Length of packet in LoRaMacBuffer
*/
uint16_t LoRaMacBufferPktLen;
/*!
* Device nonce is a random value extracted by issuing a sequence of RSSI
* measurements
*/
uint16_t LoRaMacDevNonce;
/*!
* Network ID ( 3 bytes )
*/
uint32_t LoRaMacNetID;
/*!
* Mote Address
*/
uint32_t LoRaMacDevAddr;
/*!
* LoRaMAC frame counter. Each time a packet is sent the counter is incremented.
* Only the 16 LSB bits are sent
*/
uint32_t UpLinkCounter;
/*!
* LoRaMAC frame counter. Each time a packet is received the counter is incremented.
* Only the 16 LSB bits are received
*/
uint32_t DownLinkCounter;
/*!
* Counts the number of missed ADR acknowledgements
*/
uint32_t AdrAckCounter;
/*!
* LoRaMac internal state
*/
uint32_t LoRaMacState;
lora_mac_timers timers;
} lora_mac_protocol_params;
/** LoRaWAN callback functions
*
*/