Skip to content

Commit ae210cd

Browse files
author
Jarkko Paso
authored
Merge pull request ARMmbed#1923 from ARMmbed/IOTTHD-3080
Iotthd 3080
2 parents 17fad47 + 9ac5301 commit ae210cd

File tree

7 files changed

+65
-24
lines changed

7 files changed

+65
-24
lines changed

source/MAC/IEEE802_15_4/mac_header_helper_functions.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "MAC/IEEE802_15_4/mac_defines.h"
2727
#include "MAC/IEEE802_15_4/mac_mcps_sap.h"
2828
#include "MAC/IEEE802_15_4/mac_header_helper_functions.h"
29+
#include "MAC/rf_driver_storage.h"
2930

3031
static uint8_t *mcps_mac_security_aux_header_start_pointer_get(const mac_pre_parsed_frame_t *buffer);
3132
static uint8_t *mac_header_information_elements_write(const mac_pre_build_frame_t *buffer, uint8_t *ptr);
@@ -569,7 +570,13 @@ uint8_t *mac_generic_packet_write(struct protocol_interface_rf_mac_setup *rf_ptr
569570
ptr += buffer->mac_payload_length;
570571
}
571572
if (rf_ptr->fhss_api) {
572-
rf_ptr->fhss_api->write_synch_info(rf_ptr->fhss_api, ie_start, buffer->headerIeLength, FHSS_DATA_FRAME, buffer->tx_time);
573+
if (buffer->fcf_dsn.frametype == FC_BEACON_FRAME) {
574+
dev_driver_tx_buffer_s *tx_buf = &rf_ptr->dev_driver_tx_buffer;
575+
uint8_t *synch_info = tx_buf->buf + rf_ptr->dev_driver->phy_driver->phy_header_length + tx_buf->len - FHSS_SYNCH_INFO_LENGTH;
576+
rf_ptr->fhss_api->write_synch_info(rf_ptr->fhss_api, synch_info, FHSS_SYNCH_INFO_LENGTH, FHSS_SYNCH_FRAME, buffer->tx_time);
577+
} else {
578+
rf_ptr->fhss_api->write_synch_info(rf_ptr->fhss_api, ie_start, buffer->headerIeLength, FHSS_DATA_FRAME, buffer->tx_time);
579+
}
573580
}
574581
return ptr;
575582
}

source/MAC/IEEE802_15_4/mac_mlme.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,8 +1710,6 @@ int8_t mac_mlme_beacon_tx(protocol_interface_rf_mac_setup_s *rf_ptr)
17101710
}*/
17111711
}
17121712
buf->priority = MAC_PD_DATA_HIGH_PRIOTITY;
1713-
1714-
tr_debug("BEA tx");
17151713
mcps_sap_pd_req_queue_write(rf_ptr, buf);
17161714
sw_mac_stats_update(rf_ptr, STAT_MAC_BEA_TX_COUNT, 0);
17171715
return 0;

source/MAC/IEEE802_15_4/mac_pd_sap.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,6 @@ static int8_t mac_data_interface_tx_done_cb(protocol_interface_rf_mac_setup_s *r
400400
return -1;
401401
}
402402

403-
if (active_buf->fcf_dsn.frametype == FC_BEACON_FRAME) {
404-
// FHSS synchronization info is written in the end of transmitted (Beacon) buffer
405-
dev_driver_tx_buffer_s *tx_buf = &rf_ptr->dev_driver_tx_buffer;
406-
uint8_t *synch_info = tx_buf->buf + rf_ptr->dev_driver->phy_driver->phy_header_length + tx_buf->len - FHSS_SYNCH_INFO_LENGTH;
407-
rf_ptr->fhss_api->write_synch_info(rf_ptr->fhss_api, synch_info, 0, FHSS_SYNCH_FRAME, 0);
408-
}
409-
410403
// Change to destination channel and write synchronization info to Beacon frames here
411404
int tx_handle_retval = rf_ptr->fhss_api->tx_handle(rf_ptr->fhss_api, !mac_is_ack_request_set(active_buf),
412405
active_buf->DstAddr, mac_convert_frame_type_to_fhss(active_buf->fcf_dsn.frametype),

source/Service_Libs/fhss/fhss.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ static int8_t fhss_beacon_create_tasklet(fhss_structure_t *fhss_structure);
4545
static void fhss_beacon_tasklet_func(arm_event_s *event);
4646
static int fhss_beacon_periodic_start(fhss_structure_t *fhss_structure, uint32_t time_to_first_beacon);
4747
static void fhss_beacon_periodic_stop(fhss_structure_t *fhss_structure);
48+
static int fhss_reset_synch_monitor(fhss_synch_monitor_s *synch_monitor);
4849

4950
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)
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
}

source/Service_Libs/fhss/fhss_channel.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@
2727

2828
#define TRACE_GROUP "fhss"
2929

30-
// Enable this flag to use channel traces
31-
// #define FHSS_CHANNEL_DEBUG
30+
#ifdef FHSS_CHANNEL_DEBUG_CBS
31+
void (*fhss_uc_switch)(void) = NULL;
32+
void (*fhss_bc_switch)(void) = NULL;
33+
#endif /*FHSS_CHANNEL_DEBUG_CBS*/
34+
35+
#ifdef FHSS_CHANNEL_DEBUG
36+
uint8_t debug_destination_channel = 0;
37+
#endif /*FHSS_CHANNEL_DEBUG*/
3238

3339
static uint8_t fhss_get_bc_index(const fhss_structure_t *fhss_structure);
3440

@@ -138,13 +144,22 @@ bool fhss_change_to_next_channel(fhss_structure_t *fhss_structure)
138144
next_channel = channel_list_get_channel(fhss_structure->bs->fhss_configuration.channel_mask, channel_index_tmp);
139145

140146
fhss_structure->rx_channel = next_channel;
141-
#ifdef FHSS_CHANNEL_DEBUG
147+
142148
if (fhss_is_current_channel_broadcast(fhss_structure) == true) {
149+
#ifdef FHSS_CHANNEL_DEBUG
143150
tr_info("%"PRIu32" BC %u", fhss_structure->platform_functions.fhss_get_timestamp(fhss_structure->fhss_api), next_channel);
151+
#endif /*FHSS_CHANNEL_DEBUG*/
144152
} else {
153+
#ifdef FHSS_CHANNEL_DEBUG_CBS
154+
if (fhss_uc_switch) {
155+
fhss_uc_switch();
156+
}
157+
#endif /*FHSS_CHANNEL_DEBUG_CBS*/
158+
#ifdef FHSS_CHANNEL_DEBUG
145159
tr_info("%"PRIu32" UC %u", fhss_structure->platform_functions.fhss_get_timestamp(fhss_structure->fhss_api), next_channel);
146-
}
147160
#endif /*FHSS_CHANNEL_DEBUG*/
161+
}
162+
148163
fhss_structure->callbacks.change_channel(fhss_structure->fhss_api, next_channel);
149164
return broadcast_channel;
150165
}
@@ -231,7 +246,7 @@ int fhss_change_to_tx_channel(fhss_structure_t *fhss_structure, uint8_t *destina
231246
uint8_t destination_channel = fhss_get_destination_channel(fhss_structure, destination_address);
232247
fhss_structure->callbacks.change_channel(fhss_structure->fhss_api, destination_channel);
233248
#ifdef FHSS_CHANNEL_DEBUG
234-
tr_info("TX channel: %u", destination_channel);
249+
debug_destination_channel = destination_channel;
235250
#endif /*FHSS_CHANNEL_DEBUG*/
236251
}
237252
}

source/Service_Libs/fhss/fhss_channel.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,18 @@ int fhss_change_to_tx_channel(fhss_structure_t *fhss_structure, uint8_t *destina
2424
int fhss_change_to_parent_channel(fhss_structure_t *fhss_structure);
2525
int fhss_change_to_rx_channel(fhss_structure_t *fhss_structure);
2626

27+
28+
// Enable this flag to use channel traces
29+
// #define FHSS_CHANNEL_DEBUG
30+
// Enable this flag to use debug callbacks
31+
// #define FHSS_CHANNEL_DEBUG_CBS
32+
33+
#ifdef FHSS_CHANNEL_DEBUG
34+
extern uint8_t debug_destination_channel;
35+
#endif /*FHSS_CHANNEL_DEBUG*/
36+
#ifdef FHSS_CHANNEL_DEBUG_CBS
37+
extern void (*fhss_uc_switch)(void);
38+
extern void (*fhss_bc_switch)(void);
39+
#endif /*FHSS_CHANNEL_DEBUG_CBS*/
40+
2741
#endif /*FHSS_CHANNEL_H_*/

test/nanostack/unittest/service_libs/fhss/test_fhss.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ static fhss_api_t *test_generate_fhss_api(void)
135135
FHSS.callbacks.read_tx_queue_size = &mac_read_tx_queue_sizes;
136136
FHSS.callbacks.synch_lost_notification = &mac_synch_lost;
137137
FHSS.callbacks.broadcast_notify = &mac_broadcast_notification;
138+
FHSS.callbacks.read_timestamp = &mac_read_phy_timestamp;
138139
test_set_fhss_default_configs();
139140
test_set_platform_api(&FHSS.platform_functions);
140141
fhss_set_callbacks(&FHSS);
@@ -640,7 +641,7 @@ bool test_fhss_beacon_tasklet_func()
640641
uint8_t source_address[8] = {1, 2, 3, 4, 5, 6, 7, 8};
641642
uint8_t synch_info[FHSS_SYNCH_INFO_LENGTH] = {0, 0, 1, 0, 5, 0x86, 0xa0, 0x03, 0xe7, 1, 10, 2, 0, 0, 0, 0, 0, 0, 0xc3, 0x50, 8};
642643
nsdynmemlib_stub.returnCounter = 1;
643-
fhss_common_stub.uint32_value = DEFAULT_TIMESTAMP + (BEACON_INFO_LIFETIME * 1000000);
644+
fhss_callbacks_stub.uint32_value = DEFAULT_TIMESTAMP + (BEACON_INFO_LIFETIME * 1000000);
644645
FHSS.fhss_api->receive_frame(api, DEFAULT_PANID, source_address, DEFAULT_TIMESTAMP, synch_info, FHSS_SYNCH_FRAME);
645646
event.event_type = FHSS_UPDATE_SYNCH_INFO_STORAGE;
646647
event_stub.func_ptr(&event);

0 commit comments

Comments
 (0)