@@ -45,6 +45,7 @@ static int8_t fhss_beacon_create_tasklet(fhss_structure_t *fhss_structure);
45
45
static void fhss_beacon_tasklet_func (arm_event_s * event );
46
46
static int fhss_beacon_periodic_start (fhss_structure_t * fhss_structure , uint32_t time_to_first_beacon );
47
47
static void fhss_beacon_periodic_stop (fhss_structure_t * fhss_structure );
48
+ static int fhss_reset_synch_monitor (fhss_synch_monitor_s * synch_monitor );
48
49
49
50
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 )
50
51
{
@@ -80,6 +81,7 @@ fhss_structure_t *fhss_enable(fhss_api_t *fhss_api, const fhss_configuration_t *
80
81
if (!fhss_struct -> bs -> fhss_configuration .fhss_max_synch_interval ) {
81
82
fhss_struct -> bs -> fhss_configuration .fhss_max_synch_interval = 240 ;
82
83
}
84
+ fhss_reset_synch_monitor (& fhss_struct -> bs -> synch_monitor );
83
85
ns_list_init (& fhss_struct -> fhss_failed_tx_list );
84
86
fhss_struct -> own_hop = 0xff ;
85
87
fhss_reset (fhss_struct );
@@ -263,6 +265,11 @@ static int fhss_update_txrx_slots(fhss_structure_t *fhss_structure)
263
265
tx_slot_up_limit += (tx_slot_length * 2 );
264
266
}
265
267
}
268
+ #ifdef FHSS_CHANNEL_DEBUG_CBS
269
+ if (fhss_bc_switch && fhss_structure -> bs -> tx_allowed != tx_allowed ) {
270
+ fhss_bc_switch ();
271
+ }
272
+ #endif /*FHSS_CHANNEL_DEBUG_CBS*/
266
273
fhss_structure -> bs -> tx_allowed = tx_allowed ;
267
274
return 0 ;
268
275
}
@@ -735,7 +742,7 @@ static int16_t fhss_synch_state_set_callback(const fhss_api_t *api, fhss_states
735
742
memcpy (fhss_structure -> synch_parent , beacon_info -> source_address , 8 );
736
743
platform_enter_critical ();
737
744
// Calculate time since the Beacon was received
738
- uint32_t elapsed_time = fhss_structure -> fhss_api -> read_timestamp (fhss_structure -> fhss_api ) - beacon_info -> timestamp ;
745
+ uint32_t elapsed_time = fhss_structure -> callbacks . read_timestamp (fhss_structure -> fhss_api ) - beacon_info -> timestamp ;
739
746
// Synchronize to given PAN
740
747
fhss_beacon_received (fhss_structure , beacon_info -> synch_info , elapsed_time );
741
748
platform_exit_critical ();
@@ -978,7 +985,6 @@ static int fhss_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_addr
978
985
if (frame_type == FHSS_DATA_FRAME ) {
979
986
if (is_broadcast_addr == true) {
980
987
if (fhss_is_current_channel_broadcast (fhss_structure ) == false) {
981
- tr_info ("Broadcast on UC channel -> Back to queue" );
982
988
return -3 ;
983
989
}
984
990
}
@@ -1059,7 +1065,7 @@ static uint8_t *fhss_beacon_encode_raw(uint8_t *buffer, const fhss_synchronizati
1059
1065
return buffer ;
1060
1066
}
1061
1067
1062
- static void fhss_beacon_build (fhss_structure_t * fhss_structure , uint8_t * dest )
1068
+ static void fhss_beacon_build (fhss_structure_t * fhss_structure , uint8_t * dest , uint32_t tx_time )
1063
1069
{
1064
1070
fhss_synchronization_beacon_payload_s temp_payload ;
1065
1071
platform_enter_critical ();
@@ -1075,8 +1081,12 @@ static void fhss_beacon_build(fhss_structure_t *fhss_structure, uint8_t *dest)
1075
1081
temp_payload .number_of_broadcast_channels = config -> fhss_number_of_bc_channels ;
1076
1082
temp_payload .number_of_tx_slots = config -> fhss_number_of_tx_slots ;
1077
1083
temp_payload .time_since_last_beacon = 0 ; // XXX not available yet
1078
- uint32_t tx_time = fhss_get_tx_time (fhss_structure , 71 , 0 , 0 );
1079
- temp_payload .processing_delay = fhss_structure -> bs -> fhss_configuration .fhss_tuning_parameters .tx_processing_delay + tx_time ;
1084
+ uint32_t time_to_tx = 0 ;
1085
+ uint32_t cur_time = fhss_structure -> callbacks .read_timestamp (fhss_structure -> fhss_api );
1086
+ if (cur_time < tx_time ) {
1087
+ time_to_tx = tx_time - cur_time ;
1088
+ }
1089
+ temp_payload .processing_delay = fhss_structure -> bs -> fhss_configuration .fhss_tuning_parameters .tx_processing_delay + time_to_tx ;
1080
1090
temp_payload .superframe_length = config -> fhss_superframe_length ;
1081
1091
temp_payload .number_of_superframes_per_channel = config -> fhss_number_of_superframes ;
1082
1092
platform_exit_critical ();
@@ -1091,7 +1101,7 @@ static int16_t fhss_write_synch_info_callback(const fhss_api_t *api, uint8_t *pt
1091
1101
if (!fhss_structure || !ptr || (frame_type != FHSS_SYNCH_FRAME )) {
1092
1102
return -1 ;
1093
1103
}
1094
- fhss_beacon_build (fhss_structure , ptr );
1104
+ fhss_beacon_build (fhss_structure , ptr , tx_time );
1095
1105
return FHSS_SYNCH_INFO_LENGTH ;
1096
1106
}
1097
1107
@@ -1123,6 +1133,9 @@ static bool fhss_data_tx_fail_callback(const fhss_api_t *api, uint8_t handle, in
1123
1133
if (fhss_structure -> fhss_state == FHSS_UNSYNCHRONIZED ) {
1124
1134
return false;
1125
1135
}
1136
+ #ifdef FHSS_CHANNEL_DEBUG
1137
+ tr_info ("TX failed on ch: %u" , debug_destination_channel );
1138
+ #endif /*FHSS_CHANNEL_DEBUG*/
1126
1139
// Channel retries are disabled -> return
1127
1140
if (fhss_structure -> bs -> fhss_configuration .fhss_number_of_channel_retries == 0 ) {
1128
1141
return false;
@@ -1162,7 +1175,7 @@ static void fhss_receive_frame_callback(const fhss_api_t *api, uint16_t pan_id,
1162
1175
fhss_update_synch_parent_address (fhss_structure );
1163
1176
platform_enter_critical ();
1164
1177
// Calculate time since the Beacon was received
1165
- uint32_t elapsed_time = api -> read_timestamp (api ) - timestamp ;
1178
+ uint32_t elapsed_time = fhss_structure -> callbacks . read_timestamp (api ) - timestamp ;
1166
1179
// Synchronize to given PAN
1167
1180
fhss_beacon_received (fhss_structure , synch_info , elapsed_time );
1168
1181
platform_exit_critical ();
@@ -1422,6 +1435,6 @@ static void fhss_beacon_tasklet_func(arm_event_s *event)
1422
1435
}
1423
1436
// Update Beacon info lifetimes
1424
1437
else if (event -> event_type == FHSS_UPDATE_SYNCH_INFO_STORAGE ) {
1425
- fhss_update_beacon_info_lifetimes (fhss_structure , fhss_read_timestamp_cb (fhss_structure -> fhss_api ));
1438
+ fhss_update_beacon_info_lifetimes (fhss_structure , fhss_structure -> callbacks . read_timestamp (fhss_structure -> fhss_api ));
1426
1439
}
1427
1440
}
0 commit comments