Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit baaec35

Browse files
author
Jarkko Paso
authored
Merge pull request ARMmbed#1644 from ARMmbed/ws_start_bc
Ws start bc
2 parents 97200b3 + 92acbd2 commit baaec35

File tree

5 files changed

+60
-8
lines changed

5 files changed

+60
-8
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,8 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
532532
cur->ws_info->hopping_schdule.fhss_bc_dwell_interval = ws_bs_ie.dwell_interval;
533533

534534
cur->ws_info->hopping_schdule.channel_function = ws_bs_ie.channel_function;
535-
// TODO: Restart unicast schedule if configuration changed, start broadcast schedule (FHSS)
536-
535+
// TODO: Restart unicast schedule if configuration changed
536+
ns_fhss_ws_set_parent(cur->ws_info->fhss_api, data->SrcAddr, &neighbor->fhss_data.bc_timing_info);
537537

538538
if (!cur->ws_info->configuration_learned) {
539539
// Generate own hopping schedules Follow first parent broadcast and plans and also use same unicast dwell

source/MAC/IEEE802_15_4/mac_mcps_sap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,7 @@ void mcps_sap_pd_req_queue_write(protocol_interface_rf_mac_setup_s *rf_mac_setup
15071507
if ((rf_mac_setup->macBroadcastDisabled == true) && !mac_is_ack_request_set(buffer)) {
15081508
goto push_to_queue;
15091509
}
1510-
if (rf_mac_setup->fhss_api) {
1510+
if (rf_mac_setup->fhss_api && (buffer->asynch_request == false)) {
15111511
if (rf_mac_setup->fhss_api->check_tx_conditions(rf_mac_setup->fhss_api, !mac_is_ack_request_set(buffer),
15121512
buffer->msduHandle, mac_convert_frame_type_to_fhss(buffer->fcf_dsn.frametype), buffer->mac_payload_length,
15131513
rf_mac_setup->dev_driver->phy_driver->phy_header_length, rf_mac_setup->dev_driver->phy_driver->phy_tail_length) == false) {

source/MAC/IEEE802_15_4/mac_pd_sap.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,9 @@ static int8_t mac_data_interface_tx_done_cb(protocol_interface_rf_mac_setup_s *r
340340
if (rf_ptr->mac_tx_result == MAC_TX_DONE) {
341341
tx_is_done = true;
342342
}
343-
rf_ptr->fhss_api->data_tx_done(rf_ptr->fhss_api, waiting_ack, tx_is_done, rf_ptr->active_pd_data_request->msduHandle);
343+
if (rf_ptr->active_pd_data_request->asynch_request == false) {
344+
rf_ptr->fhss_api->data_tx_done(rf_ptr->fhss_api, waiting_ack, tx_is_done, rf_ptr->active_pd_data_request->msduHandle);
345+
}
344346
}
345347
return 0;
346348
}

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#define IE_HEADER_ID_MASK 0x7f80
3939
#define WH_IE_ID 0x2a
4040
#define WH_SUB_ID_UTT 1
41+
#define WH_SUB_ID_BT 2
4142

4243
struct ws_ie_t {
4344
uint8_t *content_ptr;
@@ -106,10 +107,13 @@ static void fhss_broadcast_handler(const fhss_api_t *fhss_api, uint16_t delay)
106107
if (!fhss_structure) {
107108
return;
108109
}
110+
// TODO: check parent broadcast timing constantly and calculate drift error
109111
if (fhss_structure->ws->is_on_bc_channel == false) {
110112
fhss_start_timer(fhss_structure, fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval*1000, fhss_broadcast_handler);
111113
fhss_structure->ws->is_on_bc_channel = true;
112114
next_channel = fhss_ws_calc_bc_channel(fhss_structure);
115+
// TODO: Randomize polling TX queue when on broadcast channel
116+
fhss_structure->callbacks.tx_poll(fhss_structure->fhss_api);
113117
} else {
114118
uint32_t timeout = (fhss_structure->ws->fhss_configuration.fhss_broadcast_interval - fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval) * 1000;
115119
fhss_start_timer(fhss_structure, timeout, fhss_broadcast_handler);
@@ -156,6 +160,19 @@ static uint32_t fhss_ws_calculate_ufsi(fhss_structure_t *fhss_structure, uint32_
156160
return own_floor((float)(ms_since_seq_start * DEF_2E24) / (seq_length*dwell_time));
157161
}
158162

163+
static uint32_t fhss_ws_calculate_broadcast_interval_offset(fhss_structure_t *fhss_structure, uint32_t tx_time)
164+
{
165+
uint8_t dwell_time = fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval;
166+
uint32_t broadcast_interval = fhss_structure->ws->fhss_configuration.fhss_broadcast_interval;
167+
168+
uint32_t remaining_time = (fhss_structure->platform_functions.fhss_get_remaining_slots(fhss_broadcast_handler, fhss_structure->fhss_api) / 1000);
169+
if (fhss_structure->ws->is_on_bc_channel == true) {
170+
remaining_time += (broadcast_interval - dwell_time);
171+
}
172+
uint32_t time_to_tx = (tx_time - fhss_structure->fhss_api->read_timestamp(fhss_structure->fhss_api)) / 1000;
173+
return (broadcast_interval-remaining_time) + time_to_tx;
174+
}
175+
159176
static uint16_t fhss_ws_calculate_destination_slot(fhss_ws_neighbor_timing_info_t *neighbor_timing_info, uint32_t tx_time)
160177
{
161178
uint_fast24_t ufsi = neighbor_timing_info->uc_timing_info.ufsi;
@@ -238,7 +255,7 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a
238255
if (!fhss_structure) {
239256
return -1;
240257
}
241-
if (is_broadcast_addr) {
258+
if (is_broadcast_addr || (fhss_structure->ws->is_on_bc_channel == true)) {
242259
return 0;
243260
}
244261
if (fhss_structure->fhss_state == FHSS_SYNCHRONIZED) {
@@ -274,13 +291,22 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a
274291

275292
static bool fhss_ws_check_tx_conditions_callback(const fhss_api_t *api, bool is_broadcast_addr, uint8_t handle, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length)
276293
{
277-
(void) api;
278-
(void) is_broadcast_addr;
279294
(void) handle;
280295
(void) frame_type;
281296
(void) frame_length;
282297
(void) phy_header_length;
283298
(void) phy_tail_length;
299+
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
300+
if (!fhss_structure) {
301+
return true;
302+
}
303+
if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_FIXED_CHANNEL) {
304+
return true;
305+
}
306+
// Do not allow broadcast destination on unicast channel
307+
if (is_broadcast_addr && (fhss_structure->ws->is_on_bc_channel == false)) {
308+
return false;
309+
}
284310
return true;
285311
}
286312

@@ -320,6 +346,11 @@ static int16_t fhss_ws_write_synch_info_callback(const fhss_api_t *api, uint8_t
320346
uint32_t ufsi = fhss_ws_calculate_ufsi(fhss_structure, tx_time);
321347
common_write_24_bit_inverse(ufsi, header_ie.content_ptr+1);
322348
}
349+
if (fhss_ws_ie_header_discover(ptr, length, &header_ie, WH_SUB_ID_BT)) {
350+
uint32_t broadcast_interval_offset = fhss_ws_calculate_broadcast_interval_offset(fhss_structure, tx_time);
351+
common_write_16_bit_inverse(fhss_structure->ws->bc_slot, header_ie.content_ptr);
352+
common_write_24_bit_inverse(broadcast_interval_offset, header_ie.content_ptr+2);
353+
}
323354
return 0;
324355
}
325356

@@ -402,6 +433,16 @@ int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8],
402433
if (!fhss_structure->ws) {
403434
return -1;
404435
}
436+
if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_FIXED_CHANNEL) {
437+
return 0;
438+
}
439+
// Start broadcast schedule when BC intervals are known
440+
if (bc_timing_info->broadcast_interval && bc_timing_info->broadcast_dwell_interval) {
441+
fhss_start_timer(fhss_structure, (bc_timing_info->broadcast_interval-bc_timing_info->broadcast_interval_offset)*1000, fhss_broadcast_handler);
442+
fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval = bc_timing_info->broadcast_dwell_interval;
443+
fhss_structure->ws->fhss_configuration.fhss_broadcast_interval = bc_timing_info->broadcast_interval;
444+
fhss_structure->ws->bc_slot = bc_timing_info->broadcast_slot;
445+
}
405446
//TODO: support multiple parents
406447
fhss_structure->ws->parent_bc_info = bc_timing_info;
407448
return 0;

test/nanostack/unittest/service_libs/fhss_ws/test_fhss_ws.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ uint16_t common_read_16_bit_inverse(const uint8_t data_buf[__static 2])
5757
return temp_16;
5858
}
5959

60+
uint8_t *common_write_16_bit_inverse(uint16_t value, uint8_t ptr[__static 2])
61+
{
62+
*ptr++ = value;
63+
*ptr++ = value >> 8;
64+
return ptr;
65+
}
66+
6067
uint8_t *common_write_24_bit_inverse(uint_fast24_t value, uint8_t ptr[__static 3])
6168
{
6269
*ptr++ = value;
@@ -134,6 +141,7 @@ static fhss_api_t *test_generate_fhss_api(void)
134141
fhss_common_stub.fhss_struct.ws->is_on_bc_channel = false;
135142
fhss_common_stub.fhss_struct.callbacks.change_channel = &mac_set_channel;
136143
fhss_common_stub.fhss_struct.callbacks.read_mac_address = &mac_read_64bit_mac_address;
144+
fhss_common_stub.fhss_struct.callbacks.tx_poll = &mac_poll_tx_queue;
137145
test_set_platform_api(&fhss_common_stub.fhss_struct.platform_functions);
138146
fhss_ws_set_callbacks(&fhss_common_stub.fhss_struct);
139147
return &fhss_api;
@@ -352,7 +360,7 @@ bool test_fhss_ws_write_synch_info_callback()
352360
{
353361
fhss_api_t *api = test_generate_fhss_api();
354362
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_channel_function = WS_TR51CF;
355-
uint8_t synch_info[16] = {0x05, 0x15, 0x02, 0x00, 0x00, 0x00, 0x00, 0x05, 0x15, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x3f};
363+
uint8_t synch_info[100] = {0x05, 0x15, 0x02, 0x00, 0x00, 0x00, 0x00, 0x05, 0x15, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x3f};
356364
// Test when FHSS struct not found
357365
disable_fhss_struct();
358366
if (fhss_common_stub.fhss_struct.fhss_api->write_synch_info(api, synch_info, sizeof(synch_info), DEFAULT_FRAME_TYPE, DEFAULT_TX_TIME) != -1) {
@@ -517,6 +525,7 @@ bool test_fhss_ws_set_parent()
517525
broadcast_timing_info_t bc_timing_info;
518526
memset(&bc_timing_info, 0, sizeof(broadcast_timing_info_t));
519527
fhss_api_t *api = test_generate_fhss_api();
528+
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_channel_function = WS_TR51CF;
520529

521530
// Test without WS enabled FHSS
522531
fhss_structure_t fake_fhss_structure;

0 commit comments

Comments
 (0)