Skip to content

Commit 2ff90e6

Browse files
author
Jarkko Paso
authored
Configure TXRX slot length using given datarate (#2275)
1 parent a126cb7 commit 2ff90e6

File tree

6 files changed

+69
-15
lines changed

6 files changed

+69
-15
lines changed

nanostack/platform/arm_hal_phy.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ typedef enum {
161161
CHANNEL_PAGE_5 = 5, ///< Page 5
162162
CHANNEL_PAGE_6 = 6, ///< Page 6
163163
CHANNEL_PAGE_9 = 9, ///< Page 9
164-
CHANNEL_PAGE_10 = 10 ///< Page 10
164+
CHANNEL_PAGE_10 = 10, ///< Page 10
165+
CHANNEL_PAGE_UNDEFINED ///< Undefined
165166
} channel_page_e;
166167

167168
/** Modulation index */

source/MAC/IEEE802_15_4/mac_defines.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ typedef struct protocol_interface_rf_mac_setup {
245245
uint32_t mlme_tick_count;
246246
uint32_t symbol_rate;
247247
uint32_t symbol_time_us;
248+
uint32_t datarate;
248249
uint8_t max_ED;
249250
uint16_t mlme_ED_counter;
250251
mac_tx_status_t mac_tx_status;

source/MAC/IEEE802_15_4/mac_fhss_callbacks.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@ uint32_t mac_read_phy_datarate(const fhss_api_t *fhss_api)
5757
if (!mac_setup) {
5858
return 0;
5959
}
60-
uint32_t datarate = dev_get_phy_datarate(mac_setup->dev_driver->phy_driver, mac_setup->mac_channel_list.channel_page);
61-
// If datarate is not set, use default 250kbit/s.
60+
uint32_t datarate = 0;
61+
// When channel page is set, ask data rate directly from PHY driver, otherwise use data rate configured to MAC. Ultimately, use default value instead 0.
62+
if (mac_setup->mac_channel_list.channel_page != CHANNEL_PAGE_UNDEFINED) {
63+
datarate = dev_get_phy_datarate(mac_setup->dev_driver->phy_driver, mac_setup->mac_channel_list.channel_page);
64+
} else if (mac_setup->datarate) {
65+
datarate = mac_setup->datarate;
66+
}
6267
if (!datarate) {
6368
datarate = 250000;
6469
}

source/MAC/IEEE802_15_4/mac_mlme.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ int8_t mac_mlme_set_req(protocol_interface_rf_mac_setup_s *rf_mac_setup, const m
783783
rf_mac_setup->dev_driver->phy_driver->extension(PHY_EXTENSION_SET_RF_CONFIGURATION, (uint8_t *) set_req->value_pointer);
784784
mac_mlme_set_symbol_rate(rf_mac_setup);
785785
phy_rf_channel_configuration_s *config_params = (phy_rf_channel_configuration_s *)set_req->value_pointer;
786-
(void) config_params; // unused variable if traces disabled
786+
rf_mac_setup->datarate = config_params->datarate;
787787
tr_info("RF config update:");
788788
tr_info("Frequency(ch0): %"PRIu32"Hz", config_params->channel_0_center_frequency);
789789
tr_info("Channel spacing: %"PRIu32"Hz", config_params->channel_spacing);
@@ -1091,6 +1091,7 @@ protocol_interface_rf_mac_setup_s *mac_mlme_data_base_allocate(uint8_t *mac64, a
10911091
entry->aUnitBackoffPeriod = 20; //This can be different in some Platform 20 comes from 12-symbol turnaround and 8 symbol CCA read
10921092
entry->number_of_csma_ca_periods = MAC_DEFAULT_NUMBER_OF_CSMA_PERIODS;
10931093
entry->multi_cca_interval = MAC_DEFAULT_CSMA_MULTI_CCA_INTERVAL;
1094+
entry->mac_channel_list.channel_page = CHANNEL_PAGE_UNDEFINED;
10941095

10951096
if (mac_sec_mib_init(entry, storage_sizes) != 0) {
10961097
mac_mlme_data_base_deallocate(entry);

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static void fhss_event_timer_cb(int8_t timer_id, uint16_t slots);
8383
static void fhss_ws_update_uc_channel_callback(fhss_structure_t *fhss_structure);
8484
static void fhss_unicast_handler(const fhss_api_t *fhss_api, uint16_t delay);
8585
static bool fhss_ws_check_tx_allowed(fhss_structure_t *fhss_structure);
86-
static uint32_t fhss_set_txrx_slot_length(fhss_structure_t *fhss_structure);
86+
static void fhss_set_txrx_slot_length(fhss_structure_t *fhss_structure);
8787

8888
// This function supports rounding up
8989
static int64_t divide_integer(int64_t dividend, int32_t divisor)
@@ -150,7 +150,6 @@ fhss_structure_t *fhss_ws_enable(fhss_api_t *fhss_api, const fhss_ws_configurati
150150
fhss_ws_set_hop_count(fhss_struct, 0xff);
151151
fhss_struct->rx_channel = fhss_configuration->unicast_fixed_channel;
152152
fhss_struct->ws->min_synch_interval = DEFAULT_MIN_SYNCH_INTERVAL;
153-
fhss_set_txrx_slot_length(fhss_struct);
154153
ns_list_init(&fhss_struct->fhss_failed_tx_list);
155154
return fhss_struct;
156155
}
@@ -173,14 +172,46 @@ static int fhss_ws_manage_channel_table_allocation(fhss_structure_t *fhss_struct
173172
return 0;
174173
}
175174

176-
static uint32_t fhss_set_txrx_slot_length(fhss_structure_t *fhss_structure)
175+
static void fhss_set_txrx_slot_length(fhss_structure_t *fhss_structure)
177176
{
178-
uint32_t number_of_tx_slots = ((fhss_structure->ws->fhss_configuration.fhss_broadcast_interval - fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval) / WS_MAX_TXRX_SLOT_LEN_MS) / 2;
177+
// No broadcast schedule, no TX slots
178+
if (fhss_structure->ws->fhss_configuration.fhss_broadcast_interval == 0 || fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval == 0) {
179+
return;
180+
}
181+
uint32_t txrx_slot_length_ms_tmp = WS_TXRX_SLOT_LEN_MS;
182+
if (fhss_structure->callbacks.read_datarate) {
183+
/* Calculate minimum TX slot length which can fit optimal packet length twice.
184+
* Twice, because 0, 1, 4, 5... hop starts transmission at the beginning of TX slot and 2, 3, 6, 7... hop at the middle of TX slot
185+
*
186+
* hop 0
187+
* tx'ing | | | | | |
188+
* | BC | RX | TX | RX | TX | RX | TX | BC |
189+
* hop 1
190+
* tx'ing | | | | | |
191+
* | BC | TX | RX | TX | RX | TX | RX | BC |
192+
* hop 2
193+
* tx'ing | | | | | |
194+
* | BC | RX | TX | RX | TX | RX | TX | BC |
195+
* hop 3
196+
* tx'ing | | | | | |
197+
* | BC | TX | RX | TX | RX | TX | RX | BC |
198+
*/
199+
uint32_t datarate = fhss_structure->callbacks.read_datarate(fhss_structure->fhss_api);
200+
if (datarate) {
201+
txrx_slot_length_ms_tmp = ((OPTIMAL_PACKET_LENGTH * 2) * (8000000 / datarate)) / 1000;
202+
}
203+
}
204+
uint32_t number_of_tx_slots = ((fhss_structure->ws->fhss_configuration.fhss_broadcast_interval - fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval) / txrx_slot_length_ms_tmp) / 2;
179205
if (!number_of_tx_slots) {
180-
return 0;
206+
return;
181207
}
182208
fhss_structure->ws->txrx_slot_length_ms = (fhss_structure->ws->fhss_configuration.fhss_broadcast_interval - fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval) / (number_of_tx_slots * 2);
183-
return number_of_tx_slots;
209+
tr_info("TX slot length: %"PRIu32"ms", fhss_structure->ws->txrx_slot_length_ms);
210+
}
211+
212+
static uint32_t fhss_get_number_of_tx_slots(fhss_structure_t *fhss_structure)
213+
{
214+
return ((fhss_structure->ws->fhss_configuration.fhss_broadcast_interval - fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval) / fhss_structure->ws->txrx_slot_length_ms) / 2;
184215
}
185216

186217
static int32_t fhss_ws_calc_bc_channel(fhss_structure_t *fhss_structure)
@@ -397,7 +428,7 @@ static int16_t fhss_ws_synch_state_set_callback(const fhss_api_t *api, fhss_stat
397428
if (fhss_state == FHSS_SYNCHRONIZED) {
398429
uint32_t fhss_broadcast_interval = fhss_structure->ws->fhss_configuration.fhss_broadcast_interval;
399430
uint8_t fhss_bc_dwell_interval = fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval;
400-
431+
fhss_set_txrx_slot_length(fhss_structure);
401432
// Start broadcast schedule when BC intervals are known
402433
if (fhss_broadcast_interval && fhss_bc_dwell_interval) {
403434
fhss_broadcast_handler(fhss_structure->fhss_api, 0);
@@ -537,17 +568,30 @@ static bool fhss_ws_check_tx_allowed(fhss_structure_t *fhss_structure)
537568
if (fhss_structure->ws->is_on_bc_channel == true) {
538569
return true;
539570
}
540-
uint32_t number_of_tx_slots = fhss_set_txrx_slot_length(fhss_structure);
571+
uint32_t number_of_tx_slots = fhss_get_number_of_tx_slots(fhss_structure);
541572
// Allow transmission when broadcast interval is very short comparing to MAX slot length
542573
if (!number_of_tx_slots) {
543574
return true;
544575
}
545576

546577
uint32_t remaining_time_ms = get_remaining_slots_us(fhss_structure, fhss_broadcast_handler, MS_TO_US(fhss_structure->ws->fhss_configuration.fhss_broadcast_interval)) / 1000;
547578
uint32_t tx_slot_begin_ms = (fhss_structure->ws->fhss_configuration.fhss_broadcast_interval - fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval) - (fhss_structure->ws->txrx_slot_length_ms * (fhss_structure->own_hop & 1));
579+
/* Return false when our first TX slot has not yet started
580+
* |------remaining_time_ms---|
581+
* |
582+
* v
583+
* | BC | RX | TX | RX | TX | RX | TX | BC |
584+
*/
585+
if (tx_slot_begin_ms < remaining_time_ms) {
586+
return false;
587+
}
548588
tx_slot_begin_ms = tx_slot_begin_ms - (((tx_slot_begin_ms - remaining_time_ms) / (2 * fhss_structure->ws->txrx_slot_length_ms)) * (2 * fhss_structure->ws->txrx_slot_length_ms));
549589
uint32_t rx_slot_begin_ms = tx_slot_begin_ms - fhss_structure->ws->txrx_slot_length_ms;
550-
// Check if we are currently on TX slot.
590+
/* Check if we are currently on TX slot.
591+
* | | |
592+
* v v v
593+
* | BC | RX | TX | RX | TX | RX | TX | BC |
594+
*/
551595
if ((remaining_time_ms <= tx_slot_begin_ms) && (remaining_time_ms > rx_slot_begin_ms)) {
552596
return true;
553597
}

source/Service_Libs/fhss/fhss_ws.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
* At least 4 channel retries must be used: (Initial channel + WS_NUMBER_OF_CHANNEL_RETRIES) * MAC attempts = (1+4)*4=20 attempts
2222
*/
2323
#define WS_NUMBER_OF_CHANNEL_RETRIES 4
24-
//TX/RX slot length in milliseconds
25-
#define WS_MAX_TXRX_SLOT_LEN_MS 100
24+
// TX slot length is optimised to this packet length
25+
#define OPTIMAL_PACKET_LENGTH 500
26+
// Default TX/RX slot length in milliseconds. Is used when datarate is not given by PHY.
27+
#define WS_TXRX_SLOT_LEN_MS 100
2628
// Default minimum broadcast synchronization interval in seconds
2729
#define DEFAULT_MIN_SYNCH_INTERVAL 60
2830
// Drift compensation allowed if at least SYNCH_COMPENSATION_MIN_INTERVAL (seconds) since last synchronization

0 commit comments

Comments
 (0)