Skip to content

Commit

Permalink
Merge pull request ARMmbed#1527 from ARMmbed/IOTTHD-2095
Browse files Browse the repository at this point in the history
Iotthd 2095
  • Loading branch information
Jarkko Paso authored Jan 12, 2018
2 parents 209e49a + bf65e9c commit ad5a1e1
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nanostack/platform/arm_hal_phy.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ 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_READ_RX_TIME, /**< Read the time of last reception based on global time stamp. */
} phy_extension_type_e;

/** Address types */
Expand Down
41 changes: 41 additions & 0 deletions source/MAC/IEEE802_15_4/mac_pd_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,47 @@ int8_t mac_pd_sap_req(protocol_interface_rf_mac_setup_s *rf_mac_setup)
return 0;
}

/**
* 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
*
*/
static int mac_pd_sap_set_tx_time(protocol_interface_rf_mac_setup_s *rf_mac_setup, uint16_t time_to_tx)
{
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;
}
return -1;
}

/**
* Get PHY RX time.
*
* \param rf_mac_setup pointer to MAC
* \return Timestamp of last PHY reception
*
*/
static uint32_t mac_pd_sap_get_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);
return common_read_32_bit(rx_time_buffer);
}

/**
* Run Mac data interface state Machine for mac timer.
*
Expand Down
6 changes: 6 additions & 0 deletions source/MAC/rf_driver_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ int8_t arm_net_phy_register(phy_device_driver_s *phy_driver)
if (new->phy_driver->state_control) {
new->phy_driver->state_control(PHY_INTERFACE_RESET, 0);
}
if (new->phy_driver->extension) {
uint8_t tx_time_buffer[4];
uint32_t tx_time = 0;
common_write_32_bit(tx_time, tx_time_buffer);
new->phy_driver->extension(PHY_EXTENSION_SET_TX_TIME, tx_time_buffer);
}
ns_list_add_to_end(&arm_device_driver_list, new);

return new->id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ int8_t test_control(phy_interface_state_e a, uint8_t b){
return 1;
}

int8_t test_extension(phy_extension_type_e extension_type, uint8_t *data_ptr){
return 0;
}

bool test_arm_net_phy_register()
{
int8_t ret = arm_net_phy_register(NULL);
Expand Down Expand Up @@ -75,6 +79,7 @@ bool test_arm_net_phy_register()
nsdynmemlib_stub.returnCounter = 1;

driver.state_control = &test_control;
driver.extension = &test_extension;
protocol_tun_driver_stub.int8_value = 0;
ret = arm_net_phy_register(&driver);
if( ret != 0 ){
Expand Down Expand Up @@ -190,6 +195,7 @@ bool test_arm_net_phy_mac64_set()
nsdynmemlib_stub.returnCounter = 1;

driver.state_control = &test_control;
driver.extension = &test_extension;
protocol_tun_driver_stub.int8_value = 0;
int8_t ret = arm_net_phy_register(&driver);
if( ret != 0 ){
Expand All @@ -214,6 +220,7 @@ bool test_arm_net_phy_mac64_get()
nsdynmemlib_stub.returnCounter = 1;

driver.state_control = &test_control;
driver.extension = &test_extension;
protocol_tun_driver_stub.int8_value = 0;
int8_t ret = arm_net_phy_register(&driver);
if( ret != 0 ){
Expand Down Expand Up @@ -245,6 +252,7 @@ bool test_arm_net_phy_rf_type()
nsdynmemlib_stub.returnCounter = 1;

driver.state_control = &test_control;
driver.extension = &test_extension;
protocol_tun_driver_stub.int8_value = 0;
int8_t ret = arm_net_phy_register(&driver);
if( ret != 0 ){
Expand All @@ -271,6 +279,7 @@ bool test_arm_net_phy_mtu_size()
nsdynmemlib_stub.returnCounter = 1;

driver.state_control = &test_control;
driver.extension = &test_extension;
protocol_tun_driver_stub.int8_value = 0;
int8_t ret = arm_net_phy_register(&driver);
if( ret != 0 ){
Expand All @@ -297,6 +306,7 @@ bool test_arm_net_observer_cb_set()
nsdynmemlib_stub.returnCounter = 1;

driver.state_control = &test_control;
driver.extension = &test_extension;
protocol_tun_driver_stub.int8_value = 0;
arm_net_phy_register(&driver);

Expand Down

0 comments on commit ad5a1e1

Please sign in to comment.