Skip to content

Commit

Permalink
FHSS: WS FHSS to use pre-set TX time
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso committed Feb 26, 2018
1 parent feeee0f commit ac58048
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 26 deletions.
2 changes: 1 addition & 1 deletion nanostack/platform/arm_hal_phy.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ typedef enum {
PHY_EXTENSION_READ_LINK_STATUS, /**< Net library could read link status. */
PHY_EXTENSION_CONVERT_SIGNAL_INFO, /**< Convert signal info. */
PHY_EXTENSION_ACCEPT_ANY_BEACON, /**< Set boolean true or false for accept beacon from other Pan-ID than configured. Default value should be false */
PHY_EXTENSION_SET_TX_TIME, /**< Net library sets transmission time based on global time stamp. Max. 65ms from setting to TX */
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.*/
PHY_EXTENSION_READ_RX_TIME, /**< Read the time of last reception based on global time stamp. */
} phy_extension_type_e;

Expand Down
2 changes: 1 addition & 1 deletion source/MAC/IEEE802_15_4/mac_header_helper_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ uint8_t * mac_generic_packet_write(struct protocol_interface_rf_mac_setup *rf_pt
ptr += buffer->mac_payload_length;
}
if (rf_ptr->fhss_api) {
rf_ptr->fhss_api->write_synch_info(rf_ptr->fhss_api, ie_start, buffer->headerIeLength, FHSS_DATA_FRAME, 0);
rf_ptr->fhss_api->write_synch_info(rf_ptr->fhss_api, ie_start, buffer->headerIeLength, FHSS_DATA_FRAME, buffer->tx_time);
}
return ptr;
}
Expand Down
15 changes: 15 additions & 0 deletions source/MAC/IEEE802_15_4/mac_mcps_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@

#define TRACE_GROUP "mMCp"

// Used to set TX time (us) with FHSS. Must be <= 65ms.
#define MAC_TX_PROCESSING_DELAY_INITIAL 2000

typedef struct {
uint8_t address[8];
unsigned addr_type:2;
Expand Down Expand Up @@ -1362,6 +1365,17 @@ static void mac_security_authentication_data_params_set(ccm_globals_t *ccm_ptr,
}
}

static uint32_t mcps_calculate_tx_time(protocol_interface_rf_mac_setup_s *rf_mac_setup, uint16_t time_to_tx)
{
if (!rf_mac_setup->fhss_api) {
return 0;
}
// Max. time to TX is 65ms
if (time_to_tx > 65000) {
time_to_tx = 65000;
}
return rf_mac_setup->fhss_api->read_timestamp(rf_mac_setup->fhss_api) + time_to_tx;
}

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

uint8_t *mhr_start = ptr;
buffer->tx_time = mcps_calculate_tx_time(rf_ptr, MAC_TX_PROCESSING_DELAY_INITIAL);
ptr = mac_generic_packet_write(rf_ptr, ptr, buffer);

if (buffer->fcf_dsn.securityEnabled) {
Expand Down
1 change: 1 addition & 0 deletions source/MAC/IEEE802_15_4/mac_mcps_sap.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ typedef struct mac_pre_build_frame{
uint8_t *mac_payload;
uint8_t status;
uint8_t asynch_channel;
uint32_t tx_time;
bool upper_layer_request;
bool mac_allocated_payload_ptr:1;
bool asynch_request:1;
Expand Down
30 changes: 11 additions & 19 deletions source/MAC/IEEE802_15_4/mac_pd_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,28 +163,19 @@ int8_t mac_pd_sap_req(protocol_interface_rf_mac_setup_s *rf_mac_setup)
/**
* Set PHY TX time.
*
* \param rf_mac_setup pointer to MAC
* \param time_to_tx Time from present time to wanted TX time (us)
* \return 0 if success, -1 when FHSS not registered
* \param rf_mac_setup pointer to MAC.
* \param tx_time TX timestamp to be set.
*
*/
static int mac_pd_sap_set_tx_time(protocol_interface_rf_mac_setup_s *rf_mac_setup, uint16_t time_to_tx)
static void mac_pd_sap_set_phy_tx_time(protocol_interface_rf_mac_setup_s *rf_mac_setup, uint32_t tx_time)
{
if (rf_mac_setup->fhss_api) {
// Max. TX time is 65ms
if (time_to_tx > 65000) {
time_to_tx = 65000;
}
uint8_t tx_time_buffer[4];
uint32_t tx_time = rf_mac_setup->fhss_api->read_timestamp(rf_mac_setup->fhss_api) + time_to_tx;
if (!tx_time) {
tx_time++;
}
common_write_32_bit(tx_time, tx_time_buffer);
rf_mac_setup->dev_driver->phy_driver->extension(PHY_EXTENSION_SET_TX_TIME, tx_time_buffer);
return 0;
// With TX time set to zero, PHY sends immediately
if (!tx_time) {
tx_time++;
}
return -1;
uint8_t tx_time_buffer[4];
common_write_32_bit(tx_time, tx_time_buffer);
rf_mac_setup->dev_driver->phy_driver->extension(PHY_EXTENSION_SET_TX_TIME, tx_time_buffer);
}

/**
Expand All @@ -194,7 +185,7 @@ static int mac_pd_sap_set_tx_time(protocol_interface_rf_mac_setup_s *rf_mac_setu
* \return Timestamp of last PHY reception
*
*/
static uint32_t mac_pd_sap_get_rx_time(protocol_interface_rf_mac_setup_s *rf_mac_setup)
static uint32_t mac_pd_sap_get_phy_rx_time(protocol_interface_rf_mac_setup_s *rf_mac_setup)
{
uint8_t rx_time_buffer[4];
rf_mac_setup->dev_driver->phy_driver->extension(PHY_EXTENSION_READ_RX_TIME, rx_time_buffer);
Expand All @@ -216,6 +207,7 @@ void mac_pd_sap_state_machine(protocol_interface_rf_mac_setup_s *rf_mac_setup)
if (!active_buf) {
return;
}
mac_pd_sap_set_phy_tx_time(rf_mac_setup, active_buf->tx_time);
if (active_buf->fcf_dsn.frametype == FC_BEACON_FRAME) {
// FHSS synchronization info is written in the end of transmitted (Beacon) buffer
dev_driver_tx_buffer_s *tx_buf = &rf_mac_setup->dev_driver_tx_buffer;
Expand Down
9 changes: 4 additions & 5 deletions source/Service_Libs/fhss/fhss_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
// Enable this flag to use channel traces
#define FHSS_CHANNEL_DEBUG

#define DEF_2E16 16777216
#define DEF_2E24 0x1000000
#define IE_HEADER_LENGTH_MASK 0x007f
#define IE_HEADER_ID_MASK 0x7f80
#define WH_IE_ID 0x2a
Expand Down Expand Up @@ -148,14 +148,13 @@ static uint32_t fhss_ws_calculate_ufsi(fhss_structure_t *fhss_structure, uint32_
cur_slot--;
uint32_t remaining_time = (fhss_structure->platform_functions.fhss_get_remaining_slots(fhss_unicast_handler, fhss_structure->fhss_api) / 1000);
uint32_t time_to_tx = (tx_time - fhss_structure->fhss_api->read_timestamp(fhss_structure->fhss_api)) / 1000;
uint32_t ms_since_seq_start = (cur_slot * dwell_time) + (dwell_time-remaining_time) + time_to_tx;
uint64_t ms_since_seq_start = (cur_slot * dwell_time) + (dwell_time-remaining_time) + time_to_tx;
ms_since_seq_start %= (dwell_time*fhss_structure->number_of_channels);
uint32_t seq_length = 0x10000;
if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_TR51CF) {
seq_length = fhss_structure->number_of_channels;
}

return own_floor((float)(ms_since_seq_start * DEF_2E16) / (seq_length*dwell_time));
return own_floor((float)(ms_since_seq_start * DEF_2E24) / (seq_length*dwell_time));
}

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

Expand Down

0 comments on commit ac58048

Please sign in to comment.