Skip to content

Commit 7d537ea

Browse files
author
Jarkko Paso
committed
FHSS: Read timestamp from MAC/PHY instead of using FHSS own timestamp
1 parent 0206fc8 commit 7d537ea

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

nanostack/fhss_api.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,13 @@ typedef int mac_read_mac_address(const fhss_api_t *fhss_api, uint8_t *mac_addres
215215
*/
216216
typedef uint32_t mac_read_datarate(const fhss_api_t *fhss_api);
217217

218+
/**
219+
* @brief Read 32-bit timestamp.
220+
* @param fhss_api FHSS instance.
221+
* @return Timestamp.
222+
*/
223+
typedef uint32_t mac_read_timestamp(const fhss_api_t *fhss_api);
224+
218225
/**
219226
* @brief Change channel.
220227
* @param fhss_api FHSS instance.
@@ -287,6 +294,7 @@ struct fhss_callback {
287294
mac_read_tx_queue_size *read_tx_queue_size; /**< Read MAC TX queue size. */
288295
mac_read_mac_address *read_mac_address; /**< Read MAC address. */
289296
mac_read_datarate *read_datarate; /**< Read PHY datarate. */
297+
mac_read_timestamp *read_timestamp; /**< Read timestamp. */
290298
mac_change_channel *change_channel; /**< Change channel. */
291299
mac_send_fhss_frame *send_fhss_frame; /**< Send FHSS frame. */
292300
mac_synch_lost_notification *synch_lost_notification; /**< Send notification when FHSS synchronization is lost. */

source/MAC/IEEE802_15_4/mac_fhss_callbacks.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ uint32_t mac_read_phy_datarate(const fhss_api_t *fhss_api)
6565
return datarate;
6666
}
6767

68+
uint32_t mac_read_phy_timestamp(const fhss_api_t *fhss_api)
69+
{
70+
protocol_interface_rf_mac_setup_s *mac_setup = get_sw_mac_ptr_by_fhss_api(fhss_api);
71+
if (!mac_setup) {
72+
return 0;
73+
}
74+
uint32_t timestamp;
75+
mac_setup->dev_driver->phy_driver->extension(PHY_EXTENSION_GET_TIMESTAMP, (uint8_t *)&timestamp);
76+
return timestamp;
77+
}
78+
6879
int mac_set_channel(const fhss_api_t *fhss_api, uint8_t channel_number)
6980
{
7081
protocol_interface_rf_mac_setup_s *mac_setup = get_sw_mac_ptr_by_fhss_api(fhss_api);

source/MAC/IEEE802_15_4/mac_fhss_callbacks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
uint16_t mac_read_tx_queue_sizes(const fhss_api_t *fhss_api, bool broadcast_queue);
2222
int mac_read_64bit_mac_address(const fhss_api_t *fhss_api, uint8_t *mac_address);
2323
uint32_t mac_read_phy_datarate(const fhss_api_t *fhss_api);
24+
uint32_t mac_read_phy_timestamp(const fhss_api_t *fhss_api);
2425
int mac_set_channel(const fhss_api_t *fhss_api, uint8_t channel_number);
2526
int mac_fhss_frame_tx(const fhss_api_t *fhss_api, int frame_type);
2627
int mac_synch_lost(const fhss_api_t *fhss_api);

source/MAC/IEEE802_15_4/sw_mac.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ int ns_sw_mac_fhss_register(mac_api_t *mac_api, fhss_api_t *fhss_api)
176176
fhss_callback_t callbacks;
177177
callbacks.read_tx_queue_size = &mac_read_tx_queue_sizes;
178178
callbacks.read_datarate = &mac_read_phy_datarate;
179+
callbacks.read_timestamp = &mac_read_phy_timestamp;
179180
callbacks.read_mac_address = &mac_read_64bit_mac_address;
180181
callbacks.change_channel = &mac_set_channel;
181182
callbacks.send_fhss_frame = &mac_fhss_frame_tx;

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static uint32_t fhss_ws_calculate_ufsi(fhss_structure_t *fhss_structure, uint32_
174174
}
175175
cur_slot--;
176176
uint32_t remaining_time = (fhss_structure->platform_functions.fhss_get_remaining_slots(fhss_unicast_handler, fhss_structure->fhss_api) / 1000);
177-
uint32_t time_to_tx = (tx_time - fhss_structure->fhss_api->read_timestamp(fhss_structure->fhss_api)) / 1000;
177+
uint32_t time_to_tx = (tx_time - fhss_structure->callbacks.read_timestamp(fhss_structure->fhss_api)) / 1000;
178178
uint64_t ms_since_seq_start = (cur_slot * dwell_time) + (dwell_time-remaining_time) + time_to_tx;
179179
uint32_t seq_length = 0x10000;
180180
if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_TR51CF) {
@@ -193,7 +193,7 @@ static uint32_t fhss_ws_calculate_broadcast_interval_offset(fhss_structure_t *fh
193193
if (fhss_structure->ws->is_on_bc_channel == true) {
194194
remaining_time += (broadcast_interval - dwell_time);
195195
}
196-
uint32_t time_to_tx = (tx_time - fhss_structure->fhss_api->read_timestamp(fhss_structure->fhss_api)) / 1000;
196+
uint32_t time_to_tx = (tx_time - fhss_structure->callbacks.read_timestamp(fhss_structure->fhss_api)) / 1000;
197197
return (broadcast_interval-remaining_time) + time_to_tx;
198198
}
199199

@@ -592,7 +592,7 @@ int fhss_ws_set_callbacks(fhss_structure_t *fhss_structure)
592592
fhss_structure->fhss_api->data_tx_done = &fhss_ws_data_tx_done_callback;
593593
fhss_structure->fhss_api->data_tx_fail = &fhss_ws_data_tx_fail_callback;
594594
fhss_structure->fhss_api->synch_state_set = &fhss_ws_synch_state_set_callback;
595-
fhss_structure->fhss_api->read_timestamp = &fhss_read_timestamp_cb;
595+
fhss_structure->fhss_api->read_timestamp = NULL;
596596
fhss_structure->fhss_api->get_retry_period = NULL;
597597
fhss_structure->fhss_api->write_synch_info = &fhss_ws_write_synch_info_callback;
598598
fhss_structure->fhss_api->init_callbacks = &fhss_init_callbacks_cb;
@@ -612,7 +612,7 @@ int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8],
612612
return -1;
613613
}
614614

615-
uint32_t time_from_reception_ms = (fhss_structure->fhss_api->read_timestamp(fhss_structure->fhss_api) - bc_timing_info->bt_rx_timestamp)/1000;
615+
uint32_t time_from_reception_ms = (fhss_structure->callbacks.read_timestamp(fhss_structure->fhss_api) - bc_timing_info->bt_rx_timestamp)/1000;
616616
uint32_t true_bc_interval_offset = (bc_timing_info->broadcast_interval_offset + time_from_reception_ms) % bc_timing_info->broadcast_interval;
617617
uint32_t timeout = ((bc_timing_info->broadcast_interval-true_bc_interval_offset)*1000);
618618
fhss_start_timer(fhss_structure, timeout, fhss_broadcast_handler);

0 commit comments

Comments
 (0)