Skip to content

Commit c32a7da

Browse files
jhirsirlubos
authored andcommitted
samples: dect_phy: dect_shell: ping client: LBT support
LBT can be enabled by using following hook: --c_tx_lbt_period <symbol_count>, where range is 2-110. Zero disables LBT which is also a default. Additionally, --c_tx_lbt_busy_th <dbm>, can be used to set a custom threshold for LBT busy channel detection. Default is from RSSI scan BUSY threshold from settings. Jira: MOSH-633 Signed-off-by: Jani Hirsimäki <[email protected]>
1 parent 1cd0696 commit c32a7da

File tree

3 files changed

+77
-25
lines changed

3 files changed

+77
-25
lines changed

samples/dect/dect_phy/dect_shell/src/dect/dect_phy_shell.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,11 @@ static const char dect_phy_ping_cmd_usage_str[] =
742742
" --c_tx_pwr <int>, TX power (dBm),\n"
743743
" [-40,-30,-20,-16,-12,-8,-4,0,4,7,10,13,16,19,21,23].\n"
744744
" Default: from common tx settings.\n"
745+
" --c_tx_lbt_period <cnt>, Listen Before Talk (LBT) period (symbol count).\n"
746+
" Zero value disables LBT (default).\n"
747+
" Valid range for symbol count: 2-110.\n"
748+
" --c_tx_lbt_busy_th <dbm>, LBT busy RSSI threshold (dBm). Valid only when LBT\n"
749+
" is enabled. Default from RSSI busy threshold setting.\n"
745750
" --s_tx_id <id>, Target server transmitter id (default: 38).\n"
746751
" Note: lowest 16bits of transmitter id (long RD ID).\n"
747752
" -e --rx_exp_rssi_level <int>, Set expected RSSI level on RX (dBm).\n"
@@ -771,6 +776,8 @@ enum {
771776
DECT_SHELL_PING_PAYLOAD_SLOT_COUNT,
772777
DECT_SHELL_PING_TX_PWR,
773778
DECT_SHELL_PING_TX_MCS,
779+
DECT_SHELL_PING_TX_LBT_PERIOD,
780+
DECT_SHELL_PING_TX_LBT_RSSI_BUSY_THRESHOLD,
774781
DECT_SHELL_PING_DEST_SERVER_TX_ID,
775782
DECT_SHELL_PING_TX_PWR_CTRL_AUTO,
776783
DECT_SHELL_PING_TX_PWR_CTRL_PDU_RX_EXPECTED_RSSI_LEVEL,
@@ -789,6 +796,8 @@ static struct option long_options_ping[] = {
789796
{"c_slots", required_argument, 0, 'l'},
790797
{"c_tx_pwr", required_argument, 0, DECT_SHELL_PING_TX_PWR},
791798
{"c_tx_mcs", required_argument, 0, DECT_SHELL_PING_TX_MCS},
799+
{"c_tx_lbt_period", required_argument, 0, DECT_SHELL_PING_TX_LBT_PERIOD },
800+
{"c_tx_lbt_busy_th", required_argument, 0, DECT_SHELL_PING_TX_LBT_RSSI_BUSY_THRESHOLD },
792801
{"rx_exp_rssi_level", required_argument, 0, 'e'},
793802
{"s_tx_id", required_argument, 0, DECT_SHELL_PING_DEST_SERVER_TX_ID},
794803
{"tx_pwr_ctrl_pdu_rx_exp_rssi_level", required_argument, 0,
@@ -802,6 +811,7 @@ static int dect_phy_ping_cmd(const struct shell *shell, size_t argc, char **argv
802811
int ret;
803812
int long_index = 0;
804813
int opt;
814+
int tmp_value;
805815

806816
if (argc < 2) {
807817
goto show_usage;
@@ -827,6 +837,8 @@ static int dect_phy_ping_cmd(const struct shell *shell, size_t argc, char **argv
827837
params.expected_rx_rssi_level = current_settings->rx.expected_rssi_level;
828838
params.tx_power_dbm = current_settings->tx.power_dbm;
829839
params.tx_mcs = current_settings->tx.mcs;
840+
params.tx_lbt_period_symbols = 0;
841+
params.tx_lbt_rssi_busy_threshold_dbm = current_settings->rssi_scan.busy_threshold;
830842
params.debugs = true;
831843
params.rssi_reporting_enabled = false;
832844
params.pwr_ctrl_pdu_expected_rx_rssi_level = -60;
@@ -889,6 +901,31 @@ static int dect_phy_ping_cmd(const struct shell *shell, size_t argc, char **argv
889901
params.tx_mcs = atoi(optarg);
890902
break;
891903
}
904+
case DECT_SHELL_PING_TX_LBT_PERIOD: {
905+
tmp_value = atoi(optarg);
906+
if (tmp_value < DECT_PHY_LBT_PERIOD_MIN_SYM ||
907+
tmp_value > DECT_PHY_LBT_PERIOD_MAX_SYM) {
908+
desh_error("Invalid LBT period %d (range: [%d,%d])",
909+
tmp_value,
910+
DECT_PHY_LBT_PERIOD_MIN_SYM,
911+
DECT_PHY_LBT_PERIOD_MAX_SYM);
912+
goto show_usage;
913+
}
914+
params.tx_lbt_period_symbols = tmp_value;
915+
break;
916+
}
917+
case DECT_SHELL_PING_TX_LBT_RSSI_BUSY_THRESHOLD: {
918+
tmp_value = atoi(optarg);
919+
if (tmp_value >= 0 ||
920+
tmp_value < INT8_MIN) {
921+
desh_error("Invalid LBT RSSI busy threshold %d (range: [%d,-1])",
922+
tmp_value,
923+
INT8_MIN);
924+
goto show_usage;
925+
}
926+
params.tx_lbt_rssi_busy_threshold_dbm = tmp_value;
927+
break;
928+
}
892929
case DECT_SHELL_PING_CHANNEL: {
893930
params.channel = atoi(optarg);
894931
break;

samples/dect/dect_phy/dect_shell/src/dect/dect_phy_shell.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ struct dect_phy_ping_params {
106106
int32_t ping_count;
107107
int8_t tx_power_dbm;
108108
uint8_t tx_mcs;
109+
uint8_t tx_lbt_period_symbols;
110+
int8_t tx_lbt_rssi_busy_threshold_dbm;
109111
uint8_t slot_count;
110112

111113
int8_t expected_rx_rssi_level;

samples/dect/dect_phy/dect_shell/src/dect/ping/dect_phy_ping.c

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct dect_phy_ping_tx_metrics {
5555
uint32_t tx_total_data_amount;
5656
uint32_t tx_total_ping_req_count;
5757
uint32_t tx_total_ping_resp_count;
58+
uint32_t tx_failed_due_to_lbt;
5859
};
5960

6061
struct dect_phy_ping_rx_metrics {
@@ -878,7 +879,10 @@ static void dect_phy_ping_client_tx_schedule(uint64_t first_possible_tx)
878879
sched_list_item_conf->length_slots = cmd_params->slot_count;
879880
sched_list_item_conf->length_subslots = 0;
880881

881-
sched_list_item_conf->tx.phy_lbt_period = 0;
882+
sched_list_item_conf->tx.phy_lbt_period = ping_data.client_data.tx_op.lbt_period;
883+
sched_list_item_conf->tx.phy_lbt_rssi_threshold_max =
884+
ping_data.client_data.tx_op.lbt_rssi_threshold_max;
885+
882886
sched_list_item->priority = DECT_PRIORITY1_TX;
883887

884888
sched_list_item_conf->tx.combined_tx_rx_use = true;
@@ -967,7 +971,7 @@ static int dect_phy_ping_client_start(void)
967971

968972
uint64_t time_now = dect_app_modem_time_now();
969973
uint64_t first_possible_tx =
970-
time_now + (2 * US_TO_MODEM_TICKS(current_settings->scheduler.scheduling_delay_us));
974+
time_now + (5 * US_TO_MODEM_TICKS(current_settings->scheduler.scheduling_delay_us));
971975

972976
/* Sending max amount of data that can be encoded to given slot amount */
973977
int16_t ping_pdu_byte_count =
@@ -988,12 +992,14 @@ static int dect_phy_ping_client_start(void)
988992
header.feedback.format1.harq_process_number0 = DECT_HARQ_CLIENT;
989993
}
990994

991-
desh_print("Starting ping client on channel %d: byte count per TX: %d, slots %d, interval "
992-
"%d secs,"
993-
" mcs %d, count %d, timeout %d msecs, HARQ: %s, expected RSSI level on RX %d.",
995+
desh_print("Starting ping client on channel %d:\n"
996+
" byte count per TX: %d, slots %d, interval %d secs,\n"
997+
" mcs %d, LBT period %d, count %d, timeout %d msecs, HARQ: %s,\n"
998+
" expected RSSI level on RX %d.",
994999
params->channel, ping_pdu_byte_count, params->slot_count, params->interval_secs,
995-
params->tx_mcs, params->ping_count, params->timeout_msecs,
996-
(params->use_harq) ? "yes" : "no", params->expected_rx_rssi_level);
1000+
params->tx_mcs, params->tx_lbt_period_symbols, params->ping_count,
1001+
params->timeout_msecs, (params->use_harq) ? "yes" : "no",
1002+
params->expected_rx_rssi_level);
9971003

9981004
uint16_t ping_pdu_payload_byte_count =
9991005
ping_pdu_byte_count - DECT_PHY_PING_TX_DATA_PDU_LEN_WITHOUT_PAYLOAD;
@@ -1025,9 +1031,10 @@ static int dect_phy_ping_client_start(void)
10251031
ping_data.client_data.tx_op.carrier = params->channel;
10261032
ping_data.client_data.tx_op.data_size = ping_pdu_byte_count;
10271033
ping_data.client_data.tx_op.data = encoded_data_to_send;
1028-
ping_data.client_data.tx_op.lbt_period = 0;
1034+
ping_data.client_data.tx_op.lbt_period = params->tx_lbt_period_symbols *
1035+
NRF_MODEM_DECT_SYMBOL_DURATION;
10291036
ping_data.client_data.tx_op.lbt_rssi_threshold_max =
1030-
current_settings->rssi_scan.busy_threshold;
1037+
params->tx_lbt_rssi_busy_threshold_dbm;
10311038

10321039
ping_data.client_data.tx_op.network_id = current_settings->common.network_id;
10331040
ping_data.client_data.tx_op.phy_header = &ping_data.client_data.tx_phy_header;
@@ -1238,6 +1245,8 @@ dect_phy_ping_client_report_local_results_and_req_server_results(int64_t *elapse
12381245
ping_data.tx_metrics.tx_total_data_amount);
12391246
desh_print(" tx: ping req count: %d",
12401247
ping_data.tx_metrics.tx_total_ping_req_count);
1248+
desh_print(" tx: ping failed due to LBT count: %d",
1249+
ping_data.tx_metrics.tx_failed_due_to_lbt);
12411250
desh_print(" rx: ping resp count: %d",
12421251
ping_data.rx_metrics.rx_total_ping_resp_count);
12431252
desh_print(" rx: total amount of data: %d bytes",
@@ -1710,29 +1719,33 @@ static void dect_phy_ping_thread_fn(void)
17101719
struct dect_phy_common_op_completed_params *params =
17111720
(struct dect_phy_common_op_completed_params *)event.data;
17121721

1713-
if (params->status != NRF_MODEM_DECT_PHY_SUCCESS) {
1722+
if (params->status == NRF_MODEM_DECT_PHY_SUCCESS) {
1723+
if (dect_phy_ping_handle_is(params->handle)) {
1724+
dect_phy_ping_mdm_op_completed(params);
1725+
} else if (params->handle == DECT_HARQ_FEEDBACK_TX_HANDLE) {
1726+
desh_print("HARQ feedback sent.");
1727+
}
1728+
} else if (params->status != NRF_MODEM_DECT_PHY_ERR_OP_CANCELED) {
17141729
char tmp_str[128] = {0};
17151730

17161731
dect_common_utils_modem_phy_err_to_string(
17171732
params->status, params->temperature, tmp_str);
1718-
1719-
if (params->status != NRF_MODEM_DECT_PHY_ERR_OP_CANCELED) {
1720-
if (dect_phy_ping_handle_is(params->handle)) {
1721-
desh_warn("%s: ping modem operation failed: %s, "
1722-
"handle %d",
1723-
__func__, tmp_str, params->handle);
1724-
dect_phy_ping_mdm_op_completed(params);
1733+
if (dect_phy_ping_handle_is(params->handle)) {
1734+
if (params->status ==
1735+
NRF_MODEM_DECT_PHY_ERR_LBT_CHANNEL_BUSY) {
1736+
desh_warn("%s: cannot TX ping due to LBT, "
1737+
"channel was busy", __func__);
1738+
ping_data.tx_metrics.tx_failed_due_to_lbt++;
17251739
} else {
1726-
desh_error("%s: operation (handle %d) failed with "
1727-
"status: %s",
1728-
__func__, params->handle, tmp_str);
1740+
desh_warn("%s: ping modem operation "
1741+
"failed: %s, handle %d",
1742+
__func__, tmp_str, params->handle);
17291743
}
1730-
}
1731-
} else {
1732-
if (dect_phy_ping_handle_is(params->handle)) {
17331744
dect_phy_ping_mdm_op_completed(params);
1734-
} else if (params->handle == DECT_HARQ_FEEDBACK_TX_HANDLE) {
1735-
desh_print("HARQ feedback sent.");
1745+
} else {
1746+
desh_error("%s: operation (handle %d) failed with "
1747+
"status: %s",
1748+
__func__, params->handle, tmp_str);
17361749
}
17371750
}
17381751
break;

0 commit comments

Comments
 (0)