Skip to content

Commit

Permalink
Merge pull request ARMmbed#1979 from ARMmbed/IOTTHD-3233
Browse files Browse the repository at this point in the history
Iotthd 3233
  • Loading branch information
Jarkko Paso authored Feb 26, 2019
2 parents 2b356e0 + f2ba36d commit df2b98e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 7 deletions.
1 change: 0 additions & 1 deletion source/6LoWPAN/ws/ws_neighbor_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ uint8_t ws_neighbor_class_rssi_from_dbm_calculate(int8_t dbm_heard)
{
if (DEVICE_MIN_SENS > dbm_heard) {
// We are hearing packet with lower than min_sens dynamically learn the sensitivity
tr_info("heard packet below min sensitivity");
DEVICE_MIN_SENS = dbm_heard;
}
return dbm_heard - DEVICE_MIN_SENS;
Expand Down
2 changes: 1 addition & 1 deletion source/MAC/IEEE802_15_4/mac_mcps_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1740,7 +1740,7 @@ int8_t mcps_generic_ack_build(protocol_interface_rf_mac_setup_s *rf_ptr, const m
rf_ptr->dev_driver->phy_driver->extension(PHY_EXTENSION_SET_CSMA_PARAMETERS, (uint8_t *) &csma_params);
if (rf_ptr->active_pd_data_request) {
timer_mac_stop(rf_ptr);
mac_pd_sap_set_phy_tx_time(rf_ptr, 0, false);
mac_pd_abort_active_tx(rf_ptr);
}
return mcps_pd_data_cca_trig(rf_ptr, buffer);
}
Expand Down
2 changes: 1 addition & 1 deletion source/MAC/IEEE802_15_4/mac_mlme.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ static int8_t mac_mlme_8bit_set(protocol_interface_rf_mac_setup_s *rf_mac_setup,
break;

case macMinBE:
if (value > rf_mac_setup->macMaxBE) {
if (value < rf_mac_setup->macMaxBE) {
rf_mac_setup->macMinBE = value;
}
break;
Expand Down
14 changes: 14 additions & 0 deletions source/MAC/IEEE802_15_4/mac_pd_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,20 @@ int8_t mac_pd_sap_req(protocol_interface_rf_mac_setup_s *rf_mac_setup)
}


/**
* Abort active PHY transmission.
*
* \param rf_mac_setup pointer to MAC.
*
*/
void mac_pd_abort_active_tx(protocol_interface_rf_mac_setup_s *rf_mac_setup)
{
phy_csma_params_t csma_params;
// Set TX time to 0 to abort current transmission
csma_params.backoff_time = 0;
rf_mac_setup->dev_driver->phy_driver->extension(PHY_EXTENSION_SET_CSMA_PARAMETERS, (uint8_t *) &csma_params);
}

/**
* Set PHY TX time.
*
Expand Down
2 changes: 2 additions & 0 deletions source/MAC/IEEE802_15_4/mac_pd_sap.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ 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_abort_active_tx(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, bool cca_enabled);

void mac_pd_sap_rf_low_level_function_set(void *mac_ptr, void *driver);
Expand Down
25 changes: 22 additions & 3 deletions source/Service_Libs/fhss/fhss_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@ static int32_t fhss_ws_calc_bc_channel(fhss_structure_t *fhss_structure)
return next_channel;
}

static uint8_t calc_own_tx_trig_slot(uint8_t own_hop)
{
if (own_hop == 0xff) {
return 0;
}
if (own_hop & 1) {
own_hop--;
}
own_hop /= 2;
return (own_hop & 1);
}

static void fhss_broadcast_handler(const fhss_api_t *fhss_api, uint16_t delay)
{
int32_t next_channel;
Expand Down Expand Up @@ -236,13 +248,20 @@ static void fhss_broadcast_handler(const fhss_api_t *fhss_api, uint16_t delay)
// Should return to own (unicast) listening channel after broadcast channel
next_channel = fhss_structure->rx_channel;
/* Start timer with random timeout to trigger unicast TX queue poll event.
* Min random is 1/30 of the TX slot length.
* For hops 0,1,4,5,8,9,...
* Min random is 1/100 of the TX slot length.
* Max random is 1/10 of the TX slot length.
*
* For hops 2,3,6,7,10,11,...
* Min random is 1/100 of the TX slot length plus 0.5*TX slot length.
* Max random is 1/10 of the TX slot length plus 0.5*TX slot length.
* Event timer resolution is 50us.
*/
// returns 1 if polling of TX queue is done on latter half of the TX slot
uint8_t own_tx_trig_slot = calc_own_tx_trig_slot(fhss_structure->own_hop);
uint32_t txrx_slot_length_us = MS_TO_US(fhss_structure->ws->txrx_slot_length_ms);
uint16_t uc_min_random = (txrx_slot_length_us / 30) / 50;
uint16_t uc_max_random = (txrx_slot_length_us / 10) / 50;
uint16_t uc_min_random = (((txrx_slot_length_us / 2) * own_tx_trig_slot) / 50) + ((txrx_slot_length_us / 100) / 50);
uint16_t uc_max_random = (((txrx_slot_length_us / 2) * own_tx_trig_slot) / 50) + ((txrx_slot_length_us / 10) / 50);
bool tx_allowed = fhss_ws_check_tx_allowed(fhss_structure);
if (!tx_allowed) {
uc_min_random += (txrx_slot_length_us) / 50;
Expand Down
6 changes: 5 additions & 1 deletion test/nanostack/unittest/stub/mac_pd_sap_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ void mac_pd_sap_rf_low_level_function_set(void *mac_ptr, void *driver)
{
}

void mac_pd_abort_active_tx(protocol_interface_rf_mac_setup_s *rf_mac_setup)
{

}

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 All @@ -77,4 +82,3 @@ void mac_csma_backoff_start(protocol_interface_rf_mac_setup_s *rf_mac_setup)
{

}

0 comments on commit df2b98e

Please sign in to comment.