Skip to content

Commit

Permalink
Don't allow TX slot length go below allowed minimum (ARMmbed#2528)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso authored Dec 21, 2020
1 parent 8333faa commit 00bbd02
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 9 additions & 4 deletions source/Service_Libs/fhss/fhss_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void fhss_set_txrx_slot_length(fhss_structure_t *fhss_structure)
if (fhss_structure->ws->fhss_configuration.fhss_broadcast_interval == 0 || fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval == 0) {
return;
}
uint32_t txrx_slot_length_ms_tmp = WS_TXRX_SLOT_LEN_MS;
uint32_t txrx_slot_length_ms_tmp = WS_TXRX_SLOT_LEN_MS_MAX;
if (fhss_structure->callbacks.read_datarate) {
/* Calculate minimum TX slot length which can fit optimal packet length twice.
* 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
Expand All @@ -217,9 +217,14 @@ void fhss_set_txrx_slot_length(fhss_structure_t *fhss_structure)
if (datarate) {
txrx_slot_length_ms_tmp = ((fhss_structure->optimal_packet_length * 2) * (8000000 / datarate)) / 1000;
// Do not allow using too high TX slot length.
if (txrx_slot_length_ms_tmp > WS_TXRX_SLOT_LEN_MS) {
tr_debug("TX slot length setting too high %"PRIu32"ms, using %"PRIu32"ms", txrx_slot_length_ms_tmp, (uint32_t)WS_TXRX_SLOT_LEN_MS);
txrx_slot_length_ms_tmp = WS_TXRX_SLOT_LEN_MS;
if (txrx_slot_length_ms_tmp > WS_TXRX_SLOT_LEN_MS_MAX) {
tr_debug("TX slot length setting too high %"PRIu32"ms, using %"PRIu32"ms", txrx_slot_length_ms_tmp, (uint32_t)WS_TXRX_SLOT_LEN_MS_MAX);
txrx_slot_length_ms_tmp = WS_TXRX_SLOT_LEN_MS_MAX;
}
// Do not allow using too low TX slot length.
if (txrx_slot_length_ms_tmp < WS_TXRX_SLOT_LEN_MS_MIN) {
tr_debug("TX slot length setting too low %"PRIu32"ms, using %"PRIu32"ms", txrx_slot_length_ms_tmp, (uint32_t)WS_TXRX_SLOT_LEN_MS_MIN);
txrx_slot_length_ms_tmp = WS_TXRX_SLOT_LEN_MS_MIN;
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions source/Service_Libs/fhss/fhss_ws.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

// TX slot length is optimised to this packet length
#define OPTIMAL_PACKET_LENGTH 500
// Default TX/RX slot length in milliseconds. Is used when datarate is not given by PHY.
#define WS_TXRX_SLOT_LEN_MS 100
// Max TX/RX slot length in milliseconds. Is used when datarate is not given by PHY or calculated slot length exceeds maximum allowed.
#define WS_TXRX_SLOT_LEN_MS_MAX 100
// Min TX/RX slot length in milliseconds. Is used when calculated slot length is under minimum allowed.
#define WS_TXRX_SLOT_LEN_MS_MIN 10
// Default minimum broadcast synchronization interval in seconds
#define DEFAULT_MIN_SYNCH_INTERVAL 60
// Drift compensation allowed if at least SYNCH_COMPENSATION_MIN_INTERVAL (seconds) since last synchronization
Expand Down

0 comments on commit 00bbd02

Please sign in to comment.