Skip to content

Commit 0a472ae

Browse files
author
Jarkko Paso
authored
WS: Calculate UFSI drift and trace (ARMmbed#2430)
1 parent 61d3db8 commit 0a472ae

File tree

5 files changed

+45
-9
lines changed

5 files changed

+45
-9
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,7 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
14751475
if (neighbour_pointer_valid) {
14761476
etx_lqi_dbm_update(cur->id, data->mpduLinkQuality, data->signal_dbm, neighbor_info.neighbor->index, neighbor_info.neighbor->mac64);
14771477
//Update Neighbor Broadcast and Unicast Parameters
1478-
ws_neighbor_class_neighbor_unicast_time_info_update(neighbor_info.ws_neighbor, ws_utt, data->timestamp);
1478+
ws_neighbor_class_neighbor_unicast_time_info_update(neighbor_info.ws_neighbor, ws_utt, data->timestamp, (uint8_t *) data->SrcAddr);
14791479
ws_neighbor_class_neighbor_unicast_schedule_set(neighbor_info.ws_neighbor, ws_us, &cur->ws_info->hopping_schdule);
14801480
ws_neighbor_class_neighbor_broadcast_time_info_update(neighbor_info.ws_neighbor, &ws_bt_ie, data->timestamp);
14811481
ws_neighbor_class_neighbor_broadcast_schedule_set(neighbor_info.ws_neighbor, &ws_bs_ie);
@@ -1559,7 +1559,7 @@ static void ws_bootstrap_pan_config_solicit_analyse(struct protocol_interface_in
15591559
llc_neighbour_req_t neighbor_info;
15601560
if (ws_bootstrap_neighbor_info_request(cur, data->SrcAddr, &neighbor_info, false)) {
15611561
etx_lqi_dbm_update(cur->id, data->mpduLinkQuality, data->signal_dbm, neighbor_info.neighbor->index, neighbor_info.neighbor->mac64);
1562-
ws_neighbor_class_neighbor_unicast_time_info_update(neighbor_info.ws_neighbor, ws_utt, data->timestamp);
1562+
ws_neighbor_class_neighbor_unicast_time_info_update(neighbor_info.ws_neighbor, ws_utt, data->timestamp, (uint8_t *) data->SrcAddr);
15631563
ws_neighbor_class_neighbor_unicast_schedule_set(neighbor_info.ws_neighbor, ws_us, &cur->ws_info->hopping_schdule);
15641564
}
15651565

@@ -3268,7 +3268,7 @@ static int8_t ws_bootstrap_neighbor_set(protocol_interface_info_entry_t *cur, pa
32683268
return -1;
32693269
}
32703270
ws_bootstrap_neighbor_set_stable(cur, parent_ptr->addr);
3271-
ws_neighbor_class_neighbor_unicast_time_info_update(neighbor_info.ws_neighbor, &parent_ptr->ws_utt, parent_ptr->timestamp);
3271+
ws_neighbor_class_neighbor_unicast_time_info_update(neighbor_info.ws_neighbor, &parent_ptr->ws_utt, parent_ptr->timestamp, parent_ptr->addr);
32723272
ws_neighbor_class_neighbor_unicast_schedule_set(neighbor_info.ws_neighbor, &parent_ptr->ws_us, &cur->ws_info->hopping_schdule);
32733273
return 0;
32743274
}

source/6LoWPAN/ws/ws_llc_data_service.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ static void ws_llc_mac_confirm_cb(const mac_api_t *api, const mcps_data_conf_t *
493493
neighbor_info.neighbor->lifetime = neighbor_info.neighbor->link_lifetime;
494494
}
495495

496-
ws_neighbor_class_neighbor_unicast_time_info_update(neighbor_info.ws_neighbor, &ws_utt, data->timestamp);
496+
ws_neighbor_class_neighbor_unicast_time_info_update(neighbor_info.ws_neighbor, &ws_utt, data->timestamp, neighbor_info.neighbor->mac64);
497497
}
498498

499499
int8_t rsl;
@@ -702,7 +702,7 @@ static void ws_llc_data_indication_cb(const mac_api_t *api, const mcps_data_ind_
702702
return;
703703
}
704704

705-
ws_neighbor_class_neighbor_unicast_time_info_update(neighbor_info.ws_neighbor, &ws_utt, data->timestamp);
705+
ws_neighbor_class_neighbor_unicast_time_info_update(neighbor_info.ws_neighbor, &ws_utt, data->timestamp, (uint8_t *) data->SrcAddr);
706706
if (us_ie_inline) {
707707
ws_neighbor_class_neighbor_unicast_schedule_set(neighbor_info.ws_neighbor, &us_ie, &interface->ws_info->hopping_schdule);
708708
}
@@ -808,7 +808,7 @@ static void ws_llc_eapol_indication_cb(const mac_api_t *api, const mcps_data_ind
808808
temp_entry->signal_dbm = data->signal_dbm;
809809
}
810810
uint8_t auth_eui64[8];
811-
ws_neighbor_class_neighbor_unicast_time_info_update(neighbor_info.ws_neighbor, &ws_utt, data->timestamp);
811+
ws_neighbor_class_neighbor_unicast_time_info_update(neighbor_info.ws_neighbor, &ws_utt, data->timestamp, (uint8_t *) data->SrcAddr);
812812
if (us_ie_inline) {
813813
ws_neighbor_class_neighbor_unicast_schedule_set(neighbor_info.ws_neighbor, &us_ie, &interface->ws_info->hopping_schdule);
814814
}

source/6LoWPAN/ws/ws_neighbor_class.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,44 @@ void ws_neighbor_class_entry_remove(ws_neighbor_class_t *class_data, uint8_t att
8989
}
9090
}
9191

92-
void ws_neighbor_class_neighbor_unicast_time_info_update(ws_neighbor_class_entry_t *ws_neighbor, ws_utt_ie_t *ws_utt, uint32_t timestamp)
92+
#ifdef FEA_TRACE_SUPPORT
93+
static int own_ceil(float value)
9394
{
95+
int ivalue = (int)value;
96+
if (value == (float)ivalue) {
97+
return ivalue;
98+
}
99+
return ivalue + 1;
100+
}
101+
102+
static void ws_neighbor_calculate_ufsi_drift(ws_neighbor_class_entry_t *ws_neighbor, ws_utt_ie_t *ws_utt, uint32_t timestamp, uint8_t address[8])
103+
{
104+
if (ws_neighbor->fhss_data.uc_timing_info.utt_rx_timestamp && ws_neighbor->fhss_data.uc_timing_info.ufsi) {
105+
uint32_t seq_length = 0x10000;
106+
if (ws_neighbor->fhss_data.uc_timing_info.unicast_channel_function == WS_TR51CF) {
107+
seq_length = ws_neighbor->fhss_data.uc_timing_info.unicast_number_of_channels;
108+
}
109+
// Convert 24-bit UFSI to real time before drift calculation
110+
uint32_t time_since_seq_start_prev_ms = own_ceil((float)((uint64_t)ws_neighbor->fhss_data.uc_timing_info.ufsi * seq_length * ws_neighbor->fhss_data.uc_timing_info.unicast_dwell_interval) / 0x1000000);
111+
uint32_t time_since_seq_start_cur_ms = own_ceil((float)((uint64_t)ws_utt->ufsi * seq_length * ws_neighbor->fhss_data.uc_timing_info.unicast_dwell_interval) / 0x1000000);
112+
uint32_t time_since_last_ufsi_us = timestamp - ws_neighbor->fhss_data.uc_timing_info.utt_rx_timestamp;
113+
uint32_t ufsi_diff_ms = time_since_seq_start_cur_ms - time_since_seq_start_prev_ms;
114+
int32_t ufsi_drift_ms = (int32_t)(time_since_last_ufsi_us / 1000 - ufsi_diff_ms);
115+
// Only trace if there is significant error
116+
if (ufsi_drift_ms < -5 || ufsi_drift_ms > 5) {
117+
tr_debug("UFSI updated: %s, drift: %"PRIi32"ms in %"PRIu32" seconds", trace_array(address, 8), ufsi_drift_ms, time_since_last_ufsi_us / 1000000);
118+
}
119+
}
120+
}
121+
#endif
122+
123+
void ws_neighbor_class_neighbor_unicast_time_info_update(ws_neighbor_class_entry_t *ws_neighbor, ws_utt_ie_t *ws_utt, uint32_t timestamp, uint8_t address[8])
124+
{
125+
#ifdef FEA_TRACE_SUPPORT
126+
ws_neighbor_calculate_ufsi_drift(ws_neighbor, ws_utt, timestamp, address);
127+
#else
128+
(void) address;
129+
#endif
94130
ws_neighbor->fhss_data.uc_timing_info.utt_rx_timestamp = timestamp;
95131
ws_neighbor->fhss_data.uc_timing_info.ufsi = ws_utt->ufsi;
96132
}

source/6LoWPAN/ws/ws_neighbor_class.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void ws_neighbor_class_entry_remove(ws_neighbor_class_t *class_data, uint8_t att
106106
* \param timestamp timestamp for received data
107107
*
108108
*/
109-
void ws_neighbor_class_neighbor_unicast_time_info_update(ws_neighbor_class_entry_t *ws_neighbor, ws_utt_ie_t *ws_utt, uint32_t timestamp);
109+
void ws_neighbor_class_neighbor_unicast_time_info_update(ws_neighbor_class_entry_t *ws_neighbor, ws_utt_ie_t *ws_utt, uint32_t timestamp, uint8_t address[8]);
110110

111111
/**
112112
* ws_neighbor_class_neighbor_unicast_schedule_set a function for update neighbor unicast shedule information

test/nanostack/unittest/stub/ws_neighbour_class_stub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void ws_neighbor_class_entry_remove(ws_neighbor_class_t *class_data, uint8_t att
6969

7070
}
7171

72-
void ws_neighbor_class_neighbor_unicast_time_info_update(ws_neighbor_class_entry_t *ws_neighbor, ws_utt_ie_t *ws_utt, uint32_t timestamp)
72+
void ws_neighbor_class_neighbor_unicast_time_info_update(ws_neighbor_class_entry_t *ws_neighbor, ws_utt_ie_t *ws_utt, uint32_t timestamp, uint8_t address[8])
7373
{
7474

7575
}

0 commit comments

Comments
 (0)