Skip to content

Commit ac58048

Browse files
author
Jarkko Paso
committed
FHSS: WS FHSS to use pre-set TX time
1 parent feeee0f commit ac58048

File tree

6 files changed

+33
-26
lines changed

6 files changed

+33
-26
lines changed

nanostack/platform/arm_hal_phy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ typedef enum {
5656
PHY_EXTENSION_READ_LINK_STATUS, /**< Net library could read link status. */
5757
PHY_EXTENSION_CONVERT_SIGNAL_INFO, /**< Convert signal info. */
5858
PHY_EXTENSION_ACCEPT_ANY_BEACON, /**< Set boolean true or false for accept beacon from other Pan-ID than configured. Default value should be false */
59-
PHY_EXTENSION_SET_TX_TIME, /**< Net library sets transmission time based on global time stamp. Max. 65ms from setting to TX */
59+
PHY_EXTENSION_SET_TX_TIME, /**< Net library sets transmission time based on global time stamp. Max. 65ms from setting to TX. If TX time is set to zero, it should be ignored.*/
6060
PHY_EXTENSION_READ_RX_TIME, /**< Read the time of last reception based on global time stamp. */
6161
} phy_extension_type_e;
6262

source/MAC/IEEE802_15_4/mac_header_helper_functions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ uint8_t * mac_generic_packet_write(struct protocol_interface_rf_mac_setup *rf_pt
516516
ptr += buffer->mac_payload_length;
517517
}
518518
if (rf_ptr->fhss_api) {
519-
rf_ptr->fhss_api->write_synch_info(rf_ptr->fhss_api, ie_start, buffer->headerIeLength, FHSS_DATA_FRAME, 0);
519+
rf_ptr->fhss_api->write_synch_info(rf_ptr->fhss_api, ie_start, buffer->headerIeLength, FHSS_DATA_FRAME, buffer->tx_time);
520520
}
521521
return ptr;
522522
}

source/MAC/IEEE802_15_4/mac_mcps_sap.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151

5252
#define TRACE_GROUP "mMCp"
5353

54+
// Used to set TX time (us) with FHSS. Must be <= 65ms.
55+
#define MAC_TX_PROCESSING_DELAY_INITIAL 2000
56+
5457
typedef struct {
5558
uint8_t address[8];
5659
unsigned addr_type:2;
@@ -1362,6 +1365,17 @@ static void mac_security_authentication_data_params_set(ccm_globals_t *ccm_ptr,
13621365
}
13631366
}
13641367

1368+
static uint32_t mcps_calculate_tx_time(protocol_interface_rf_mac_setup_s *rf_mac_setup, uint16_t time_to_tx)
1369+
{
1370+
if (!rf_mac_setup->fhss_api) {
1371+
return 0;
1372+
}
1373+
// Max. time to TX is 65ms
1374+
if (time_to_tx > 65000) {
1375+
time_to_tx = 65000;
1376+
}
1377+
return rf_mac_setup->fhss_api->read_timestamp(rf_mac_setup->fhss_api) + time_to_tx;
1378+
}
13651379

13661380
static int8_t mcps_generic_packet_build(protocol_interface_rf_mac_setup_s *rf_ptr, mac_pre_build_frame_t *buffer) {
13671381
phy_device_driver_s *dev_driver = rf_ptr->dev_driver->phy_driver;
@@ -1435,6 +1449,7 @@ static int8_t mcps_generic_packet_build(protocol_interface_rf_mac_setup_s *rf_pt
14351449
tx_buf->len = frame_length;
14361450

14371451
uint8_t *mhr_start = ptr;
1452+
buffer->tx_time = mcps_calculate_tx_time(rf_ptr, MAC_TX_PROCESSING_DELAY_INITIAL);
14381453
ptr = mac_generic_packet_write(rf_ptr, ptr, buffer);
14391454

14401455
if (buffer->fcf_dsn.securityEnabled) {

source/MAC/IEEE802_15_4/mac_mcps_sap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ typedef struct mac_pre_build_frame{
125125
uint8_t *mac_payload;
126126
uint8_t status;
127127
uint8_t asynch_channel;
128+
uint32_t tx_time;
128129
bool upper_layer_request;
129130
bool mac_allocated_payload_ptr:1;
130131
bool asynch_request:1;

source/MAC/IEEE802_15_4/mac_pd_sap.c

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -163,28 +163,19 @@ int8_t mac_pd_sap_req(protocol_interface_rf_mac_setup_s *rf_mac_setup)
163163
/**
164164
* Set PHY TX time.
165165
*
166-
* \param rf_mac_setup pointer to MAC
167-
* \param time_to_tx Time from present time to wanted TX time (us)
168-
* \return 0 if success, -1 when FHSS not registered
166+
* \param rf_mac_setup pointer to MAC.
167+
* \param tx_time TX timestamp to be set.
169168
*
170169
*/
171-
static int mac_pd_sap_set_tx_time(protocol_interface_rf_mac_setup_s *rf_mac_setup, uint16_t time_to_tx)
170+
static void mac_pd_sap_set_phy_tx_time(protocol_interface_rf_mac_setup_s *rf_mac_setup, uint32_t tx_time)
172171
{
173-
if (rf_mac_setup->fhss_api) {
174-
// Max. TX time is 65ms
175-
if (time_to_tx > 65000) {
176-
time_to_tx = 65000;
177-
}
178-
uint8_t tx_time_buffer[4];
179-
uint32_t tx_time = rf_mac_setup->fhss_api->read_timestamp(rf_mac_setup->fhss_api) + time_to_tx;
180-
if (!tx_time) {
181-
tx_time++;
182-
}
183-
common_write_32_bit(tx_time, tx_time_buffer);
184-
rf_mac_setup->dev_driver->phy_driver->extension(PHY_EXTENSION_SET_TX_TIME, tx_time_buffer);
185-
return 0;
172+
// With TX time set to zero, PHY sends immediately
173+
if (!tx_time) {
174+
tx_time++;
186175
}
187-
return -1;
176+
uint8_t tx_time_buffer[4];
177+
common_write_32_bit(tx_time, tx_time_buffer);
178+
rf_mac_setup->dev_driver->phy_driver->extension(PHY_EXTENSION_SET_TX_TIME, tx_time_buffer);
188179
}
189180

190181
/**
@@ -194,7 +185,7 @@ static int mac_pd_sap_set_tx_time(protocol_interface_rf_mac_setup_s *rf_mac_setu
194185
* \return Timestamp of last PHY reception
195186
*
196187
*/
197-
static uint32_t mac_pd_sap_get_rx_time(protocol_interface_rf_mac_setup_s *rf_mac_setup)
188+
static uint32_t mac_pd_sap_get_phy_rx_time(protocol_interface_rf_mac_setup_s *rf_mac_setup)
198189
{
199190
uint8_t rx_time_buffer[4];
200191
rf_mac_setup->dev_driver->phy_driver->extension(PHY_EXTENSION_READ_RX_TIME, rx_time_buffer);
@@ -216,6 +207,7 @@ void mac_pd_sap_state_machine(protocol_interface_rf_mac_setup_s *rf_mac_setup)
216207
if (!active_buf) {
217208
return;
218209
}
210+
mac_pd_sap_set_phy_tx_time(rf_mac_setup, active_buf->tx_time);
219211
if (active_buf->fcf_dsn.frametype == FC_BEACON_FRAME) {
220212
// FHSS synchronization info is written in the end of transmitted (Beacon) buffer
221213
dev_driver_tx_buffer_s *tx_buf = &rf_mac_setup->dev_driver_tx_buffer;

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
// Enable this flag to use channel traces
3535
#define FHSS_CHANNEL_DEBUG
3636

37-
#define DEF_2E16 16777216
37+
#define DEF_2E24 0x1000000
3838
#define IE_HEADER_LENGTH_MASK 0x007f
3939
#define IE_HEADER_ID_MASK 0x7f80
4040
#define WH_IE_ID 0x2a
@@ -148,14 +148,13 @@ static uint32_t fhss_ws_calculate_ufsi(fhss_structure_t *fhss_structure, uint32_
148148
cur_slot--;
149149
uint32_t remaining_time = (fhss_structure->platform_functions.fhss_get_remaining_slots(fhss_unicast_handler, fhss_structure->fhss_api) / 1000);
150150
uint32_t time_to_tx = (tx_time - fhss_structure->fhss_api->read_timestamp(fhss_structure->fhss_api)) / 1000;
151-
uint32_t ms_since_seq_start = (cur_slot * dwell_time) + (dwell_time-remaining_time) + time_to_tx;
151+
uint64_t ms_since_seq_start = (cur_slot * dwell_time) + (dwell_time-remaining_time) + time_to_tx;
152152
ms_since_seq_start %= (dwell_time*fhss_structure->number_of_channels);
153153
uint32_t seq_length = 0x10000;
154154
if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_TR51CF) {
155155
seq_length = fhss_structure->number_of_channels;
156156
}
157-
158-
return own_floor((float)(ms_since_seq_start * DEF_2E16) / (seq_length*dwell_time));
157+
return own_floor((float)(ms_since_seq_start * DEF_2E24) / (seq_length*dwell_time));
159158
}
160159

161160
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)
@@ -164,7 +163,7 @@ static uint16_t fhss_ws_calculate_destination_slot(fhss_structure_t *fhss_struct
164163
if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_TR51CF) {
165164
seq_length = fhss_structure->number_of_channels;
166165
}
167-
uint32_t dest_ms_since_seq_start = own_ceil((float)(ufsi*seq_length*dwell_time) / DEF_2E16);
166+
uint32_t dest_ms_since_seq_start = own_ceil((float)(ufsi*seq_length*dwell_time) / DEF_2E24);
168167
return (own_floor(((float)((tx_time - ufsi_timestamp)/1000 + dest_ms_since_seq_start) / dwell_time)) % seq_length);
169168
}
170169

0 commit comments

Comments
 (0)