Skip to content

Commit e64bd19

Browse files
author
Jarkko Paso
committed
FHSS: Implemented checking TX time
1 parent 0ba4b9a commit e64bd19

File tree

8 files changed

+49
-46
lines changed

8 files changed

+49
-46
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ static int8_t ws_bootstrap_up(protocol_interface_info_entry_t *cur)
229229
tr_debug("Interface not yet fully configured");
230230
return -5;
231231
}
232-
ws_enable_fhss(cur);
233232

234233
addr_interface_set_ll64(cur, NULL);
235234
cur->nwk_nd_re_scan_count = 0;
@@ -913,7 +912,7 @@ static void ws_bootstrap_mac_activate(protocol_interface_info_entry_t *cur, uint
913912
static void ws_bootstrap_fhss_activate(protocol_interface_info_entry_t *cur)
914913
{
915914
tr_debug("FHSS activate");
916-
915+
ws_enable_fhss(cur);
917916
ws_llc_hopping_schedule_config(cur, &cur->ws_info->hopping_schdule);
918917
// Only supporting fixed channel
919918

source/MAC/IEEE802_15_4/mac_fhss_callbacks.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ uint32_t mac_read_phy_datarate(const fhss_api_t *fhss_api)
5757
if (!mac_setup) {
5858
return 0;
5959
}
60-
return dev_get_phy_datarate(mac_setup->dev_driver->phy_driver, mac_setup->mac_channel_list.channel_page);
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.
62+
if (!datarate) {
63+
datarate = 250000;
64+
}
65+
return datarate;
6166
}
6267

6368
int mac_set_channel(const fhss_api_t *fhss_api, uint8_t channel_number)

source/MAC/IEEE802_15_4/mac_pd_sap.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -340,21 +340,23 @@ static int8_t mac_data_interface_tx_done_cb(protocol_interface_rf_mac_setup_s *r
340340
uint8_t *synch_info = tx_buf->buf + rf_ptr->dev_driver->phy_driver->phy_header_length + tx_buf->len - FHSS_SYNCH_INFO_LENGTH;
341341
rf_ptr->fhss_api->write_synch_info(rf_ptr->fhss_api, synch_info, 0, FHSS_SYNCH_FRAME, 0);
342342
}
343-
// Change to destination channel and write synchronization info to Beacon frames here
344-
int tx_handle_retval = rf_ptr->fhss_api->tx_handle(rf_ptr->fhss_api, !mac_is_ack_request_set(active_buf),
343+
if (active_buf->asynch_request == false) {
344+
// Change to destination channel and write synchronization info to Beacon frames here
345+
int tx_handle_retval = rf_ptr->fhss_api->tx_handle(rf_ptr->fhss_api, !mac_is_ack_request_set(active_buf),
345346
active_buf->DstAddr, mac_convert_frame_type_to_fhss(active_buf->fcf_dsn.frametype),
346347
active_buf->mac_payload_length, rf_ptr->dev_driver->phy_driver->phy_header_length,
347348
rf_ptr->dev_driver->phy_driver->phy_tail_length, active_buf->tx_time);
348-
// When FHSS TX handle returns -1, transmission of the packet is currently not allowed -> restart CCA timer
349-
if (tx_handle_retval == -1) {
350-
mac_sap_cca_fail_cb(rf_ptr);
351-
return -2;
352-
}
353-
// When FHSS TX handle returns -3, we are trying to transmit broadcast packet on unicast channel -> push back
354-
// to queue by using CCA fail event
355-
if (tx_handle_retval == -3) {
356-
mac_tx_done_state_set(rf_ptr, MAC_CCA_FAIL);
357-
return -3;
349+
// When FHSS TX handle returns -1, transmission of the packet is currently not allowed -> restart CCA timer
350+
if (tx_handle_retval == -1) {
351+
mac_sap_cca_fail_cb(rf_ptr);
352+
return -2;
353+
}
354+
// When FHSS TX handle returns -3, we are trying to transmit broadcast packet on unicast channel -> push back
355+
// to queue by using CCA fail event
356+
if (tx_handle_retval == -3) {
357+
mac_tx_done_state_set(rf_ptr, MAC_CCA_FAIL);
358+
return -3;
359+
}
358360
}
359361
}
360362
return 0;

source/Service_Libs/fhss/fhss.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -474,11 +474,6 @@ static uint32_t fhss_get_remaining_tx_time(fhss_structure_t *fhss_structure)
474474
return remaining_tx_time;
475475
}
476476

477-
uint32_t fhss_get_tx_time(fhss_structure_t *fhss_structure, uint16_t bytes_to_send, uint8_t phy_header_length, uint8_t phy_tail_length)
478-
{
479-
return ((1000000 / (fhss_structure->datarate / 8)) * (bytes_to_send + phy_header_length + phy_tail_length));
480-
}
481-
482477
// CCA adds extra 2ms with FHSS
483478
#define CCA_FHSS_PERIOD 2000
484479
// Ack frame length
@@ -721,8 +716,6 @@ static void fhss_synch_state_set_callback(const fhss_api_t *api, fhss_states fhs
721716
}
722717
fhss_generate_scramble_table(fhss_structure);
723718

724-
uint32_t datarate = fhss_structure->callbacks.read_datarate(fhss_structure->fhss_api);
725-
fhss_set_datarate(fhss_structure, datarate);
726719
uint8_t mac_address[8];
727720
fhss_structure->callbacks.read_mac_address(fhss_structure->fhss_api, mac_address);
728721
fhss_structure->bs->uc_channel_index = fhss_get_offset(fhss_structure, mac_address);
@@ -1197,7 +1190,7 @@ static uint16_t fhss_get_retry_period_callback(const fhss_api_t *api, uint8_t *d
11971190

11981191
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
11991192
if (fhss_structure) {
1200-
uint32_t datarate = fhss_structure->datarate;
1193+
uint32_t datarate = fhss_structure->callbacks.read_datarate(fhss_structure->fhss_api);
12011194
uint16_t max_tx_length;
12021195

12031196
if (datarate && phy_mtu) {

source/Service_Libs/fhss/fhss.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ struct fhss_bs
111111

112112
fhss_structure_t *fhss_enable(fhss_api_t *fhss_api, const fhss_configuration_t *fhss_configuration, const fhss_timer_t *fhss_timer, fhss_statistics_t *fhss_statistics);
113113
bool fhss_is_synch_root(fhss_structure_t *fhss_structure);
114-
uint32_t fhss_get_tx_time(fhss_structure_t *fhss_structure, uint16_t bytes_to_send, uint8_t phy_header_length, uint8_t phy_tail_length);
115114
/**
116115
* Calculate time in microseconds to start of next superframe.
117116
*

source/Service_Libs/fhss/fhss_common.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,6 @@ static fhss_structure_t *fhss_get_object_with_timer_id(const int8_t timer_id)
8989
return NULL;
9090
}
9191

92-
int8_t fhss_set_datarate(fhss_structure_t *fhss_structure, uint32_t datarate)
93-
{
94-
if (!fhss_structure) {
95-
return -1;
96-
}
97-
// If datarate is not set, use default 250kbit/s. Datarate is used as divider later.
98-
if (!datarate) {
99-
datarate = 250000;
100-
}
101-
fhss_structure->datarate = datarate;
102-
return 0;
103-
}
104-
10592
fhss_structure_t *fhss_get_object_with_api(const fhss_api_t *fhss_api)
10693
{
10794
if (!fhss_api || !fhss_struct) {
@@ -299,3 +286,8 @@ void fhss_failed_list_free(fhss_structure_t *fhss_structure)
299286
fhss_failed_handle_remove(fhss_structure, i);
300287
}
301288
}
289+
290+
uint32_t fhss_get_tx_time(fhss_structure_t *fhss_structure, uint16_t bytes_to_send, uint8_t phy_header_length, uint8_t phy_tail_length)
291+
{
292+
return ((1000000 / (fhss_structure->callbacks.read_datarate(fhss_structure->fhss_api) / 8)) * (bytes_to_send + phy_header_length + phy_tail_length));
293+
}

source/Service_Libs/fhss/fhss_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ struct fhss_structure
4343
uint8_t active_fhss_events;
4444
uint16_t number_of_channels;
4545
fhss_states fhss_state;
46-
uint32_t datarate;
4746
uint32_t fhss_timeout;
4847
uint32_t fhss_timer;
4948
struct fhss_api *fhss_api;
@@ -74,4 +73,5 @@ int fhss_failed_handle_remove(fhss_structure_t *fhss_structure, uint8_t handle);
7473
int fhss_failed_handle_add(fhss_structure_t *fhss_structure, uint8_t handle, uint8_t bad_channel);
7574
fhss_failed_tx_t *fhss_failed_handle_find(fhss_structure_t *fhss_structure, uint8_t handle);
7675
void fhss_failed_list_free(fhss_structure_t *fhss_structure);
76+
uint32_t fhss_get_tx_time(fhss_structure_t *fhss_structure, uint16_t bytes_to_send, uint8_t phy_header_length, uint8_t phy_tail_length);
7777
#endif /*FHSS_COMMON_H_*/

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -339,24 +339,29 @@ static bool fhss_ws_check_tx_allowed(fhss_structure_t *fhss_structure)
339339
return false;
340340
}
341341

342+
static bool fhss_ws_check_tx_time(fhss_structure_t *fhss_structure, uint16_t tx_length, uint8_t phy_header_length, uint8_t phy_tail_length)
343+
{
344+
if (!fhss_structure->ws->fhss_configuration.fhss_broadcast_interval || !fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval) {
345+
return true;
346+
}
347+
uint32_t tx_time = fhss_get_tx_time(fhss_structure, tx_length, phy_header_length, phy_tail_length);
348+
uint32_t time_to_bc_channel = fhss_structure->platform_functions.fhss_get_remaining_slots(fhss_broadcast_handler, fhss_structure->fhss_api);
349+
if (tx_time > time_to_bc_channel) {
350+
return false;
351+
}
352+
return true;
353+
}
354+
342355
static bool fhss_ws_check_tx_conditions_callback(const fhss_api_t *api, bool is_broadcast_addr, uint8_t handle, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length)
343356
{
344-
(void) handle;
345357
(void) frame_type;
346-
(void) frame_length;
347-
(void) phy_header_length;
348-
(void) phy_tail_length;
349358
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
350359
if (!fhss_structure) {
351360
return true;
352361
}
353362
if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_FIXED_CHANNEL) {
354363
return true;
355364
}
356-
// This condition will check that message is not sent on bad channel
357-
if (fhss_check_bad_channel(fhss_structure, handle) == false) {
358-
return false;
359-
}
360365
// Do not allow broadcast destination on unicast channel
361366
if (is_broadcast_addr && (fhss_structure->ws->is_on_bc_channel == false)) {
362367
return false;
@@ -365,6 +370,14 @@ static bool fhss_ws_check_tx_conditions_callback(const fhss_api_t *api, bool is_
365370
if (!is_broadcast_addr && (fhss_structure->ws->is_on_bc_channel == true)) {
366371
return false;
367372
}
373+
// This condition will check that message is not sent on bad channel
374+
if (fhss_check_bad_channel(fhss_structure, handle) == false) {
375+
return false;
376+
}
377+
// Check that there is enough unicast TX time before next broadcast channel. We try to avoid delaying the change to broadcast channel because of ongoing transmission.
378+
if (!is_broadcast_addr && !fhss_ws_check_tx_time(fhss_structure, frame_length, phy_header_length, phy_tail_length)) {
379+
return false;
380+
}
368381
// Check TX/RX slot for unicast frames
369382
if (!is_broadcast_addr && !fhss_ws_check_tx_allowed(fhss_structure)) {
370383
return false;

0 commit comments

Comments
 (0)