Skip to content

Commit 3383e91

Browse files
author
Jarkko Paso
authored
Merge pull request #2163 from ARMmbed/IOTTHD-3558
Iotthd 3558
2 parents 5907042 + 81f7511 commit 3383e91

File tree

6 files changed

+87
-3
lines changed

6 files changed

+87
-3
lines changed

nanostack/mlme.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ typedef enum {
264264
macAutoRequestKeyIndex = 0x7b, /*<The index of the key used for automatic data*/
265265
macDefaultKeySource = 0x7c, /*<Default key source*/
266266
//NON standard extension
267+
macTXPower = 0xf8, /*<TX output power*/
268+
macCCAThreshold = 0xf9, /*<CCA threshold*/
267269
macMultiCSMAParameters = 0xfa, /*<Multi CSMA parameters*/
268270
macRfConfiguration = 0xfb, /*<RF channel configuration parameters*/
269271
macAcceptByPassUnknowDevice = 0xfc, /*< Accept data trough MAC if packet is data can be authenticated by group key nad MIC. Security enforsment point must be handled carefully these packets */

nanostack/net_interface.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,34 @@ extern void net_get_version_information(uint8_t *ptr);
10931093

10941094
extern int arm_nwk_sleepy_device_parent_buffer_size_set(int8_t interface_id, uint16_t big_packet_threshold, uint16_t small_packets_per_child_count, uint16_t big_packets_total_count);
10951095

1096+
/**
1097+
* \brief Set CCA threshold.
1098+
*
1099+
* This function can be used to set CCA threshold to PHY layer. Threshold is given as percentage of maximum threshold.
1100+
* 0 is the lowest(strictest) possible threshold and 100 is the highest possible threshold.
1101+
*
1102+
* Note! Software MAC must be created and registered before using this function.
1103+
*
1104+
* \param interface_id Network interface ID.
1105+
* \param cca_threshold CCA threshold (%).
1106+
* \return 0 on success, <0 on errors.
1107+
*/
1108+
extern int8_t arm_nwk_set_cca_threshold(int8_t interface_id, uint8_t cca_threshold);
1109+
1110+
/**
1111+
* \brief Set TX output power.
1112+
*
1113+
* This function can be used to set TX output power to PHY layer. TX power is given as percentage of maximum output power.
1114+
* 0 is the lowest possible TX power and 100 is the highest possible TX power.
1115+
*
1116+
* Note! Software MAC must be created and registered before using this function.
1117+
*
1118+
* \param interface_id Network interface ID.
1119+
* \param tx_power TX output power (%).
1120+
* \return 0 on success, <0 on errors.
1121+
*/
1122+
extern int8_t arm_nwk_set_tx_output_power(int8_t interface_id, uint8_t tx_power);
1123+
10961124

10971125
#ifdef __cplusplus
10981126
}

nanostack/platform/arm_hal_phy.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ typedef enum {
7676
PHY_EXTENSION_GET_TIMESTAMP, /**< Read 32-bit constant monotonic time stamp in us */
7777
PHY_EXTENSION_SET_CSMA_PARAMETERS, /**< CSMA parameter's are given by phy_csma_params_t structure remember type cast uint8_t pointer to structure type*/
7878
PHY_EXTENSION_GET_SYMBOLS_PER_SECOND, /**< Read Symbols per seconds which will help to convert symbol time to real time */
79-
PHY_EXTENSION_SET_RF_CONFIGURATION, /**< Set RF configuration using phy_rf_channel_parameters_s structure */
80-
PHY_EXTENSION_FILTERING_SUPPORT /**< Return filtering modes that can be supported by the PHY driver. See phy_link_filters_e */
79+
PHY_EXTENSION_SET_RF_CONFIGURATION, /**< Set RF configuration using phy_rf_channel_configuration_s structure */
80+
PHY_EXTENSION_FILTERING_SUPPORT, /**< Return filtering modes that can be supported by the PHY driver. See phy_link_filters_e */
81+
PHY_EXTENSION_SET_TX_POWER, /**< Set TX output power which is given as percentage of maximum. 0 is the lowest possible TX power and 100 is the highest possible TX power */
82+
PHY_EXTENSION_SET_CCA_THRESHOLD /**< Set CCA threshold which is given as percentage of maximum threshold. 0 is the lowest(strictest) possible threshold and 100 is the highest possible threshold */
8183
} phy_extension_type_e;
8284

8385
/** Address types */

source/MAC/IEEE802_15_4/mac_mlme.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ int8_t mac_mlme_set_req(protocol_interface_rf_mac_setup_s *rf_mac_setup, const m
738738
if (!set_req || !rf_mac_setup || !rf_mac_setup->dev_driver || !rf_mac_setup->dev_driver->phy_driver) {
739739
return -1;
740740
}
741-
741+
uint8_t *pu8 = NULL;
742742
switch (set_req->attr) {
743743
case macAckWaitDuration:
744744
return mac_mlme_set_ack_wait_duration(rf_mac_setup, set_req);
@@ -758,11 +758,29 @@ int8_t mac_mlme_set_req(protocol_interface_rf_mac_setup_s *rf_mac_setup, const m
758758
memcpy(rf_mac_setup->coord_long_address, set_req->value_pointer, 8);
759759
}
760760
return 0;
761+
case macTXPower:
762+
pu8 = (uint8_t *) set_req->value_pointer;
763+
rf_mac_setup->dev_driver->phy_driver->extension(PHY_EXTENSION_SET_TX_POWER, pu8);
764+
tr_debug("Set TX output power to %u%%", *pu8);
765+
return 0;
766+
case macCCAThreshold:
767+
pu8 = (uint8_t *) set_req->value_pointer;
768+
rf_mac_setup->dev_driver->phy_driver->extension(PHY_EXTENSION_SET_CCA_THRESHOLD, pu8);
769+
tr_debug("Set CCA threshold to %u%%", *pu8);
770+
return 0;
761771
case macMultiCSMAParameters:
762772
return mac_mlme_set_multi_csma_parameters(rf_mac_setup, set_req);
763773
case macRfConfiguration:
764774
rf_mac_setup->dev_driver->phy_driver->extension(PHY_EXTENSION_SET_RF_CONFIGURATION, (uint8_t *) set_req->value_pointer);
765775
mac_mlme_set_symbol_rate(rf_mac_setup);
776+
phy_rf_channel_configuration_s *config_params = (phy_rf_channel_configuration_s *)set_req->value_pointer;
777+
tr_info("RF config update:");
778+
tr_info("Frequency(ch0): %"PRIu32"Hz", config_params->channel_0_center_frequency);
779+
tr_info("Channel spacing: %"PRIu32"Hz", config_params->channel_spacing);
780+
tr_info("Datarate: %"PRIu32"bps", config_params->datarate);
781+
tr_info("Number of channels: %u", config_params->number_of_channels);
782+
tr_info("Modulation: %u", config_params->modulation);
783+
tr_info("Modulation index: %u", config_params->modulation_index);
766784
return 0;
767785
default:
768786
return mac_mlme_handle_set_values(rf_mac_setup, set_req);

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ static uint32_t fhss_set_txrx_slot_length(fhss_structure_t *fhss_structure);
8888
// This function supports rounding up
8989
static int64_t divide_integer(int64_t dividend, int32_t divisor)
9090
{
91+
if (!divisor) {
92+
return dividend;
93+
}
9194
if (dividend < 0) {
9295
return (dividend - divisor / 2) / divisor;
9396
}

source/libNET/src/ns_net.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,3 +1497,34 @@ int arm_nwk_sleepy_device_parent_buffer_size_set(int8_t interface_id, uint16_t b
14971497
return -1;
14981498
}
14991499

1500+
int8_t arm_nwk_set_cca_threshold(int8_t interface_id, uint8_t cca_threshold)
1501+
{
1502+
protocol_interface_info_entry_t *cur;
1503+
cur = protocol_stack_interface_info_get_by_id(interface_id);
1504+
if (!cur || !cur->mac_api || (cca_threshold > 100)) {
1505+
return -1;
1506+
}
1507+
mlme_set_t set_req;
1508+
set_req.attr = macCCAThreshold;
1509+
set_req.attr_index = 0;
1510+
set_req.value_pointer = &cca_threshold;
1511+
set_req.value_size = sizeof(cca_threshold);
1512+
cur->mac_api->mlme_req(cur->mac_api, MLME_SET, &set_req);
1513+
return 0;
1514+
}
1515+
1516+
int8_t arm_nwk_set_tx_output_power(int8_t interface_id, uint8_t tx_power)
1517+
{
1518+
protocol_interface_info_entry_t *cur;
1519+
cur = protocol_stack_interface_info_get_by_id(interface_id);
1520+
if (!cur || !cur->mac_api || (tx_power > 100)) {
1521+
return -1;
1522+
}
1523+
mlme_set_t set_req;
1524+
set_req.attr = macTXPower;
1525+
set_req.attr_index = 0;
1526+
set_req.value_pointer = &tx_power;
1527+
set_req.value_size = sizeof(tx_power);
1528+
cur->mac_api->mlme_req(cur->mac_api, MLME_SET, &set_req);
1529+
return 0;
1530+
}

0 commit comments

Comments
 (0)