Skip to content

Commit 23d3a58

Browse files
author
Jarkko Paso
committed
MAC: Created a function to set TX time
1 parent 2384c33 commit 23d3a58

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
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. */
59+
PHY_EXTENSION_SET_TX_TIME, /**< Net library sets transmission time based on global time stamp. Max. 65ms from setting to TX */
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_pd_sap.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,33 @@ int8_t mac_pd_sap_req(protocol_interface_rf_mac_setup_s *rf_mac_setup)
160160
return 0;
161161
}
162162

163+
/**
164+
* Set PHY TX time.
165+
*
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
169+
*
170+
*/
171+
static int mac_pd_sap_set_tx_time(protocol_interface_rf_mac_setup_s *rf_mac_setup, uint16_t time_to_tx)
172+
{
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;
186+
}
187+
return -1;
188+
}
189+
163190
/**
164191
* Run Mac data interface state Machine for mac timer.
165192
*

source/MAC/rf_driver_storage.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ int8_t arm_net_phy_register(phy_device_driver_s *phy_driver)
9595
if (new->phy_driver->state_control) {
9696
new->phy_driver->state_control(PHY_INTERFACE_RESET, 0);
9797
}
98+
if (new->phy_driver->extension) {
99+
uint8_t tx_time_buffer[4];
100+
uint32_t tx_time = 0;
101+
common_write_32_bit(tx_time, tx_time_buffer);
102+
new->phy_driver->extension(PHY_EXTENSION_SET_TX_TIME, tx_time_buffer);
103+
}
98104
ns_list_add_to_end(&arm_device_driver_list, new);
99105

100106
return new->id;

0 commit comments

Comments
 (0)