Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 4859f16

Browse files
Juha Heiskanenjuhhei01
authored andcommitted
MAC RF extension enable
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.
1 parent e73e9b2 commit 4859f16

File tree

7 files changed

+61
-22
lines changed

7 files changed

+61
-22
lines changed

source/MAC/IEEE802_15_4/mac_defines.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ typedef struct protocol_interface_rf_mac_setup {
170170
bool macRfRadioTxActive:1;
171171
bool macBroadcastDisabled:1;
172172
bool scan_active:1;
173+
bool rf_csma_extension_supported:1;
173174
/* CSMA Params */
174175
unsigned macMinBE:4;
175176
unsigned macMaxBE:4;
@@ -202,6 +203,7 @@ typedef struct protocol_interface_rf_mac_setup {
202203
uint8_t mac_cca_retry;
203204
uint8_t mac_ack_wait_duration;
204205
uint8_t mac_mlme_retry_max;
206+
uint8_t aUnitBackoffPeriod;
205207
/* Indirect queue parameters */
206208
struct mac_pre_build_frame *indirect_pd_data_request_queue;
207209
arm_event_t mac_mcps_timer_event;
@@ -218,6 +220,8 @@ typedef struct protocol_interface_rf_mac_setup {
218220
int8_t cca_timer_id;
219221
int8_t bc_timer_id;
220222
uint32_t mlme_tick_count;
223+
uint32_t symbol_rate;
224+
uint32_t symbol_time_us;
221225
uint8_t max_ED;
222226
uint16_t mlme_ED_counter;
223227
mac_tx_status_t mac_tx_status;

source/MAC/IEEE802_15_4/mac_mcps_sap.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ static bool mac_read_active_event(protocol_interface_rf_mac_setup_s *rf_mac_setu
7272

7373
static int8_t mac_tasklet_event_handler = -1;
7474

75+
/**
76+
* Get PHY time stamp.
77+
*
78+
* \param rf_mac_setup pointer to MAC
79+
* \return Timestamp from PHY
80+
*
81+
*/
82+
static uint32_t mac_mcps_sap_get_phy_timestamp(protocol_interface_rf_mac_setup_s *rf_mac_setup)
83+
{
84+
uint32_t timestamp;
85+
rf_mac_setup->dev_driver->phy_driver->extension(PHY_EXTENSION_GET_TIMESTAMP, (uint8_t *)&timestamp);
86+
return timestamp;
87+
}
88+
7589
static void mac_data_request_init(protocol_interface_rf_mac_setup_s *rf_mac_setup, mac_pre_build_frame_t *buffer)
7690
{
7791
rf_mac_setup->active_pd_data_request = buffer;
@@ -1370,14 +1384,11 @@ static void mac_security_authentication_data_params_set(ccm_globals_t *ccm_ptr,
13701384

13711385
static uint32_t mcps_calculate_tx_time(protocol_interface_rf_mac_setup_s *rf_mac_setup, uint32_t time_to_tx)
13721386
{
1373-
if (!rf_mac_setup->fhss_api) {
1374-
return 0;
1375-
}
13761387
// Max. time to TX is 65ms
13771388
if (time_to_tx > 65000) {
13781389
time_to_tx = 65000;
13791390
}
1380-
return rf_mac_setup->fhss_api->read_timestamp(rf_mac_setup->fhss_api) + time_to_tx;
1391+
return mac_mcps_sap_get_phy_timestamp(rf_mac_setup) + time_to_tx;
13811392
}
13821393

13831394
static void mcps_generic_sequence_number_allocate(protocol_interface_rf_mac_setup_s *rf_ptr, mac_pre_build_frame_t *buffer)
@@ -1402,7 +1413,7 @@ static void mcps_generic_sequence_number_allocate(protocol_interface_rf_mac_setu
14021413
static uint32_t mcps_generic_backoff_calc(protocol_interface_rf_mac_setup_s *rf_ptr)
14031414
{
14041415
uint32_t random_period = mac_csma_backoff_get(rf_ptr);
1405-
if (rf_ptr->fhss_api) {
1416+
if (rf_ptr->rf_csma_extension_supported) {
14061417
return mcps_calculate_tx_time(rf_ptr, random_period);
14071418
}
14081419
return random_period;
@@ -1563,9 +1574,15 @@ static int8_t mcps_pd_data_cca_trig(protocol_interface_rf_mac_setup_s *rf_ptr, m
15631574
{
15641575
mac_mlme_mac_radio_enable(rf_ptr);
15651576

1566-
if (rf_ptr->fhss_api) {
1577+
if (rf_ptr->rf_csma_extension_supported) {
15671578
//Write TX time
1568-
mac_pd_sap_set_phy_tx_time(rf_ptr, buffer->tx_time);
1579+
bool cca_enabled;
1580+
if (buffer->fcf_dsn.frametype == MAC_FRAME_ACK) {
1581+
cca_enabled = false;
1582+
} else {
1583+
cca_enabled = true;
1584+
}
1585+
mac_pd_sap_set_phy_tx_time(rf_ptr, buffer->tx_time, cca_enabled);
15691586
if (mac_plme_cca_req(rf_ptr) != 0) {
15701587
return -1;
15711588
}

source/MAC/IEEE802_15_4/mac_mlme.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,7 @@ protocol_interface_rf_mac_setup_s * mac_mlme_data_base_allocate(uint8_t *mac64,
995995
entry->bc_timer_id = -1;
996996
entry->mac_interface_id = -1;
997997
entry->dev_driver = dev_driver;
998+
entry->aUnitBackoffPeriod = 20; //This can be different in some Platform 20 comes from 12-symbol turnaround and 8 symbol CCA read
998999

9991000
if (mac_sec_mib_init(entry, storage_sizes) != 0) {
10001001
mac_mlme_data_base_deallocate(entry);
@@ -1060,6 +1061,15 @@ protocol_interface_rf_mac_setup_s * mac_mlme_data_base_allocate(uint8_t *mac64,
10601061
entry->mac_mcps_timer_event.receiver = entry->mac_tasklet_id;
10611062
entry->mac_mcps_timer_event.sender = 0;
10621063
entry->mac_mcps_timer_event.event_id = 0;
1064+
bool rf_support = false;
1065+
dev_driver->phy_driver->extension(PHY_EXTENSION_DYNAMIC_RF_SUPPORTED, (uint8_t*)&rf_support);
1066+
entry->rf_csma_extension_supported = rf_support;
1067+
if (entry->rf_csma_extension_supported) {
1068+
entry->dev_driver->phy_driver->extension(PHY_EXTENSION_GET_SYMBOLS_PER_SECOND, (uint8_t*) &entry->symbol_rate);
1069+
entry->symbol_time_us = 1000000 / entry->symbol_rate;
1070+
tr_debug("SW-MAC driver support rf extension %"PRIu32" symbol/seconds %"PRIu32" us symbol time length", entry->symbol_rate, entry->symbol_time_us);
1071+
}
1072+
10631073
//How many 10us ticks backoff period is for waiting 20symbols which is typically 10 bytes time
10641074
entry->backoff_period_in_10us = mac_backoff_ticks_calc(dev_driver->phy_driver);
10651075
return entry;

source/MAC/IEEE802_15_4/mac_pd_sap.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ static void mac_csma_backoff_start(protocol_interface_rf_mac_setup_s *rf_mac_set
8383
uint32_t mac_csma_backoff_get(protocol_interface_rf_mac_setup_s *rf_mac_setup)
8484
{
8585
uint8_t backoff = mac_csma_random_backoff_get(rf_mac_setup);
86-
uint32_t backoff_in_us = backoff * rf_mac_setup->backoff_period_in_10us * 10;
86+
uint32_t backoff_in_us;
87+
//Multiple aUnitBackoffPeriod symbol time
88+
if (rf_mac_setup->rf_csma_extension_supported) {
89+
backoff_in_us = backoff * rf_mac_setup->aUnitBackoffPeriod * rf_mac_setup->symbol_time_us;
90+
} else {
91+
backoff_in_us = backoff * rf_mac_setup->backoff_period_in_10us * 10;
92+
}
8793

8894
if (backoff_in_us == 0) {
8995
backoff_in_us = 1;
@@ -181,15 +187,16 @@ int8_t mac_pd_sap_req(protocol_interface_rf_mac_setup_s *rf_mac_setup)
181187
* \param tx_time TX timestamp to be set.
182188
*
183189
*/
184-
void mac_pd_sap_set_phy_tx_time(protocol_interface_rf_mac_setup_s *rf_mac_setup, uint32_t tx_time)
190+
void mac_pd_sap_set_phy_tx_time(protocol_interface_rf_mac_setup_s *rf_mac_setup, uint32_t tx_time, bool cca_enabled)
185191
{
186192
// With TX time set to zero, PHY sends immediately
187193
if (!tx_time) {
188194
tx_time++;
189195
}
190-
uint8_t tx_time_buffer[4];
191-
common_write_32_bit(tx_time, tx_time_buffer);
192-
rf_mac_setup->dev_driver->phy_driver->extension(PHY_EXTENSION_SET_TX_TIME, tx_time_buffer);
196+
phy_csma_params_t csma_params;
197+
csma_params.symbol_backoff_time = tx_time;
198+
csma_params.cca_enabled = cca_enabled;
199+
rf_mac_setup->dev_driver->phy_driver->extension(PHY_EXTENSION_SET_CSMA_PARAMETERS, (uint8_t*) &csma_params);
193200
}
194201

195202
/**
@@ -222,7 +229,14 @@ void mac_pd_sap_state_machine(protocol_interface_rf_mac_setup_s *rf_mac_setup)
222229
if (!active_buf) {
223230
return;
224231
}
225-
mac_pd_sap_set_phy_tx_time(rf_mac_setup, active_buf->tx_time);
232+
bool cca_enabled;
233+
if (active_buf->fcf_dsn.frametype == MAC_FRAME_ACK) {
234+
cca_enabled = false;
235+
} else {
236+
cca_enabled = true;
237+
}
238+
239+
mac_pd_sap_set_phy_tx_time(rf_mac_setup, active_buf->tx_time, cca_enabled);
226240
if (active_buf->fcf_dsn.frametype == FC_BEACON_FRAME) {
227241
// FHSS synchronization info is written in the end of transmitted (Beacon) buffer
228242
dev_driver_tx_buffer_s *tx_buf = &rf_mac_setup->dev_driver_tx_buffer;
@@ -435,7 +449,7 @@ int8_t mac_pd_sap_data_cb(void *identifier, arm_phy_sap_msg_t *message)
435449
sw_mac_stats_update(rf_ptr, STAT_MAC_RX_DROP, 0);
436450
return -3;
437451
}
438-
if (rf_ptr->fhss_api) {
452+
if (rf_ptr->rf_csma_extension_supported) {
439453
buffer->timestamp = mac_pd_sap_get_phy_rx_time(rf_ptr);
440454
}
441455
buffer->ack_pendinfg_status = mac_data_interface_read_last_ack_pending_status(rf_ptr);

source/MAC/IEEE802_15_4/mac_pd_sap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int8_t mac_pd_sap_req(struct protocol_interface_rf_mac_setup *rf_mac_setup);
3939

4040
int8_t mac_plme_cca_req(struct protocol_interface_rf_mac_setup *rf_mac_setup);
4141

42-
void mac_pd_sap_set_phy_tx_time(struct protocol_interface_rf_mac_setup *rf_mac_setup, uint32_t tx_time);
42+
void mac_pd_sap_set_phy_tx_time(struct protocol_interface_rf_mac_setup *rf_mac_setup, uint32_t tx_time, bool cca_enabled);
4343

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

source/MAC/rf_driver_storage.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,6 @@ 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-
}
10498
ns_list_add_to_end(&arm_device_driver_list, new);
10599

106100
return new->id;

test/nanostack/unittest/stub/mac_pd_sap_stub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void mac_pd_sap_rf_low_level_function_set(void *mac_ptr, void *driver)
5353
{
5454
}
5555

56-
void mac_pd_sap_set_phy_tx_time(struct protocol_interface_rf_mac_setup *rf_mac_setup, uint32_t tx_time)
56+
void mac_pd_sap_set_phy_tx_time(struct protocol_interface_rf_mac_setup *rf_mac_setup, uint32_t tx_time, bool cca_enabled)
5757
{
5858

5959
}

0 commit comments

Comments
 (0)