diff --git a/features/lorawan/lorastack/phy/LoRaPHYAS923.cpp b/features/lorawan/lorastack/phy/LoRaPHYAS923.cpp index e5e37e8f84..d04b7e7073 100644 --- a/features/lorawan/lorastack/phy/LoRaPHYAS923.cpp +++ b/features/lorawan/lorastack/phy/LoRaPHYAS923.cpp @@ -184,6 +184,32 @@ */ #define AS923_RX_WND_2_DR DR_2 +/*! + * Beacon default frequency + */ +#define AS923_BEACON_CHANNEL_FREQ 923400000 + +/*! + * Ping slot default frequency + */ +#define AS923_PING_CHANNEL_FREQ 923400000 + +/*! + * Size of RFU 1 field + */ +#define AS923_BEACON_RFU1_SIZE 2 + +/*! + * Size of RFU 2 field + */ +#define AS923_BEACON_RFU2_SIZE 0 + +/*! + * Datarate of the beacon channel + */ +#define AS923_BEACON_CHANNEL_DR DR_3 + + /*! * Band 0 definition * { DutyCycle, TxMaxPower, LastJoinTxDoneTime, LastTxDoneTime, TimeOff } @@ -324,6 +350,11 @@ LoRaPHYAS923::LoRaPHYAS923() phy_params.ack_timeout_rnd = AS923_ACK_TIMEOUT_RND; phy_params.rx_window2_datarate = AS923_RX_WND_2_DR; phy_params.rx_window2_frequency = AS923_RX_WND_2_FREQ; + phy_params.beacon.default_frequency = AS923_BEACON_CHANNEL_FREQ; + phy_params.beacon.datarate = AS923_BEACON_CHANNEL_DR; + phy_params.beacon.rfu1_size = AS923_BEACON_RFU1_SIZE; + phy_params.beacon.rfu2_size = AS923_BEACON_RFU2_SIZE; + phy_params.ping_slot_default_frequency = AS923_PING_CHANNEL_FREQ; } LoRaPHYAS923::~LoRaPHYAS923() diff --git a/features/lorawan/lorastack/phy/LoRaPHYAU915.cpp b/features/lorawan/lorastack/phy/LoRaPHYAU915.cpp index 24c8519000..580d47ef41 100644 --- a/features/lorawan/lorastack/phy/LoRaPHYAU915.cpp +++ b/features/lorawan/lorastack/phy/LoRaPHYAU915.cpp @@ -163,6 +163,41 @@ */ #define AU915_RX_WND_2_DR DR_8 +/*! + * Beacon default frequency + */ +#define AU915_BEACON_CHANNEL_FREQ 923300000 + +/*! + * Beacon frequency channel stepwidth + */ +#define AU915_BEACON_CHANNEL_STEPWIDTH 600000 + +/*! + * Number of possible beacon channels + */ +#define AU915_BEACON_NB_CHANNELS 8 + +/*! + * Ping slot default frequency + */ +#define AU915_PING_CHANNEL_FREQ 923300000 + +/*! + * Size of RFU 1 field + */ +#define AU915_BEACON_RFU1_SIZE 3 + +/*! + * Size of RFU 2 field + */ +#define AU915_BEACON_RFU2_SIZE 1 + +/*! + * Datarate of the beacon channel + */ +#define AU915_BEACON_CHANNEL_DR DR_8 + /*! * Band 0 definition * { DutyCycle, TxMaxPower, LastJoinTxDoneTime, LastTxDoneTime, TimeOff } @@ -335,55 +370,18 @@ LoRaPHYAU915::LoRaPHYAU915() phy_params.ack_timeout_rnd = AU915_ACK_TIMEOUT_RND; phy_params.rx_window2_datarate = AU915_RX_WND_2_DR; phy_params.rx_window2_frequency = AU915_RX_WND_2_FREQ; + + phy_params.beacon.default_frequency = AU915_BEACON_CHANNEL_FREQ; + phy_params.beacon.datarate = AU915_BEACON_CHANNEL_DR; + phy_params.beacon.rfu1_size = AU915_BEACON_RFU1_SIZE; + phy_params.beacon.rfu2_size = AU915_BEACON_RFU2_SIZE; + phy_params.ping_slot_default_frequency = AU915_PING_CHANNEL_FREQ; } LoRaPHYAU915::~LoRaPHYAU915() { } -bool LoRaPHYAU915::rx_config(rx_config_params_t *params) -{ - int8_t dr = params->datarate; - uint8_t max_payload = 0; - int8_t phy_dr = 0; - uint32_t frequency = params->frequency; - - if (_radio->get_status() != RF_IDLE) { - return false; - } - - if (params->rx_slot == RX_SLOT_WIN_1) { - // Apply window 1 frequency - frequency = AU915_FIRST_RX1_CHANNEL - + (params->channel % 8) * AU915_STEPWIDTH_RX1_CHANNEL; - // Caller may print the frequency to log so update it to match actual frequency - params->frequency = frequency; - } - - // Read the physical datarate from the datarates table - phy_dr = datarates_AU915[dr]; - - _radio->lock(); - - _radio->set_channel(frequency); - - // Radio configuration - _radio->set_rx_config(MODEM_LORA, params->bandwidth, phy_dr, 1, 0, 8, - params->window_timeout, false, 0, false, 0, 0, true, - params->is_rx_continuous); - - if (params->is_repeater_supported == true) { - max_payload = max_payload_with_repeater_AU915[dr]; - } else { - max_payload = max_payload_AU915[dr]; - } - _radio->set_max_payload_length(MODEM_LORA, - max_payload + LORA_MAC_FRMPAYLOAD_OVERHEAD); - - _radio->unlock(); - - return true; -} bool LoRaPHYAU915::tx_config(tx_config_params_t *params, int8_t *tx_power, lorawan_time_t *tx_toa) @@ -661,3 +659,27 @@ void LoRaPHYAU915::fill_channel_mask_with_value(uint16_t *channel_mask, channel_mask[i] = value; } } + + +uint32_t LoRaPHYAU915::get_beacon_frequency(uint32_t beacon_time) +{ + uint8_t channel; + + channel = (beacon_time / LORA_BEACON_INTERVAL) % AU915_BEACON_NB_CHANNELS; + return AU915_BEACON_CHANNEL_FREQ + (channel * AU915_BEACON_CHANNEL_STEPWIDTH); +} + +uint32_t LoRaPHYAU915::get_ping_slot_frequency(uint32_t dev_addr, uint32_t beacon_time) +{ + uint8_t channel = (dev_addr + (beacon_time / LORA_BEACON_INTERVAL)) % AU915_BEACON_NB_CHANNELS; + return AU915_FIRST_RX1_CHANNEL + (channel * AU915_STEPWIDTH_RX1_CHANNEL); +} + +uint32_t LoRaPHYAU915::get_rx1_frequency(uint8_t channel) +{ + // For AU915 spectrum, we have 8 Downstream channels, MAC would have + // selected a channel randomly from 72 Upstream channels, that index is + // passed in rx_config_params_t. Based on that channel index, we choose the + // frequency for first RX slot + return AU915_FIRST_RX1_CHANNEL + (channel % 8) * AU915_STEPWIDTH_RX1_CHANNEL; +} \ No newline at end of file diff --git a/features/lorawan/lorastack/phy/LoRaPHYAU915.h b/features/lorawan/lorastack/phy/LoRaPHYAU915.h index cdcce73ea4..a1a46ad707 100644 --- a/features/lorawan/lorastack/phy/LoRaPHYAU915.h +++ b/features/lorawan/lorastack/phy/LoRaPHYAU915.h @@ -57,8 +57,6 @@ public: LoRaPHYAU915(); virtual ~LoRaPHYAU915(); - virtual bool rx_config(rx_config_params_t *config); - virtual bool tx_config(tx_config_params_t *config, int8_t *txPower, lorawan_time_t *txTimeOnAir); @@ -77,6 +75,12 @@ public: virtual uint8_t apply_DR_offset(int8_t dr, int8_t dr_offset); + virtual uint32_t get_rx1_frequency(uint8_t channel); + + virtual uint32_t get_beacon_frequency(uint32_t beacon_time); + + virtual uint32_t get_ping_slot_frequency(uint32_t dev_addr, uint32_t beacon_time); + private: /** diff --git a/features/lorawan/lorastack/phy/LoRaPHYCN470.cpp b/features/lorawan/lorastack/phy/LoRaPHYCN470.cpp index 3385cfe669..f879b7db58 100644 --- a/features/lorawan/lorastack/phy/LoRaPHYCN470.cpp +++ b/features/lorawan/lorastack/phy/LoRaPHYCN470.cpp @@ -183,6 +183,40 @@ static const band_t CN470_BAND0 = {1, CN470_MAX_TX_POWER, 0, 0, 0}; // 100.0 % */ #define CN470_STEPWIDTH_RX1_CHANNEL ((uint32_t) 200000) +/*! + * Beacon default frequency + */ +#define CN470_BEACON_CHANNEL_FREQ 508300000 + +/*! + * Beacon frequency channel stepwidth + */ +#define CN470_BEACON_CHANNEL_STEPWIDTH 200000 + +/*! + * Number of possible beacon channels + */ +#define CN470_BEACON_NB_CHANNELS 8 + +/*! + * Ping slot default frequency + */ +#define CN470_PING_CHANNEL_FREQ 500300000 + +/*! + * Size of RFU 1 field + */ +#define CN470_BEACON_RFU1_SIZE 3 + +/*! + * Size of RFU 2 field + */ +#define CN470_BEACON_RFU2_SIZE 1 + +/*! + * Datarate of the beacon channel + */ +#define CN470_BEACON_CHANNEL_DR DR_2 /*! * Data rates table definition */ @@ -294,6 +328,13 @@ LoRaPHYCN470::LoRaPHYCN470() phy_params.ack_timeout_rnd = CN470_ACK_TIMEOUT_RND; phy_params.rx_window2_datarate = CN470_RX_WND_2_DR; phy_params.rx_window2_frequency = CN470_RX_WND_2_FREQ; + + + phy_params.beacon.default_frequency = CN470_BEACON_CHANNEL_FREQ; + phy_params.beacon.datarate = CN470_BEACON_CHANNEL_DR; + phy_params.beacon.rfu1_size = CN470_BEACON_RFU1_SIZE; + phy_params.beacon.rfu2_size = CN470_BEACON_RFU2_SIZE; + phy_params.ping_slot_default_frequency = CN470_PING_CHANNEL_FREQ; } LoRaPHYCN470::~LoRaPHYCN470() @@ -358,57 +399,6 @@ lorawan_status_t LoRaPHYCN470::set_next_channel(channel_selection_params_t *para return LORAWAN_STATUS_NO_CHANNEL_FOUND; } -bool LoRaPHYCN470::rx_config(rx_config_params_t *config) -{ - int8_t dr = config->datarate; - uint8_t max_payload = 0; - int8_t phy_dr = 0; - uint32_t frequency = config->frequency; - - _radio->lock(); - - if (_radio->get_status() != RF_IDLE) { - _radio->unlock(); - return false; - } - - _radio->unlock(); - - if (config->rx_slot == RX_SLOT_WIN_1) { - // Apply window 1 frequency - frequency = CN470_FIRST_RX1_CHANNEL + (config->channel % 48) * CN470_STEPWIDTH_RX1_CHANNEL; - // Caller may print the frequency to log so update it to match actual frequency - config->frequency = frequency; - } - - // Read the physical datarate from the datarates table - phy_dr = datarates_CN470[dr]; - - _radio->lock(); - - _radio->set_channel(frequency); - - // Radio configuration - _radio->set_rx_config(MODEM_LORA, config->bandwidth, phy_dr, 1, 0, - MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH, - config->window_timeout, false, 0, false, 0, 0, true, - config->is_rx_continuous); - - _radio->unlock(); - - if (config->is_repeater_supported == true) { - max_payload = max_payloads_with_repeater_CN470[dr]; - } else { - max_payload = max_payloads_CN470[dr]; - } - - _radio->lock(); - _radio->set_max_payload_length(MODEM_LORA, max_payload + LORA_MAC_FRMPAYLOAD_OVERHEAD); - _radio->unlock(); - - return true; -} - bool LoRaPHYCN470::tx_config(tx_config_params_t *config, int8_t *tx_power, lorawan_time_t *tx_toa) { @@ -574,3 +564,26 @@ uint8_t LoRaPHYCN470::accept_rx_param_setup_req(rx_param_setup_req_t *params) return status; } + +uint32_t LoRaPHYCN470::get_beacon_frequency(uint32_t beacon_time) +{ + uint8_t channel; + + channel = (beacon_time / LORA_BEACON_INTERVAL) % CN470_BEACON_NB_CHANNELS; + return CN470_BEACON_CHANNEL_FREQ + (channel * CN470_BEACON_CHANNEL_STEPWIDTH); +} + +uint32_t LoRaPHYCN470::get_ping_slot_frequency(uint32_t dev_addr, uint32_t beacon_time) +{ + uint8_t channel = (dev_addr + (beacon_time / LORA_BEACON_INTERVAL)) % CN470_BEACON_NB_CHANNELS; + return CN470_FIRST_RX1_CHANNEL + (channel * CN470_STEPWIDTH_RX1_CHANNEL); +} + +uint32_t LoRaPHYCN470::get_rx1_frequency(uint8_t channel) +{ + // For CN470 spectrum, we have 8 Downstream channels, MAC would have + // selected a channel randomly from 96 Upstream channels, that index is + // passed in rx_config_params_t. Based on that channel index, we choose the + // frequency for first RX slot + return CN470_FIRST_RX1_CHANNEL + (channel % 8) * CN470_STEPWIDTH_RX1_CHANNEL; +} \ No newline at end of file diff --git a/features/lorawan/lorastack/phy/LoRaPHYCN470.h b/features/lorawan/lorastack/phy/LoRaPHYCN470.h index 81d07a2b11..9879718015 100644 --- a/features/lorawan/lorastack/phy/LoRaPHYCN470.h +++ b/features/lorawan/lorastack/phy/LoRaPHYCN470.h @@ -62,8 +62,6 @@ public: uint8_t *channel, lorawan_time_t *time, lorawan_time_t *aggregate_timeoff); - virtual bool rx_config(rx_config_params_t *config); - virtual bool tx_config(tx_config_params_t *config, int8_t *tx_power, lorawan_time_t *tx_toa); @@ -73,6 +71,12 @@ public: virtual uint8_t accept_rx_param_setup_req(rx_param_setup_req_t *params); + virtual uint32_t get_rx1_frequency(uint8_t channel); + + virtual uint32_t get_beacon_frequency(uint32_t beacon_time); + + virtual uint32_t get_ping_slot_frequency(uint32_t dev_addr, uint32_t beacon_time); + private: /*! diff --git a/features/lorawan/lorastack/phy/LoRaPHYCN779.cpp b/features/lorawan/lorastack/phy/LoRaPHYCN779.cpp index d19e95efb1..a7cf8a13e2 100644 --- a/features/lorawan/lorastack/phy/LoRaPHYCN779.cpp +++ b/features/lorawan/lorastack/phy/LoRaPHYCN779.cpp @@ -181,6 +181,31 @@ */ #define CN779_RX_WND_2_DR DR_0 +/*! + * Beacon default frequency + */ +#define CN779_BEACON_CHANNEL_FREQ 785000000 + +/*! + * Beacon default frequency + */ +#define CN779_PING_CHANNEL_FREQ 785000000 + +/*! + * Size of RFU 1 field + */ +#define CN779_BEACON_RFU1_SIZE 2 + +/*! + * Size of RFU 2 field + */ +#define CN779_BEACON_RFU2_SIZE 0 + +/*! + * Datarate of the beacon channel + */ +#define CN779_BEACON_CHANNEL_DR DR_3 + /*! * Band 0 definition * { DutyCycle, TxMaxPower, LastJoinTxDoneTime, LastTxDoneTime, TimeOff } @@ -313,6 +338,11 @@ LoRaPHYCN779::LoRaPHYCN779() phy_params.ack_timeout_rnd = CN779_ACK_TIMEOUT_RND; phy_params.rx_window2_datarate = CN779_RX_WND_2_DR; phy_params.rx_window2_frequency = CN779_RX_WND_2_FREQ; + phy_params.beacon.default_frequency = CN779_BEACON_CHANNEL_FREQ; + phy_params.beacon.datarate = CN779_BEACON_CHANNEL_DR; + phy_params.beacon.rfu1_size = CN779_BEACON_RFU1_SIZE; + phy_params.beacon.rfu2_size = CN779_BEACON_RFU2_SIZE; + phy_params.ping_slot_default_frequency = CN779_PING_CHANNEL_FREQ; } LoRaPHYCN779::~LoRaPHYCN779() diff --git a/features/lorawan/lorastack/phy/LoRaPHYEU433.cpp b/features/lorawan/lorastack/phy/LoRaPHYEU433.cpp index 50d60ffd50..2cb3908998 100644 --- a/features/lorawan/lorastack/phy/LoRaPHYEU433.cpp +++ b/features/lorawan/lorastack/phy/LoRaPHYEU433.cpp @@ -181,6 +181,32 @@ */ #define EU433_RX_WND_2_DR DR_0 +/*! + * Beacon default frequency + */ +#define EU433_BEACON_CHANNEL_FREQ 434665000 + +/*! + * Ping slot default frequency + */ +#define EU433_PING_CHANNEL_FREQ 434665000 + +/*! + * Size of RFU 1 field + */ +#define EU433_BEACON_RFU1_SIZE 2 + +/*! + * Size of RFU 2 field + */ +#define EU433_BEACON_RFU2_SIZE 0 + +/*! + * Datarate of the beacon channel + */ +#define EU433_BEACON_CHANNEL_DR DR_3 + + /*! * Band 0 definition * { DutyCycle, TxMaxPower, LastJoinTxDoneTime, LastTxDoneTime, TimeOff } @@ -314,6 +340,11 @@ LoRaPHYEU433::LoRaPHYEU433() phy_params.ack_timeout_rnd = EU433_ACK_TIMEOUT_RND; phy_params.rx_window2_datarate = EU433_RX_WND_2_DR; phy_params.rx_window2_frequency = EU433_RX_WND_2_FREQ; + phy_params.beacon.default_frequency = EU433_BEACON_CHANNEL_FREQ; + phy_params.beacon.datarate = EU433_BEACON_CHANNEL_DR; + phy_params.beacon.rfu1_size = EU433_BEACON_RFU1_SIZE; + phy_params.beacon.rfu2_size = EU433_BEACON_RFU2_SIZE; + phy_params.ping_slot_default_frequency = EU433_PING_CHANNEL_FREQ; } LoRaPHYEU433::~LoRaPHYEU433() diff --git a/features/lorawan/lorastack/phy/LoRaPHYEU868.cpp b/features/lorawan/lorastack/phy/LoRaPHYEU868.cpp index ba1301c015..bd2a543944 100644 --- a/features/lorawan/lorastack/phy/LoRaPHYEU868.cpp +++ b/features/lorawan/lorastack/phy/LoRaPHYEU868.cpp @@ -159,6 +159,31 @@ */ #define EU868_ACKTIMEOUT 2000 +/*! + * Beacon default frequency + */ +#define EU868_BEACON_CHANNEL_FREQ 869525000 + +/*! + * Beacon default frequency + */ +#define EU868_PING_CHANNEL_FREQ 869525000 + +/*! + * Size of RFU 1 field + */ +#define EU868_BEACON_RFU1_SIZE 2 + +/*! + * Size of RFU 2 field + */ +#define EU868_BEACON_RFU2_SIZE 0 + +/*! + * Datarate of the beacon channel + */ +#define EU868_BEACON_CHANNEL_DR DR_3 + /*! * Random ack timeout limits */ @@ -344,6 +369,11 @@ LoRaPHYEU868::LoRaPHYEU868() phy_params.ack_timeout_rnd = EU868_ACK_TIMEOUT_RND; phy_params.rx_window2_datarate = EU868_RX_WND_2_DR; phy_params.rx_window2_frequency = EU868_RX_WND_2_FREQ; + phy_params.beacon.default_frequency = EU868_BEACON_CHANNEL_FREQ; + phy_params.beacon.datarate = EU868_BEACON_CHANNEL_DR; + phy_params.beacon.rfu1_size = EU868_BEACON_RFU1_SIZE; + phy_params.beacon.rfu2_size = EU868_BEACON_RFU2_SIZE; + phy_params.ping_slot_default_frequency = EU868_PING_CHANNEL_FREQ; } LoRaPHYEU868::~LoRaPHYEU868() diff --git a/features/lorawan/lorastack/phy/LoRaPHYIN865.cpp b/features/lorawan/lorastack/phy/LoRaPHYIN865.cpp index bdcfcc24a3..a42850b0ad 100644 --- a/features/lorawan/lorastack/phy/LoRaPHYIN865.cpp +++ b/features/lorawan/lorastack/phy/LoRaPHYIN865.cpp @@ -178,6 +178,30 @@ */ #define IN865_RX_WND_2_DR DR_2 +/*! + * Beacon frequency + */ +#define IN865_BEACON_CHANNEL_FREQ 866500000 + +/*! + * Ping slot default frequency + */ +#define IN865_PING_CHANNEL_FREQ 866500000 + +/*! + * Size of RFU1 field + */ +#define IN865_BEACON_RFU1_SIZE 1 +/*! + * Size of RFU2 field + */ +#define IN865_BEACON_RFU2_SIZE 3 + +/*! + * Datarate of the beacon channel + */ +#define IN865_BEACON_CHANNEL_DR DR_4 + /*! * Band 0 definition * { DutyCycle, TxMaxPower, LastJoinTxDoneTime, LastTxDoneTime, TimeOff } @@ -315,6 +339,12 @@ LoRaPHYIN865::LoRaPHYIN865() phy_params.ack_timeout_rnd = IN865_ACK_TIMEOUT_RND; phy_params.rx_window2_datarate = IN865_RX_WND_2_DR; phy_params.rx_window2_frequency = IN865_RX_WND_2_FREQ; + phy_params.beacon.default_frequency = IN865_BEACON_CHANNEL_FREQ; + phy_params.beacon.datarate = IN865_BEACON_CHANNEL_DR; + phy_params.beacon.rfu1_size = IN865_BEACON_RFU1_SIZE; + phy_params.beacon.rfu2_size = IN865_BEACON_RFU2_SIZE; + phy_params.ping_slot_default_frequency = IN865_PING_CHANNEL_FREQ; + } LoRaPHYIN865::~LoRaPHYIN865() diff --git a/features/lorawan/lorastack/phy/LoRaPHYKR920.cpp b/features/lorawan/lorastack/phy/LoRaPHYKR920.cpp index ba9cf74cd6..c40f1e7fe1 100644 --- a/features/lorawan/lorastack/phy/LoRaPHYKR920.cpp +++ b/features/lorawan/lorastack/phy/LoRaPHYKR920.cpp @@ -182,6 +182,30 @@ */ #define KR920_RX_WND_2_DR DR_0 +/*! + * Beacon frequency + */ +#define KR920_BEACON_CHANNEL_FREQ 923100000 + +/*! + * Ping slot default frequency + */ +#define KR920_PING_CHANNEL_FREQ 923100000 + +/*! + * Size of RFU1 field + */ +#define KR920_BEACON_RFU1_SIZE 2 +/*! + * Size of RFU2 field + */ +#define KR920_BEACON_RFU2_SIZE 0 + +/*! + * Datarate of the beacon channel + */ +#define KR920_BEACON_CHANNEL_DR DR_3 + /*! * Band 0 definition * { DutyCycle, TxMaxPower, LastJoinTxDoneTime, LastTxDoneTime, TimeOff } @@ -324,6 +348,11 @@ LoRaPHYKR920::LoRaPHYKR920() phy_params.ack_timeout_rnd = KR920_ACK_TIMEOUT_RND; phy_params.rx_window2_datarate = KR920_RX_WND_2_DR; phy_params.rx_window2_frequency = KR920_RX_WND_2_FREQ; + phy_params.beacon.default_frequency = KR920_BEACON_CHANNEL_FREQ; + phy_params.beacon.datarate = KR920_BEACON_CHANNEL_DR; + phy_params.beacon.rfu1_size = KR920_BEACON_RFU1_SIZE; + phy_params.beacon.rfu2_size = KR920_BEACON_RFU2_SIZE; + phy_params.ping_slot_default_frequency = KR920_PING_CHANNEL_FREQ; } LoRaPHYKR920::~LoRaPHYKR920() diff --git a/features/lorawan/lorastack/phy/LoRaPHYUS915.cpp b/features/lorawan/lorastack/phy/LoRaPHYUS915.cpp index 1b46ddec98..e375f0a0b8 100644 --- a/features/lorawan/lorastack/phy/LoRaPHYUS915.cpp +++ b/features/lorawan/lorastack/phy/LoRaPHYUS915.cpp @@ -180,6 +180,50 @@ static const band_t US915_BAND0 = { 1, US915_MAX_TX_POWER, 0, 0, 0 }; // 100.0 */ #define US915_STEPWIDTH_RX1_CHANNEL ( (uint32_t) 600000 ) +/* + * CLASS B + */ + +/*! + * Beacon frequency + */ +#define US915_BEACON_CHANNEL_FREQ 923300000 + +/*! + * Beacon frequency channel stepwidth + */ +#define US915_BEACON_CHANNEL_STEPWIDTH 600000 + +/*! + * Number of possible beacon channels + */ +#define US915_BEACON_NB_CHANNELS 8 + +/*! + * Payload size of a beacon frame + */ +#define US915_BEACON_SIZE 23 + +/*! + * Payload size of a beacon frame + */ +#define US915_BEACON_PREAMBLE_LEN 10 + +/*! + * Size of RFU 1 field + */ +#define US915_RFU1_SIZE 5 + +/*! + * Size of RFU 2 field + */ +#define US915_RFU2_SIZE 3 + +/*! + * Datarate of the beacon channel + */ +#define US915_BEACON_CHANNEL_DR DR_8 + /*! * Data rates table definition */ @@ -313,6 +357,11 @@ LoRaPHYUS915::LoRaPHYUS915() phy_params.ack_timeout_rnd = US915_ACK_TIMEOUT_RND; phy_params.rx_window2_datarate = US915_RX_WND_2_DR; phy_params.rx_window2_frequency = US915_RX_WND_2_FREQ; + + phy_params.beacon.default_frequency = US915_BEACON_CHANNEL_FREQ; + phy_params.beacon.datarate = US915_BEACON_CHANNEL_DR; + phy_params.beacon.rfu1_size = US915_RFU1_SIZE; + phy_params.beacon.rfu2_size = US915_RFU2_SIZE; } LoRaPHYUS915::~LoRaPHYUS915() @@ -350,68 +399,6 @@ void LoRaPHYUS915::restore_default_channels() intersect_channel_mask(channel_mask, current_channel_mask, US915_CHANNEL_MASK_SIZE); } -bool LoRaPHYUS915::rx_config(rx_config_params_t *config) -{ - int8_t dr = config->datarate; - uint8_t max_payload = 0; - int8_t phy_dr = 0; - uint32_t frequency = config->frequency; - - _radio->lock(); - - if (_radio->get_status() != RF_IDLE) { - - _radio->unlock(); - return false; - - } - - _radio->unlock(); - - // For US915 spectrum, we have 8 Downstream channels, MAC would have - // selected a channel randomly from 72 Upstream channels, that index is - // passed in rx_config_params_t. Based on that channel index, we choose the - // frequency for first RX slot - if (config->rx_slot == RX_SLOT_WIN_1) { - // Apply window 1 frequency - frequency = US915_FIRST_RX1_CHANNEL + (config->channel % 8) * US915_STEPWIDTH_RX1_CHANNEL; - // Caller may print the frequency to log so update it to match actual frequency - config->frequency = frequency; - } - - // Read the physical datarate from the datarates table - phy_dr = datarates_US915[dr]; - - _radio->lock(); - - _radio->set_channel(frequency); - - // Radio configuration - _radio->set_rx_config(MODEM_LORA, config->bandwidth, phy_dr, 1, 0, - MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH, - config->window_timeout, false, 0, false, 0, 0, true, - config->is_rx_continuous); - _radio->unlock(); - - if (config->is_repeater_supported == true) { - - max_payload = max_payloads_with_repeater_US915[dr]; - - } else { - - max_payload = max_payloads_US915[dr]; - - } - - _radio->lock(); - - _radio->set_max_payload_length(MODEM_LORA, max_payload + LORA_MAC_FRMPAYLOAD_OVERHEAD); - - _radio->unlock(); - - return true; -} - bool LoRaPHYUS915::tx_config(tx_config_params_t *config, int8_t *tx_power, lorawan_time_t *tx_toa) { @@ -696,3 +683,27 @@ void LoRaPHYUS915::fill_channel_mask_with_value(uint16_t *channel_mask, channel_mask[i] = value; } } + +uint32_t LoRaPHYUS915::get_beacon_frequency(uint32_t beacon_time) +{ + uint8_t channel; + + channel = (beacon_time / LORA_BEACON_INTERVAL) % US915_BEACON_NB_CHANNELS; + return US915_BEACON_CHANNEL_FREQ + (channel * US915_BEACON_CHANNEL_STEPWIDTH); +} + +uint32_t LoRaPHYUS915::get_ping_slot_frequency(uint32_t dev_addr, uint32_t beacon_time) +{ + uint8_t channel = (dev_addr + (beacon_time / LORA_BEACON_INTERVAL)) % US915_BEACON_NB_CHANNELS; + return US915_FIRST_RX1_CHANNEL + (channel * US915_STEPWIDTH_RX1_CHANNEL); +} + +uint32_t LoRaPHYUS915::get_rx1_frequency(uint8_t channel) +{ + // For US915 spectrum, we have 8 Downstream channels, MAC would have + // selected a channel randomly from 72 Upstream channels, that index is + // passed in rx_config_params_t. Based on that channel index, we choose the + // frequency for first RX slot + + return US915_FIRST_RX1_CHANNEL + (channel % 8) * US915_STEPWIDTH_RX1_CHANNEL; +} diff --git a/features/lorawan/lorastack/phy/LoRaPHYUS915.h b/features/lorawan/lorastack/phy/LoRaPHYUS915.h index 00c50f2fbe..b958cd1f17 100644 --- a/features/lorawan/lorastack/phy/LoRaPHYUS915.h +++ b/features/lorawan/lorastack/phy/LoRaPHYUS915.h @@ -58,8 +58,6 @@ public: virtual void restore_default_channels(); - virtual bool rx_config(rx_config_params_t *config); - virtual bool tx_config(tx_config_params_t *config, int8_t *tx_power, lorawan_time_t *tx_toa); @@ -77,6 +75,12 @@ public: virtual uint8_t apply_DR_offset(int8_t dr, int8_t dr_offset); + virtual uint32_t get_rx1_frequency(uint8_t channel); + + virtual uint32_t get_beacon_frequency(uint32_t beacon_time); + + virtual uint32_t get_ping_slot_frequency(uint32_t dev_addr, uint32_t beacon_time); + private: /**