28
28
#include "eventOS_callback_timer.h"
29
29
#include "randLIB.h"
30
30
#include "ns_trace.h"
31
+ #include "platform/arm_hal_interrupt.h"
31
32
#include <string.h>
32
33
33
34
#define TRACE_GROUP "fhss"
@@ -255,7 +256,11 @@ static uint32_t fhss_ws_calculate_broadcast_interval_offset(fhss_structure_t *fh
255
256
if (fhss_structure -> ws -> is_on_bc_channel == true) {
256
257
remaining_time += (broadcast_interval - dwell_time );
257
258
}
258
- uint32_t time_to_tx = (tx_time - fhss_structure -> callbacks .read_timestamp (fhss_structure -> fhss_api )) / 1000 ;
259
+ uint32_t time_to_tx = 0 ;
260
+ uint32_t cur_time = fhss_structure -> callbacks .read_timestamp (fhss_structure -> fhss_api );
261
+ if (cur_time < tx_time ) {
262
+ time_to_tx = (tx_time - cur_time ) / 1000 ;
263
+ }
259
264
return (broadcast_interval - remaining_time ) + time_to_tx ;
260
265
}
261
266
@@ -504,6 +509,7 @@ static int16_t fhss_ws_write_synch_info_callback(const fhss_api_t *api, uint8_t
504
509
if (!fhss_structure || !ptr || (frame_type != FHSS_DATA_FRAME )) {
505
510
return -1 ;
506
511
}
512
+ platform_enter_critical ();
507
513
struct ws_ie_t header_ie ;
508
514
header_ie .id = WH_IE_ID ;
509
515
if (fhss_ws_ie_header_discover (ptr , length , & header_ie , WH_SUB_ID_UTT )) {
@@ -515,6 +521,7 @@ static int16_t fhss_ws_write_synch_info_callback(const fhss_api_t *api, uint8_t
515
521
common_write_16_bit_inverse (fhss_structure -> ws -> bc_slot , header_ie .content_ptr );
516
522
common_write_24_bit_inverse (broadcast_interval_offset , header_ie .content_ptr + 2 );
517
523
}
524
+ platform_exit_critical ();
518
525
//TODO return destination channel here
519
526
return fhss_structure -> rx_channel ;
520
527
}
@@ -660,18 +667,19 @@ int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8],
660
667
if (!bc_timing_info -> broadcast_interval || !bc_timing_info -> broadcast_dwell_interval ) {
661
668
return -1 ;
662
669
}
663
-
670
+ platform_enter_critical ();
664
671
uint32_t time_from_reception_ms = (fhss_structure -> callbacks .read_timestamp (fhss_structure -> fhss_api ) - bc_timing_info -> bt_rx_timestamp )/1000 ;
665
672
uint32_t true_bc_interval_offset = (bc_timing_info -> broadcast_interval_offset + time_from_reception_ms ) % bc_timing_info -> broadcast_interval ;
666
673
uint32_t timeout = ((bc_timing_info -> broadcast_interval - true_bc_interval_offset )* 1000 );
674
+ fhss_structure -> ws -> is_on_bc_channel = false;
667
675
fhss_start_timer (fhss_structure , timeout , fhss_broadcast_handler );
668
676
uint16_t slots_since_reception = (bc_timing_info -> broadcast_interval_offset + time_from_reception_ms ) / bc_timing_info -> broadcast_interval ;
669
677
// TODO: Calculate drift error
670
678
fhss_structure -> ws -> fhss_configuration .fhss_bc_dwell_interval = bc_timing_info -> broadcast_dwell_interval ;
671
679
fhss_structure -> ws -> fhss_configuration .fhss_broadcast_interval = bc_timing_info -> broadcast_interval ;
672
680
fhss_set_txrx_slot_length (fhss_structure );
673
681
fhss_structure -> ws -> bc_slot = bc_timing_info -> broadcast_slot + slots_since_reception ;
674
-
682
+ platform_exit_critical ();
675
683
//TODO: support multiple parents
676
684
fhss_structure -> ws -> parent_bc_info = bc_timing_info ;
677
685
return 0 ;
0 commit comments