Skip to content

Commit

Permalink
Merge pull request ARMmbed#1836 from ARMmbed/IOTTHD-2828
Browse files Browse the repository at this point in the history
Iotthd 2828
  • Loading branch information
Jarkko Paso authored Oct 9, 2018
2 parents b074d0e + 5ddf5fa commit 514bb58
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion source/MAC/IEEE802_15_4/mac_mcps_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,7 @@ int8_t mcps_generic_ack_build(protocol_interface_rf_mac_setup_s *rf_ptr, const m

tx_buf->len = frame_length;
uint8_t *mhr_start = ptr;
buffer->tx_time = rx_time + 196; //Send 196 us later
buffer->tx_time = mac_mcps_sap_get_phy_timestamp(rf_ptr) + 300; //Send 300 us later

ptr = mac_generic_packet_write(rf_ptr, ptr, buffer);

Expand Down
26 changes: 20 additions & 6 deletions source/Service_Libs/fhss/fhss_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ static void fhss_unicast_handler(const fhss_api_t *fhss_api, uint16_t delay);
static bool fhss_ws_check_tx_allowed(fhss_structure_t *fhss_structure);
static uint8_t fhss_set_txrx_slot_length(fhss_structure_t *fhss_structure);

// This function supports rounding up
static uint32_t divide_integer(uint32_t dividend, uint32_t divisor)
{
return (dividend + divisor/2) / divisor;
}

fhss_structure_t *fhss_ws_enable(fhss_api_t *fhss_api, const fhss_ws_configuration_t *fhss_configuration, const fhss_timer_t *fhss_timer)
{
if (!fhss_api || !fhss_configuration || !fhss_timer) {
Expand Down Expand Up @@ -164,12 +170,12 @@ static void fhss_broadcast_handler(const fhss_api_t *fhss_api, uint16_t delay)
// Should return to own (unicast) listening channel after broadcast channel
next_channel = fhss_structure->rx_channel;
/* Start timer with random timeout to trigger unicast TX queue poll event.
* Min random is 50us.
* Min random is 1/30 of the TX slot length.
* Max random is 1/10 of the TX slot length.
* Event timer resolution is 50us.
*/
uint32_t txrx_slot_length_us = fhss_structure->ws->txrx_slot_length_ms * 1000;
uint16_t uc_min_random = 1;
uint16_t uc_min_random = (txrx_slot_length_us / 30) / 50;
uint16_t uc_max_random = (txrx_slot_length_us / 10) / 50;
bool tx_allowed = fhss_ws_check_tx_allowed(fhss_structure);
if (!tx_allowed) {
Expand Down Expand Up @@ -254,14 +260,14 @@ static uint32_t fhss_ws_calculate_broadcast_interval_offset(fhss_structure_t *fh
uint8_t dwell_time = fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval;
uint32_t broadcast_interval = fhss_structure->ws->fhss_configuration.fhss_broadcast_interval;

uint32_t remaining_time = (fhss_structure->platform_functions.fhss_get_remaining_slots(fhss_broadcast_handler, fhss_structure->fhss_api) / 1000);
uint32_t remaining_time = divide_integer(fhss_structure->platform_functions.fhss_get_remaining_slots(fhss_broadcast_handler, fhss_structure->fhss_api), 1000);
if (fhss_structure->ws->is_on_bc_channel == true) {
remaining_time += (broadcast_interval - dwell_time);
}
uint32_t time_to_tx = 0;
uint32_t cur_time = fhss_structure->callbacks.read_timestamp(fhss_structure->fhss_api);
if (cur_time < tx_time) {
time_to_tx = (tx_time - cur_time) / 1000;
time_to_tx = divide_integer(tx_time - cur_time, 1000);
}
return (broadcast_interval-remaining_time) + time_to_tx;
}
Expand Down Expand Up @@ -360,9 +366,17 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a
if (!fhss_structure) {
return -1;
}
if (is_broadcast_addr || (fhss_structure->ws->is_on_bc_channel == true)) {
if (is_broadcast_addr) {
return 0;
}
// Do not allow unicast destination on broadcast channel
if (!is_broadcast_addr && (fhss_structure->ws->is_on_bc_channel == true)) {
return -1;
}
// Check TX/RX slot
if (!fhss_ws_check_tx_allowed(fhss_structure)) {
return -1;
}
if (fhss_structure->fhss_state == FHSS_SYNCHRONIZED) {
fhss_ws_neighbor_timing_info_t *neighbor_timing_info = fhss_structure->ws->get_neighbor_info(api, destination_address);
if (!neighbor_timing_info) {
Expand Down Expand Up @@ -673,7 +687,7 @@ int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8],
fhss_structure->ws->synchronization_time = fhss_structure->callbacks.read_timestamp(fhss_structure->fhss_api);
platform_enter_critical();
fhss_stop_timer(fhss_structure, fhss_broadcast_handler);
uint32_t time_from_reception_ms = (fhss_structure->callbacks.read_timestamp(fhss_structure->fhss_api) - bc_timing_info->bt_rx_timestamp)/1000;
uint32_t time_from_reception_ms = divide_integer(fhss_structure->callbacks.read_timestamp(fhss_structure->fhss_api) - bc_timing_info->bt_rx_timestamp, 1000);
uint32_t true_bc_interval_offset = (bc_timing_info->broadcast_interval_offset + time_from_reception_ms) % bc_timing_info->broadcast_interval;
uint32_t timeout = ((bc_timing_info->broadcast_interval-true_bc_interval_offset)*1000);

Expand Down

0 comments on commit 514bb58

Please sign in to comment.