Skip to content

Commit

Permalink
MAC RF extension enable
Browse files Browse the repository at this point in the history
SW mac creare verify if driver support dynamic CSMA parameters and
timestamp. Create also get driver symbol rate and calculate symbol tx
time in us.

MAC read Symbol timestamp now trough rf extension.
  • Loading branch information
Juha Heiskanen authored and juhhei01 committed Apr 27, 2018
1 parent e73e9b2 commit 4859f16
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 22 deletions.
4 changes: 4 additions & 0 deletions source/MAC/IEEE802_15_4/mac_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ typedef struct protocol_interface_rf_mac_setup {
bool macRfRadioTxActive:1;
bool macBroadcastDisabled:1;
bool scan_active:1;
bool rf_csma_extension_supported:1;
/* CSMA Params */
unsigned macMinBE:4;
unsigned macMaxBE:4;
Expand Down Expand Up @@ -202,6 +203,7 @@ typedef struct protocol_interface_rf_mac_setup {
uint8_t mac_cca_retry;
uint8_t mac_ack_wait_duration;
uint8_t mac_mlme_retry_max;
uint8_t aUnitBackoffPeriod;
/* Indirect queue parameters */
struct mac_pre_build_frame *indirect_pd_data_request_queue;
arm_event_t mac_mcps_timer_event;
Expand All @@ -218,6 +220,8 @@ typedef struct protocol_interface_rf_mac_setup {
int8_t cca_timer_id;
int8_t bc_timer_id;
uint32_t mlme_tick_count;
uint32_t symbol_rate;
uint32_t symbol_time_us;
uint8_t max_ED;
uint16_t mlme_ED_counter;
mac_tx_status_t mac_tx_status;
Expand Down
31 changes: 24 additions & 7 deletions source/MAC/IEEE802_15_4/mac_mcps_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ static bool mac_read_active_event(protocol_interface_rf_mac_setup_s *rf_mac_setu

static int8_t mac_tasklet_event_handler = -1;

/**
* Get PHY time stamp.
*
* \param rf_mac_setup pointer to MAC
* \return Timestamp from PHY
*
*/
static uint32_t mac_mcps_sap_get_phy_timestamp(protocol_interface_rf_mac_setup_s *rf_mac_setup)
{
uint32_t timestamp;
rf_mac_setup->dev_driver->phy_driver->extension(PHY_EXTENSION_GET_TIMESTAMP, (uint8_t *)&timestamp);
return timestamp;
}

static void mac_data_request_init(protocol_interface_rf_mac_setup_s *rf_mac_setup, mac_pre_build_frame_t *buffer)
{
rf_mac_setup->active_pd_data_request = buffer;
Expand Down Expand Up @@ -1370,14 +1384,11 @@ 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, uint32_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;
return mac_mcps_sap_get_phy_timestamp(rf_mac_setup) + time_to_tx;
}

static void mcps_generic_sequence_number_allocate(protocol_interface_rf_mac_setup_s *rf_ptr, mac_pre_build_frame_t *buffer)
Expand All @@ -1402,7 +1413,7 @@ static void mcps_generic_sequence_number_allocate(protocol_interface_rf_mac_setu
static uint32_t mcps_generic_backoff_calc(protocol_interface_rf_mac_setup_s *rf_ptr)
{
uint32_t random_period = mac_csma_backoff_get(rf_ptr);
if (rf_ptr->fhss_api) {
if (rf_ptr->rf_csma_extension_supported) {
return mcps_calculate_tx_time(rf_ptr, random_period);
}
return random_period;
Expand Down Expand Up @@ -1563,9 +1574,15 @@ static int8_t mcps_pd_data_cca_trig(protocol_interface_rf_mac_setup_s *rf_ptr, m
{
mac_mlme_mac_radio_enable(rf_ptr);

if (rf_ptr->fhss_api) {
if (rf_ptr->rf_csma_extension_supported) {
//Write TX time
mac_pd_sap_set_phy_tx_time(rf_ptr, buffer->tx_time);
bool cca_enabled;
if (buffer->fcf_dsn.frametype == MAC_FRAME_ACK) {
cca_enabled = false;
} else {
cca_enabled = true;
}
mac_pd_sap_set_phy_tx_time(rf_ptr, buffer->tx_time, cca_enabled);
if (mac_plme_cca_req(rf_ptr) != 0) {
return -1;
}
Expand Down
10 changes: 10 additions & 0 deletions source/MAC/IEEE802_15_4/mac_mlme.c
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,7 @@ protocol_interface_rf_mac_setup_s * mac_mlme_data_base_allocate(uint8_t *mac64,
entry->bc_timer_id = -1;
entry->mac_interface_id = -1;
entry->dev_driver = dev_driver;
entry->aUnitBackoffPeriod = 20; //This can be different in some Platform 20 comes from 12-symbol turnaround and 8 symbol CCA read

if (mac_sec_mib_init(entry, storage_sizes) != 0) {
mac_mlme_data_base_deallocate(entry);
Expand Down Expand Up @@ -1060,6 +1061,15 @@ protocol_interface_rf_mac_setup_s * mac_mlme_data_base_allocate(uint8_t *mac64,
entry->mac_mcps_timer_event.receiver = entry->mac_tasklet_id;
entry->mac_mcps_timer_event.sender = 0;
entry->mac_mcps_timer_event.event_id = 0;
bool rf_support = false;
dev_driver->phy_driver->extension(PHY_EXTENSION_DYNAMIC_RF_SUPPORTED, (uint8_t*)&rf_support);
entry->rf_csma_extension_supported = rf_support;
if (entry->rf_csma_extension_supported) {
entry->dev_driver->phy_driver->extension(PHY_EXTENSION_GET_SYMBOLS_PER_SECOND, (uint8_t*) &entry->symbol_rate);
entry->symbol_time_us = 1000000 / entry->symbol_rate;
tr_debug("SW-MAC driver support rf extension %"PRIu32" symbol/seconds %"PRIu32" us symbol time length", entry->symbol_rate, entry->symbol_time_us);
}

//How many 10us ticks backoff period is for waiting 20symbols which is typically 10 bytes time
entry->backoff_period_in_10us = mac_backoff_ticks_calc(dev_driver->phy_driver);
return entry;
Expand Down
28 changes: 21 additions & 7 deletions source/MAC/IEEE802_15_4/mac_pd_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ static void mac_csma_backoff_start(protocol_interface_rf_mac_setup_s *rf_mac_set
uint32_t mac_csma_backoff_get(protocol_interface_rf_mac_setup_s *rf_mac_setup)
{
uint8_t backoff = mac_csma_random_backoff_get(rf_mac_setup);
uint32_t backoff_in_us = backoff * rf_mac_setup->backoff_period_in_10us * 10;
uint32_t backoff_in_us;
//Multiple aUnitBackoffPeriod symbol time
if (rf_mac_setup->rf_csma_extension_supported) {
backoff_in_us = backoff * rf_mac_setup->aUnitBackoffPeriod * rf_mac_setup->symbol_time_us;
} else {
backoff_in_us = backoff * rf_mac_setup->backoff_period_in_10us * 10;
}

if (backoff_in_us == 0) {
backoff_in_us = 1;
Expand Down Expand Up @@ -181,15 +187,16 @@ int8_t mac_pd_sap_req(protocol_interface_rf_mac_setup_s *rf_mac_setup)
* \param tx_time TX timestamp to be set.
*
*/
void mac_pd_sap_set_phy_tx_time(protocol_interface_rf_mac_setup_s *rf_mac_setup, uint32_t tx_time)
void mac_pd_sap_set_phy_tx_time(protocol_interface_rf_mac_setup_s *rf_mac_setup, uint32_t tx_time, bool cca_enabled)
{
// With TX time set to zero, PHY sends immediately
if (!tx_time) {
tx_time++;
}
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);
phy_csma_params_t csma_params;
csma_params.symbol_backoff_time = tx_time;
csma_params.cca_enabled = cca_enabled;
rf_mac_setup->dev_driver->phy_driver->extension(PHY_EXTENSION_SET_CSMA_PARAMETERS, (uint8_t*) &csma_params);
}

/**
Expand Down Expand Up @@ -222,7 +229,14 @@ 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);
bool cca_enabled;
if (active_buf->fcf_dsn.frametype == MAC_FRAME_ACK) {
cca_enabled = false;
} else {
cca_enabled = true;
}

mac_pd_sap_set_phy_tx_time(rf_mac_setup, active_buf->tx_time, cca_enabled);
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 Expand Up @@ -435,7 +449,7 @@ int8_t mac_pd_sap_data_cb(void *identifier, arm_phy_sap_msg_t *message)
sw_mac_stats_update(rf_ptr, STAT_MAC_RX_DROP, 0);
return -3;
}
if (rf_ptr->fhss_api) {
if (rf_ptr->rf_csma_extension_supported) {
buffer->timestamp = mac_pd_sap_get_phy_rx_time(rf_ptr);
}
buffer->ack_pendinfg_status = mac_data_interface_read_last_ack_pending_status(rf_ptr);
Expand Down
2 changes: 1 addition & 1 deletion source/MAC/IEEE802_15_4/mac_pd_sap.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int8_t mac_pd_sap_req(struct protocol_interface_rf_mac_setup *rf_mac_setup);

int8_t mac_plme_cca_req(struct protocol_interface_rf_mac_setup *rf_mac_setup);

void mac_pd_sap_set_phy_tx_time(struct protocol_interface_rf_mac_setup *rf_mac_setup, uint32_t tx_time);
void mac_pd_sap_set_phy_tx_time(struct protocol_interface_rf_mac_setup *rf_mac_setup, uint32_t tx_time, bool cca_enabled);

void mac_pd_sap_rf_low_level_function_set(void *mac_ptr, void *driver);

Expand Down
6 changes: 0 additions & 6 deletions source/MAC/rf_driver_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,6 @@ 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
2 changes: 1 addition & 1 deletion test/nanostack/unittest/stub/mac_pd_sap_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void mac_pd_sap_rf_low_level_function_set(void *mac_ptr, void *driver)
{
}

void mac_pd_sap_set_phy_tx_time(struct protocol_interface_rf_mac_setup *rf_mac_setup, uint32_t tx_time)
void mac_pd_sap_set_phy_tx_time(struct protocol_interface_rf_mac_setup *rf_mac_setup, uint32_t tx_time, bool cca_enabled)
{

}
Expand Down

0 comments on commit 4859f16

Please sign in to comment.