@@ -45,6 +45,7 @@ static int8_t fhss_beacon_create_tasklet(fhss_structure_t *fhss_structure);
4545static void fhss_beacon_tasklet_func (arm_event_s * event );
4646static int fhss_beacon_periodic_start (fhss_structure_t * fhss_structure , uint32_t time_to_first_beacon );
4747static void fhss_beacon_periodic_stop (fhss_structure_t * fhss_structure );
48+ static int fhss_reset_synch_monitor (fhss_synch_monitor_s * synch_monitor );
4849
4950fhss_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 )
5051{
@@ -80,6 +81,7 @@ fhss_structure_t *fhss_enable(fhss_api_t *fhss_api, const fhss_configuration_t *
8081 if (!fhss_struct -> bs -> fhss_configuration .fhss_max_synch_interval ) {
8182 fhss_struct -> bs -> fhss_configuration .fhss_max_synch_interval = 240 ;
8283 }
84+ fhss_reset_synch_monitor (& fhss_struct -> bs -> synch_monitor );
8385 ns_list_init (& fhss_struct -> fhss_failed_tx_list );
8486 fhss_struct -> own_hop = 0xff ;
8587 fhss_reset (fhss_struct );
@@ -263,6 +265,11 @@ static int fhss_update_txrx_slots(fhss_structure_t *fhss_structure)
263265 tx_slot_up_limit += (tx_slot_length * 2 );
264266 }
265267 }
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*/
266273 fhss_structure -> bs -> tx_allowed = tx_allowed ;
267274 return 0 ;
268275}
@@ -735,7 +742,7 @@ static int16_t fhss_synch_state_set_callback(const fhss_api_t *api, fhss_states
735742 memcpy (fhss_structure -> synch_parent , beacon_info -> source_address , 8 );
736743 platform_enter_critical ();
737744 // 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 ;
739746 // Synchronize to given PAN
740747 fhss_beacon_received (fhss_structure , beacon_info -> synch_info , elapsed_time );
741748 platform_exit_critical ();
@@ -978,7 +985,6 @@ static int fhss_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_addr
978985 if (frame_type == FHSS_DATA_FRAME ) {
979986 if (is_broadcast_addr == true) {
980987 if (fhss_is_current_channel_broadcast (fhss_structure ) == false) {
981- tr_info ("Broadcast on UC channel -> Back to queue" );
982988 return -3 ;
983989 }
984990 }
@@ -1059,7 +1065,7 @@ static uint8_t *fhss_beacon_encode_raw(uint8_t *buffer, const fhss_synchronizati
10591065 return buffer ;
10601066}
10611067
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 )
10631069{
10641070 fhss_synchronization_beacon_payload_s temp_payload ;
10651071 platform_enter_critical ();
@@ -1075,8 +1081,12 @@ static void fhss_beacon_build(fhss_structure_t *fhss_structure, uint8_t *dest)
10751081 temp_payload .number_of_broadcast_channels = config -> fhss_number_of_bc_channels ;
10761082 temp_payload .number_of_tx_slots = config -> fhss_number_of_tx_slots ;
10771083 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 ;
10801090 temp_payload .superframe_length = config -> fhss_superframe_length ;
10811091 temp_payload .number_of_superframes_per_channel = config -> fhss_number_of_superframes ;
10821092 platform_exit_critical ();
@@ -1091,7 +1101,7 @@ static int16_t fhss_write_synch_info_callback(const fhss_api_t *api, uint8_t *pt
10911101 if (!fhss_structure || !ptr || (frame_type != FHSS_SYNCH_FRAME )) {
10921102 return -1 ;
10931103 }
1094- fhss_beacon_build (fhss_structure , ptr );
1104+ fhss_beacon_build (fhss_structure , ptr , tx_time );
10951105 return FHSS_SYNCH_INFO_LENGTH ;
10961106}
10971107
@@ -1123,6 +1133,9 @@ static bool fhss_data_tx_fail_callback(const fhss_api_t *api, uint8_t handle, in
11231133 if (fhss_structure -> fhss_state == FHSS_UNSYNCHRONIZED ) {
11241134 return false;
11251135 }
1136+ #ifdef FHSS_CHANNEL_DEBUG
1137+ tr_info ("TX failed on ch: %u" , debug_destination_channel );
1138+ #endif /*FHSS_CHANNEL_DEBUG*/
11261139 // Channel retries are disabled -> return
11271140 if (fhss_structure -> bs -> fhss_configuration .fhss_number_of_channel_retries == 0 ) {
11281141 return false;
@@ -1162,7 +1175,7 @@ static void fhss_receive_frame_callback(const fhss_api_t *api, uint16_t pan_id,
11621175 fhss_update_synch_parent_address (fhss_structure );
11631176 platform_enter_critical ();
11641177 // 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 ;
11661179 // Synchronize to given PAN
11671180 fhss_beacon_received (fhss_structure , synch_info , elapsed_time );
11681181 platform_exit_critical ();
@@ -1422,6 +1435,6 @@ static void fhss_beacon_tasklet_func(arm_event_s *event)
14221435 }
14231436 // Update Beacon info lifetimes
14241437 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 ));
14261439 }
14271440}
0 commit comments