Skip to content

Commit 6dffbd9

Browse files
jhirsinordicjm
authored andcommitted
samples: dect_phy: dect_shell: rssi_scan: subslot count based verdict
In addition to default high/low rssi_scan: option for MAC spec like rssi_scan: busy/possible/free subslot count based RSSI scan, hooks: --verdict_type_count and with more details for busy/possible subslots: --verdict_type_count_details Additionally, reporting renewed for the verdicts including the proposal for best possible channel (based on MAC spec). dect sett to have new hook for adjusting default (75%) SCAN_SUITABLE percent: --rssi_scan_suitable_percent Jira: MOSH-592, MOSH-612 Signed-off-by: Jani Hirsimäki <[email protected]>
1 parent b7a776f commit 6dffbd9

File tree

15 files changed

+1046
-313
lines changed

15 files changed

+1046
-313
lines changed

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ DECT NR+ samples
264264
* :ref:`dect_shell_application` sample:
265265

266266
* A brief mac level sample on top of dect_phy api. New commands to create a periodic cluster beacon, scan for it, associate/disassociate a PT/client, and send data to a FT/beacon random access window. Note: this is just a sample/initials of a mac implementation and thus not a full MAC implementation and not fully compliant with dect nr+ mac spec (ETSI TS 103 636-4).
267+
* dect rssi_scan: In addition to default high/low rssi_scan: option for MAC spec like rssi_scan: busy/possible/free subslot count based RSSI scan.
267268

268269
Edge Impulse samples
269270
--------------------

samples/dect/dect_phy/dect_shell/README.rst

Lines changed: 255 additions & 76 deletions
Large diffs are not rendered by default.

samples/dect/dect_phy/dect_shell/src/dect/common/dect_common.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,11 @@ typedef struct {
248248

249249
#define MS_TO_SUBSLOTS(x) (((x) / 10) * 48)
250250

251-
#define DECT_RADIO_SLOT_SYMBOL_COUNT (10)
252-
#define DECT_RADIO_SUBSLOT_SYMBOL_COUNT (5)
251+
#define DECT_RADIO_FRAME_SYMBOL_COUNT \
252+
((NRF_MODEM_DECT_MODEM_TIME_TICK_RATE_KHZ * 10) / NRF_MODEM_DECT_SYMBOL_DURATION)
253253

254-
#define DECT_RADIO_FRAME_SYMBOL_COUNT (DECT_RADIO_FRAME_SLOT_COUNT * DECT_RADIO_SLOT_SYMBOL_COUNT)
254+
#define DECT_RADIO_SLOT_SYMBOL_COUNT (DECT_RADIO_FRAME_SYMBOL_COUNT / DECT_RADIO_FRAME_SLOT_COUNT)
255+
#define DECT_RADIO_SUBSLOT_SYMBOL_COUNT (DECT_RADIO_SLOT_SYMBOL_COUNT / 2)
255256

256257
/******************************************************************************/
257258
#endif /* DECT_COMMON_H */

samples/dect/dect_phy/dect_shell/src/dect/common/dect_common_settings.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ static const struct dect_phy_settings_scheduler phy_scheduler_common_settings =
4040
};
4141

4242
static const struct dect_phy_settings_rssi_scan phy_rssi_scan_settings_data = {
43-
.time_per_channel_ms = (DECT_PHY_SETT_DEFAULT_BEACON_TX_INTERVAL_SECS * 1000) + 10,
43+
.result_verdict_type = DECT_PHY_RSSI_SCAN_RESULT_VERDICT_TYPE_ALL,
44+
.time_per_channel_ms =
45+
(DECT_PHY_SETT_DEFAULT_BEACON_TX_INTERVAL_SECS * 1000) + 10,
46+
.type_subslots_params.scan_suitable_percent = DECT_PHY_SETT_DEFAULT_SCAN_SUITABLE_PERCENT,
47+
4448
.busy_threshold = DECT_PHY_SETT_DEFAULT_RSSI_SCAN_THRESHOLD_MAX,
4549
.free_threshold = DECT_PHY_SETT_DEFAULT_RSSI_SCAN_THRESHOLD_MIN,
4650
};

samples/dect/dect_phy/dect_shell/src/dect/common/dect_common_settings.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@
3939
/* free" if max(RSSI-1) ≤ DECT_PHY_SETT_DEFAULT_RSSI_SCAN_THRESHOLD_MIN*/
4040
#define DECT_PHY_SETT_DEFAULT_RSSI_SCAN_THRESHOLD_MIN -85
4141

42+
/* SCAN_SUITABLE as per MAC spec */
43+
#define DECT_PHY_SETT_DEFAULT_SCAN_SUITABLE_PERCENT 75
44+
45+
/* SCAN_MEAS_DURATION as per MAC spec */
46+
#define DECT_PHY_DETT_DEFAULT_SCAN_MEAS_DURATION_SLOTS 24
47+
4248
/************************************************************************************************/
4349
struct dect_phy_settings_common_tx {
4450
int32_t power_dbm;
@@ -75,11 +81,29 @@ struct dect_phy_settings_scheduler {
7581
uint64_t scheduling_delay_us;
7682
};
7783

84+
enum dect_phy_settings_rssi_scan_result_verdict_type {
85+
/* Result verdicted based on highest/lowest measured RSSI value from all measurements */
86+
DECT_PHY_RSSI_SCAN_RESULT_VERDICT_TYPE_ALL = 1,
87+
88+
/* Result verdicted SCAN_SUITABLE percent subslot count as per MAC spec ch. 5.1.2 */
89+
DECT_PHY_RSSI_SCAN_RESULT_VERDICT_TYPE_SUBSLOT_COUNT = 2,
90+
};
91+
92+
struct dect_phy_settings_rssi_scan_verdict_type_subslot_params {
93+
uint8_t scan_suitable_percent;
94+
bool detail_print;
95+
};
96+
7897
struct dect_phy_settings_rssi_scan {
98+
enum dect_phy_settings_rssi_scan_result_verdict_type result_verdict_type;
99+
struct dect_phy_settings_rssi_scan_verdict_type_subslot_params type_subslots_params;
100+
79101
uint32_t time_per_channel_ms;
102+
80103
int32_t free_threshold; /* if equal or less considered as free */
81104
/* rssi_scanning_busy_threshold <= possible < rssi_scanning_free_threshold*/
82105
int32_t busy_threshold; /* if higher considered as busy */
106+
83107
};
84108
struct dect_phy_settings_common {
85109
uint32_t network_id;

samples/dect/dect_phy/dect_shell/src/dect/common/dect_phy_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ struct dect_phy_data_rcv_common_params {
112112
#define ANSI_COLOR_RED "\x1b[31m"
113113
#define ANSI_COLOR_YELLOW "\x1b[33m"
114114
#define ANSI_COLOR_GREEN "\x1b[32m"
115+
#define ANSI_COLOR_BLUE "\x1b[34m"
115116

116117
#define DECT_TX_STATUS_LED DK_LED1 /* Thingy91x: red */
117118
#define DECT_BEACON_ON_STATUS_LED DK_LED2 /* Thingy91x: blue */

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

Lines changed: 92 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ static struct dect_phy_ctrl_data {
7474
bool rssi_scan_on_going;
7575
bool rssi_scan_cmd_running;
7676
struct dect_phy_rssi_scan_params rssi_scan_params;
77-
struct dect_phy_rssi_channel_scan_result_t rssi_scan_results;
7877
dect_phy_ctrl_rssi_scan_completed_callback_t rssi_scan_complete_cb;
7978

8079
/* Registered callbacks for ext command usage */
@@ -91,8 +90,7 @@ K_SEM_DEFINE(phy_api_init, 0, 1);
9190

9291
/**************************************************************************************************/
9392

94-
static void dect_phy_rssi_channel_scan_callback(
95-
struct dect_phy_rssi_channel_scan_result_t *p_scan_results);
93+
static void dect_phy_rssi_channel_scan_completed_cb(enum nrf_modem_dect_phy_err phy_status);
9694
static void dect_phy_ctrl_on_modem_lib_init(int ret, void *ctx);
9795

9896
/**************************************************************************************************/
@@ -386,21 +384,30 @@ static void dect_phy_ctrl_msgq_thread_handler(void)
386384
}
387385

388386
case DECT_PHY_CTRL_OP_RSSI_SCAN_RUN: {
387+
int err = 0;
388+
389389
if (ctrl_data.rssi_scan_on_going ||
390390
(ctrl_data.rssi_scan_cmd_running &&
391391
ctrl_data.rssi_scan_params.interval_secs)) {
392392
if (ctrl_data.rssi_scan_params.suspend_scheduler) {
393393
dect_phy_api_scheduler_suspend();
394394
}
395-
dect_phy_scan_rssi_start(&ctrl_data.rssi_scan_params,
396-
dect_phy_rssi_channel_scan_callback);
395+
err = dect_phy_scan_rssi_start(
396+
&ctrl_data.rssi_scan_params,
397+
dect_phy_rssi_channel_scan_completed_cb);
398+
if (err) {
399+
desh_error("RSSI scan start failed: %d", err);
400+
dect_phy_ctrl_rssi_scan_stop();
401+
}
397402
}
398403
break;
399404
}
400405
case DECT_PHY_CTRL_OP_PHY_API_MDM_RSSI_CB_ON_RX_OP: {
401406
if (ctrl_data.rx_cmd_on_going || ctrl_data.ext_command_running) {
402407
dect_phy_scan_rssi_finished_handle(NRF_MODEM_DECT_PHY_SUCCESS);
403-
dect_phy_scan_rssi_data_reinit_with_current_params();
408+
if (dect_phy_scan_rssi_data_reinit_with_current_params()) {
409+
desh_error("Cannot reinit rssi scan data");
410+
}
404411
}
405412
break;
406413
}
@@ -613,7 +620,7 @@ static void dect_phy_ctrl_mdm_on_rssi_cb(const uint64_t *time,
613620
{
614621
dect_app_modem_time_save(time);
615622

616-
if (ctrl_data.rssi_scan_on_going) {
623+
if (ctrl_data.rssi_scan_on_going || ctrl_data.rx_cmd_on_going) {
617624
dect_phy_scan_rssi_cb_handle(NRF_MODEM_DECT_PHY_SUCCESS, p_result);
618625
} else if (ctrl_data.ext_cmd.direct_rssi_cb != NULL) {
619626
ctrl_data.ext_cmd.direct_rssi_cb(p_result);
@@ -782,13 +789,18 @@ int dect_phy_ctrl_rx_start(struct dect_phy_rx_cmd_params *params)
782789

783790
struct dect_phy_rssi_scan_params rssi_params = {
784791
.channel = params->channel,
792+
.result_verdict_type = DECT_PHY_RSSI_SCAN_RESULT_VERDICT_TYPE_ALL,
785793
.busy_rssi_limit = params->busy_rssi_limit,
786794
.free_rssi_limit = params->free_rssi_limit,
787795
.interval_secs = params->rssi_interval_secs,
788796
};
789797

790798
ctrl_data.rx_cmd_params = *params;
791-
dect_phy_scan_rssi_data_init(&rssi_params);
799+
err = dect_phy_scan_rssi_data_init(&rssi_params);
800+
if (err) {
801+
desh_error("RSSI scan data init failed: err", err);
802+
return err;
803+
}
792804

793805
err = dect_phy_rx_msgq_data_op_add(DECT_PHY_RX_OP_START, (void *)params,
794806
sizeof(struct dect_phy_rx_cmd_params));
@@ -865,48 +877,88 @@ void dect_phy_ctrl_status_get_n_print(void)
865877

866878
/**************************************************************************************************/
867879

880+
int dect_phy_ctrl_rssi_scan_results_print_and_best_channel_get(bool print_results)
881+
{
882+
struct dect_phy_rssi_scan_channel_results scan_results;
883+
int err = dect_phy_scan_rssi_channel_results_get(&scan_results);
884+
int best_channel = -ENODATA;
885+
886+
if (err) {
887+
desh_error("RSSI scan results not available.");
888+
return -ENODATA;
889+
}
890+
best_channel = dect_phy_scan_rssi_results_based_best_channel_get();
891+
892+
if (print_results) {
893+
desh_print("--------------------------------------------------------------"
894+
"---------------");
895+
desh_print(" RSSI scan done. Found %d free, %d possible and "
896+
"%d busy channels.",
897+
scan_results.free_channels_count, scan_results.possible_channels_count,
898+
scan_results.busy_channels_count);
899+
}
900+
901+
if (best_channel <= 0) {
902+
desh_print(" No best channel found.");
903+
return -ENODATA;
904+
}
905+
906+
char final_verdict_str[10];
907+
struct dect_phy_rssi_scan_data_result scan_result;
908+
909+
if (print_results) {
910+
desh_print(" Best channel: %d", best_channel);
911+
}
912+
913+
err = dect_phy_scan_rssi_results_get_by_channel(best_channel, &scan_result);
914+
if (err) {
915+
desh_warn(" No scan result found for best channel.");
916+
return best_channel;
917+
}
918+
919+
if (print_results) {
920+
dect_phy_rssi_scan_result_verdict_to_string(scan_result.result, final_verdict_str);
921+
922+
desh_print(" Final verdict: %s", final_verdict_str);
923+
924+
if (ctrl_data.rssi_scan_params.result_verdict_type ==
925+
DECT_PHY_RSSI_SCAN_RESULT_VERDICT_TYPE_SUBSLOT_COUNT) {
926+
desh_print(" Free subslots: %d",
927+
scan_result.subslot_count_type_results.free_subslot_count);
928+
desh_print(" Possible subslots: %d",
929+
scan_result.subslot_count_type_results.possible_subslot_count);
930+
desh_print(" Busy subslots: %d",
931+
scan_result.subslot_count_type_results.busy_subslot_count);
932+
}
933+
}
934+
return best_channel;
935+
}
936+
868937
static void dect_phy_ctrl_rssi_scan_timer_handler(struct k_timer *timer_id)
869938
{
870939
dect_phy_ctrl_msgq_non_data_op_add(DECT_PHY_CTRL_OP_RSSI_SCAN_RUN);
871940
}
872941
K_TIMER_DEFINE(rssi_scan_timer, dect_phy_ctrl_rssi_scan_timer_handler, NULL);
873942

874-
static void dect_phy_rssi_channel_scan_callback(
875-
struct dect_phy_rssi_channel_scan_result_t *p_scan_results)
943+
static void dect_phy_rssi_channel_scan_completed_cb(enum nrf_modem_dect_phy_err phy_status)
876944
{
877-
memcpy(ctrl_data.rssi_scan_results.free_channels, p_scan_results->free_channels,
878-
p_scan_results->free_channels_count * sizeof(uint16_t));
879-
ctrl_data.rssi_scan_results.free_channels_count = p_scan_results->free_channels_count;
880-
881-
memcpy(ctrl_data.rssi_scan_results.possible_channels, p_scan_results->possible_channels,
882-
p_scan_results->possible_channels_count * sizeof(uint16_t));
883-
ctrl_data.rssi_scan_results.possible_channels_count =
884-
p_scan_results->possible_channels_count;
885-
886-
memcpy(ctrl_data.rssi_scan_results.busy_channels, p_scan_results->busy_channels,
887-
p_scan_results->busy_channels_count * sizeof(uint16_t));
888-
ctrl_data.rssi_scan_results.busy_channels_count = p_scan_results->busy_channels_count;
889-
890-
desh_print(" RSSI scan done. Found %d free, %d possible and %d busy channels.",
891-
ctrl_data.rssi_scan_results.free_channels_count,
892-
ctrl_data.rssi_scan_results.possible_channels_count,
893-
ctrl_data.rssi_scan_results.busy_channels_count);
945+
(void)dect_phy_ctrl_rssi_scan_results_print_and_best_channel_get(true);
894946

895-
if (p_scan_results->phy_status == NRF_MODEM_DECT_PHY_SUCCESS) {
947+
if (phy_status == NRF_MODEM_DECT_PHY_SUCCESS) {
896948
k_sem_give(&rssi_scan_sema);
897949
} else {
898950
char tmp_str[128] = {0};
899951

900952
dect_common_utils_modem_phy_err_to_string(
901-
p_scan_results->phy_status, NRF_MODEM_DECT_PHY_TEMP_NOT_MEASURED, tmp_str);
953+
phy_status, NRF_MODEM_DECT_PHY_TEMP_NOT_MEASURED, tmp_str);
902954

903955
k_sem_reset(&rssi_scan_sema); /* -EAGAIN should be returned from k_sem_take() */
904-
desh_warn(" RSSI scan failed: %s (%d)", tmp_str, p_scan_results->phy_status);
956+
desh_warn(" RSSI scan failed: %s (%d)", tmp_str, phy_status);
905957
}
906958
dect_phy_api_scheduler_resume();
907959
ctrl_data.rssi_scan_on_going = false;
908960
if (ctrl_data.rssi_scan_complete_cb) {
909-
ctrl_data.rssi_scan_complete_cb(p_scan_results->phy_status);
961+
ctrl_data.rssi_scan_complete_cb(phy_status);
910962
}
911963
if (ctrl_data.rssi_scan_cmd_running && ctrl_data.rssi_scan_params.interval_secs) {
912964
k_timer_start(&rssi_scan_timer, K_SECONDS(ctrl_data.rssi_scan_params.interval_secs),
@@ -1177,8 +1229,16 @@ bool dect_phy_ctrl_phy_api_scheduler_suspended(void)
11771229

11781230
int dect_phy_ctrl_ext_command_start(struct dect_phy_ctrl_ext_callbacks ext_callbacks)
11791231
{
1180-
if (!dect_phy_ctrl_mdm_phy_api_initialized() || ctrl_data.rssi_scan_on_going ||
1232+
if (!dect_phy_ctrl_mdm_phy_api_initialized()) {
1233+
desh_error("(%s): Phy api not initialized", (__func__));
1234+
return -EACCES;
1235+
}
1236+
1237+
if (ctrl_data.rssi_scan_on_going ||
11811238
ctrl_data.perf_on_going || ctrl_data.ping_on_going) {
1239+
desh_error("(%s): Operation already on going. "
1240+
"Stop all before starting running ext command.",
1241+
(__func__));
11821242
return -EBUSY;
11831243
}
11841244
ctrl_data.ext_cmd = ext_callbacks;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ int dect_phy_ctrl_rssi_scan_start(
5858
dect_phy_ctrl_rssi_scan_completed_callback_t fp_result_callback);
5959
void dect_phy_ctrl_rssi_scan_stop(void);
6060

61+
int dect_phy_ctrl_rssi_scan_results_print_and_best_channel_get(bool print_results);
62+
6163
/******************************************************************************/
6264

6365
bool dect_phy_ctrl_mdm_phy_api_initialized(void);

0 commit comments

Comments
 (0)