Skip to content

Commit 75d93f8

Browse files
author
Jarkko Paso
authored
Merge pull request ARMmbed#1564 from ARMmbed/IOTTHD-2213
FHSS: Calculate destination slot and ufsi
2 parents 15d4465 + c718985 commit 75d93f8

File tree

8 files changed

+62
-14
lines changed

8 files changed

+62
-14
lines changed

nanostack/fhss_api.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,14 @@ typedef bool fhss_use_broadcast_queue(const fhss_api_t *api, bool is_broadcast_a
8686
* @param frame_length MSDU length of the frame.
8787
* @param phy_header_length PHY header length.
8888
* @param phy_tail_length PHY tail length.
89+
* @param tx_time TX time.
8990
* @return 0 Success.
9091
* @return -1 Transmission of the packet is currently not allowed, try again.
9192
* @return -2 Invalid api.
9293
* @return -3 Broadcast packet on Unicast channel (not allowed), push packet back to queue.
9394
* @return -4 Synchronization info missing.
9495
*/
95-
typedef int fhss_tx_handle(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length);
96+
typedef int fhss_tx_handle(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length, uint32_t tx_time);
9697

9798
/**
9899
* @brief Check TX permission.

source/MAC/IEEE802_15_4/mac_pd_sap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ void mac_pd_sap_state_machine(protocol_interface_rf_mac_setup_s *rf_mac_setup)
227227
int tx_handle_retval = rf_mac_setup->fhss_api->tx_handle(rf_mac_setup->fhss_api, !mac_is_ack_request_set(active_buf),
228228
active_buf->DstAddr, mac_convert_frame_type_to_fhss(active_buf->fcf_dsn.frametype),
229229
active_buf->mac_payload_length, rf_mac_setup->dev_driver->phy_driver->phy_header_length,
230-
rf_mac_setup->dev_driver->phy_driver->phy_tail_length);
230+
rf_mac_setup->dev_driver->phy_driver->phy_tail_length, 0);
231231
// When FHSS TX handle returns -1, transmission of the packet is currently not allowed -> restart CCA timer
232232
if (tx_handle_retval == -1) {
233233
timer_mac_start(rf_mac_setup, MAC_TIMER_CCA, randLIB_get_random_in_range(20, 400) + 1);

source/Service_Libs/fhss/fhss.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,8 +841,9 @@ static void fhss_superframe_callback(fhss_structure_t *fhss_structure)
841841
}
842842
}
843843

844-
static int fhss_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length)
844+
static int fhss_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length, uint32_t tx_time)
845845
{
846+
(void) tx_time;
846847
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
847848
if (!fhss_structure) {
848849
return -2;

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
// Enable this flag to use channel traces
3434
#define FHSS_CHANNEL_DEBUG
3535

36+
#define DEF_2E16 16777216
37+
3638
static void fhss_ws_update_uc_channel_callback(fhss_structure_t *fhss_structure);
3739

3840
fhss_structure_t *fhss_ws_enable(fhss_api_t *fhss_api, const fhss_ws_configuration_t *fhss_configuration, const fhss_timer_t *fhss_timer)
@@ -102,6 +104,50 @@ static void fhss_broadcast_handler(const fhss_api_t *fhss_api, uint16_t delay)
102104
}
103105
}
104106

107+
static int own_floor(float value)
108+
{
109+
return (int)value;
110+
}
111+
112+
static int own_ceil(float value)
113+
{
114+
int ivalue = (int)value;
115+
if (value == (float)ivalue) {
116+
return ivalue;
117+
}
118+
return ivalue + 1;
119+
}
120+
121+
static uint32_t fhss_ws_calculate_ufsi(fhss_structure_t *fhss_structure, uint32_t tx_time)
122+
{
123+
uint8_t dwell_time = fhss_structure->fhss_conf.fhss_ws_configuration.fhss_uc_dwell_interval;
124+
uint16_t cur_slot = fhss_structure->ws->uc_slot;
125+
if (cur_slot == 0) {
126+
cur_slot = fhss_structure->number_of_channels;
127+
}
128+
cur_slot--;
129+
uint32_t remaining_time = (fhss_structure->platform_functions.fhss_get_remaining_slots(fhss_superframe_handler, fhss_structure->fhss_api) / 1000);
130+
uint32_t time_to_tx = (tx_time - fhss_structure->fhss_api->read_timestamp(fhss_structure->fhss_api)) / 1000;
131+
uint32_t ms_since_seq_start = (cur_slot * dwell_time) + (dwell_time-remaining_time) + time_to_tx;
132+
ms_since_seq_start %= (dwell_time*fhss_structure->number_of_channels);
133+
uint32_t seq_length = 0x10000;
134+
if (fhss_structure->ws->channel_function == WS_TR51CF) {
135+
seq_length = fhss_structure->number_of_channels;
136+
}
137+
138+
return own_floor((float)(ms_since_seq_start * DEF_2E16) / (seq_length*dwell_time));
139+
}
140+
141+
static uint16_t fhss_ws_calculate_destination_slot(fhss_structure_t *fhss_structure, uint32_t ufsi, uint32_t ufsi_timestamp, uint8_t dwell_time, uint32_t tx_time)
142+
{
143+
uint32_t seq_length = 0x10000;
144+
if (fhss_structure->ws->channel_function == WS_TR51CF) {
145+
seq_length = fhss_structure->number_of_channels;
146+
}
147+
uint32_t dest_ms_since_seq_start = own_ceil((float)(ufsi*seq_length*dwell_time) / DEF_2E16);
148+
return (own_floor(((float)((tx_time - ufsi_timestamp)/1000 + dest_ms_since_seq_start) / dwell_time)) % seq_length);
149+
}
150+
105151
static uint32_t fhss_ws_get_sf_timeout_callback(fhss_structure_t *fhss_structure)
106152
{
107153
return fhss_structure->fhss_conf.fhss_ws_configuration.fhss_uc_dwell_interval * 1000;
@@ -159,7 +205,7 @@ static void fhss_ws_update_uc_channel_callback(fhss_structure_t *fhss_structure)
159205
fhss_structure->callbacks.change_channel(fhss_structure->fhss_api, next_channel);
160206
}
161207

162-
static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length)
208+
static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length, uint32_t tx_time)
163209
{
164210
(void) is_broadcast_addr;
165211
(void) frame_type;
@@ -172,8 +218,8 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a
172218
}
173219
if (fhss_structure->fhss_state == FHSS_SYNCHRONIZED) {
174220
int32_t tx_channel;
175-
//TODO: Compute destination slot using neighbour table
176-
uint16_t destination_slot = fhss_structure->ws->uc_slot;
221+
//TODO: Get destination UFSI, timestamp and dwell time from neighbour table
222+
uint16_t destination_slot = fhss_ws_calculate_destination_slot(fhss_structure, 0, 0, fhss_structure->fhss_conf.fhss_ws_configuration.fhss_uc_dwell_interval, tx_time);
177223
if (fhss_structure->ws->channel_function == WS_TR51CF) {
178224
tx_channel = tr51_get_uc_channel_index(destination_slot, destination_address, fhss_structure->number_of_channels);
179225
} else if(fhss_structure->ws->channel_function == WS_DH1CF) {

test/nanostack/unittest/mac/mac_mcps_sap/test_mac_mcps_sap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ static protocol_interface_rf_mac_setup_s * test_mac_rf_mac_class_allocate(void)
261261
return rf_mac_setup;
262262
}
263263

264-
static int fhss_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length)
264+
static int fhss_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length, uint32_t tx_time)
265265
{
266266
return 0;
267267
}

test/nanostack/unittest/mac/mac_pd_sap/test_mac_pd_sap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static int8_t test_rf_virtual_tx(const virtual_data_req_t *data_req,int8_t drive
5151
return 0;
5252
}
5353

54-
static int fhss_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length)
54+
static int fhss_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length, uint32_t tx_time)
5555
{
5656
return 0;
5757
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -729,27 +729,27 @@ bool test_fhss_tx_handle_callback()
729729
fhss_struct->synch_configuration.fhss_number_of_tx_slots = 1;
730730
fhss_set_callbacks(fhss_struct);
731731
// Broadcast data on unicast channel should return -3
732-
if (fhss_struct->fhss_api->tx_handle(&fhss_api, true, NULL, FHSS_DATA_FRAME, 0, 0, 0) != -3) {
732+
if (fhss_struct->fhss_api->tx_handle(&fhss_api, true, NULL, FHSS_DATA_FRAME, 0, 0, 0, 0) != -3) {
733733
return false;
734734
}
735735
// Test sending of Beacon
736-
if (fhss_struct->fhss_api->tx_handle(&fhss_api, true, NULL, FHSS_SYNCH_FRAME, 0, 0, 0) != 0) {
736+
if (fhss_struct->fhss_api->tx_handle(&fhss_api, true, NULL, FHSS_SYNCH_FRAME, 0, 0, 0, 0) != 0) {
737737
return false;
738738
}
739739
// When TX is not allowed, should return -1 for data frame
740740
fhss_struct->tx_allowed = false;
741741
fhss_struct->fhss_state = FHSS_SYNCHRONIZED;
742-
if (fhss_struct->fhss_api->tx_handle(&fhss_api, false, NULL, FHSS_DATA_FRAME, 0, 0, 0) != -1) {
742+
if (fhss_struct->fhss_api->tx_handle(&fhss_api, false, NULL, FHSS_DATA_FRAME, 0, 0, 0, 0) != -1) {
743743
return false;
744744
}
745745
// When TX is allowed, should return 0 for data frame
746746
fhss_struct->tx_allowed = true;
747747
fhss_struct->fhss_state = FHSS_UNSYNCHRONIZED;
748-
if (fhss_struct->fhss_api->tx_handle(&fhss_api, false, NULL, FHSS_DATA_FRAME, 0, 0, 0) != 0) {
748+
if (fhss_struct->fhss_api->tx_handle(&fhss_api, false, NULL, FHSS_DATA_FRAME, 0, 0, 0, 0) != 0) {
749749
return false;
750750
}
751751
// Test changing to parent channel to send synch request
752-
if (fhss_struct->fhss_api->tx_handle(&fhss_api, false, NULL, FHSS_SYNCH_REQUEST_FRAME, 0, 0, 0) != 0) {
752+
if (fhss_struct->fhss_api->tx_handle(&fhss_api, false, NULL, FHSS_SYNCH_REQUEST_FRAME, 0, 0, 0, 0) != 0) {
753753
return false;
754754
}
755755
free(fhss_struct);

test/nanostack/unittest/stub/fhss_mac_interface_stub.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extern fhss_mac_interface_stub_def fhss_mac_interface_stub;
3434

3535
bool fhss_is_broadcast_channel_cb(const fhss_api_t *api);
3636
bool fhss_use_broadcast_queue_cb(const fhss_api_t *api, bool is_broadcast_addr, int frame_type);
37-
int fhss_tx_handle_cb(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length);
37+
int fhss_tx_handle_cb(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length, uint32_t tx_time);
3838
bool fhss_check_tx_conditions_cb(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);
3939
void fhss_receive_frame_cb(const fhss_api_t *api, uint16_t pan_id, uint8_t *source_address, uint32_t timestamp, uint8_t *synch_info, int frame_type);
4040
void fhss_data_tx_done_cb(const fhss_api_t *api, bool waiting_ack, bool tx_completed, uint8_t handle);

0 commit comments

Comments
 (0)