From 19737078565965dff8397ec4f104e67fe44fe27d Mon Sep 17 00:00:00 2001 From: Nordic Builder Date: Mon, 20 Jan 2025 15:17:08 +0000 Subject: [PATCH 1/3] manifest: Update sdk-nrfxlib revision (auto-manifest PR) Automatically created by Github Action Signed-off-by: Nordic Builder --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 06ca7ab6913..dc178519e9c 100644 --- a/west.yml +++ b/west.yml @@ -147,7 +147,7 @@ manifest: - name: nrfxlib repo-path: sdk-nrfxlib path: nrfxlib - revision: b5c1a8486da16af75d36a6221d677768bc9556a6 + revision: pull/1637/head - name: trusted-firmware-m repo-path: sdk-trusted-firmware-m path: modules/tee/tf-m/trusted-firmware-m From f778479ca88e9b84baa6563ea9a5669a5e46e7be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jani=20Hirsim=C3=A4ki?= Date: Wed, 22 Jan 2025 11:31:14 +0200 Subject: [PATCH 2/3] samples: dect_phy: dect_shell: modem 1.1 support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Major modem/libmodem api update. Also did related changes: - new commands: activate/deactivate, radio_mode - new setting: startup radio mode for activation - pcc/pdc rx includes handle but not carrier/channel, thus keeping up to date information for that. - ping/perf/rf_tool: still own callbacks but no reinit of phy api, doing cancel(all) instead. - rf_tool: decreased --frame_repeat_count default to 15. - rf_tool: "rf_tool command done" print at the end. - radio mode query is used. - latency info usage is added. Jira: MOSH-621 Signed-off-by: Jani Hirsimäki --- samples/dect/dect_phy/dect_shell/README.rst | 34 +- .../dect_shell/src/dect/common/dect_common.h | 9 + .../src/dect/common/dect_common_settings.c | 2 + .../src/dect/common/dect_common_settings.h | 4 +- .../src/dect/common/dect_common_utils.c | 34 +- .../src/dect/common/dect_common_utils.h | 8 + .../src/dect/common/dect_phy_api_scheduler.c | 21 +- .../src/dect/common/dect_phy_api_scheduler.h | 4 +- .../src/dect/common/dect_phy_common.h | 19 +- .../src/dect/common/dect_phy_common_rx.c | 49 +- .../src/dect/common/dect_phy_common_rx.h | 7 +- .../dect_shell/src/dect/dect_phy_ctrl.c | 1088 ++++++++++++----- .../dect_shell/src/dect/dect_phy_ctrl.h | 38 +- .../dect_shell/src/dect/dect_phy_scan.c | 69 +- .../dect_shell/src/dect/dect_phy_scan.h | 2 +- .../dect_shell/src/dect/dect_phy_shell.c | 222 +++- .../dect_shell/src/dect/dect_phy_shell.h | 3 +- .../dect_shell/src/dect/mac/dect_phy_mac.c | 14 +- .../src/dect/mac/dect_phy_mac_client.c | 4 +- .../dect/mac/dect_phy_mac_cluster_beacon.c | 2 +- .../dect/mac/dect_phy_mac_cluster_beacon.h | 2 +- .../src/dect/mac/dect_phy_mac_ctrl.c | 50 +- .../src/dect/mac/dect_phy_mac_nbr.c | 15 +- .../dect_shell/src/dect/perf/dect_phy_perf.c | 298 ++--- .../dect_shell/src/dect/ping/dect_phy_ping.c | 311 ++--- .../src/dect/rf_tool/dect_phy_rf_tool.c | 271 ++-- samples/dect/dect_phy/dect_shell/src/main.c | 4 +- .../dect_shell/src/utils/desh_print.c | 16 +- 28 files changed, 1581 insertions(+), 1019 deletions(-) diff --git a/samples/dect/dect_phy/dect_shell/README.rst b/samples/dect/dect_phy/dect_shell/README.rst index 3f952b4693d..92945e9c38d 100644 --- a/samples/dect/dect_phy/dect_shell/README.rst +++ b/samples/dect/dect_phy/dect_shell/README.rst @@ -38,7 +38,10 @@ Main command structure: .. code-block:: console dect + activate + deactivate sett + radio_mode rssi_scan ping perf @@ -286,15 +289,6 @@ Example 2: HARQ dect perf -c --c_gap_subslots 4 --c_tx_mcs 4 --c_slots 4 --s_tx_id 39 -t 12 --c_harq_feedback_rx_delay_subslots 2 --c_harq_feedback_rx_subslots 3 --c_harq_process_nbr_max 7 -a --channel 1671 -* Client side: Decrease default scheduler delay and rerun the previous step: - - .. code-block:: console - - dect sett -d 5000 - - .. note:: - Set the delay back to default to avoid scheduler problems on other use cases. - RX/TX testing with RF tool ========================== @@ -329,13 +323,13 @@ Example 1: bi-directional testing .. code-block:: console dect sett -t 39 - dect rf_tool -m rx_tx --rx_find_sync --frame_repeat_count 50 --frame_repeat_count_intervals 10 -c 1677 + dect rf_tool -m rx_tx --rx_find_sync --frame_repeat_count 15 --frame_repeat_count_intervals 10 -c 1677 * Client side: Trigger to start operation: .. code-block:: console - dect rf_tool -m rx_tx --frame_repeat_count 50 --frame_repeat_count_intervals 10 -t 39 -c 1677 + dect rf_tool -m rx_tx --frame_repeat_count 15 --frame_repeat_count_intervals 10 -t 39 -c 1677 Example 2: unidirectional testing --------------------------------- @@ -346,7 +340,7 @@ Example 2: unidirectional testing .. code-block:: console dect sett -t 39 - dect rf_tool -m rx --rx_find_sync --frame_repeat_count 50 -c 1677 + dect rf_tool -m rx --rx_find_sync --frame_repeat_count 15 -c 1677 * RX device option 2: RX device on ``rx_cont`` mode: @@ -360,13 +354,13 @@ Example 2: unidirectional testing .. code-block:: console dect sett -t 39 - dect rf_tool -m rx_cont --rf_mode_peer tx --frame_repeat_count 50 --rx_find_sync -c 1677 + dect rf_tool -m rx_cont --rf_mode_peer tx --frame_repeat_count 15 --rx_find_sync -c 1677 * TX device: Trigger to start operation: .. code-block:: console - dect rf_tool -m tx --frame_repeat_count 50 -c 1677 -t 39 + dect rf_tool -m tx --frame_repeat_count 15 -c 1677 -t 39 * RX device with option 2: Stop continuous RX to give a report: @@ -388,20 +382,20 @@ Example 3: duty cycle (RX+TX) testing .. code-block:: console server: - dect rf_tool -m rx_tx --rx_find_sync --rx_subslot_count 9 --rx_idle_subslot_count 3 --tx_subslot_count 8 --tx_idle_subslot_count 3 --frame_repeat_count 50 -c 1677 + dect rf_tool -m rx_tx --rx_find_sync --rx_subslot_count 9 --rx_idle_subslot_count 3 --tx_subslot_count 8 --tx_idle_subslot_count 3 --frame_repeat_count 15 -c 1677 client: - dect rf_tool -m rx_tx --rx_subslot_count 9 --rx_idle_subslot_count 3 --tx_subslot_count 8 --tx_idle_subslot_count 3 --frame_repeat_count 50 -c 1677 -t 39 + dect rf_tool -m rx_tx --rx_subslot_count 9 --rx_idle_subslot_count 3 --tx_subslot_count 8 --tx_idle_subslot_count 3 --frame_repeat_count 15 -c 1677 -t 39 RX/TX duty cycle percentage 82.50%: .. code-block:: console server: - dect rf_tool -m rx_tx --rx_find_sync --rx_subslot_count 17 --rx_idle_subslot_count 3 --tx_subslot_count 16 --tx_idle_subslot_count 4 --frame_repeat_count 50 -c 1677 + dect rf_tool -m rx_tx --rx_find_sync --rx_subslot_count 17 --rx_idle_subslot_count 3 --tx_subslot_count 16 --tx_idle_subslot_count 4 --frame_repeat_count 15 -c 1677 client: - dect rf_tool -m rx_tx --rx_subslot_count 17 --rx_idle_subslot_count 3 --tx_subslot_count 16 --tx_idle_subslot_count 4 --frame_repeat_count 50 -c 1677 -t 39 + dect rf_tool -m rx_tx --rx_subslot_count 17 --rx_idle_subslot_count 3 --tx_subslot_count 16 --tx_idle_subslot_count 4 --frame_repeat_count 15 -c 1677 -t 39 * TX/RX testing on separate devices: @@ -433,10 +427,10 @@ Example 4: Bi-directional testing with more data .. code-block:: console server: - dect rf_tool -m rx_tx --rx_find_sync --rx_subslot_count 9 --rx_idle_subslot_count 4 --tx_subslot_count 8 --tx_idle_subslot_count 4 --tx_mcs 4 --frame_repeat_count 50 -c 1677 + dect rf_tool -m rx_tx --rx_find_sync --rx_subslot_count 9 --rx_idle_subslot_count 4 --tx_subslot_count 8 --tx_idle_subslot_count 4 --tx_mcs 4 --frame_repeat_count 15 -c 1677 client: - dect rf_tool -m rx_tx --rx_subslot_count 9 --rx_idle_subslot_count 4 --tx_subslot_count 8 --tx_idle_subslot_count 4 --tx_mcs 4 --frame_repeat_count 50 -c 1677 --tx_pwr 15 -t 39 + dect rf_tool -m rx_tx --rx_subslot_count 9 --rx_idle_subslot_count 4 --tx_subslot_count 8 --tx_idle_subslot_count 4 --tx_mcs 4 --frame_repeat_count 15 -c 1677 --tx_pwr 15 -t 39 Dect NR+ PHY MAC ================ diff --git a/samples/dect/dect_phy/dect_shell/src/dect/common/dect_common.h b/samples/dect/dect_phy/dect_shell/src/dect/common/dect_common.h index b3fa1e57ed3..26f9443aa96 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/common/dect_common.h +++ b/samples/dect/dect_phy/dect_shell/src/dect/common/dect_common.h @@ -213,6 +213,15 @@ typedef struct { #define DECT_PHY_SUPPORTED_CHANNEL_BAND22_MIN 1691 #define DECT_PHY_SUPPORTED_CHANNEL_BAND22_MAX 1711 +#define DESH_DECT_PHY_SUPPORTED_BAND_COUNT 5 + +/************************************************************************************************/ + +#define DECT_PHY_CLASS_1_MAX_TX_POWER_DBM 23 +#define DECT_PHY_CLASS_2_MAX_TX_POWER_DBM 21 +#define DECT_PHY_CLASS_3_MAX_TX_POWER_DBM 19 +#define DECT_PHY_CLASS_4_MAX_TX_POWER_DBM 10 + /************************************************************************************************/ #define US_TO_MODEM_TICKS(x) ((uint64_t)(((x) * NRF_MODEM_DECT_MODEM_TIME_TICK_RATE_KHZ) / 1000)) diff --git a/samples/dect/dect_phy/dect_shell/src/dect/common/dect_common_settings.c b/samples/dect/dect_phy/dect_shell/src/dect/common/dect_common_settings.c index 474eac23422..20de04a4883 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/common/dect_common_settings.c +++ b/samples/dect/dect_phy/dect_shell/src/dect/common/dect_common_settings.c @@ -53,6 +53,8 @@ static const struct dect_phy_settings_common phy_common_settings_data = { .network_id = DECT_PHY_DEFAULT_NETWORK_ID, .transmitter_id = DECT_PHY_DEFAULT_TRANSMITTER_LONG_RD_ID, .band_nbr = 1, + .activate_at_startup = true, + .startup_radio_mode = NRF_MODEM_DECT_PHY_RADIO_MODE_LOW_LATENCY, }; static const struct dect_phy_settings phy_settings_data_defaults = { diff --git a/samples/dect/dect_phy/dect_shell/src/dect/common/dect_common_settings.h b/samples/dect/dect_phy/dect_shell/src/dect/common/dect_common_settings.h index 196e755bdf0..e7868d7089b 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/common/dect_common_settings.h +++ b/samples/dect/dect_phy/dect_shell/src/dect/common/dect_common_settings.h @@ -16,7 +16,7 @@ #define DECT_PHY_DEFAULT_NETWORK_ID 0x12345678 #define DECT_PHY_DEFAULT_TRANSMITTER_LONG_RD_ID 38 -#define DECT_PHY_API_SCHEDULER_OFFSET_US (10000) +#define DECT_PHY_API_SCHEDULER_OFFSET_US (5000) #define DECT_PHY_SETT_DEFAULT_BEACON_TX_INTERVAL_SECS 2 @@ -109,6 +109,8 @@ struct dect_phy_settings_common { uint32_t network_id; uint32_t transmitter_id; uint16_t band_nbr; + bool activate_at_startup; + enum nrf_modem_dect_phy_radio_mode startup_radio_mode; uint16_t short_rd_id; /* Generated random value, cannot be set */ }; diff --git a/samples/dect/dect_phy/dect_shell/src/dect/common/dect_common_utils.c b/samples/dect/dect_phy/dect_shell/src/dect/common/dect_common_utils.c index bc02504e1a7..8a4ff0b9606 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/common/dect_common_utils.c +++ b/samples/dect/dect_phy/dect_shell/src/dect/common/dect_common_utils.c @@ -229,7 +229,7 @@ const char *dect_common_utils_modem_phy_err_to_string(enum nrf_modem_dect_phy_er {NRF_MODEM_DECT_PHY_SUCCESS, "NRF_MODEM_DECT_PHY_SUCCESS"}, {NRF_MODEM_DECT_PHY_ERR_LBT_CHANNEL_BUSY, "ERR_LBT_CHANNEL_BUSY"}, {NRF_MODEM_DECT_PHY_ERR_UNSUPPORTED_OP, "ERR_UNSUPPORTED_OP"}, - {NRF_MODEM_DECT_PHY_ERR_NO_ONGOING_OP, "ERR_NO_ONGOING_OP"}, + {NRF_MODEM_DECT_PHY_ERR_NOT_FOUND, "ERR_NOT_FOUND"}, {NRF_MODEM_DECT_PHY_ERR_NO_MEMORY, "ERR_NO_MEMORY"}, {NRF_MODEM_DECT_PHY_ERR_NOT_ALLOWED, "ERR_NOT_ALLOWED"}, {NRF_MODEM_DECT_PHY_OK_WITH_HARQ_RESET, "PHY_OK_WITH_HARQ_RESET"}, @@ -244,15 +244,18 @@ const char *dect_common_utils_modem_phy_err_to_string(enum nrf_modem_dect_phy_er {NRF_MODEM_DECT_PHY_ERR_PAYLOAD_UNAVAILABLE, "ERR_PAYLOAD_UNAVAILABLE"}, {NRF_MODEM_DECT_PHY_ERR_OP_CANCELED, "PHY_ERR_OP_CANCELED"}, {NRF_MODEM_DECT_PHY_ERR_COMBINED_OP_FAILED, "ERR_COMBINED_OP_FAILED"}, + {NRF_MODEM_DECT_PHY_ERR_RADIO_MODE_CONFLICT, "ERR_RADIO_MODE_CONFLICT"}, {NRF_MODEM_DECT_PHY_ERR_UNSUPPORTED_CARRIER, "ERR_UNSUPPORTED_CARRIER"}, {NRF_MODEM_DECT_PHY_ERR_UNSUPPORTED_DATA_SIZE, "ERR_UNSUPPORTED_DATA_SIZE"}, {NRF_MODEM_DECT_PHY_ERR_INVALID_NETWORK_ID, "ERR_INVALID_NETWORK_ID"}, {NRF_MODEM_DECT_PHY_ERR_INVALID_PHY_HEADER, "ERR_INVALID_PHY_HEADER"}, {NRF_MODEM_DECT_PHY_ERR_INVALID_DURATION, "ERR_INVALID_DURATION"}, {NRF_MODEM_DECT_PHY_ERR_INVALID_PARAMETER, "ERR_INVALID_PARAMETER"}, + {NRF_MODEM_DECT_PHY_ERR_TX_POWER_OVER_MAX_LIMIT, "ERR_TX_POWER_OVER_MAX_LIMIT"}, {NRF_MODEM_DECT_PHY_ERR_MODEM_ERROR, "ERR_MODEM_ERROR"}, {NRF_MODEM_DECT_PHY_ERR_MODEM_ERROR_RF_STATE, "ERR_MODEM_ERROR_RF_STATE"}, {NRF_MODEM_DECT_PHY_ERR_TEMP_HIGH, "ERR_TEMP_HIGH"}, + {NRF_MODEM_DECT_PHY_ERR_PROD_LOCK, "ERR_PROD_LOCK"}, /* Specific internal errors: */ {DECT_SCHEDULER_DELAYED_ERROR, "DECT_SCHEDULER_DELAYED_ERROR"}, {DECT_SCHEDULER_SCHEDULER_FATAL_MEM_ALLOC_ERROR, @@ -489,3 +492,32 @@ bool dect_common_utils_mdm_ticks_is_in_range(uint64_t time, uint64_t start, uint { return (time >= start && time <= end); } + +/**************************************************************************************************/ + +const char *dect_common_utils_radio_mode_to_string(int mode, char *out_str_buff) +{ + struct mapping_tbl_item const mapping_table[] = { + {NRF_MODEM_DECT_PHY_RADIO_MODE_LOW_LATENCY, "Low latency"}, + {NRF_MODEM_DECT_PHY_RADIO_MODE_LOW_LATENCY_WITH_STANDBY, + "Low latency with standby"}, + {NRF_MODEM_DECT_PHY_RADIO_MODE_NON_LBT_WITH_STANDBY, "LBT disabled, with standby"}, + {-1, NULL}}; + + return dect_common_utils_map_to_string(mapping_table, mode, out_str_buff); +} + +/**************************************************************************************************/ + +int8_t dect_common_utils_max_tx_pwr_dbm_by_pwr_class(uint8_t power_class) +{ + if (power_class == 1) { + return DECT_PHY_CLASS_1_MAX_TX_POWER_DBM; + } else if (power_class == 2) { + return DECT_PHY_CLASS_2_MAX_TX_POWER_DBM; + } else if (power_class == 3) { + return DECT_PHY_CLASS_3_MAX_TX_POWER_DBM; + } else { + return DECT_PHY_CLASS_4_MAX_TX_POWER_DBM; + } +} diff --git a/samples/dect/dect_phy/dect_shell/src/dect/common/dect_common_utils.h b/samples/dect/dect_phy/dect_shell/src/dect/common/dect_common_utils.h index 2b5d7e95d14..fa8cc78224a 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/common/dect_common_utils.h +++ b/samples/dect/dect_phy/dect_shell/src/dect/common/dect_common_utils.h @@ -94,4 +94,12 @@ bool dect_common_utils_32bit_network_id_validate(uint32_t network_id); bool dect_common_utils_mdm_ticks_is_in_range(uint64_t time, uint64_t start, uint64_t end); +/******************************************************************************/ + +const char *dect_common_utils_radio_mode_to_string(int mode, char *out_str_buff); + +/******************************************************************************/ + +int8_t dect_common_utils_max_tx_pwr_dbm_by_pwr_class(uint8_t power_class); + #endif /* DECT_COMMON_UTILS_H */ diff --git a/samples/dect/dect_phy/dect_shell/src/dect/common/dect_phy_api_scheduler.c b/samples/dect/dect_phy/dect_shell/src/dect/common/dect_phy_api_scheduler.c index f8911e875e1..321384b354e 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/common/dect_phy_api_scheduler.c +++ b/samples/dect/dect_phy/dect_shell/src/dect/common/dect_phy_api_scheduler.c @@ -14,6 +14,8 @@ #include "dect_common_settings.h" #include "dect_phy_common_rx.h" +#include "dect_phy_ctrl.h" + #include "dect_phy_api_scheduler_integration.h" #include "dect_phy_api_scheduler.h" @@ -64,7 +66,6 @@ static void dect_phy_api_scheduler_led_off_timer_handler(struct k_timer *timer_i static bool dect_phy_api_scheduler_list_remove_from_tail(void); static void dect_phy_api_scheduler_list_purge(void); -static bool dect_phy_api_scheduler_list_is_empty(void); static struct dect_phy_api_scheduler_list_item * dect_phy_api_scheduler_done_list_item_add(struct dect_phy_api_scheduler_list_item *new_list_item); @@ -212,7 +213,7 @@ static bool dect_phy_api_scheduler_list_remove_from_tail(void) return return_value; } -static bool dect_phy_api_scheduler_list_is_empty(void) +bool dect_phy_api_scheduler_list_is_empty(void) { return sys_dlist_is_empty(&to_be_sheduled_list); } @@ -476,11 +477,12 @@ struct dect_phy_api_scheduler_list_item * dect_phy_api_scheduler_list_item_add(struct dect_phy_api_scheduler_list_item *new_list_item) { struct dect_phy_api_scheduler_list_item *iterator = NULL; - const uint32_t scheduler_offset = DECT_PHY_TX_RX_SCHEDULING_OFFSET_MDM_TICKS; if (new_list_item == NULL) { return NULL; } + uint32_t scheduler_offset = dect_phy_ctrl_modem_latency_min_margin_between_ops_get(); + const uint64_t new_frame_time = new_list_item->sched_config.frame_time; const uint64_t next_frame_time = new_frame_time + DECT_RADIO_FRAME_DURATION_IN_MODEM_TICKS; const uint64_t new_length_mdm_ticks = @@ -888,18 +890,6 @@ dect_phy_api_scheduler_done_list_item_find_by_phy_handle(uint32_t handle) return iterator; } -static void dect_phy_api_scheduler_done_list_items_stop_in_modem(void) -{ - struct dect_phy_api_scheduler_list_item *iterator = NULL; - - SYS_DLIST_FOR_EACH_CONTAINER(&done_sheduled_list, iterator, dnode) { - if (!iterator->stop_requested) { - (void)nrf_modem_dect_phy_rx_stop(iterator->phy_op_handle); - iterator->stop_requested = true; - } - } -} - static void dect_phy_api_scheduler_done_list_mdm_op_complete( struct dect_phy_common_op_completed_params *params, struct dect_phy_api_scheduler_list_item *list_item) @@ -1499,7 +1489,6 @@ static void dect_phy_api_scheduler_th_handler(void) } case DECT_PHY_API_EVENT_SCHEDULER_OP_SUSPEND: { scheduler_data.state = SCHEDULER_STATE_SUSPENDED; - dect_phy_api_scheduler_done_list_items_stop_in_modem(); dect_phy_api_scheduler_suspended_evt_send(); break; } diff --git a/samples/dect/dect_phy/dect_shell/src/dect/common/dect_phy_api_scheduler.h b/samples/dect/dect_phy/dect_shell/src/dect/common/dect_phy_api_scheduler.h index b57c8090e16..667c200ce59 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/common/dect_phy_api_scheduler.h +++ b/samples/dect/dect_phy/dect_shell/src/dect/common/dect_phy_api_scheduler.h @@ -13,7 +13,7 @@ /* Following defines the time how much in advance is scheduled to modem */ #define DECT_PHY_API_SCHEDULER_OP_TIME_WINDOW_MS 500 -#define DECT_PHY_API_SCHEDULER_OP_MAX_COUNT 20 +#define DECT_PHY_API_SCHEDULER_OP_MAX_COUNT 30 #define DECT_SCHEDULER_DELAYED_ERROR 6666 #define DECT_SCHEDULER_SCHEDULER_FATAL_MEM_ALLOC_ERROR 6667 @@ -217,6 +217,8 @@ void dect_phy_api_scheduler_list_delete_all_items(void); /* purge */ uint64_t dect_phy_api_scheduler_list_item_last_scheduled_modem_frame_time_get(void); +bool dect_phy_api_scheduler_list_is_empty(void); + /**************************************************************************************************/ /* Scheduler done list API */ diff --git a/samples/dect/dect_phy/dect_shell/src/dect/common/dect_phy_common.h b/samples/dect/dect_phy/dect_shell/src/dect/common/dect_phy_common.h index b454d1bf7c0..1eef8448d91 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/common/dect_phy_common.h +++ b/samples/dect/dect_phy/dect_shell/src/dect/common/dect_phy_common.h @@ -15,8 +15,6 @@ /******************************************************************************/ -#define DECT_PHY_MAX_TX_PWR_DBM 23 - #define DECT_PHY_LBT_PERIOD_MAX_SYM (NRF_MODEM_DECT_LBT_PERIOD_MAX / NRF_MODEM_DECT_SYMBOL_DURATION) #define DECT_PHY_LBT_PERIOD_MIN_SYM (NRF_MODEM_DECT_LBT_PERIOD_MIN / NRF_MODEM_DECT_SYMBOL_DURATION) @@ -35,17 +33,10 @@ struct dect_phy_common_harq_feedback_data { uint8_t encoded_data_to_send[DECT_DATA_MAX_LEN]; /* DECT_MAC_MESSAGE_TYPE_HARQ_FEEDBACK */ }; -struct dect_phy_common_op_initialized_params { - uint64_t time; - int16_t temperature; - struct nrf_modem_dect_phy_modem_cfg modem_configuration; - enum nrf_modem_dect_phy_err status; -}; - struct dect_phy_common_op_pcc_rcv_params { uint64_t time; uint64_t stf_start_time; - struct nrf_modem_dect_phy_rx_pcc_status pcc_status; + struct nrf_modem_dect_phy_pcc_event pcc_status; uint8_t phy_len; enum dect_phy_packet_length_type phy_len_type; @@ -60,17 +51,17 @@ struct dect_phy_common_op_pcc_rcv_params { struct dect_phy_common_op_pcc_crc_fail_params { uint64_t time; - struct nrf_modem_dect_phy_rx_pcc_crc_failure crc_failure; + struct nrf_modem_dect_phy_pcc_crc_failure_event crc_failure; }; struct dect_phy_common_op_pdc_crc_fail_params { uint64_t time; - struct nrf_modem_dect_phy_rx_pdc_crc_failure crc_failure; + struct nrf_modem_dect_phy_pdc_crc_failure_event crc_failure; }; struct dect_phy_commmon_op_pdc_rcv_params { - struct nrf_modem_dect_phy_rx_pdc_status rx_status; + struct nrf_modem_dect_phy_pdc_event rx_status; - uint16_t last_rx_op_channel; + uint16_t rx_channel; uint8_t last_received_pcc_short_nw_id; uint16_t last_received_pcc_transmitter_short_rd_id; diff --git a/samples/dect/dect_phy/dect_shell/src/dect/common/dect_phy_common_rx.c b/samples/dect/dect_phy/dect_shell/src/dect/common/dect_phy_common_rx.c index 798d5b172f1..e4170bf029e 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/common/dect_phy_common_rx.c +++ b/samples/dect/dect_phy/dect_shell/src/dect/common/dect_phy_common_rx.c @@ -11,15 +11,52 @@ #include -static uint16_t last_rx_op_channel; +#include "dect_phy_common_rx.h" -int dect_phy_common_rx_op(const struct nrf_modem_dect_phy_rx_params *rx) +/* Phy handle to channel mapping table */ +static uint16_t phy_handle_to_channel_map[DECT_PHY_COMMON_RX_OP_HANDLES_MAX][2]; +static uint16_t current_phy_handle_insert_index; + +static void dect_phy_common_rx_op_handle_to_channel_set(uint32_t handle, uint16_t channel) { - last_rx_op_channel = rx->carrier; - return nrf_modem_dect_phy_rx(rx); + int insert_index; + bool already_in_table = false; + + if (current_phy_handle_insert_index == DECT_PHY_COMMON_RX_OP_HANDLES_MAX) { + current_phy_handle_insert_index = 0; + } + insert_index = current_phy_handle_insert_index; + + for (int i = 0; i < DECT_PHY_COMMON_RX_OP_HANDLES_MAX; i++) { + if (phy_handle_to_channel_map[i][0] == handle) { + insert_index = i; + already_in_table = true; + break; + } + } + + phy_handle_to_channel_map[insert_index][0] = handle; + phy_handle_to_channel_map[insert_index][1] = channel; + + if (!already_in_table) { + current_phy_handle_insert_index++; + } } -uint16_t dect_phy_common_rx_get_last_rx_op_channel(void) +int dect_phy_common_rx_op_handle_to_channel_get(uint32_t handle, uint16_t *channel_out) { - return last_rx_op_channel; + for (int i = 0; i < DECT_PHY_COMMON_RX_OP_HANDLES_MAX; i++) { + if (phy_handle_to_channel_map[i][0] == handle) { + *channel_out = phy_handle_to_channel_map[i][1]; + return 0; + } + } + return -1; +} + +int dect_phy_common_rx_op(const struct nrf_modem_dect_phy_rx_params *rx) +{ + dect_phy_common_rx_op_handle_to_channel_set(rx->handle, rx->carrier); + + return nrf_modem_dect_phy_rx(rx); } diff --git a/samples/dect/dect_phy/dect_shell/src/dect/common/dect_phy_common_rx.h b/samples/dect/dect_phy/dect_shell/src/dect/common/dect_phy_common_rx.h index 749be9ecb46..c51d631a257 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/common/dect_phy_common_rx.h +++ b/samples/dect/dect_phy/dect_shell/src/dect/common/dect_phy_common_rx.h @@ -8,11 +8,14 @@ #define DECT_PHY_COMMON_RX_H #include +#include "dect_phy_api_scheduler.h" /* Due to lack of information of a carrier/channel in pdc_cb from libmodem/modem, - * a small wrapper for RX operations is needed to have a glue to which channel pdc_cb is for. + * you need to keep up-to-date information, that is PHY handle - channel mapping. */ +#define DECT_PHY_COMMON_RX_OP_HANDLES_MAX DECT_PHY_API_SCHEDULER_OP_MAX_COUNT + int dect_phy_common_rx_op(const struct nrf_modem_dect_phy_rx_params *rx); -uint16_t dect_phy_common_rx_get_last_rx_op_channel(void); +int dect_phy_common_rx_op_handle_to_channel_get(uint32_t handle, uint16_t *channel_out); #endif /* DECT_PHY_COMMON_RX_H */ diff --git a/samples/dect/dect_phy/dect_shell/src/dect/dect_phy_ctrl.c b/samples/dect/dect_phy/dect_shell/src/dect/dect_phy_ctrl.c index ca513ff4f67..3a8243801c6 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/dect_phy_ctrl.c +++ b/samples/dect/dect_phy/dect_shell/src/dect/dect_phy_ctrl.c @@ -43,7 +43,18 @@ struct k_work_q dect_phy_ctrl_work_q; /* States of all commands */ static struct dect_phy_ctrl_data { bool phy_api_initialized; - struct nrf_modem_dect_phy_init_params dect_phy_init_params; + + int band_info_count; + struct nrf_modem_dect_phy_band band_info[DESH_DECT_PHY_SUPPORTED_BAND_COUNT]; + bool band_info_band4_supported; + + bool mdm_latency_info_valid; + struct nrf_modem_dect_phy_latency_info mdm_latency_info; + + struct nrf_modem_dect_phy_config_params dect_phy_init_params; + + bool last_set_radio_mode_successful; + enum nrf_modem_dect_phy_radio_mode last_set_radio_mode; uint16_t phy_api_init_count; bool phy_api_capabilities_printed; @@ -88,14 +99,16 @@ static struct dect_phy_ctrl_data { K_SEM_DEFINE(rssi_scan_sema, 0, 1); -K_SEM_DEFINE(dect_phy_ctrl_mdm_api_deinit_sema, 0, 1); K_SEM_DEFINE(dect_phy_ctrl_mdm_api_init_sema, 0, 1); +K_SEM_DEFINE(dect_phy_ctrl_mdm_api_op_cancel_sema, 0, 1); +K_SEM_DEFINE(dect_phy_ctrl_mdm_api_radio_mode_config_sema, 0, 1); +K_MUTEX_DEFINE(dect_phy_ctrl_mdm_api_op_cancel_all_mutex); /**************************************************************************************************/ static void dect_phy_rssi_channel_scan_completed_cb(enum nrf_modem_dect_phy_err phy_status); static void dect_phy_ctrl_on_modem_lib_init(int ret, void *ctx); -static int dect_phy_ctrl_phy_reinit(void); +static int dect_phy_ctrl_phy_handlers_init(void); /**************************************************************************************************/ @@ -136,6 +149,204 @@ int dect_phy_ctrl_msgq_data_op_add(uint16_t event_id, void *data, size_t data_si return 0; } +/**************************************************************************************************/ + +static void dect_phy_ctrl_phy_configure_from_settings(void) +{ + struct dect_phy_settings *current_settings = dect_common_settings_ref_get(); + int ret; + + /* Configure modem */ + ctrl_data.dect_phy_init_params.harq_rx_expiry_time_us = + current_settings->harq.mdm_init_harq_expiry_time_us; + ctrl_data.dect_phy_init_params.harq_rx_process_count = + current_settings->harq.mdm_init_harq_process_count; + ctrl_data.dect_phy_init_params.band_group_index = + ((current_settings->common.band_nbr == 4) ? 1 : 0); + + ret = nrf_modem_dect_phy_configure(&ctrl_data.dect_phy_init_params); + if (ret) { + desh_error("%s: nrf_modem_dect_phy_configure returned: %i", + (__func__), ret); + } + + /* Wait that configure is done */ + ret = k_sem_take(&dect_phy_ctrl_mdm_api_init_sema, K_SECONDS(5)); + if (ret) { + desh_error("(%s): nrf_modem_dect_phy_configure() timeout.", (__func__)); + } else { + desh_print("DECT modem configured to band #%d.", + current_settings->common.band_nbr); + } +} + +static void dect_phy_ctrl_radio_activate(enum nrf_modem_dect_phy_radio_mode radio_mode) +{ + int ret = nrf_modem_dect_phy_activate(radio_mode); + char tmp_str[128] = {0}; + + if (ret) { + desh_error("(%s): nrf_modem_dect_phy_activate() failed: %d", + (__func__), ret); + return; + } + + /* Wait that activate is done */ + ret = k_sem_take(&dect_phy_ctrl_mdm_api_init_sema, K_SECONDS(5)); + if (ret) { + ctrl_data.last_set_radio_mode_successful = false; + desh_error("(%s): nrf_modem_dect_phy_activate() timeout.", + (__func__)); + } else { + ctrl_data.last_set_radio_mode = radio_mode; + ctrl_data.last_set_radio_mode_successful = true; + desh_print("DECT modem activated to radio mode: %s.", + dect_common_utils_radio_mode_to_string( + radio_mode, tmp_str)); + } +} + +/**************************************************************************************************/ +void dect_phy_ctrl_utils_mdm_latency_info_print(void) +{ + char tmp_str[128] = {0}; + + if (!ctrl_data.mdm_latency_info_valid) { + desh_error("DECT modem latency info not valid."); + return; + } + desh_print("DECT modem latency info:"); + desh_print(" Radio mode specific latencies:"); + + for (int i = 0; i < NRF_MODEM_DECT_PHY_RADIO_MODE_COUNT; i++) { + desh_print(" Radio mode: %s", + dect_common_utils_radio_mode_to_string(i, tmp_str)); + desh_print(" scheduled_operation_transition: %d", + ctrl_data.mdm_latency_info.radio_mode[i] + .scheduled_operation_transition); + desh_print(" scheduled_operation_startup: %d", + ctrl_data.mdm_latency_info.radio_mode[i] + .scheduled_operation_startup); + for (int j = 0; j < NRF_MODEM_DECT_PHY_RADIO_MODE_COUNT; j++) { + desh_print(" radio mode transition delay to %s: %d", + dect_common_utils_radio_mode_to_string(j, tmp_str), + ctrl_data.mdm_latency_info.radio_mode[i] + .radio_mode_transition[j]); + } + } + + desh_print(" Operation latencies:"); + desh_print(" RX:"); + desh_print(" idle_to_active: %d", + ctrl_data.mdm_latency_info.operation.receive.idle_to_active); + desh_print(" active_to_idle_rssi: %d", + ctrl_data.mdm_latency_info.operation.receive.active_to_idle_rssi); + desh_print(" active_to_idle_rx: %d", + ctrl_data.mdm_latency_info.operation.receive.active_to_idle_rx); + desh_print(" stop_to_rf_off: %d", + ctrl_data.mdm_latency_info.operation.receive.stop_to_rf_off); + desh_print(" TX:"); + desh_print(" idle_to_active: %d", + ctrl_data.mdm_latency_info.operation.transmit.idle_to_active); + desh_print(" active_to_idle: %d", + ctrl_data.mdm_latency_info.operation.transmit.active_to_idle); + desh_print(" Modem radio configuration durations:"); + desh_print(" DECT PHY initialization duration: %d", + ctrl_data.mdm_latency_info.stack.initialization); + desh_print(" DECT PHY deinitialization duration: %d", + ctrl_data.mdm_latency_info.stack.deinitialization); + desh_print(" DECT PHY configuration duration: %d", + ctrl_data.mdm_latency_info.stack.configuration); + desh_print(" DECT PHY activation duration: %d", + ctrl_data.mdm_latency_info.stack.activation); + desh_print(" DECT PHY deactivation duration: %d", + ctrl_data.mdm_latency_info.stack.deactivation); +} + +int8_t dect_phy_ctrl_utils_mdm_max_tx_pwr_dbm_get_by_channel(uint16_t channel) +{ + for (int i = 0; i < ctrl_data.band_info_count; i++) { + if (channel >= ctrl_data.band_info[i].min_carrier && + channel <= ctrl_data.band_info[i].max_carrier) { + return dect_common_utils_max_tx_pwr_dbm_by_pwr_class( + ctrl_data.band_info[i].power_class); + } + } + /* Fallback to safest choise, the lowest max */ + return DECT_PHY_CLASS_4_MAX_TX_POWER_DBM; +} + +uint8_t dect_phy_ctrl_utils_mdm_max_tx_phy_pwr_get_by_channel(uint16_t channel) +{ + int8_t max_permitted_pwr_dbm = + dect_phy_ctrl_utils_mdm_max_tx_pwr_dbm_get_by_channel(channel); + + return dect_common_utils_dbm_to_phy_tx_power(max_permitted_pwr_dbm); +} + +uint8_t dect_phy_ctrl_utils_mdm_next_supported_phy_tx_power_get(uint8_t phy_power, uint16_t channel) +{ + uint8_t max_phy_pwr = dect_phy_ctrl_utils_mdm_max_tx_phy_pwr_get_by_channel(channel); + uint8_t next_phy_pwr = dect_common_utils_next_phy_tx_power_get(phy_power); + + if (next_phy_pwr > max_phy_pwr) { + next_phy_pwr = max_phy_pwr; + } + return next_phy_pwr; +} + +void dect_phy_ctrl_utils_mdm_band_info_print(void) +{ + desh_print("DECT modem band info:"); + for (int i = 0; i < ctrl_data.band_info_count; i++) { + desh_print(" Band number: %d", ctrl_data.band_info[i].band_number); + desh_print(" Band group index: %d", ctrl_data.band_info[i].band_group_index); + desh_print(" Min carrier: %d", ctrl_data.band_info[i].min_carrier); + desh_print(" Max carrier: %d", ctrl_data.band_info[i].max_carrier); + desh_print(" Power class: %d", ctrl_data.band_info[i].power_class); + desh_print(" Max power: %ddBm", + dect_common_utils_max_tx_pwr_dbm_by_pwr_class( + ctrl_data.band_info[i].power_class)); + desh_print(" RX gain: %d\n", ctrl_data.band_info[i].rx_gain); + } +} + +/**************************************************************************************************/ + +static void dect_phy_ctrl_radio_configure_activate_from_settings(void) +{ + struct dect_phy_settings *current_settings = dect_common_settings_ref_get(); + int ret; + + ret = nrf_modem_dect_phy_band_get(); + if (ret) { + desh_error("%s: nrf_modem_dect_phy_band_get returned: %i", + (__func__), ret); + } + + /* Wait that band_get is done */ + ret = k_sem_take(&dect_phy_ctrl_mdm_api_init_sema, K_SECONDS(5)); + if (ret) { + desh_error("(%s): nrf_modem_dect_phy_band_get() timeout.", (__func__)); + } else { + dect_phy_ctrl_utils_mdm_band_info_print(); + + if (!ctrl_data.band_info_band4_supported && + current_settings->common.band_nbr == 4) { + desh_error("Band 4 is not supported in modem - setting default band #1."); + current_settings->common.band_nbr = 1; + } + } + + dect_phy_ctrl_phy_configure_from_settings(); + if (current_settings->common.activate_at_startup) { + dect_phy_ctrl_radio_activate(current_settings->common.startup_radio_mode); + } else { + desh_print("DECT modem not activated."); + desh_print(" Activation can be done manually by using command \"dect activate\"."); + } +} + static void dect_phy_ctrl_msgq_thread_handler(void) { struct dect_phy_common_op_event_msgq_item event; @@ -144,6 +355,58 @@ static void dect_phy_ctrl_msgq_thread_handler(void) k_msgq_get(&dect_phy_ctrl_msgq, &event, K_FOREVER); switch (event.id) { + case DECT_PHY_CTRL_OP_RADIO_ACTIVATED: { + struct nrf_modem_dect_phy_activate_event *evt = + (struct nrf_modem_dect_phy_activate_event *)event.data; + char tmp_str[128] = {0}; + + dect_common_utils_modem_phy_err_to_string( + evt->err, evt->temp, tmp_str); + + if (evt->err != NRF_MODEM_DECT_PHY_SUCCESS) { + desh_error("(%s): radio activation failed: %d (%s)", + (__func__), evt->err, tmp_str); + ctrl_data.last_set_radio_mode_successful = false; + } else { + ctrl_data.last_set_radio_mode_successful = true; + } + break; + } + case DECT_PHY_CTRL_OP_RADIO_DEACTIVATED: { + struct nrf_modem_dect_phy_deactivate_event *evt = + (struct nrf_modem_dect_phy_deactivate_event *)event.data; + char tmp_str[128] = {0}; + + dect_common_utils_modem_phy_err_to_string( + evt->err, NRF_MODEM_DECT_PHY_TEMP_NOT_MEASURED, tmp_str); + + if (evt->err != NRF_MODEM_DECT_PHY_SUCCESS) { + desh_error("(%s): radio deactivation failed: %d (%s)", + (__func__), evt->err, tmp_str); + } else { + desh_print("Radio deactivated."); + } + break; + } + case DECT_PHY_CTRL_OP_RADIO_MODE_CONFIGURED: { + struct nrf_modem_dect_phy_radio_config_event *evt = + (struct nrf_modem_dect_phy_radio_config_event *)event.data; + char tmp_str[128] = {0}; + + dect_common_utils_modem_phy_err_to_string( + evt->err, NRF_MODEM_DECT_PHY_TEMP_NOT_MEASURED, tmp_str); + + if (evt->err != NRF_MODEM_DECT_PHY_SUCCESS) { + desh_error("(%s): radio mode configuration failed: %d (%s)", + (__func__), evt->err, tmp_str); + ctrl_data.last_set_radio_mode_successful = false; + } else { + ctrl_data.last_set_radio_mode_successful = true; + desh_print("Radio mode configured."); + } + break; + } + case DECT_PHY_CTRL_OP_SCHEDULER_SUSPENDED: { ctrl_data.scheduler_suspended = true; break; @@ -156,7 +419,7 @@ static void dect_phy_ctrl_msgq_thread_handler(void) ctrl_data.perf_ongoing = false; dect_phy_ctrl_msgq_non_data_op_add(DECT_PHY_CTRL_OP_DEBUG_ON); - dect_phy_ctrl_phy_reinit(); + dect_phy_ctrl_phy_handlers_init(); desh_print("perf command done."); break; @@ -165,7 +428,7 @@ static void dect_phy_ctrl_msgq_thread_handler(void) ctrl_data.ping_ongoing = false; dect_phy_ctrl_msgq_non_data_op_add(DECT_PHY_CTRL_OP_DEBUG_ON); - dect_phy_ctrl_phy_reinit(); + dect_phy_ctrl_phy_handlers_init(); desh_print("ping command done."); break; } @@ -173,7 +436,8 @@ static void dect_phy_ctrl_msgq_thread_handler(void) ctrl_data.cert_ongoing = false; dect_phy_ctrl_msgq_non_data_op_add(DECT_PHY_CTRL_OP_DEBUG_ON); - dect_phy_ctrl_phy_reinit(); + dect_phy_ctrl_phy_handlers_init(); + desh_print("rf_tool command done."); break; } case DECT_PHY_CTRL_OP_DEBUG_ON: { @@ -185,84 +449,73 @@ static void dect_phy_ctrl_msgq_thread_handler(void) break; } case DECT_PHY_CTRL_OP_SETTINGS_UPDATED: { - bool phy_api_reinit_needed = *((bool *)event.data); - - if (phy_api_reinit_needed) { - dect_phy_ctrl_phy_reinit(); - } if (ctrl_data.ext_cmd.sett_changed_cb != NULL) { ctrl_data.ext_cmd.sett_changed_cb(); } break; } case DECT_PHY_CTRL_OP_PHY_API_MDM_INITIALIZED: { - struct dect_phy_common_op_initialized_params *params = - (struct dect_phy_common_op_initialized_params *)event.data; + struct nrf_modem_dect_phy_init_event *params = + (struct nrf_modem_dect_phy_init_event *)event.data; char tmp_str[128] = {0}; + int ret; - if (params->temperature != NRF_MODEM_DECT_PHY_TEMP_NOT_MEASURED) { - ctrl_data.last_valid_temperature = params->temperature; + if (params->temp != NRF_MODEM_DECT_PHY_TEMP_NOT_MEASURED) { + ctrl_data.last_valid_temperature = params->temp; } - if (params->status) { + if (params->err != NRF_MODEM_DECT_PHY_SUCCESS) { dect_common_utils_modem_phy_err_to_string( - params->status, params->temperature, tmp_str); + params->err, params->temp, tmp_str); - desh_error("(%s): init failed (time %llu, temperature %d, " + desh_error("(%s): init failed (temperature %d, " "temp_limit %d): %d (%s)", - (__func__), params->time, params->temperature, - params->modem_configuration.temperature_limit, - params->status, tmp_str); + (__func__), params->temp, + params->temperature_limit, + params->err, tmp_str); } else { + k_sleep(K_MSEC(100)); if (ctrl_data.phy_api_init_count <= 1) { desh_print("DECT modem initialized:"); desh_print(" current temperature: %dC", - params->temperature); - desh_print(" max operating temperature: %dC", - params->modem_configuration.temperature_limit); - desh_print(" Latencies (in mdm time)"); - desh_print( - " from Idle to RSSI RF sampling start: %d", - params->modem_configuration.latency.idle_to_rssi); - desh_print( - " from RF sampling of RSSI to Idle: %d", - params->modem_configuration.latency.rssi_to_idle); - desh_print(" from Idle to RX RF sampling start: %d", - params->modem_configuration.latency.idle_to_rx); - desh_print(" from RF sampling of RX to Idle: %d", - params->modem_configuration.latency.rx_to_idle); - desh_print(" from RF sampling of RX with RSSI " - "measurement to " - "Idle: %d", - params->modem_configuration.latency - .rx_rssi_to_idle); - desh_print( - " from RX stop request to RF sampling stop: %d", - params->modem_configuration.latency - .rx_stop_to_rf_off); - desh_print(" from Idle to TX RF sample transmission " - "start: %d", - params->modem_configuration.latency.idle_to_tx); - desh_print(" from Idle to TX with LBT monitoring RF " - "sampling " - "start: %d", - params->modem_configuration.latency - .idle_to_tx_with_lbt); - desh_print( - " from TX RF sample transmission end (with or " - "without LBT) to Idle: %d", - params->modem_configuration.latency.tx_to_idle); - desh_print(" from Idle to TX with LBT monitoring RF " - "sampling start " - "in TX-RX operation: %d", - params->modem_configuration.latency - .idle_to_txrx_with_lbt); - desh_print( - " from TX RF sample transmission end to RX RF " - "sampling start in TX-RX operation: %d", - params->modem_configuration.latency.txrx_tx_to_rx); + params->temp); } } + k_sleep(K_MSEC(100)); /* Wait that prev print is done */ + + /* Capability query */ + ret = nrf_modem_dect_phy_capability_get(); /* asynch: result in callback */ + if (ret) { + printk("nrf_modem_dect_phy_capability_get returned: %i\n", ret); + } + + /* Wait that Capability is done */ + ret = k_sem_take(&dect_phy_ctrl_mdm_api_init_sema, K_SECONDS(5)); + if (ret) { + desh_error("(%s): nrf_modem_dect_phy_capability_get() timeout.", + (__func__)); + /* continue */ + } + + k_sleep(K_MSEC(100)); /* Wait that capability print is done */ + + ret = nrf_modem_dect_phy_latency_get(); + if (ret) { + desh_error("nrf_modem_dect_phy_latency_get returned: %i", ret); + } + + /* Wait that latency query is done */ + ret = k_sem_take(&dect_phy_ctrl_mdm_api_init_sema, K_SECONDS(5)); + if (ret) { + desh_error("(%s): nrf_modem_dect_phy_latency_get() timeout.", + (__func__)); + /* continue */ + } else { + dect_phy_ctrl_utils_mdm_latency_info_print(); + } + + /* Configure and activate */ + dect_phy_ctrl_radio_configure_activate_from_settings(); break; } @@ -270,8 +523,10 @@ static void dect_phy_ctrl_msgq_thread_handler(void) struct dect_phy_common_op_pcc_crc_fail_params *params = (struct dect_phy_common_op_pcc_crc_fail_params *)event.data; - desh_warn("RX PCC CRC error (time %llu): SNR %d, RSSI-2 %d (%d dBm)", - params->time, params->crc_failure.snr, params->crc_failure.rssi_2, + desh_warn("RX PCC CRC error (time %llu, handle %d): " + "SNR %d, RSSI-2 %d (%d dBm)", + params->time, params->crc_failure.handle, + params->crc_failure.snr, params->crc_failure.rssi_2, (params->crc_failure.rssi_2 / 2)); break; } @@ -279,8 +534,10 @@ static void dect_phy_ctrl_msgq_thread_handler(void) struct dect_phy_common_op_pdc_crc_fail_params *params = (struct dect_phy_common_op_pdc_crc_fail_params *)event.data; - desh_warn("RX PDC CRC error (time %llu): SNR %d, RSSI-2 %d (%d dBm)", - params->time, params->crc_failure.snr, params->crc_failure.rssi_2, + desh_warn("RX PDC CRC error (time %llu, handle %d): " + "SNR %d, RSSI-2 %d (%d dBm)", + params->time, params->crc_failure.handle, + params->crc_failure.snr, params->crc_failure.rssi_2, (params->crc_failure.rssi_2 / 2)); break; } @@ -295,10 +552,11 @@ static void dect_phy_ctrl_msgq_thread_handler(void) if (ctrl_data.debug) { int16_t rssi_level = params->pcc_status.rssi_2 / 2; - desh_print("PCC received (stf start time %llu): " + desh_print("PCC received (stf start time %llu, handle %d): " "status: \"%s\", snr %d, " "RSSI-2 %d (RSSI %d)", - params->stf_start_time, tmp_str, params->pcc_status.snr, + params->stf_start_time, params->pcc_status.handle, + tmp_str, params->pcc_status.snr, params->pcc_status.rssi_2, rssi_level); } if (params->pcc_status.header_status == @@ -338,7 +596,7 @@ static void dect_phy_ctrl_msgq_thread_handler(void) if (!data_handled) { unsigned char hex_data[128]; int i; - struct nrf_modem_dect_phy_rx_pdc_status *p_rx_status = + struct nrf_modem_dect_phy_pdc_event *p_rx_status = &(params->rx_status); int16_t rssi_level = p_rx_status->rssi_2 / 2; @@ -411,6 +669,7 @@ static void dect_phy_ctrl_msgq_thread_handler(void) (ctrl_data.rssi_scan_cmd_running && ctrl_data.rssi_scan_params.interval_secs)) { if (ctrl_data.rssi_scan_params.suspend_scheduler) { + dect_phy_ctrl_mdm_op_cancel_all(); dect_phy_api_scheduler_suspend(); } err = dect_phy_scan_rssi_start( @@ -446,94 +705,99 @@ K_THREAD_DEFINE(dect_phy_ctrl_msgq_th, DECT_PHY_CTRL_STACK_SIZE, dect_phy_ctrl_m /**************************************************************************************************/ -static void dect_phy_ctrl_mdm_initialize_cb(const uint64_t *time, int16_t temperature, - enum nrf_modem_dect_phy_err status, - const struct nrf_modem_dect_phy_modem_cfg *modem_configuration) +static void dect_phy_ctrl_mdm_initialize_cb(const struct nrf_modem_dect_phy_init_event *evt) { - struct dect_phy_common_op_initialized_params ctrl_op_initialized_params; - - dect_app_modem_time_save(time); - ctrl_op_initialized_params.time = *time; - ctrl_op_initialized_params.temperature = temperature; - ctrl_op_initialized_params.status = status; - ctrl_op_initialized_params.modem_configuration = *modem_configuration; - - if (status == NRF_MODEM_DECT_PHY_SUCCESS) { + if (evt->err == NRF_MODEM_DECT_PHY_SUCCESS) { ctrl_data.phy_api_init_count++; ctrl_data.phy_api_initialized = true; } k_sem_give(&dect_phy_ctrl_mdm_api_init_sema); dect_phy_ctrl_msgq_data_op_add(DECT_PHY_CTRL_OP_PHY_API_MDM_INITIALIZED, - (void *)&ctrl_op_initialized_params, - sizeof(struct dect_phy_common_op_initialized_params)); + (void *)evt, + sizeof(struct nrf_modem_dect_phy_init_event)); } -static void dect_phy_ctrl_mdm_time_query_cb( - uint64_t const *time, enum nrf_modem_dect_phy_err status) +static void dect_phy_ctrl_mdm_on_deinit_cb(const struct nrf_modem_dect_phy_deinit_event *deinit_evt) { - dect_app_modem_time_save(time); + ctrl_data.phy_api_initialized = false; +} - if (ctrl_data.time_cmd) { - if (status != NRF_MODEM_DECT_PHY_SUCCESS) { - printk("\nCannot get modem time, err %d", status); - return; - } +void dect_phy_ctrl_mdm_activate_cb(const struct nrf_modem_dect_phy_activate_event *evt) +{ + k_sem_give(&dect_phy_ctrl_mdm_api_init_sema); + dect_phy_ctrl_msgq_data_op_add(DECT_PHY_CTRL_OP_RADIO_ACTIVATED, + (void *)evt, + sizeof(struct nrf_modem_dect_phy_activate_event)); +} - uint64_t time_now = dect_app_modem_time_now(); - static const char *behind_str = "behind"; - static const char *ahead_str = "ahead"; - int64_t time_diff = *time - time_now; +void dect_phy_ctrl_mdm_deactivate_cb(const struct nrf_modem_dect_phy_deactivate_event *evt) +{ + dect_phy_ctrl_msgq_data_op_add(DECT_PHY_CTRL_OP_RADIO_DEACTIVATED, + (void *)evt, + sizeof(struct nrf_modem_dect_phy_deactivate_event)); +} - if (time_diff >= 0) { - printk("\nModem time: %llu, app time %lld (%s by %lld ticks)\n", *time, - time_now, behind_str, time_diff); - } else { - printk("\nModem time: %llu, app time %lld (%s by %lld ticks)\n", *time, - time_now, ahead_str, time_diff); - } +void dect_phy_ctrl_mdm_configure_cb(const struct nrf_modem_dect_phy_configure_event *evt) +{ + if (evt->err != NRF_MODEM_DECT_PHY_SUCCESS) { + printk("PHY configure failed: %d\n", evt->err); } - ctrl_data.time_cmd = false; + k_sem_give(&dect_phy_ctrl_mdm_api_init_sema); } -static void dect_phy_ctrl_mdm_rx_operation_stop_cb(uint64_t const *time, - enum nrf_modem_dect_phy_err status, uint32_t handle) +void dect_phy_ctrl_mdm_radio_config_cb( + const struct nrf_modem_dect_phy_radio_config_event *evt) { - dect_app_modem_time_save(time); + k_sem_give(&dect_phy_ctrl_mdm_api_radio_mode_config_sema); + dect_phy_ctrl_msgq_data_op_add(DECT_PHY_CTRL_OP_RADIO_MODE_CONFIGURED, + (void *)evt, + sizeof(struct nrf_modem_dect_phy_radio_config_event)); } -static void dect_phy_ctrl_mdm_operation_complete_cb(uint64_t const *time, int16_t temperature, - enum nrf_modem_dect_phy_err status, uint32_t handle) +static void dect_phy_ctrl_mdm_operation_complete_cb( + const struct nrf_modem_dect_phy_op_complete_event *evt, uint64_t *time) { struct dect_phy_common_op_completed_params op_completed_params = { - .handle = handle, - .temperature = temperature, - .status = status, + .handle = evt->handle, + .temperature = evt->temp, + .status = evt->err, .time = *time, }; - - dect_app_modem_time_save(time); dect_phy_api_scheduler_mdm_op_completed(&op_completed_params); dect_phy_ctrl_msgq_data_op_add(DECT_PHY_CTRL_OP_PHY_API_MDM_COMPLETED, (void *)&op_completed_params, sizeof(struct dect_phy_common_op_completed_params)); } +static void dect_phy_ctrl_mdm_on_rssi_cb(const struct nrf_modem_dect_phy_rssi_event *evt) +{ + + if (ctrl_data.rssi_scan_ongoing || ctrl_data.rx_cmd_on_going) { + dect_phy_scan_rssi_cb_handle(NRF_MODEM_DECT_PHY_SUCCESS, evt); + } else if (ctrl_data.ext_cmd.direct_rssi_cb != NULL) { + ctrl_data.ext_cmd.direct_rssi_cb(evt); + } +} + +void dect_phy_ctrl_mdm_cancel_cb(const struct nrf_modem_dect_phy_cancel_event *evt) +{ + k_sem_give(&dect_phy_ctrl_mdm_api_op_cancel_sema); +} + static void -dect_phy_ctrl_mdm_on_rx_pcc_cb(uint64_t const *time, - struct nrf_modem_dect_phy_rx_pcc_status const *p_rx_status, - union nrf_modem_dect_phy_hdr const *p_phy_header) +dect_phy_ctrl_mdm_on_rx_pcc_cb(const struct nrf_modem_dect_phy_pcc_event *evt, + uint64_t *time) { struct dect_phy_common_op_pcc_rcv_params ctrl_pcc_op_params; - ctrl_data.last_received_stf_start_time = p_rx_status->stf_start_time; - dect_app_modem_time_save(time); + ctrl_data.last_received_stf_start_time = evt->stf_start_time; - if (p_rx_status->header_status == NRF_MODEM_DECT_PHY_HDR_STATUS_VALID) { - struct dect_phy_ctrl_field_common *phy_h = (void *)p_phy_header; - const uint8_t *p_ptr = (uint8_t *)p_phy_header; + if (evt->header_status == NRF_MODEM_DECT_PHY_HDR_STATUS_VALID) { + struct dect_phy_ctrl_field_common *phy_h = (void *)&evt->hdr; + const uint8_t *p_ptr = (uint8_t *)&evt->hdr; uint8_t short_nw_id; int16_t pcc_rx_pwr_dbm = @@ -563,10 +827,10 @@ dect_phy_ctrl_mdm_on_rx_pcc_cb(uint64_t const *time, ctrl_pcc_op_params.phy_len_type = phy_h->packet_length_type; } - ctrl_pcc_op_params.pcc_status = *p_rx_status; - ctrl_pcc_op_params.phy_header = *p_phy_header; + ctrl_pcc_op_params.pcc_status = *evt; + ctrl_pcc_op_params.phy_header = evt->hdr; ctrl_pcc_op_params.time = *time; - ctrl_pcc_op_params.stf_start_time = p_rx_status->stf_start_time; + ctrl_pcc_op_params.stf_start_time = evt->stf_start_time; if (ctrl_data.ext_cmd.direct_pcc_rcv_cb != NULL) { ctrl_data.ext_cmd.direct_pcc_rcv_cb(&ctrl_pcc_op_params); @@ -577,26 +841,43 @@ dect_phy_ctrl_mdm_on_rx_pcc_cb(uint64_t const *time, sizeof(struct dect_phy_common_op_pcc_rcv_params)); } -static void dect_phy_ctrl_mdm_on_rx_pdc_cb(uint64_t const *time, - struct nrf_modem_dect_phy_rx_pdc_status const *p_rx_status, - void const *p_data, uint32_t length) +static void dect_phy_ctrl_mdm_on_pcc_crc_failure_cb( + const struct nrf_modem_dect_phy_pcc_crc_failure_event *evt, uint64_t *time) { - int16_t rssi_level = p_rx_status->rssi_2 / 2; + struct dect_phy_common_op_pcc_crc_fail_params pdc_crc_fail_params = { + .time = *time, + .crc_failure = *evt, + }; - dect_app_modem_time_save(time); + dect_phy_ctrl_msgq_data_op_add(DECT_PHY_CTRL_OP_PHY_API_MDM_RX_PCC_CRC_ERROR, + (void *)&pdc_crc_fail_params, + sizeof(struct dect_phy_common_op_pcc_crc_fail_params)); +} + +static void dect_phy_ctrl_mdm_on_rx_pdc_cb(const struct nrf_modem_dect_phy_pdc_event *evt) +{ + int16_t rssi_level = evt->rssi_2 / 2; + uint16_t channel; + int err; struct dect_phy_commmon_op_pdc_rcv_params ctrl_pdc_op_params; struct dect_phy_api_scheduler_op_pdc_type_rcvd_params pdc_op_params; - ctrl_pdc_op_params.rx_status = *p_rx_status; + ctrl_pdc_op_params.rx_status = *evt; - ctrl_pdc_op_params.data_length = length; + ctrl_pdc_op_params.data_length = evt->len; ctrl_pdc_op_params.time = ctrl_data.last_received_stf_start_time; ctrl_pdc_op_params.rx_pwr_dbm = ctrl_data.last_received_pcc_pwr_dbm; ctrl_pdc_op_params.rx_mcs = ctrl_data.last_received_pcc_mcs; ctrl_pdc_op_params.rx_rssi_level_dbm = rssi_level; - ctrl_pdc_op_params.last_rx_op_channel = dect_phy_common_rx_get_last_rx_op_channel(); + ctrl_pdc_op_params.rx_channel = 0; + + err = dect_phy_common_rx_op_handle_to_channel_get(evt->handle, &channel); + if (!err) { + ctrl_pdc_op_params.rx_channel = channel; + } + ctrl_pdc_op_params.last_received_pcc_short_nw_id = ctrl_data.last_received_pcc_short_nw_id; ctrl_pdc_op_params.last_received_pcc_transmitter_short_rd_id = ctrl_data.last_received_pcc_transmitter_short_rd_id; @@ -604,8 +885,8 @@ static void dect_phy_ctrl_mdm_on_rx_pdc_cb(uint64_t const *time, ctrl_data.last_received_pcc_phy_len_type; ctrl_pdc_op_params.last_received_pcc_phy_len = ctrl_data.last_received_pcc_phy_len; - if (length <= sizeof(ctrl_pdc_op_params.data)) { - memcpy(ctrl_pdc_op_params.data, p_data, length); + if (evt->len <= sizeof(ctrl_pdc_op_params.data)) { + memcpy(ctrl_pdc_op_params.data, evt->data, evt->len); if (ctrl_data.ext_cmd.direct_pdc_rcv_cb != NULL) { ctrl_data.ext_cmd.direct_pdc_rcv_cb(&ctrl_pdc_op_params); } @@ -616,160 +897,234 @@ static void dect_phy_ctrl_mdm_on_rx_pdc_cb(uint64_t const *time, } else { printk("Received data is too long to be received by CTRL TH - discarded (len %d, " "buf size %d)\n", - length, sizeof(ctrl_pdc_op_params.data)); + evt->len, sizeof(ctrl_pdc_op_params.data)); } - pdc_op_params.data_length = length; + pdc_op_params.data_length = evt->len; pdc_op_params.time = ctrl_data.last_received_stf_start_time; pdc_op_params.rx_pwr_dbm = ctrl_data.last_received_pcc_pwr_dbm; pdc_op_params.rx_rssi_dbm = rssi_level; - if (length <= sizeof(pdc_op_params.data)) { - memcpy(pdc_op_params.data, p_data, length); + if (evt->len <= sizeof(pdc_op_params.data)) { + memcpy(pdc_op_params.data, evt->data, evt->len); dect_phy_api_scheduler_mdm_pdc_data_recv(&pdc_op_params); } else { printk("Received data is too long to be received by SCHEDULER TH - discarded (len " "%d, buf size %d)\n", - length, sizeof(pdc_op_params.data)); + evt->len, sizeof(pdc_op_params.data)); } } -static void dect_phy_ctrl_mdm_on_rssi_cb(const uint64_t *time, - const struct nrf_modem_dect_phy_rssi_meas *p_result) -{ - dect_app_modem_time_save(time); - - if (ctrl_data.rssi_scan_ongoing || ctrl_data.rx_cmd_on_going) { - dect_phy_scan_rssi_cb_handle(NRF_MODEM_DECT_PHY_SUCCESS, p_result); - } else if (ctrl_data.ext_cmd.direct_rssi_cb != NULL) { - ctrl_data.ext_cmd.direct_rssi_cb(p_result); - } -} - -static void dect_phy_ctrl_mdm_on_link_configuration_cb(uint64_t const *time, - enum nrf_modem_dect_phy_err status) -{ - dect_app_modem_time_save(time); -} - -static void dect_phy_ctrl_mdm_on_pcc_crc_failure_cb( - uint64_t const *time, struct nrf_modem_dect_phy_rx_pcc_crc_failure const *crc_failure) -{ - struct dect_phy_common_op_pcc_crc_fail_params pdc_crc_fail_params = { - .time = *time, - .crc_failure = *crc_failure, - }; - - dect_app_modem_time_save(time); - dect_phy_ctrl_msgq_data_op_add(DECT_PHY_CTRL_OP_PHY_API_MDM_RX_PCC_CRC_ERROR, - (void *)&pdc_crc_fail_params, - sizeof(struct dect_phy_common_op_pcc_crc_fail_params)); -} - static void dect_phy_ctrl_mdm_on_pdc_crc_failure_cb( - uint64_t const *time, struct nrf_modem_dect_phy_rx_pdc_crc_failure const *crc_failure) + const struct nrf_modem_dect_phy_pdc_crc_failure_event *evt, uint64_t *time) { struct dect_phy_common_op_pdc_crc_fail_params pdc_crc_fail_params = { .time = *time, - .crc_failure = *crc_failure, + .crc_failure = *evt, }; - dect_app_modem_time_save(time); dect_phy_ctrl_msgq_data_op_add(DECT_PHY_CTRL_OP_PHY_API_MDM_RX_PDC_CRC_ERROR, (void *)&pdc_crc_fail_params, sizeof(struct dect_phy_common_op_pdc_crc_fail_params)); } -static void dect_phy_ctrl_mdm_on_capability_get_cb( - const uint64_t *time, enum nrf_modem_dect_phy_err err, - const struct nrf_modem_dect_phy_capability *capabilities) +void dect_phy_ctrl_mdm_time_query_cb( + const struct nrf_modem_dect_phy_time_get_event *evt, uint64_t *time) { + if (ctrl_data.time_cmd) { + if (evt->err != NRF_MODEM_DECT_PHY_SUCCESS) { + printk("\nCannot get modem time, err %d", evt->err); + return; + } + + uint64_t time_now = dect_app_modem_time_now(); + static const char *behind_str = "behind"; + static const char *ahead_str = "ahead"; + int64_t time_diff = *time - time_now; + + if (time_diff >= 0) { + printk("\nModem time: %llu, app time %lld (%s by %lld ticks)\n", *time, + time_now, behind_str, time_diff); + } else { + printk("\nModem time: %llu, app time %lld (%s by %lld ticks)\n", *time, + time_now, ahead_str, time_diff); + } + } + ctrl_data.time_cmd = false; +} + + +void dect_phy_ctrl_mdm_on_capability_get_cb( + const struct nrf_modem_dect_phy_capability_get_event *evt) +{ + if (evt->err != NRF_MODEM_DECT_PHY_SUCCESS) { + printk("Cannot get modem capabilities, err %d\n", evt->err); + return; + } if (!ctrl_data.phy_api_capabilities_printed) { - printk("\nModem capabilities:\n"); - printk(" DECT NR+ version: %d\n", capabilities->dect_version); - for (int i = 0; i < capabilities->variant_count; i++) { - printk(" power_class[%d]: %d\n", i, - capabilities->variant[i].power_class); - printk(" rx_spatial_streams[%d]: %d\n", i, - capabilities->variant[i].rx_spatial_streams); - printk(" rx_tx_diversity[%d]: %d\n", i, - capabilities->variant[i].rx_tx_diversity); - printk(" rx_gain[%d]: %ddBm\n", i, - capabilities->variant[i].rx_gain); - printk(" mcs_max[%d]: %d\n", i, - capabilities->variant[i].mcs_max); - printk(" harq_soft_buf_size[%d]: %d\n", i, - capabilities->variant[i].harq_soft_buf_size); - printk(" harq_process_count_max[%d]: %d\n", i, - capabilities->variant[i].harq_process_count_max); - printk(" harq_feedback_delay[%d]: %d\n", i, - capabilities->variant[i].harq_feedback_delay); - printk(" mu[%d]: %d\n", i, - capabilities->variant[i].mu); - printk(" beta[%d]: %d\n", i, - capabilities->variant[i].beta); + struct nrf_modem_dect_phy_capability *capability = evt->capability; + + if (capability == NULL) { + printk("\nModem capabilities:\n"); + printk(" No capabilities available\n"); + } else { + printk("\nModem capabilities:\n"); + printk(" DECT NR+ version: %d\n", capability->dect_version); + printk(" DECT NR+ variant count: %d\n", capability->variant_count); + for (int i = 0; i < capability->variant_count; i++) { + printk(" rx_spatial_streams[%d]: %d\n", i, + capability->variant[i].rx_spatial_streams); + printk(" rx_tx_diversity[%d]: %d\n", i, + capability->variant[i].rx_tx_diversity); + printk(" mcs_max[%d]: %d\n", i, + capability->variant[i].mcs_max); + printk(" harq_soft_buf_size[%d]: %d\n", i, + capability->variant[i].harq_soft_buf_size); + printk(" harq_process_count_max[%d]: %d\n", i, + capability->variant[i].harq_process_count_max); + printk(" harq_feedback_delay[%d]: %d\n", i, + capability->variant[i].harq_feedback_delay); + printk(" mu[%d]: %d\n", i, + capability->variant[i].mu); + + /* desh supports only 1 for mu */ + __ASSERT_NO_MSG(capability->variant[i].mu == 1); + + printk(" beta[%d]: %d\n", i, + capability->variant[i].beta); + } } ctrl_data.phy_api_capabilities_printed = true; } + k_sem_give(&dect_phy_ctrl_mdm_api_init_sema); } -static void dect_phy_ctrl_mdm_on_stf_cover_seq_control_cb( - const uint64_t *time, enum nrf_modem_dect_phy_err err) +static void dect_phy_ctrl_mdm_on_band_get_cb(const struct nrf_modem_dect_phy_band_get_event *evt) { - printk("WARN: Unexpectedly in %s\n", (__func__)); + ctrl_data.band_info_count = 0; + ctrl_data.band_info_band4_supported = false; + + for (size_t i = 0; i < evt->band_count && i < DESH_DECT_PHY_SUPPORTED_BAND_COUNT; i++) { + /* Store band info */ + ctrl_data.band_info[i] = evt->band[i]; + ctrl_data.band_info_count++; + if (ctrl_data.band_info[i].band_number == 4) { + ctrl_data.band_info_band4_supported = true; + } + } + k_sem_give(&dect_phy_ctrl_mdm_api_init_sema); } -static void dect_phy_ctrl_mdm_on_deinit_cb(const uint64_t *time, enum nrf_modem_dect_phy_err err) +static void dect_phy_ctrl_mdm_on_latency_cb(const struct nrf_modem_dect_phy_latency_info_event *evt) { - ctrl_data.phy_api_initialized = false; - k_sem_give(&dect_phy_ctrl_mdm_api_deinit_sema); -} - -static const struct nrf_modem_dect_phy_callbacks dect_phy_api_config = { - - .init = dect_phy_ctrl_mdm_initialize_cb, - .rx_stop = dect_phy_ctrl_mdm_rx_operation_stop_cb, - .op_complete = dect_phy_ctrl_mdm_operation_complete_cb, - .pcc = dect_phy_ctrl_mdm_on_rx_pcc_cb, - .pcc_crc_err = dect_phy_ctrl_mdm_on_pcc_crc_failure_cb, - .pdc = dect_phy_ctrl_mdm_on_rx_pdc_cb, - .pdc_crc_err = dect_phy_ctrl_mdm_on_pdc_crc_failure_cb, - .rssi = dect_phy_ctrl_mdm_on_rssi_cb, - .link_config = dect_phy_ctrl_mdm_on_link_configuration_cb, - .time_get = dect_phy_ctrl_mdm_time_query_cb, - .capability_get = dect_phy_ctrl_mdm_on_capability_get_cb, - .stf_cover_seq_control = dect_phy_ctrl_mdm_on_stf_cover_seq_control_cb, - .deinit = dect_phy_ctrl_mdm_on_deinit_cb, -}; + if (evt->err == NRF_MODEM_DECT_PHY_SUCCESS && evt->latency_info != NULL) { + ctrl_data.mdm_latency_info = *evt->latency_info; + ctrl_data.mdm_latency_info_valid = true; + } else { + ctrl_data.mdm_latency_info_valid = false; + } -static void dect_phy_ctrl_phy_init(void) -{ - struct dect_phy_settings *current_settings = dect_common_settings_ref_get(); - int ret = nrf_modem_dect_phy_callback_set(&dect_phy_api_config); + k_sem_give(&dect_phy_ctrl_mdm_api_init_sema); +} - ctrl_data.dect_phy_init_params.harq_rx_expiry_time_us = - current_settings->harq.mdm_init_harq_expiry_time_us; +void dect_phy_ctrl_mdm_evt_handler(const struct nrf_modem_dect_phy_event *evt) +{ + dect_app_modem_time_save(&evt->time); + + switch (evt->id) { + case NRF_MODEM_DECT_PHY_EVT_INIT: + dect_phy_ctrl_mdm_initialize_cb(&evt->init); + break; + case NRF_MODEM_DECT_PHY_EVT_DEINIT: + dect_phy_ctrl_mdm_on_deinit_cb(&evt->deinit); + break; + case NRF_MODEM_DECT_PHY_EVT_ACTIVATE: + dect_phy_ctrl_mdm_activate_cb(&evt->activate); + break; + case NRF_MODEM_DECT_PHY_EVT_DEACTIVATE: + dect_phy_ctrl_mdm_deactivate_cb(&evt->deactivate); + break; + case NRF_MODEM_DECT_PHY_EVT_CONFIGURE: + dect_phy_ctrl_mdm_configure_cb(&evt->configure); + break; + case NRF_MODEM_DECT_PHY_EVT_RADIO_CONFIG: + dect_phy_ctrl_mdm_radio_config_cb(&evt->radio_config); + break; + case NRF_MODEM_DECT_PHY_EVT_COMPLETED: + dect_phy_ctrl_mdm_operation_complete_cb(&evt->op_complete, (uint64_t *)&evt->time); + break; + case NRF_MODEM_DECT_PHY_EVT_CANCELED: + dect_phy_ctrl_mdm_cancel_cb(&evt->cancel); + break; + case NRF_MODEM_DECT_PHY_EVT_RSSI: + dect_phy_ctrl_mdm_on_rssi_cb(&evt->rssi); + break; + case NRF_MODEM_DECT_PHY_EVT_PCC: + dect_phy_ctrl_mdm_on_rx_pcc_cb(&evt->pcc, (uint64_t *)&evt->time); + break; + case NRF_MODEM_DECT_PHY_EVT_PCC_ERROR: + dect_phy_ctrl_mdm_on_pcc_crc_failure_cb(&evt->pcc_crc_err, (uint64_t *)&evt->time); + break; + case NRF_MODEM_DECT_PHY_EVT_PDC: + dect_phy_ctrl_mdm_on_rx_pdc_cb(&evt->pdc); + break; + case NRF_MODEM_DECT_PHY_EVT_PDC_ERROR: + dect_phy_ctrl_mdm_on_pdc_crc_failure_cb(&evt->pdc_crc_err, (uint64_t *)&evt->time); + break; + case NRF_MODEM_DECT_PHY_EVT_TIME: + dect_phy_ctrl_mdm_time_query_cb(&evt->time_get, (uint64_t *)&evt->time); + break; + case NRF_MODEM_DECT_PHY_EVT_CAPABILITY: + dect_phy_ctrl_mdm_on_capability_get_cb(&evt->capability_get); + break; + case NRF_MODEM_DECT_PHY_EVT_BANDS: + dect_phy_ctrl_mdm_on_band_get_cb(&evt->band_get); + break; + case NRF_MODEM_DECT_PHY_EVT_LATENCY: + dect_phy_ctrl_mdm_on_latency_cb(&evt->latency_get); + break; + default: + printk("%s: WARN: Unexpected event id %d\n", (__func__), evt->id); + break; + } +} - ctrl_data.dect_phy_init_params.harq_rx_process_count = - current_settings->harq.mdm_init_harq_process_count; - ctrl_data.dect_phy_init_params.reserved = 0; - ctrl_data.dect_phy_init_params.band4_support = - ((current_settings->common.band_nbr == 4) ? 1 : 0); +static void dect_phy_ctrl_phy_init(void) +{ + int ret = nrf_modem_dect_phy_event_handler_set(dect_phy_ctrl_mdm_evt_handler); if (ret) { - printk("nrf_modem_dect_phy_callback_set returned: %i\n", ret); + printk("nrf_modem_dect_phy_event_handler_set returned: %i\n", ret); } else { - ret = nrf_modem_dect_phy_init(&ctrl_data.dect_phy_init_params); + ret = nrf_modem_dect_phy_init(); if (ret) { printk("nrf_modem_dect_phy_init returned: %i\n", ret); - } else { - ret = nrf_modem_dect_phy_capability_get(); /* asynch: result in callback */ - if (ret) { - printk("nrf_modem_dect_phy_capability_get returned: %i\n", ret); - } } } } +void dect_phy_ctrl_mdm_op_cancel_all(void) +{ + int err; + + k_mutex_lock(&dect_phy_ctrl_mdm_api_op_cancel_all_mutex, K_FOREVER); + + k_sem_reset(&dect_phy_ctrl_mdm_api_op_cancel_sema); + err = nrf_modem_dect_phy_cancel(NRF_MODEM_DECT_PHY_HANDLE_CANCEL_ALL); + + if (err) { + desh_error("%s: cannot cancel ongoing operations: %d", (__func__), err); + /* continue */ + } else { + /* Wait that cancel(all) is done */ + err = k_sem_take(&dect_phy_ctrl_mdm_api_op_cancel_sema, K_SECONDS(5)); + if (err) { + desh_error("%s: nrf_modem_dect_phy_cancel() timeout.", (__func__)); + /* continue */ + } + } + k_mutex_unlock(&dect_phy_ctrl_mdm_api_op_cancel_all_mutex); +} + /**************************************************************************************************/ int dect_phy_ctrl_time_query(void) @@ -788,6 +1143,68 @@ int dect_phy_ctrl_modem_temperature_get(void) return ctrl_data.last_valid_temperature; } +int dect_phy_ctrl_current_radio_mode_get( + enum nrf_modem_dect_phy_radio_mode *radio_mode) +{ + if (!ctrl_data.phy_api_initialized) { + desh_error("Phy api not initialized"); + return -EACCES; + } + *radio_mode = ctrl_data.last_set_radio_mode; + + return 0; +} + +static enum nrf_modem_dect_phy_radio_mode dect_phy_ctrl_last_radio_mode_get(void) +{ + return ctrl_data.last_set_radio_mode; +} + +static struct nrf_modem_dect_phy_latency_info *dect_phy_ctrl_modem_latency_info_ref_get(void) +{ + return &ctrl_data.mdm_latency_info; +} + +uint64_t dect_phy_ctrl_modem_latency_min_margin_between_ops_get(void) +{ + uint64_t latency = DECT_PHY_TX_RX_SCHEDULING_OFFSET_MDM_TICKS; + + if (ctrl_data.mdm_latency_info_valid) { + struct nrf_modem_dect_phy_latency_info *latency_info = + dect_phy_ctrl_modem_latency_info_ref_get(); + enum nrf_modem_dect_phy_radio_mode radio_mode = dect_phy_ctrl_last_radio_mode_get(); + uint32_t scheduler_offset = + latency_info->radio_mode[radio_mode] + .scheduled_operation_transition; + + latency = scheduler_offset; + } + return latency; +} + +uint64_t dect_phy_ctrl_modem_latency_for_next_op_get(bool is_tx) +{ + uint64_t latency = DECT_PHY_TX_RX_SCHEDULING_OFFSET_MDM_TICKS; + uint64_t min_margin = dect_phy_ctrl_modem_latency_min_margin_between_ops_get(); + + if (ctrl_data.mdm_latency_info_valid) { + struct nrf_modem_dect_phy_latency_info *latency_info = + dect_phy_ctrl_modem_latency_info_ref_get(); + enum nrf_modem_dect_phy_radio_mode radio_mode = dect_phy_ctrl_last_radio_mode_get(); + + if (is_tx) { + latency = latency_info->radio_mode[radio_mode] + .scheduled_operation_startup + + latency_info->operation.transmit.idle_to_active; + } else { + latency = latency_info->radio_mode[radio_mode] + .scheduled_operation_startup + + latency_info->operation.receive.idle_to_active; + } + } + return MAX(latency, min_margin); +} + /**************************************************************************************************/ bool dect_phy_ctrl_rx_is_ongoing(void) @@ -798,7 +1215,7 @@ bool dect_phy_ctrl_rx_is_ongoing(void) void dect_phy_ctrl_rx_stop(void) { ctrl_data.rx_cmd_on_going = false; - (void)nrf_modem_dect_phy_rx_stop(ctrl_data.rx_cmd_params.handle); + (void)nrf_modem_dect_phy_cancel(ctrl_data.rx_cmd_params.handle); dect_phy_api_scheduler_resume(); } @@ -822,6 +1239,7 @@ int dect_phy_ctrl_rx_start(struct dect_phy_rx_cmd_params *params, bool restart) } if (params->suspend_scheduler) { + dect_phy_ctrl_mdm_op_cancel_all(); dect_phy_api_scheduler_suspend(); } @@ -911,6 +1329,7 @@ void dect_phy_ctrl_status_get_n_print(void) sprintf(tmp_mdm_str, "%d", temperature); } desh_print(" Modem temperature: %sC", tmp_mdm_str); + dect_phy_ctrl_utils_mdm_band_info_print(); #if defined(CONFIG_BME680) struct sensor_value data = {0}; @@ -1038,41 +1457,23 @@ static void dect_phy_rssi_channel_scan_completed_cb(enum nrf_modem_dect_phy_err } } -static int dect_phy_ctrl_phy_reinit(void) +static int dect_phy_ctrl_phy_handlers_init(void) { int ret; - k_sem_reset(&dect_phy_ctrl_mdm_api_deinit_sema); - ret = nrf_modem_dect_phy_deinit(); - if (ret) { - desh_error("nrf_modem_dect_phy_deinit failed, err=%d", ret); - return ret; - } + dect_phy_ctrl_mdm_op_cancel_all(); - /* Wait that deinit is done */ - ret = k_sem_take(&dect_phy_ctrl_mdm_api_deinit_sema, K_SECONDS(10)); + ret = nrf_modem_dect_phy_event_handler_set(dect_phy_ctrl_mdm_evt_handler); if (ret) { - desh_error("(%s): nrf_modem_dect_phy_deinit() timeout.", (__func__)); - return -ETIMEDOUT; + desh_error("nrf_modem_dect_phy_event_handler_set returned: %i", ret); } - k_sem_reset(&dect_phy_ctrl_mdm_api_init_sema); - dect_phy_ctrl_phy_init(); - - /* Wait that init is done */ - ret = k_sem_take(&dect_phy_ctrl_mdm_api_init_sema, K_SECONDS(60)); - if (ret) { - desh_error("(%s): nrf_modem_dect_phy_init() timeout.", (__func__)); - return -ETIMEDOUT; - } - return 0; + return ret; } int dect_phy_ctrl_rssi_scan_start(struct dect_phy_rssi_scan_params *params, dect_phy_ctrl_rssi_scan_completed_callback_t fp_result_callback) { - int ret; - if (!ctrl_data.phy_api_initialized) { desh_error("Phy api not initialized"); return -EACCES; @@ -1091,19 +1492,10 @@ int dect_phy_ctrl_rssi_scan_start(struct dect_phy_rssi_scan_params *params, ctrl_data.rssi_scan_complete_cb = fp_result_callback; if (params->suspend_scheduler) { + dect_phy_ctrl_mdm_op_cancel_all(); dect_phy_api_scheduler_suspend(); } - if (params->reinit_mdm_api) { - ret = dect_phy_ctrl_phy_reinit(); - if (ret) { - if (params->suspend_scheduler) { - dect_phy_api_scheduler_resume(); - } - return ret; - } - } - dect_phy_ctrl_msgq_non_data_op_add(DECT_PHY_CTRL_OP_RSSI_SCAN_RUN); return 0; } @@ -1154,21 +1546,7 @@ int dect_phy_ctrl_perf_cmd(struct dect_phy_perf_params *params) "DECT operation already on going. Stop all before starting running perf."); return -EBUSY; } - k_sem_reset(&dect_phy_ctrl_mdm_api_deinit_sema); - - /* We want to have own callbacks for perf command */ - ret = nrf_modem_dect_phy_deinit(); - if (ret) { - desh_error("nrf_modem_dect_phy_deinit failed, err=%d", ret); - return ret; - } - - /* Wait that deinit is done */ - ret = k_sem_take(&dect_phy_ctrl_mdm_api_deinit_sema, K_SECONDS(10)); - if (ret) { - desh_error("(%s): nrf_modem_dect_phy_deinit() timeout.", (__func__)); - return -ETIMEDOUT; - } + dect_phy_ctrl_mdm_op_cancel_all(); dect_phy_ctrl_msgq_non_data_op_add(DECT_PHY_CTRL_OP_DEBUG_OFF); ctrl_data.perf_ongoing = true; @@ -1192,26 +1570,13 @@ void dect_phy_ctrl_perf_cmd_stop(void) int dect_phy_ctrl_ping_cmd(struct dect_phy_ping_params *params) { int ret; + if (dect_phy_ctrl_op_ongoing()) { desh_error("Operation already on going. Stop all before starting running ping."); return -EBUSY; } - k_sem_reset(&dect_phy_ctrl_mdm_api_deinit_sema); - - /* We want to have own mdm phy api callbacks for ping command */ - ret = nrf_modem_dect_phy_deinit(); - if (ret) { - desh_error("nrf_modem_dect_phy_deinit failed, err=%d", ret); - return ret; - } - - /* Wait that deinit is done */ - ret = k_sem_take(&dect_phy_ctrl_mdm_api_deinit_sema, K_SECONDS(10)); - if (ret) { - desh_error("(%s): nrf_modem_dect_phy_deinit() timeout.", (__func__)); - return -ETIMEDOUT; - } + dect_phy_ctrl_mdm_op_cancel_all(); dect_phy_ctrl_msgq_non_data_op_add(DECT_PHY_CTRL_OP_DEBUG_OFF); ctrl_data.ping_ongoing = true; ret = dect_phy_ping_cmd_handle(params); @@ -1240,22 +1605,7 @@ int dect_phy_ctrl_rf_tool_cmd(struct dect_phy_rf_tool_params *params) return -EBUSY; } - k_sem_reset(&dect_phy_ctrl_mdm_api_deinit_sema); - - /* We want to have own mdm phy api callbacks for cert command */ - ret = nrf_modem_dect_phy_deinit(); - if (ret) { - desh_error("(%s): nrf_modem_dect_phy_deinit failed, err=%d", (__func__), ret); - return ret; - } - - /* Wait that deinit is done */ - ret = k_sem_take(&dect_phy_ctrl_mdm_api_deinit_sema, K_SECONDS(10)); - if (ret) { - desh_error("(%s): nrf_modem_dect_phy_deinit() timeout.", (__func__)); - return -ETIMEDOUT; - } - + dect_phy_ctrl_mdm_op_cancel_all(); dect_phy_ctrl_msgq_non_data_op_add(DECT_PHY_CTRL_OP_DEBUG_OFF); ctrl_data.cert_ongoing = true; ret = dect_phy_rf_tool_cmd_handle(params); @@ -1365,6 +1715,94 @@ bool dect_phy_ctrl_nbr_is_in_channel(uint16_t channel) /**************************************************************************************************/ +int dect_phy_ctrl_activate_cmd(enum nrf_modem_dect_phy_radio_mode radio_mode) +{ + if (!ctrl_data.phy_api_initialized) { + desh_error("Phy api not initialized"); + return -EACCES; + } + dect_phy_ctrl_phy_configure_from_settings(); + dect_phy_ctrl_radio_activate(radio_mode); + + return 0; +} + +int dect_phy_ctrl_deactivate_cmd(void) +{ + int ret; + + if (!ctrl_data.phy_api_initialized) { + desh_error("Phy api not initialized"); + return -EACCES; + } + + ret = nrf_modem_dect_phy_deactivate(); + if (ret) { + desh_error("nrf_modem_dect_phy_deactivate() failed, err=%d", ret); + } + return ret; +} + +int dect_phy_ctrl_radio_mode_cmd(enum nrf_modem_dect_phy_radio_mode radio_mode) +{ + if (!ctrl_data.phy_api_initialized) { + desh_error("Phy api not initialized"); + return -EACCES; + } + + if (dect_phy_ctrl_op_ongoing()) { + /* Cancel all from modem before */ + desh_warn("Operation already on going. " + "Canceling all operations in modem " + "before starting running radio mode change."); + dect_phy_ctrl_mdm_op_cancel_all(); + } + + uint64_t first_possible_tx; + uint64_t time_now = dect_app_modem_time_now(); + struct dect_phy_settings *current_settings = dect_common_settings_ref_get(); + + first_possible_tx = + time_now + + dect_phy_ctrl_modem_latency_for_next_op_get(true) + + US_TO_MODEM_TICKS(current_settings->scheduler.scheduling_delay_us); + + struct nrf_modem_dect_phy_radio_config_params config_params = { + .radio_mode = radio_mode, + .start_time = first_possible_tx, + .handle = DECT_PHY_RADIO_MODE_CONFIG_HANDLE, + }; + int ret = nrf_modem_dect_phy_radio_config(&config_params); + + ctrl_data.last_set_radio_mode_successful = false; + if (ret) { + desh_error("nrf_modem_dect_phy_radio_config() failed, err=%d", ret); + } + + /* Wait that radio mode configure is done */ + ret = k_sem_take(&dect_phy_ctrl_mdm_api_radio_mode_config_sema, K_SECONDS(5)); + if (ret) { + desh_error("(%s): nrf_modem_dect_phy_radio_config() timeout.", (__func__)); + ctrl_data.last_set_radio_mode_successful = false; + } else { + char tmp_str[128] = {0}; + + dect_common_utils_radio_mode_to_string(radio_mode, tmp_str); + if (ctrl_data.last_set_radio_mode_successful) { + ctrl_data.last_set_radio_mode = radio_mode; + desh_print("DECT radio mode configured to: %s.", tmp_str); + } else { + desh_error("DECT radio mode configuration failed to %s.", tmp_str); + desh_print("Last set DECT radio mode %s.", + dect_common_utils_radio_mode_to_string( + ctrl_data.last_set_radio_mode, tmp_str)); + } + } + return ret; +} + +/**************************************************************************************************/ + static void dect_phy_ctrl_on_modem_lib_init(int ret, void *ctx) { ARG_UNUSED(ret); diff --git a/samples/dect/dect_phy/dect_shell/src/dect/dect_phy_ctrl.h b/samples/dect/dect_phy/dect_shell/src/dect/dect_phy_ctrl.h index f43189bdcbd..ae51b537091 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/dect_phy_ctrl.h +++ b/samples/dect/dect_phy/dect_shell/src/dect/dect_phy_ctrl.h @@ -35,6 +35,10 @@ #define DECT_PHY_CTRL_OP_SCHEDULER_SUSPENDED 18 #define DECT_PHY_CTRL_OP_SCHEDULER_RESUMED 19 +#define DECT_PHY_CTRL_OP_RADIO_ACTIVATED 20 +#define DECT_PHY_CTRL_OP_RADIO_DEACTIVATED 21 +#define DECT_PHY_CTRL_OP_RADIO_MODE_CONFIGURED 22 + /******************************************************************************/ int dect_phy_ctrl_msgq_non_data_op_add(uint16_t event_id); @@ -42,16 +46,29 @@ int dect_phy_ctrl_msgq_data_op_add(uint16_t event_id, void *data, size_t data_si /******************************************************************************/ +int dect_phy_ctrl_activate_cmd(enum nrf_modem_dect_phy_radio_mode radio_mode); +int dect_phy_ctrl_deactivate_cmd(void); +int dect_phy_ctrl_radio_mode_cmd(enum nrf_modem_dect_phy_radio_mode radio_mode); + +/******************************************************************************/ + void dect_phy_ctrl_status_get_n_print(void); int dect_phy_ctrl_rx_start(struct dect_phy_rx_cmd_params *params, bool restart); void dect_phy_ctrl_rx_stop(void); bool dect_phy_ctrl_rx_is_ongoing(void); +int dect_phy_ctrl_current_radio_mode_get( + enum nrf_modem_dect_phy_radio_mode *radio_mode); int dect_phy_ctrl_time_query(void); +void dect_phy_ctrl_mdm_op_cancel_all(void); + int dect_phy_ctrl_modem_temperature_get(void); +uint64_t dect_phy_ctrl_modem_latency_for_next_op_get(bool is_tx); +uint64_t dect_phy_ctrl_modem_latency_min_margin_between_ops_get(void); + /******************************************************************************/ typedef void (*dect_phy_ctrl_rssi_scan_completed_callback_t)( @@ -68,6 +85,11 @@ int dect_phy_ctrl_rssi_scan_results_print_and_best_channel_get(bool print_result bool dect_phy_ctrl_mdm_phy_api_initialized(void); bool dect_phy_ctrl_phy_api_scheduler_suspended(void); +int8_t dect_phy_ctrl_utils_mdm_max_tx_pwr_dbm_get_by_channel(uint16_t channel); +uint8_t dect_phy_ctrl_utils_mdm_max_tx_phy_pwr_get_by_channel(uint16_t channel); +uint8_t dect_phy_ctrl_utils_mdm_next_supported_phy_tx_power_get( + uint8_t phy_power, uint16_t channel); + /******************************************************************************/ int dect_phy_ctrl_perf_cmd(struct dect_phy_perf_params *params); @@ -113,7 +135,7 @@ int dect_phy_ctrl_th_register_default_phy_api_pdc_rcv_cb( /* Callback for receiving RSSI measurement results */ typedef void (*dect_phy_ctrl_ext_phy_api_direct_rssi_cb_t)( - const struct nrf_modem_dect_phy_rssi_meas *meas_results); + const struct nrf_modem_dect_phy_rssi_event *meas_results); /* Callback for receiving modem operation complete events */ typedef void (*dect_phy_ctrl_ext_phy_api_mdm_op_complete_cb_t)( @@ -148,4 +170,18 @@ struct dect_phy_ctrl_ext_callbacks { int dect_phy_ctrl_ext_command_start(struct dect_phy_ctrl_ext_callbacks ext_callbacks); void dect_phy_ctrl_ext_command_stop(void); +/******************************************************************************/ + +/* Common modem callbacks that can be handled by dect_phy_ctrl */ +void dect_phy_ctrl_mdm_time_query_cb( + const struct nrf_modem_dect_phy_time_get_event *evt, uint64_t *time); +void dect_phy_ctrl_mdm_radio_config_cb( + const struct nrf_modem_dect_phy_radio_config_event *evt); +void dect_phy_ctrl_mdm_activate_cb(const struct nrf_modem_dect_phy_activate_event *evt); +void dect_phy_ctrl_mdm_deactivate_cb(const struct nrf_modem_dect_phy_deactivate_event *evt); +void dect_phy_ctrl_mdm_cancel_cb(const struct nrf_modem_dect_phy_cancel_event *evt); +void dect_phy_ctrl_mdm_configure_cb(const struct nrf_modem_dect_phy_configure_event *evt); +void dect_phy_ctrl_mdm_on_capability_get_cb( + const struct nrf_modem_dect_phy_capability_get_event *evt); + #endif /* DECT_PHY_CTRL_H */ diff --git a/samples/dect/dect_phy/dect_shell/src/dect/dect_phy_scan.c b/samples/dect/dect_phy/dect_shell/src/dect/dect_phy_scan.c index 9200da8cdd6..0edf8e08e19 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/dect_phy_scan.c +++ b/samples/dect/dect_phy/dect_shell/src/dect/dect_phy_scan.c @@ -32,7 +32,6 @@ struct dect_phy_rssi_scan_data { /* Current scanning state */ enum nrf_modem_dect_phy_err phy_status; - uint64_t start_time_mdm_ticks; uint32_t total_time_subslots; uint16_t current_scan_count; /* Scan count per channel */ uint16_t current_saturated_count; @@ -88,42 +87,13 @@ void dect_phy_scan_rssi_rx_th_run(struct dect_phy_rssi_scan_params *cmd_params) .duration = rssi_scan_data.total_time_subslots, .reporting_interval = NRF_MODEM_DECT_PHY_RSSI_INTERVAL_24_SLOTS, }; - uint64_t mdm_time_now = dect_app_modem_time_now(); int ret = 0; struct dect_phy_settings *curr_settings = dect_common_settings_ref_get(); + uint64_t latency = dect_phy_ctrl_modem_latency_for_next_op_get(false) + + (US_TO_MODEM_TICKS(curr_settings->scheduler.scheduling_delay_us)); + uint64_t mdm_time_now = dect_app_modem_time_now(); - if (rssi_scan_data.start_time_mdm_ticks == 0) { - /* 1st time*/ - int factor = 1; - - if (!dect_phy_api_scheduler_done_list_is_empty()) { - /* Something cooking there, let's wait more */ - factor = 2; - } - if (cmd_params->suspend_scheduler) { - /* Wait for a while to get modem emptied of already scheduled stuff */ - rssi_params.start_time = - mdm_time_now + - (factor * - MS_TO_MODEM_TICKS(DECT_PHY_API_SCHEDULER_OP_TIME_WINDOW_MS + 100)); - rssi_scan_data.start_time_mdm_ticks = rssi_params.start_time; - } else { - rssi_scan_data.start_time_mdm_ticks = mdm_time_now; - } - } else { - if (cmd_params->suspend_scheduler && !dect_phy_api_scheduler_done_list_is_empty()) { - rssi_params.start_time = - mdm_time_now + - (US_TO_MODEM_TICKS(curr_settings->scheduler.scheduling_delay_us)); - } - } - - /* Override set start time to zero if mdm api was reinited then no other - * operations on the way - */ - if (cmd_params->reinit_mdm_api) { - rssi_params.start_time = 0; - } + rssi_params.start_time = mdm_time_now + latency; ret = nrf_modem_dect_phy_rssi(&rssi_params); if (ret) { @@ -717,7 +687,6 @@ void dect_phy_scan_rssi_finished_handle(enum nrf_modem_dect_phy_err status) rssi_scan_data.current_channel != dect_common_utils_channel_max_on_band( curr_settings->common.band_nbr))) { /* Start a new round in next channel */ - rssi_scan_data.start_time_mdm_ticks = dect_app_modem_time_now(); rssi_scan_data.first_mdm_meas_time_mdm_ticks = 0; rssi_scan_data.rssi_high_level = -127; rssi_scan_data.rssi_low_level = 1; @@ -771,7 +740,7 @@ void dect_phy_scan_rssi_finished_handle(enum nrf_modem_dect_phy_err status) /**************************************************************************************************/ void dect_phy_scan_rssi_cb_handle(enum nrf_modem_dect_phy_err status, - struct nrf_modem_dect_phy_rssi_meas const *p_result) + struct nrf_modem_dect_phy_rssi_event const *p_result) { if (status == NRF_MODEM_DECT_PHY_SUCCESS) { __ASSERT_NO_MSG(p_result != NULL); @@ -886,32 +855,42 @@ void dect_phy_scan_rx_th_run(struct dect_phy_rx_cmd_params *params) .duration = SECONDS_TO_MODEM_TICKS(params->duration_secs), .rssi_interval = NRF_MODEM_DECT_PHY_RSSI_INTERVAL_OFF, }; - int ret; + int err; + struct dect_phy_settings *current_settings = dect_common_settings_ref_get(); + uint64_t time_now = dect_app_modem_time_now(); if (params->rssi_interval_secs) { rx_op.rssi_interval = NRF_MODEM_DECT_PHY_RSSI_INTERVAL_24_SLOTS; } if (params->suspend_scheduler) { - /* Modem is not necessarily idle thus start_time zero cannot be used. */ /* Wait for a while to get modem emptied of already scheduled stuff */ - - uint64_t time_now = dect_app_modem_time_now(); - rx_op.start_time = time_now + (2 * MS_TO_MODEM_TICKS(DECT_PHY_API_SCHEDULER_OP_TIME_WINDOW_MS)); - } + } else { + enum nrf_modem_dect_phy_radio_mode radio_mode; + + uint64_t latency = dect_phy_ctrl_modem_latency_for_next_op_get(false) + + (3 * US_TO_MODEM_TICKS(current_settings->scheduler.scheduling_delay_us)); + err = dect_phy_ctrl_current_radio_mode_get(&radio_mode); + if (!err && radio_mode == NRF_MODEM_DECT_PHY_RADIO_MODE_LOW_LATENCY && + dect_phy_api_scheduler_list_is_empty()) { + rx_op.start_time = 0; + } else { + rx_op.start_time = time_now + latency; + } + } rx_op.filter = params->filter; desh_print("-----------------------------------------------------------------------------"); desh_print("Starting RX: channel %d, rssi_level %d, duration %d secs.", params->channel, params->expected_rssi_level, params->duration_secs); - ret = dect_phy_common_rx_op(&rx_op); - if (ret) { - desh_error("nrf_modem_dect_phy_rx failed %d", ret); + err = dect_phy_common_rx_op(&rx_op); + if (err) { + desh_error("nrf_modem_dect_phy_rx failed %d", err); } } diff --git a/samples/dect/dect_phy/dect_shell/src/dect/dect_phy_scan.h b/samples/dect/dect_phy/dect_shell/src/dect/dect_phy_scan.h index be802846f49..1c6ed0c9009 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/dect_phy_scan.h +++ b/samples/dect/dect_phy/dect_shell/src/dect/dect_phy_scan.h @@ -73,7 +73,7 @@ void dect_phy_scan_rssi_stop(void); void dect_phy_scan_rssi_rx_th_run(struct dect_phy_rssi_scan_params *cmd_params); void dect_phy_scan_rssi_finished_handle(enum nrf_modem_dect_phy_err status); void dect_phy_scan_rssi_cb_handle(enum nrf_modem_dect_phy_err status, - struct nrf_modem_dect_phy_rssi_meas const *p_result); + struct nrf_modem_dect_phy_rssi_event const *p_result); int dect_phy_scan_rssi_data_init(struct dect_phy_rssi_scan_params *params); int dect_phy_scan_rssi_data_reinit_with_current_params(void); diff --git a/samples/dect/dect_phy/dect_shell/src/dect/dect_phy_shell.c b/samples/dect/dect_phy/dect_shell/src/dect/dect_phy_shell.c index d8dfc04ea35..68481f5ecbf 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/dect_phy_shell.c +++ b/samples/dect/dect_phy/dect_shell/src/dect/dect_phy_shell.c @@ -103,6 +103,8 @@ static const char dect_phy_perf_cmd_usage_str[] = " Default: as slots (c_gap_slots).\n" " --c_tx_pwr , TX power (dBm),\n" " [-40,-30,-20,-16,-12,-8,-4,0,4,7,10,13,16,19,21,23].\n" + " See supported max for the used band by using\n" + " \"dect status\" -command output.\n" " Default: from common tx settings.\n" " --c_tx_mcs , Set client TX MCS. Default: from common tx settings.\n" " -d, --debug, Print CRC errors. Note: might impact on actual\n" @@ -411,6 +413,8 @@ static const char dect_phy_rf_tool_cmd_usage_str[] = " Default: from common rx settings.\n" " -p --tx_pwr , TX power (dBm),\n" " [-40,-30,-20,-16,-12,-8,-4,0,4,7,10,13,16,19,21,23]\n" + " See supported max for the used band by using\n" + " \"dect status\" -command output.\n" " Default: from common tx settings.\n" " --tx_mcs , Set TX MCS. Default: from common tx settings.\n" "Frame structure:\n" @@ -426,7 +430,7 @@ static const char dect_phy_rf_tool_cmd_usage_str[] = " configured frame are scheduled at once and\n" " is also a reporting interval.\n" " There is no delay between frames.\n" - " Default: 100.\n" + " Default: 15.\n" " --frame_repeat_count_intervals , The number of intervals for\n" " frame_repeat_count.\n" " Intervals are scheduled ASAP after\n" @@ -517,7 +521,7 @@ static int dect_phy_rf_tool_cmd(const struct shell *shell, size_t argc, char **a params.expected_rx_rssi_level = current_settings->rx.expected_rssi_level; params.find_rx_sync = false; params.continuous = false; - params.frame_repeat_count = 50; + params.frame_repeat_count = 15; params.frame_repeat_count_intervals = 5; params.rx_frame_start_offset = 0; @@ -741,6 +745,8 @@ static const char dect_phy_ping_cmd_usage_str[] = " --c_tx_mcs , Set client TX MCS. Default: from common tx settings.\n" " --c_tx_pwr , TX power (dBm),\n" " [-40,-30,-20,-16,-12,-8,-4,0,4,7,10,13,16,19,21,23].\n" + " See supported max for the used band by using\n" + " \"dect status\" -command output.\n" " Default: from common tx settings.\n" " --c_tx_lbt_period , Listen Before Talk (LBT) period (symbol count).\n" " Zero value disables LBT (default).\n" @@ -992,6 +998,152 @@ static void dect_phy_status_cmd(const struct shell *shell, size_t argc, char **a /**************************************************************************************************/ +static const char dect_phy_activate_cmd_usage_str[] = + "Usage: dect activate \n" + " Activate PHY software stack in given radio mode.\n" + "Options:\n" + " -1, --low_latency, Default. This mode has the lowest latency,\n" + " the best RX/TX switching performance,\n" + " and the highest power consumption.\n" + " -2, --low_latency_with_standby, This mode has the same RX/TX switching\n" + " performance as the low latency mode,\n" + " but higher operation start-up latency.\n" + " Power consumption is thus lower compared to\n" + " the low latency mode.\n" + " -3, --non_lbt_with_standby, This mode has the lowest power consumption,\n" + " due the to modem entering standby mode when possible\n" + " and not using LBT, at the cost\n" + " of higher start-up latency and worse RX/TX switching\n" + " performance compared to the other radio modes.\n"; + +/* Specifying the expected options (both long and short): */ +static struct option long_options_radio_mode_conf[] = { + { "low_latency", no_argument, 0, '0' }, + { "low_latency_with_standby", no_argument, 0, '1' }, + { "non_lbt_with_standby", no_argument, 0, '2' }, + { 0, 0, 0, 0 } }; + +static void dect_phy_activate_cmd(const struct shell *shell, size_t argc, char **argv) +{ + enum nrf_modem_dect_phy_radio_mode radio_mode = NRF_MODEM_DECT_PHY_RADIO_MODE_LOW_LATENCY; + + int long_index = 0; + int opt, ret; + + optreset = 1; + optind = 1; + while ((opt = getopt_long(argc, argv, "123h", long_options_radio_mode_conf, &long_index)) != + -1) { + switch (opt) { + case '1': + radio_mode = NRF_MODEM_DECT_PHY_RADIO_MODE_LOW_LATENCY; + break; + case '2': + radio_mode = NRF_MODEM_DECT_PHY_RADIO_MODE_LOW_LATENCY_WITH_STANDBY; + break; + case '3': + radio_mode = NRF_MODEM_DECT_PHY_RADIO_MODE_NON_LBT_WITH_STANDBY; + break; + case 'h': + goto show_usage; + case '?': + default: + desh_error("Unknown option (%s). See usage:", argv[optind - 1]); + goto show_usage; + } + } + if (optind < argc) { + desh_error("Arguments without '-' not supported: %s", argv[argc - 1]); + goto show_usage; + } + + ret = dect_phy_ctrl_activate_cmd(radio_mode); + if (ret) { + desh_error("Cannot start activate command, ret: %d", ret); + } + return; + +show_usage: + desh_print_no_format(dect_phy_activate_cmd_usage_str); +} + +static void dect_phy_deactivate_cmd(const struct shell *shell, size_t argc, char **argv) +{ + int ret = dect_phy_ctrl_deactivate_cmd(); + + if (ret) { + desh_error("Cannot start deactivate command, ret: %d", ret); + } else { + desh_print("Deactivation started."); + } +} + +/**************************************************************************************************/ + +static const char dect_phy_radio_mode_cmd_usage_str[] = + "Usage: dect radio_mode \n" + " Configure radio mode.\n" + "Options:\n" + " -1, --low_latency, Default. This mode has the lowest latency,\n" + " the best RX/TX switching performance,\n" + " and the highest power consumption.\n" + " -2, --low_latency_with_standby, This mode has the same RX/TX switching\n" + " performance as the low latency mode,\n" + " but higher operation start-up latency.\n" + " Power consumption is thus lower compared to\n" + " the low latency mode.\n" + " -3, --non_lbt_with_standby, This mode has the lowest power consumption,\n" + " due the to modem entering standby mode when possible\n" + " and not using LBT, at the cost\n" + " of higher start-up latency and worse RX/TX switching\n" + " performance compared to the other radio modes.\n"; + +static void dect_phy_radio_mode_cmd(const struct shell *shell, size_t argc, char **argv) +{ + enum nrf_modem_dect_phy_radio_mode radio_mode = NRF_MODEM_DECT_PHY_RADIO_MODE_LOW_LATENCY; + + int long_index = 0; + int opt, ret; + + optreset = 1; + optind = 1; + while ((opt = getopt_long(argc, argv, "123h", long_options_radio_mode_conf, &long_index)) != + -1) { + switch (opt) { + case '1': + radio_mode = NRF_MODEM_DECT_PHY_RADIO_MODE_LOW_LATENCY; + break; + case '2': + radio_mode = NRF_MODEM_DECT_PHY_RADIO_MODE_LOW_LATENCY_WITH_STANDBY; + break; + case '3': + radio_mode = NRF_MODEM_DECT_PHY_RADIO_MODE_NON_LBT_WITH_STANDBY; + break; + case 'h': + goto show_usage; + case '?': + default: + desh_error("Unknown option (%s). See usage:", argv[optind - 1]); + goto show_usage; + } + } + if (optind < argc) { + desh_error("Arguments without '-' not supported: %s", argv[argc - 1]); + goto show_usage; + } + + ret = dect_phy_ctrl_radio_mode_cmd(radio_mode); + if (ret) { + desh_error("Cannot start activate command, ret: %d", ret); + } + return; + +show_usage: + desh_print_no_format(dect_phy_radio_mode_cmd_usage_str); +} + +/**************************************************************************************************/ + static void dect_phy_time_cmd(const struct shell *shell, size_t argc, char **argv) { int ret = dect_phy_ctrl_time_query(); @@ -1116,7 +1268,6 @@ static int dect_phy_rssi_scan_cmd(const struct shell *shell, size_t argc, char * } case 'f': { params.suspend_scheduler = true; - params.reinit_mdm_api = true; break; } case 'a': { @@ -1374,6 +1525,12 @@ static const char dect_phy_sett_cmd_usage_str[] = " (e.g. in rssi_scan).\n" " Default: band #1. Other supported bands are:\n" " 2, 4, 9 and 22.\n" + " -m, --radio_mode <#>, Enable/Disable activation at start-up.\n" + " With radio mode:\n" + " 1: Low latency (default).\n" + " 2: Low latency with standby.\n" + " 3: LBT (Listen Before Talk) disabled, with standby.\n" + " 4: Disabled and radio not activated at start-up.\n" " -d, --sche_delay , Estimated scheduling delay (us).\n" "RSSI measurement settings:\n" " --rssi_scan_time , Channel access: set the time (msec) that is used for\n" @@ -1395,6 +1552,8 @@ static const char dect_phy_sett_cmd_usage_str[] = "Common TX settings:\n" " --tx_pwr , Set default TX power (dBm).\n" " [-40,-30,-20,-16,-12,-8,-4,0,4,7,10,13,16,19,21,23]\n" + " See supported max for the used band by using\n" + " \"dect status\" -command output.\n" " --tx_mcs , Set default MCS on TX (0-4).\n" "HARQ parameters in modem init:\n" " --mdm_init_harq_process_count , Count of HARQ RX processes for modem init\n" @@ -1428,6 +1587,7 @@ static struct option long_options_settings[] = { {"tx_id", required_argument, 0, 't'}, {"band_nbr", required_argument, 0, 'b'}, {"sche_delay", required_argument, 0, 'd'}, + {"radio_mode", required_argument, 0, 'm'}, {"rx_exp_rssi_level", required_argument, 0, DECT_SHELL_SETT_COMMON_RX_EXP_RSSI_LEVEL}, {"tx_pwr", required_argument, 0, DECT_SHELL_SETT_COMMON_TX_PWR}, {"tx_mcs", required_argument, 0, DECT_SHELL_SETT_COMMON_TX_MCS}, @@ -1454,6 +1614,8 @@ static struct option long_options_settings[] = { static void dect_phy_sett_cmd_print(struct dect_phy_settings *dect_sett) { + char tmp_str[128] = {0}; + desh_print("Common settings:"); desh_print(" network id (32bit).............................%u (0x%08x)", dect_sett->common.network_id, dect_sett->common.network_id); @@ -1463,6 +1625,13 @@ static void dect_phy_sett_cmd_print(struct dect_phy_settings *dect_sett) dect_sett->common.short_rd_id, dect_sett->common.short_rd_id); desh_print(" band number....................................%d", dect_sett->common.band_nbr); + if (dect_sett->common.activate_at_startup) { + desh_print(" Startup activation radio mode..................%s", + dect_common_utils_radio_mode_to_string( + dect_sett->common.startup_radio_mode, tmp_str)); + } else { + desh_print(" Startup activation.............................Disabled"); + } desh_print("Common RX settings:"); desh_print(" expected RSSI level..........................%d", dect_sett->rx.expected_rssi_level); @@ -1509,7 +1678,6 @@ static int dect_phy_sett_cmd(const struct shell *shell, size_t argc, char **argv int long_index = 0; int opt, tmp_value; - bool phy_api_reinit_needed = false; if (argc < 2) { goto show_usage; @@ -1517,8 +1685,8 @@ static int dect_phy_sett_cmd(const struct shell *shell, size_t argc, char **argv dect_common_settings_read(¤t_settings); newsettings = current_settings; - while ((opt = getopt_long(argc, argv, "d:n:t:b:rh", long_options_settings, &long_index)) != - -1) { + while ((opt = getopt_long( + argc, argv, "m:d:n:t:b:rh", long_options_settings, &long_index)) != -1) { switch (opt) { case 'r': { dect_common_settings_read(¤t_settings); @@ -1538,6 +1706,26 @@ static int dect_phy_sett_cmd(const struct shell *shell, size_t argc, char **argv newsettings.common.network_id = tmp_value; break; } + case 'm': { + tmp_value = atoi(optarg); + newsettings.common.activate_at_startup = true; + if (tmp_value == 1) { + newsettings.common.startup_radio_mode = + NRF_MODEM_DECT_PHY_RADIO_MODE_LOW_LATENCY; + } else if (tmp_value == 2) { + newsettings.common.startup_radio_mode = + NRF_MODEM_DECT_PHY_RADIO_MODE_LOW_LATENCY_WITH_STANDBY; + } else if (tmp_value == 3) { + newsettings.common.startup_radio_mode = + NRF_MODEM_DECT_PHY_RADIO_MODE_NON_LBT_WITH_STANDBY; + } else if (tmp_value == 4) { + newsettings.common.activate_at_startup = false; + } else { + desh_error("Give decent value for Radio Mode [1-3].", tmp_value); + return -EINVAL; + } + break; + } case 't': { tmp_value = shell_strtoul(optarg, 10, &ret); if (ret) { @@ -1560,8 +1748,8 @@ static int dect_phy_sett_cmd(const struct shell *shell, size_t argc, char **argv current_settings.common.band_nbr != 4) || (current_settings.common.band_nbr == 4 && newsettings.common.band_nbr != 4)) { - /* If changing to/from 4, we need dto reinit PHY API */ - phy_api_reinit_needed = true; + desh_warn("Note: Band change to/from 4 requires " + "a reboot or a reactivate."); } break; } @@ -1646,7 +1834,6 @@ static int dect_phy_sett_cmd(const struct shell *shell, size_t argc, char **argv } case DECT_SHELL_SETT_RESET_ALL: { dect_common_settings_defaults_set(); - phy_api_reinit_needed = true; goto settings_updated; } case 'h': @@ -1664,10 +1851,7 @@ static int dect_phy_sett_cmd(const struct shell *shell, size_t argc, char **argv dect_common_settings_write(&newsettings); settings_updated: - dect_phy_ctrl_msgq_data_op_add( - DECT_PHY_CTRL_OP_SETTINGS_UPDATED, - (void *)&phy_api_reinit_needed, - sizeof(bool)); + dect_phy_ctrl_msgq_non_data_op_add(DECT_PHY_CTRL_OP_SETTINGS_UPDATED); return 0; show_usage: @@ -1702,6 +1886,18 @@ SHELL_SUBCMD_ADD((dect), sett, NULL, "Set and read common dect settings.\n" " Usage: dect sett -h", dect_phy_sett_cmd, 1, 10); +SHELL_SUBCMD_ADD((dect), activate, NULL, + "Activate radio.\n" + " Usage: dect activate -h", + dect_phy_activate_cmd, 1, 10); +SHELL_SUBCMD_ADD((dect), deactivate, NULL, + "De-activate radio.\n" + " Usage: dect deactivate", + dect_phy_deactivate_cmd, 1, 0); +SHELL_SUBCMD_ADD((dect), radio_mode, NULL, + "Activate radio.\n" + " Usage: dect radio_mode -h", + dect_phy_radio_mode_cmd, 1, 10); SHELL_SUBCMD_ADD((dect), rssi_scan, NULL, "Execute RSSI measurement/scan.\n" " Usage: dect rssi_scan [options: see: dect rssi_scan -h]", diff --git a/samples/dect/dect_phy/dect_shell/src/dect/dect_phy_shell.h b/samples/dect/dect_phy/dect_shell/src/dect/dect_phy_shell.h index 494225a80cf..6cbae1b6d7f 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/dect_phy_shell.h +++ b/samples/dect/dect_phy/dect_shell/src/dect/dect_phy_shell.h @@ -125,7 +125,6 @@ struct dect_phy_ping_params { #define DECT_PHY_SHELL_RSSI_SCAN_DEFAULT_DURATION_MS \ ((DECT_PHY_SETT_DEFAULT_BEACON_TX_INTERVAL_SECS * 1000) + 10) struct dect_phy_rssi_scan_params { - bool reinit_mdm_api; bool suspend_scheduler; bool only_allowed_channels; /* At band #1, scan only allowed channels per Harmonized std */ @@ -176,6 +175,8 @@ struct dect_phy_common_op_event_msgq_item { #define DECT_PHY_COMMON_RX_CMD_HANDLE 50 #define DECT_PHY_COMMON_RSSI_SCAN_HANDLE 60 +#define DECT_PHY_RADIO_MODE_CONFIG_HANDLE 70 + #define DECT_PHY_MAC_BEACON_LMS_RSSI_SCAN_HANDLE 99 #define DECT_PHY_MAC_BEACON_TX_HANDLE 100 diff --git a/samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac.c b/samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac.c index 27fcbeba649..f7c422ab5a9 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac.c +++ b/samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac.c @@ -379,14 +379,15 @@ bool dect_phy_mac_handle(struct dect_phy_commmon_op_pdc_rcv_params *rcv_params) } const uint8_t *p_ptr = data_ptr + 1; - struct nrf_modem_dect_phy_rx_pdc_status *p_rx_status = &(rcv_params->rx_status); + struct nrf_modem_dect_phy_pdc_event *p_rx_status = &(rcv_params->rx_status); dect_phy_mac_common_header_t common_header; int16_t rssi_level = p_rx_status->rssi_2 / 2; if (print) { - desh_print("PDC received (stf start time %llu): snr %d, " + desh_print("PDC received (stf start time %llu, handle %d): snr %d, " "RSSI-2 %d (RSSI %d), len %d", - rcv_params->time, p_rx_status->snr, p_rx_status->rssi_2, rssi_level, + rcv_params->time, p_rx_status->handle, + p_rx_status->snr, p_rx_status->rssi_2, rssi_level, rcv_params->data_length); dect_phy_mac_type_header_print(&type_header); @@ -398,9 +399,10 @@ bool dect_phy_mac_handle(struct dect_phy_commmon_op_pdc_rcv_params *rcv_params) if (!handled) { /* In failure, we want to print what we got */ if (!print) { - desh_print("PDC received (stf start time %llu): snr %d, " + desh_print("PDC received (stf start time %llu, handle %d): snr %d, " "RSSI-2 %d (RSSI %d), len %d", - rcv_params->time, p_rx_status->snr, p_rx_status->rssi_2, rssi_level, + rcv_params->time, p_rx_status->handle, + p_rx_status->snr, p_rx_status->rssi_2, rssi_level, rcv_params->data_length); } desh_error("Failed to decode MAC Common header"); @@ -448,7 +450,7 @@ bool dect_phy_mac_handle(struct dect_phy_commmon_op_pdc_rcv_params *rcv_params) /* If received cluster beacon with RA IE, store as a neighbor */ if (beacon_msg != NULL && ra_ie != NULL) { dect_phy_mac_nbr_info_store_n_update( - &rcv_params->time, rcv_params->last_rx_op_channel, + &rcv_params->time, rcv_params->rx_channel, common_header.nw_id, rcv_params->last_received_pcc_short_nw_id, common_header.transmitter_id, rcv_params->last_received_pcc_transmitter_short_rd_id, beacon_msg, diff --git a/samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac_client.c b/samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac_client.c index 85612017aed..4076e52a9b1 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac_client.c +++ b/samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac_client.c @@ -166,8 +166,8 @@ static uint64_t dect_phy_mac_client_next_rach_tx_time_get( uint64_t time_now = dect_app_modem_time_now(); uint64_t beacon_received = target_nbr->time_rcvd_mdm_ticks; - uint64_t first_possible_tx = - time_now + (US_TO_MODEM_TICKS(current_settings->scheduler.scheduling_delay_us)); + uint64_t first_possible_tx = time_now + dect_phy_ctrl_modem_latency_for_next_op_get(true) + + (US_TO_MODEM_TICKS(current_settings->scheduler.scheduling_delay_us)); uint64_t next_beacon_frame_start, beacon_interval_mdm_ticks, ra_start_mdm_ticks; uint64_t ra_interval_mdm_ticks, last_valid_rach_rx_frame_time; diff --git a/samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac_cluster_beacon.c b/samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac_cluster_beacon.c index c10322f3136..539afbe7ab7 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac_cluster_beacon.c +++ b/samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac_cluster_beacon.c @@ -226,7 +226,7 @@ void dect_phy_mac_ctrl_lms_rssi_scan_data_init(int beacon_tx_slot_count) } void dect_phy_mac_ctrl_cluster_beacon_phy_api_direct_rssi_cb( - const struct nrf_modem_dect_phy_rssi_meas *p_meas_results) + const struct nrf_modem_dect_phy_rssi_event *p_meas_results) { /* Handle Last Minute Scan results. This assumes that start time was frame start. */ bool busy_in_beacon_tx = false; diff --git a/samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac_cluster_beacon.h b/samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac_cluster_beacon.h index b11aed4aeca..4a2b7e9d352 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac_cluster_beacon.h +++ b/samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac_cluster_beacon.h @@ -35,7 +35,7 @@ void dect_phy_mac_cluster_beacon_update(void); void dect_phy_mac_cluster_beacon_status_print(void); void dect_phy_mac_ctrl_cluster_beacon_phy_api_direct_rssi_cb( - const struct nrf_modem_dect_phy_rssi_meas *meas_results); + const struct nrf_modem_dect_phy_rssi_event *meas_results); bool dect_phy_mac_cluster_beacon_is_running(void); diff --git a/samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac_ctrl.c b/samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac_ctrl.c index 3aa47d92d26..8dce9f9a5d4 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac_ctrl.c +++ b/samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac_ctrl.c @@ -83,7 +83,7 @@ static void dect_phy_mac_ctrl_beacon_start_work_handler(struct k_work *work_item .stop_on_1st_free_channel = false, .dont_stop_on_this_channel = 0, .dont_stop_on_nbr_channels = true, - .reinit_mdm_api = true, + .suspend_scheduler = true, .only_allowed_channels = true, }; @@ -253,6 +253,20 @@ int dect_phy_mac_ctrl_associate(struct dect_phy_mac_associate_params *params) return ret; } + enum nrf_modem_dect_phy_radio_mode radio_mode; + + ret = dect_phy_ctrl_current_radio_mode_get(&radio_mode); + if (!ret && radio_mode == NRF_MODEM_DECT_PHY_RADIO_MODE_NON_LBT_WITH_STANDBY) { + char tmp_str[128] = {0}; + + dect_common_utils_radio_mode_to_string(radio_mode, tmp_str); + + /* We need to disable LBT */ + desh_warn("Accociate req to RA resource requires LBT to be used, continue -- " + "but current radio mode is %s and operation will fail in modem.", + tmp_str); + } + ret = dect_phy_mac_client_associate(scan_info, params); if (ret) { desh_error("Cannot start client_associate: %d", ret); @@ -281,6 +295,20 @@ int dect_phy_mac_ctrl_dissociate(struct dect_phy_mac_associate_params *params) return ret; } + enum nrf_modem_dect_phy_radio_mode radio_mode; + + ret = dect_phy_ctrl_current_radio_mode_get(&radio_mode); + if (!ret && radio_mode == NRF_MODEM_DECT_PHY_RADIO_MODE_NON_LBT_WITH_STANDBY) { + char tmp_str[128] = {0}; + + dect_common_utils_radio_mode_to_string(radio_mode, tmp_str); + + /* We need to disable LBT */ + desh_warn("Accociate req to RA resource requires LBT to be used, continue -- " + "but current radio mode is %s and operation will fail in modem.", + tmp_str); + } + ret = dect_phy_mac_client_dissociate(scan_info, params); if (ret) { desh_error("Cannot start client_dissociate: %d", ret); @@ -309,6 +337,20 @@ int dect_phy_mac_ctrl_rach_tx_start(struct dect_phy_mac_rach_tx_params *params) return ret; } + enum nrf_modem_dect_phy_radio_mode radio_mode; + + ret = dect_phy_ctrl_current_radio_mode_get(&radio_mode); + if (!ret && radio_mode == NRF_MODEM_DECT_PHY_RADIO_MODE_NON_LBT_WITH_STANDBY) { + char tmp_str[128] = {0}; + + dect_common_utils_radio_mode_to_string(radio_mode, tmp_str); + + /* We need to disable LBT */ + desh_warn("Accociate req to RA resource requires LBT to be used, continue -- " + "but current radio mode is %s and operation will fail in modem.", + tmp_str); + } + ret = dect_phy_mac_client_rach_tx_start(scan_info, params); if (ret) { desh_error("Cannot start client_rach_tx: %d", ret); @@ -339,6 +381,11 @@ void dect_phy_mac_ctrl_th_phy_api_mdm_op_complete_cb( if (params->status != NRF_MODEM_DECT_PHY_SUCCESS) { char tmp_str[128] = {0}; + if (params->status == NRF_MODEM_DECT_PHY_ERR_OP_CANCELED) { + /* Intentionally cancelled - do not print PHY_ERR_OP_CANCELED */ + goto specific_handles; + } + dect_common_utils_modem_phy_err_to_string(params->status, params->temperature, tmp_str); if (params->handle == DECT_PHY_MAC_BEACON_TX_HANDLE) { @@ -378,6 +425,7 @@ void dect_phy_mac_ctrl_th_phy_api_mdm_op_complete_cb( } } +specific_handles: if (!dect_phy_mac_cluster_beacon_is_running() && (params->handle == DECT_PHY_MAC_CLIENT_RA_TX_HANDLE || params->handle == DECT_PHY_MAC_CLIENT_ASSOCIATION_RX_HANDLE || diff --git a/samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac_nbr.c b/samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac_nbr.c index c9add9872c9..8c8e294a3c3 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac_nbr.c +++ b/samples/dect/dect_phy/dect_shell/src/dect/mac/dect_phy_mac_nbr.c @@ -112,9 +112,9 @@ bool dect_phy_mac_nbr_info_store_n_update(uint64_t const *rcv_time, uint16_t cha (__func__), long_rd_id); done = false; } else { - desh_print("Neighbor with long rd id %u (0x%08x), short rd id %u (0x%04x) " - "stored to nbr list.", - long_rd_id, long_rd_id, short_rd_id, short_rd_id); + desh_print("Neighbor with long rd id %u (0x%08x), short rd id %u (0x%04x), " + "channel %d, stored to nbr list.", + long_rd_id, long_rd_id, short_rd_id, short_rd_id, channel); } } else { /* Already existing beacon: update */ @@ -124,6 +124,9 @@ bool dect_phy_mac_nbr_info_store_n_update(uint64_t const *rcv_time, uint16_t cha nbr_ptr->time_rcvd_mdm_ticks, *rcv_time); + if (channel) { + nbr_ptr->channel = channel; + } nbr_ptr->short_rd_id = short_rd_id; nbr_ptr->nw_id_24msb = nw_id_24msb; nbr_ptr->nw_id_8lsb = nw_id_8lsb; @@ -137,11 +140,11 @@ bool dect_phy_mac_nbr_info_store_n_update(uint64_t const *rcv_time, uint16_t cha if (print_update) { desh_print("Neighbor with long rd id %u (0x%08x), short rd id %u (0x%04x), " - "nw (24bit MSB: %u (0x%06x), 8bit LSB: %u (0x%02x))\n" + "nw (24bit MSB: %u (0x%06x), 8bit LSB: %u (0x%02x)), channel %d\n" " updated with time %llu (time shift %lld mdm ticks) to nbr list.", long_rd_id, long_rd_id, short_rd_id, short_rd_id, nw_id_24msb, - nw_id_24msb, nw_id_8lsb, nw_id_8lsb, nbr_ptr->time_rcvd_mdm_ticks, - time_shift_mdm_ticks); + nw_id_24msb, nw_id_8lsb, nw_id_8lsb, nbr_ptr->channel, + nbr_ptr->time_rcvd_mdm_ticks, time_shift_mdm_ticks); } } k_mutex_unlock(&nbr_list_mutex); diff --git a/samples/dect/dect_phy/dect_shell/src/dect/perf/dect_phy_perf.c b/samples/dect/dect_phy/dect_shell/src/dect/perf/dect_phy_perf.c index 4659553a8bf..edc8c847118 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/perf/dect_phy_perf.c +++ b/samples/dect/dect_phy/dect_shell/src/dect/perf/dect_phy_perf.c @@ -31,8 +31,6 @@ BUILD_ASSERT((sizeof(dect_phy_perf_pdu_t) == DECT_DATA_MAX_LEN), "dect_phy_perf_pdu_t must be 700 bytes"); -K_SEM_DEFINE(perf_phy_api_init, 0, 1); - #define DECT_PHY_PERF_HARQ_TX_PROCESS_COUNT 8 #define DECT_PHY_PERF_HARQ_TX_PROCESS_TIMEOUT_SECS 2 #define DECT_PHY_PERF_CLIENT_TX_WINDOW_COUNT 7 @@ -120,7 +118,6 @@ static struct dect_phy_perf_data { int64_t time_started_ms; struct dect_phy_perf_params cmd_params; - struct nrf_modem_dect_phy_modem_cfg mdm_init_conf; struct dect_phy_perf_rx_metrics rx_metrics; struct dect_phy_perf_tx_metrics tx_metrics; @@ -154,9 +151,8 @@ static int dect_phy_perf_rx_pdc_data_handle(struct dect_phy_data_rcv_common_para #define DECT_PHY_PERF_EVENT_RX_PCC_CRC_ERROR 4 #define DECT_PHY_PERF_EVENT_RX_PDC_CRC_ERROR 5 #define DECT_PHY_PERF_EVENT_RX_PCC 6 -#define DECT_PHY_PERF_EVENT_MDM_INITIALIZED 7 -#define DECT_PHY_PERF_EVENT_HARQ_TX_WIN_TIMER 8 -#define DECT_PHY_PERF_EVENT_CMD_DONE 9 +#define DECT_PHY_PERF_EVENT_HARQ_TX_WIN_TIMER 7 +#define DECT_PHY_PERF_EVENT_CMD_DONE 8 static int dect_phy_perf_msgq_non_data_op_add(uint16_t event_id); static int dect_phy_perf_msgq_data_op_add(uint16_t event_id, void *data, size_t data_size); @@ -410,69 +406,40 @@ static uint8_t dect_phy_perf_current_free_harq_tx_process_count_get(void) /**************************************************************************************************/ -static void dect_phy_perf_initialize_cb(const uint64_t *time, int16_t temperature, - enum nrf_modem_dect_phy_err status, - const struct nrf_modem_dect_phy_modem_cfg *modem_configuration) -{ - struct dect_phy_common_op_initialized_params initialized_evt_params; - - initialized_evt_params.time = *time; - initialized_evt_params.temperature = temperature; - initialized_evt_params.status = status; - initialized_evt_params.modem_configuration = *modem_configuration; - - dect_app_modem_time_save(time); - dect_phy_perf_msgq_data_op_add(DECT_PHY_PERF_EVENT_MDM_INITIALIZED, - (void *)&initialized_evt_params, - sizeof(struct dect_phy_common_op_initialized_params)); -} - -static void dect_phy_perf_rx_op_stop_cb(uint64_t const *time, enum nrf_modem_dect_phy_err status, - uint32_t handle) -{ - dect_app_modem_time_save(time); -} - -static void dect_phy_perf_op_complete_cb(uint64_t const *time, int16_t temperature, - enum nrf_modem_dect_phy_err status, uint32_t handle) +static void dect_phy_perf_mdm_op_complete_cb( + const struct nrf_modem_dect_phy_op_complete_event *evt, uint64_t *time) { struct dect_phy_common_op_completed_params perf_op_completed_params = { - .handle = handle, - .temperature = temperature, - .status = status, + .handle = evt->handle, + .temperature = evt->temp, + .status = evt->err, .time = *time, }; - dect_app_modem_time_save(time); - dect_phy_perf_msgq_data_op_add(DECT_PHY_PERF_EVENT_MDM_OP_COMPLETED, (void *)&perf_op_completed_params, sizeof(struct dect_phy_common_op_completed_params)); } -static void dect_phy_perf_rx_pcc_cb(uint64_t const *time, - struct nrf_modem_dect_phy_rx_pcc_status const *p_rx_status, - union nrf_modem_dect_phy_hdr const *p_phy_header) +static void dect_phy_perf_mdm_pcc_cb(const struct nrf_modem_dect_phy_pcc_event *evt, uint64_t *time) { struct dect_phy_common_op_pcc_rcv_params ctrl_pcc_op_params; struct dect_phy_perf_params *cmd_params = &(perf_data.cmd_params); uint64_t harq_feedback_start_time = 0; - struct dect_phy_header_type2_format0_t *header = (void *)p_phy_header; + struct dect_phy_header_type2_format0_t *header = (void *)&evt->hdr; uint16_t len_slots = header->packet_length + 1; /* Always in slots */ struct dect_phy_header_type2_format1_t feedback_header; - dect_app_modem_time_save(time); - - ctrl_pcc_op_params.pcc_status = *p_rx_status; - ctrl_pcc_op_params.phy_header = *p_phy_header; + ctrl_pcc_op_params.pcc_status = *evt; + ctrl_pcc_op_params.phy_header = evt->hdr; ctrl_pcc_op_params.phy_len = header->packet_length; ctrl_pcc_op_params.phy_len_type = header->packet_length_type; ctrl_pcc_op_params.time = *time; - ctrl_pcc_op_params.stf_start_time = p_rx_status->stf_start_time; + ctrl_pcc_op_params.stf_start_time = evt->stf_start_time; if (cmd_params->use_harq && cmd_params->role == DECT_PHY_COMMON_ROLE_SERVER) { harq_feedback_start_time = - p_rx_status->stf_start_time + + evt->stf_start_time + (len_slots * DECT_RADIO_SLOT_DURATION_IN_MODEM_TICKS) + (cmd_params->server_harq_feedback_tx_delay_subslot_count * DECT_RADIO_SUBSLOT_DURATION_IN_MODEM_TICKS); @@ -481,9 +448,9 @@ static void dect_phy_perf_rx_pcc_cb(uint64_t const *time, /* Provide HARQ feedback if requested */ perf_data.rx_metrics.rx_last_pcc_received = k_uptime_get(); - if (p_rx_status->header_status == NRF_MODEM_DECT_PHY_HDR_STATUS_VALID) { - struct dect_phy_ctrl_field_common *phy_h = (void *)p_phy_header; - const uint8_t *p_ptr = (uint8_t *)p_phy_header; + if (evt->header_status == NRF_MODEM_DECT_PHY_HDR_STATUS_VALID) { + struct dect_phy_ctrl_field_common *phy_h = (void *)&evt->hdr; + const uint8_t *p_ptr = (uint8_t *)&evt->hdr; /* Get to transmitter_identity_hi */ p_ptr++; @@ -492,7 +459,7 @@ static void dect_phy_perf_rx_pcc_cb(uint64_t const *time, perf_data.rx_metrics.rx_last_pcc_phy_pwr = phy_h->transmit_power; if (cmd_params->role == DECT_PHY_COMMON_ROLE_SERVER) { - if (p_rx_status->phy_type == DECT_PHY_HEADER_TYPE2) { + if (evt->phy_type == DECT_PHY_HEADER_TYPE2) { struct nrf_modem_dect_phy_tx_params harq_tx = perf_data.server_data.harq_feedback_data.params; @@ -567,126 +534,73 @@ static void dect_phy_perf_rx_pcc_cb(uint64_t const *time, sizeof(struct dect_phy_common_op_pcc_rcv_params)); } -static void dect_phy_perf_pcc_crc_failure_cb( - uint64_t const *time, struct nrf_modem_dect_phy_rx_pcc_crc_failure const *crc_failure) +static void dect_phy_perf_mdm_pcc_crc_failure_cb( + const struct nrf_modem_dect_phy_pcc_crc_failure_event *evt, uint64_t *time) { struct dect_phy_common_op_pcc_crc_fail_params pdc_crc_fail_params = { .time = *time, - .crc_failure = *crc_failure, + .crc_failure = *evt, }; - dect_app_modem_time_save(time); dect_phy_perf_msgq_data_op_add(DECT_PHY_PERF_EVENT_RX_PCC_CRC_ERROR, (void *)&pdc_crc_fail_params, sizeof(struct dect_phy_common_op_pcc_crc_fail_params)); } -static void dect_phy_perf_rx_pdc_cb(uint64_t const *time, - struct nrf_modem_dect_phy_rx_pdc_status const *p_rx_status, - void const *p_data, uint32_t length) +static void dect_phy_perf_mdm_pdc_cb(const struct nrf_modem_dect_phy_pdc_event *evt, uint64_t *time) { - int16_t rssi_level = p_rx_status->rssi_2 / 2; - - dect_app_modem_time_save(time); + int16_t rssi_level = evt->rssi_2 / 2; struct dect_phy_commmon_op_pdc_rcv_params perf_pdc_op_params; - perf_pdc_op_params.rx_status = *p_rx_status; + perf_pdc_op_params.rx_status = *evt; - perf_pdc_op_params.data_length = length; + perf_pdc_op_params.data_length = evt->len; perf_pdc_op_params.time = *time; perf_pdc_op_params.rx_pwr_dbm = 0; /* Not needed from PDC */ perf_pdc_op_params.rx_rssi_level_dbm = rssi_level; - perf_pdc_op_params.last_rx_op_channel = perf_data.cmd_params.channel; + perf_pdc_op_params.rx_channel = perf_data.cmd_params.channel; - if (length <= sizeof(perf_pdc_op_params.data)) { - memcpy(perf_pdc_op_params.data, p_data, length); + if (evt->len <= sizeof(perf_pdc_op_params.data)) { + memcpy(perf_pdc_op_params.data, evt->data, evt->len); dect_phy_perf_msgq_data_op_add(DECT_PHY_PERF_EVENT_RX_PDC_DATA, (void *)&perf_pdc_op_params, sizeof(struct dect_phy_commmon_op_pdc_rcv_params)); } else { printk("Received data is too long to be received by PERF TH - discarded (len %d, " "buf size %d)\n", - length, sizeof(perf_pdc_op_params.data)); + evt->len, sizeof(perf_pdc_op_params.data)); } } -static void dect_phy_perf_on_pdc_crc_failure_cb( - uint64_t const *time, struct nrf_modem_dect_phy_rx_pdc_crc_failure const *crc_failure) +static void dect_phy_perf_mdm_pdc_crc_failure_cb( + const struct nrf_modem_dect_phy_pdc_crc_failure_event *evt, uint64_t *time) { struct dect_phy_common_op_pdc_crc_fail_params pdc_crc_fail_params = { .time = *time, - .crc_failure = *crc_failure, + .crc_failure = *evt, }; - dect_app_modem_time_save(time); dect_phy_perf_msgq_data_op_add(DECT_PHY_PERF_EVENT_RX_PDC_CRC_ERROR, (void *)&pdc_crc_fail_params, sizeof(struct dect_phy_common_op_pdc_crc_fail_params)); } -static void dect_phy_perf_on_rssi_cb(const uint64_t *time, - const struct nrf_modem_dect_phy_rssi_meas *p_result) -{ - printk("WARN: Unexpectedly in %s\n", (__func__)); -} - -static void dect_phy_perf_link_configuration_cb( - uint64_t const *time, enum nrf_modem_dect_phy_err status) -{ - printk("WARN: Unexpectedly in %s\n", (__func__)); -} - -static void dect_phy_perf_time_query_cb(uint64_t const *time, enum nrf_modem_dect_phy_err status) -{ - printk("WARN: Unexpectedly in %s\n", (__func__)); -} - -static void dect_phy_perf_capability_get_cb(const uint64_t *time, enum nrf_modem_dect_phy_err err, - const struct nrf_modem_dect_phy_capability *capabilities) +static void dect_phy_perf_mdm_capability_get_cb( + const struct nrf_modem_dect_phy_capability_get_event *evt) { - dect_app_modem_time_save(time); - - for (int i = 0; i < capabilities->variant_count; i++) { - if (capabilities->variant[i].harq_process_count_max != + for (int i = 0; i < evt->capability->variant_count; i++) { + if (evt->capability->variant[i].harq_process_count_max != DECT_PHY_PERF_HARQ_TX_PROCESS_COUNT) { printk("Modem HARQ max process count (%d) does not match expected count: " "%d!!!!\n", - capabilities->variant[i].harq_process_count_max, + evt->capability->variant[i].harq_process_count_max, DECT_PHY_PERF_HARQ_TX_PROCESS_COUNT); } } } -static void dect_phy_perf_stf_cover_seq_control_cb( - const uint64_t *time, enum nrf_modem_dect_phy_err err) -{ - printk("WARN: Unexpectedly in %s\n", (__func__)); -} - -extern struct k_sem dect_phy_ctrl_mdm_api_deinit_sema; -static void dect_phy_perf_deinit_cb(const uint64_t *time, enum nrf_modem_dect_phy_err err) -{ - k_sem_give(&dect_phy_ctrl_mdm_api_deinit_sema); -} - -static const struct nrf_modem_dect_phy_callbacks perf_phy_api_config = { - .init = dect_phy_perf_initialize_cb, - .rx_stop = dect_phy_perf_rx_op_stop_cb, - .op_complete = dect_phy_perf_op_complete_cb, - .pcc = dect_phy_perf_rx_pcc_cb, - .pcc_crc_err = dect_phy_perf_pcc_crc_failure_cb, - .pdc = dect_phy_perf_rx_pdc_cb, - .pdc_crc_err = dect_phy_perf_on_pdc_crc_failure_cb, - .rssi = dect_phy_perf_on_rssi_cb, - .link_config = dect_phy_perf_link_configuration_cb, - .time_get = dect_phy_perf_time_query_cb, - .capability_get = dect_phy_perf_capability_get_cb, - .stf_cover_seq_control = dect_phy_perf_stf_cover_seq_control_cb, - .deinit = dect_phy_perf_deinit_cb, -}; - /**************************************************************************************************/ static void dect_phy_perf_client_tx_with_harq(uint64_t first_possible_tx) @@ -897,7 +811,7 @@ static int dect_phy_perf_client_start(void) uint64_t time_now = dect_app_modem_time_now(); uint64_t first_possible_tx = time_now + - (US_TO_MODEM_TICKS(current_settings->scheduler.scheduling_delay_us + 4000)); + (US_TO_MODEM_TICKS(2 * current_settings->scheduler.scheduling_delay_us + 4000)); /* Sending max amount of data that can be encoded to given slot amount */ int16_t perf_pdu_byte_count = @@ -1005,11 +919,24 @@ static int dect_phy_perf_start(struct dect_phy_perf_params *params, ret = dect_phy_perf_client_start(); } else { __ASSERT_NO_MSG(params->role == DECT_PHY_COMMON_ROLE_SERVER); + enum nrf_modem_dect_phy_radio_mode radio_mode; + uint64_t next_possible_start_time = 0; + + + ret = dect_phy_ctrl_current_radio_mode_get(&radio_mode); desh_print("Starting server RX: channel %d, exp_rssi_level %d, duration %d secs.", params->channel, params->expected_rx_rssi_level, params->duration_secs); - ret = dect_phy_perf_server_rx_start(0); + if (!ret && radio_mode != NRF_MODEM_DECT_PHY_RADIO_MODE_LOW_LATENCY) { + uint64_t time_now = dect_app_modem_time_now(); + struct dect_phy_settings *current_settings = dect_common_settings_ref_get(); + + next_possible_start_time = + time_now + (3 * US_TO_MODEM_TICKS( + current_settings->scheduler.scheduling_delay_us)); + } + ret = dect_phy_perf_server_rx_start(next_possible_start_time); } return ret; } @@ -1050,8 +977,9 @@ static int dect_phy_perf_tx_request_results(void) .transmitter_identity_lo = (uint8_t)(current_settings->common.transmitter_id & 0xFF), .df_mcs = 0, - .transmit_power = dect_common_utils_next_phy_tx_power_get( - dect_common_utils_dbm_to_phy_tx_power(params->tx_power_dbm)), + .transmit_power = dect_phy_ctrl_utils_mdm_next_supported_phy_tx_power_get( + dect_common_utils_dbm_to_phy_tx_power(params->tx_power_dbm), + params->channel), .receiver_identity_hi = (uint8_t)(params->destination_transmitter_id >> 8), .receiver_identity_lo = (uint8_t)(params->destination_transmitter_id & 0xFF), .feedback.format1.format = 0, @@ -1188,8 +1116,8 @@ static int dect_phy_perf_server_results_tx(char *result_str) .transmitter_identity_lo = (uint8_t)(current_settings->common.transmitter_id & 0xFF), .df_mcs = 1, - .transmit_power = dect_common_utils_next_phy_tx_power_get( - perf_data.rx_metrics.rx_last_pcc_phy_pwr), + .transmit_power = dect_phy_ctrl_utils_mdm_next_supported_phy_tx_power_get( + perf_data.rx_metrics.rx_last_pcc_phy_pwr, params->channel), .receiver_identity_hi = (uint8_t)(perf_data.rx_metrics.rx_last_tx_id >> 8), .receiver_identity_lo = (uint8_t)(perf_data.rx_metrics.rx_last_tx_id & 0xFF), .feedback.format1.format = 0, @@ -1298,7 +1226,7 @@ static void dect_phy_perf_server_report_local_and_tx_results(void) (strlen(results_str) + 1), results_str); /* Send results to client: */ - (void)nrf_modem_dect_phy_rx_stop(DECT_PHY_PERF_SERVER_RX_HANDLE); + (void)nrf_modem_dect_phy_cancel(DECT_PHY_PERF_SERVER_RX_HANDLE); if (dect_phy_perf_server_results_tx(results_str)) { desh_error("Cannot start sending server results"); } @@ -1532,25 +1460,6 @@ static void dect_phy_perf_thread_fn(void) dect_phy_perf_client_tx_with_harq(next_possible_tx); break; } - case DECT_PHY_PERF_EVENT_MDM_INITIALIZED: { - struct dect_phy_common_op_initialized_params *params = - (struct dect_phy_common_op_initialized_params *)event.data; - - if (params->status) { - desh_error("(%s): init failed (time %llu, temperature %d, " - "temp_limit %d): %d", - (__func__), params->time, params->temperature, - params->modem_configuration.temperature_limit, - params->status); - } else { - desh_print("dect phy api initialized for perf command."); - perf_data.mdm_init_conf = params->modem_configuration; - dect_phy_perf_harq_tx_process_table_init( - perf_data.cmd_params.client_harq_process_nbr_max); - } - k_sem_give(&perf_phy_api_init); - break; - } case DECT_PHY_PERF_EVENT_MDM_OP_COMPLETED: { struct dect_phy_common_op_completed_params *params = @@ -1719,10 +1628,11 @@ static void dect_phy_perf_thread_fn(void) perf_data.rx_metrics.rx_last_pcc_print_zticks = z_ticks_last_pcc_print; - desh_print("Periodic debug: PCC received (time %llu): " - "status: \"%s\", snr %d, " + desh_print("Periodic debug: PCC received (time %llu, " + "handle %d): status: \"%s\", snr %d, " "RSSI %d, tx pwr %d dbm", - params->time, tmp_str, params->pcc_status.snr, + params->time, params->pcc_status.handle, + tmp_str, params->pcc_status.snr, rssi_level, dect_common_utils_phy_tx_power_to_dbm( phy_h->transmit_power)); @@ -1763,13 +1673,15 @@ static void dect_phy_perf_thread_fn(void) char snum[64] = {0}; unsigned char hex_data[128]; int i; - struct nrf_modem_dect_phy_rx_pdc_status *p_rx_status = + struct nrf_modem_dect_phy_pdc_event *p_rx_status = &(params->rx_status); int16_t rssi_level = p_rx_status->rssi_2 / 2; - desh_print("PDC received (time %llu): snr %d, RSSI-2 %d " + desh_print("PDC received (time %llu, handle %d): " + "snr %d, RSSI-2 %d " "(RSSI %d), len %d", - params->time, p_rx_status->snr, + params->time, p_rx_status->handle, + p_rx_status->snr, p_rx_status->rssi_2, rssi_level, params->data_length); @@ -1837,49 +1749,68 @@ static int dect_phy_perf_msgq_non_data_op_add(uint16_t event_id) /**************************************************************************************************/ -static void dect_phy_perf_phy_init(struct nrf_modem_dect_phy_init_params *init_params) +void dect_phy_perf_mdm_evt_handler(const struct nrf_modem_dect_phy_event *evt) +{ + dect_app_modem_time_save(&evt->time); + + switch (evt->id) { + case NRF_MODEM_DECT_PHY_EVT_COMPLETED: + dect_phy_perf_mdm_op_complete_cb(&evt->op_complete, (uint64_t *)&evt->time); + break; + case NRF_MODEM_DECT_PHY_EVT_PCC: + dect_phy_perf_mdm_pcc_cb(&evt->pcc, (uint64_t *)&evt->time); + break; + case NRF_MODEM_DECT_PHY_EVT_PCC_ERROR: + dect_phy_perf_mdm_pcc_crc_failure_cb(&evt->pcc_crc_err, (uint64_t *)&evt->time); + break; + case NRF_MODEM_DECT_PHY_EVT_PDC: + dect_phy_perf_mdm_pdc_cb(&evt->pdc, (uint64_t *) &evt->time); + break; + case NRF_MODEM_DECT_PHY_EVT_PDC_ERROR: + dect_phy_perf_mdm_pdc_crc_failure_cb(&evt->pdc_crc_err, (uint64_t *)&evt->time); + break; + case NRF_MODEM_DECT_PHY_EVT_CAPABILITY: + dect_phy_perf_mdm_capability_get_cb(&evt->capability_get); + break; + + /* Callbacks handled by dect_phy_ctrl */ + case NRF_MODEM_DECT_PHY_EVT_RADIO_CONFIG: + dect_phy_ctrl_mdm_radio_config_cb(&evt->radio_config); + break; + case NRF_MODEM_DECT_PHY_EVT_ACTIVATE: + dect_phy_ctrl_mdm_activate_cb(&evt->activate); + break; + case NRF_MODEM_DECT_PHY_EVT_DEACTIVATE: + dect_phy_ctrl_mdm_deactivate_cb(&evt->deactivate); + break; + case NRF_MODEM_DECT_PHY_EVT_CANCELED: + dect_phy_ctrl_mdm_cancel_cb(&evt->cancel); + break; + + default: + printk("%s: WARN: Unexpected event id %d\n", (__func__), evt->id); + break; + } +} + +static void dect_phy_perf_phy_init(void) { - int ret = nrf_modem_dect_phy_callback_set(&perf_phy_api_config); + int ret = nrf_modem_dect_phy_event_handler_set(dect_phy_perf_mdm_evt_handler); if (ret) { - printk("nrf_modem_dect_phy_callback_set returned: %i\n", ret); - } else { - ret = nrf_modem_dect_phy_init(init_params); - - if (ret) { - printk("nrf_modem_dect_phy_init returned: %i\n", ret); - } else { - ret = nrf_modem_dect_phy_capability_get(); /* asynch: result in callback */ - if (ret) { - printk("nrf_modem_dect_phy_capability_get returned: %i\n", ret); - } - } + printk("nrf_modem_dect_phy_event_handler_set returned: %i\n", ret); } } int dect_phy_perf_cmd_handle(struct dect_phy_perf_params *params) { int ret; - struct dect_phy_settings *current_settings = dect_common_settings_ref_get(); - struct nrf_modem_dect_phy_init_params perf_phy_init_params = { - .harq_rx_expiry_time_us = params->mdm_init_harq_expiry_time_us, - .harq_rx_process_count = params->mdm_init_harq_process_count, - .reserved = 0, - .band4_support = ((current_settings->common.band_nbr == 4) ? 1 : 0), - }; if (perf_data.perf_ongoing) { desh_error("perf command already running"); return -1; } - k_sem_reset(&perf_phy_api_init); - dect_phy_perf_phy_init(&perf_phy_init_params); - - ret = k_sem_take(&perf_phy_api_init, K_SECONDS(5)); - if (ret) { - desh_error("(%s): nrf_modem_dect_phy_init() timeout.", (__func__)); - return -ETIMEDOUT; - } + dect_phy_perf_phy_init(); ret = dect_phy_perf_start(params, START); if (ret) { @@ -1907,7 +1838,6 @@ void dect_phy_perf_cmd_stop(void) } } else { dect_phy_perf_msgq_non_data_op_add(DECT_PHY_PERF_EVENT_SERVER_REPORT); - nrf_modem_dect_phy_rx_stop(DECT_PHY_PERF_SERVER_RX_HANDLE); dect_phy_perf_server_data_ongoing_rx_count_decrease(); dect_phy_perf_msgq_non_data_op_add(DECT_PHY_PERF_EVENT_CMD_DONE); } diff --git a/samples/dect/dect_phy/dect_shell/src/dect/ping/dect_phy_ping.c b/samples/dect/dect_phy/dect_shell/src/dect/ping/dect_phy_ping.c index 6851958b2e3..dc71c57c9ba 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/ping/dect_phy_ping.c +++ b/samples/dect/dect_phy/dect_shell/src/dect/ping/dect_phy_ping.c @@ -173,11 +173,10 @@ static int dect_phy_ping_rx_pdc_data_handle(struct dect_phy_data_rcv_common_para #define DECT_PHY_PING_EVENT_RX_PCC_CRC_ERROR 4 #define DECT_PHY_PING_EVENT_RX_PDC_CRC_ERROR 5 #define DECT_PHY_PING_EVENT_RX_PCC 6 -#define DECT_PHY_PING_EVENT_MDM_INITIALIZED 7 -#define DECT_PHY_PING_EVENT_CMD_DONE 8 -#define DECT_PHY_PING_EVENT_CLIENT_SCHEDULER_PINGING_DONE 9 -#define DECT_PHY_PING_EVENT_RSSI_COUNT_DONE 10 -#define DECT_PHY_PING_EVENT_HARQ_PAYLOAD_STORED 11 +#define DECT_PHY_PING_EVENT_CMD_DONE 7 +#define DECT_PHY_PING_EVENT_CLIENT_SCHEDULER_PINGING_DONE 8 +#define DECT_PHY_PING_EVENT_RSSI_COUNT_DONE 9 +#define DECT_PHY_PING_EVENT_HARQ_PAYLOAD_STORED 10 static int dect_phy_ping_msgq_data_op_add(uint16_t event_id, void *data, size_t data_size); @@ -380,7 +379,8 @@ void dect_phy_ping_harq_client_nak_handle(void) (void *)&(new_sched_list_item_conf->tx.phy_header); header->df_redundancy_version = redundancy_version; - header->transmit_power = dect_common_utils_next_phy_tx_power_get(header->transmit_power); + header->transmit_power = dect_phy_ctrl_utils_mdm_next_supported_phy_tx_power_get( + header->transmit_power, new_sched_list_item_conf->channel); /* Add tx operation to scheduler list */ if (!dect_phy_api_scheduler_list_item_add(new_sched_list_item)) { @@ -475,6 +475,14 @@ static uint16_t dect_phy_ping_auto_pwr_ctrl_target_pwr_calculate(void) rssi_diff = abs(target_rssi - ping_data.rx_metrics.rx_latest_rssi_level); target_power = target_power + rssi_diff; } + /* Check that not over the permitted max on used channel */ + int8_t max_permitted_pwr_dbm = dect_phy_ctrl_utils_mdm_max_tx_pwr_dbm_get_by_channel( + ping_data.cmd_params.channel); + + if (target_power > max_permitted_pwr_dbm) { + target_power = max_permitted_pwr_dbm; + } + return target_power; } @@ -490,67 +498,39 @@ static void dect_phy_ping_client_data_tx_total_data_amount_decrease(void) /**************************************************************************************************/ -static void dect_phy_ping_initialize_cb(const uint64_t *time, int16_t temperature, - enum nrf_modem_dect_phy_err status, - const struct nrf_modem_dect_phy_modem_cfg *modem_configuration) -{ - struct dect_phy_common_op_initialized_params initialized_evt_params; - - initialized_evt_params.time = *time; - initialized_evt_params.temperature = temperature; - initialized_evt_params.status = status; - initialized_evt_params.modem_configuration = *modem_configuration; - - dect_app_modem_time_save(time); - dect_phy_ping_msgq_data_op_add(DECT_PHY_PING_EVENT_MDM_INITIALIZED, - (void *)&initialized_evt_params, - sizeof(struct dect_phy_common_op_initialized_params)); -} - -static void dect_phy_ping_rx_op_stop_cb(uint64_t const *time, enum nrf_modem_dect_phy_err status, - uint32_t handle) -{ - dect_app_modem_time_save(time); -} - -static void dect_phy_ping_op_complete_cb(uint64_t const *time, int16_t temperature, - enum nrf_modem_dect_phy_err status, uint32_t handle) +static void dect_phy_ping_mdm_op_complete_cb( + const struct nrf_modem_dect_phy_op_complete_event *evt, uint64_t *time) { struct dect_phy_common_op_completed_params ping_op_completed_params = { - .handle = handle, - .temperature = temperature, - .status = status, + .handle = evt->handle, + .temperature = evt->temp, + .status = evt->err, .time = *time, }; - dect_app_modem_time_save(time); - dect_phy_api_scheduler_mdm_op_completed(&ping_op_completed_params); dect_phy_ping_msgq_data_op_add(DECT_PHY_PING_EVENT_MDM_OP_COMPLETED, (void *)&ping_op_completed_params, sizeof(struct dect_phy_common_op_completed_params)); } -static void dect_phy_ping_rx_pcc_cb(uint64_t const *time, - struct nrf_modem_dect_phy_rx_pcc_status const *p_rx_status, - union nrf_modem_dect_phy_hdr const *p_phy_header) +static void dect_phy_ping_mdm_pcc_cb( + const struct nrf_modem_dect_phy_pcc_event *evt, uint64_t *time) { struct dect_phy_common_op_pcc_rcv_params ctrl_pcc_op_params; struct dect_phy_ping_params *cmd_params = &(ping_data.cmd_params); uint64_t harq_feedback_start_time = 0; - dect_app_modem_time_save(time); - - ctrl_pcc_op_params.pcc_status = *p_rx_status; - ctrl_pcc_op_params.phy_header = *p_phy_header; + ctrl_pcc_op_params.pcc_status = *evt; + ctrl_pcc_op_params.phy_header = evt->hdr; ctrl_pcc_op_params.time = *time; - ctrl_pcc_op_params.stf_start_time = p_rx_status->stf_start_time; + ctrl_pcc_op_params.stf_start_time = evt->stf_start_time; /* Others from struct dect_phy_common_op_pcc_rcv_params are not needed */ /* Provide HARQ feedback if requested */ - if (p_rx_status->header_status == NRF_MODEM_DECT_PHY_HDR_STATUS_VALID && - p_rx_status->phy_type == DECT_PHY_HEADER_TYPE2) { - struct dect_phy_header_type2_format0_t *header = (void *)p_phy_header; + if (evt->header_status == NRF_MODEM_DECT_PHY_HDR_STATUS_VALID && + evt->phy_type == DECT_PHY_HEADER_TYPE2) { + struct dect_phy_header_type2_format0_t *header = (void *)&evt->hdr; if (cmd_params->role == DECT_PHY_COMMON_ROLE_SERVER && header->format == DECT_PHY_HEADER_FORMAT_000 && @@ -574,7 +554,8 @@ static void dect_phy_ping_rx_pcc_cb(uint64_t const *time, feedback_header.format = DECT_PHY_HEADER_FORMAT_001; feedback_header.df_mcs = 0; feedback_header.transmit_power = - dect_common_utils_next_phy_tx_power_get(header->transmit_power); + dect_phy_ctrl_utils_mdm_next_supported_phy_tx_power_get( + header->transmit_power, harq_tx.carrier); feedback_header.receiver_identity_hi = header->transmitter_identity_hi; feedback_header.receiver_identity_lo = header->transmitter_identity_lo; feedback_header.spatial_streams = header->spatial_streams; @@ -590,7 +571,7 @@ static void dect_phy_ping_rx_pcc_cb(uint64_t const *time, memcpy(&phy_header.type_2, &feedback_header, sizeof(phy_header.type_2)); harq_tx.phy_header = &phy_header; harq_feedback_start_time = - p_rx_status->stf_start_time + + evt->stf_start_time + (len_slots * DECT_RADIO_SLOT_DURATION_IN_MODEM_TICKS) + (current_settings->harq.harq_feedback_tx_delay_subslot_count * DECT_RADIO_SUBSLOT_DURATION_IN_MODEM_TICKS); @@ -607,64 +588,59 @@ static void dect_phy_ping_rx_pcc_cb(uint64_t const *time, sizeof(struct dect_phy_common_op_pcc_rcv_params)); } -static void dect_phy_ping_pcc_crc_failure_cb( - uint64_t const *time, struct nrf_modem_dect_phy_rx_pcc_crc_failure const *crc_failure) +static void dect_phy_ping_mdm_pcc_crc_failure_cb( + const struct nrf_modem_dect_phy_pcc_crc_failure_event *evt, uint64_t *time) { struct dect_phy_common_op_pcc_crc_fail_params pdc_crc_fail_params = { .time = *time, - .crc_failure = *crc_failure, + .crc_failure = *evt, }; - dect_app_modem_time_save(time); dect_phy_ping_msgq_data_op_add(DECT_PHY_PING_EVENT_RX_PCC_CRC_ERROR, (void *)&pdc_crc_fail_params, sizeof(struct dect_phy_common_op_pcc_crc_fail_params)); } -static void dect_phy_ping_rx_pdc_cb(uint64_t const *time, - struct nrf_modem_dect_phy_rx_pdc_status const *p_rx_status, - void const *p_data, uint32_t length) +static void dect_phy_ping_mdm_pdc_cb(const struct nrf_modem_dect_phy_pdc_event *evt, + uint64_t *time) { - int16_t rssi_level = p_rx_status->rssi_2 / 2; - - dect_app_modem_time_save(time); - + int16_t rssi_level = evt->rssi_2 / 2; struct dect_phy_commmon_op_pdc_rcv_params ping_pdc_op_params = { 0 }; - ping_pdc_op_params.rx_status = *p_rx_status; + ping_pdc_op_params.rx_status = *evt; - ping_pdc_op_params.data_length = length; + ping_pdc_op_params.data_length = evt->len; ping_pdc_op_params.time = *time; ping_pdc_op_params.rx_pwr_dbm = dect_common_utils_phy_tx_power_to_dbm(ping_data.rx_metrics.rx_phy_transmit_pwr); ping_pdc_op_params.rx_mcs = ping_data.rx_metrics.rx_last_pcc_mcs; ping_pdc_op_params.rx_rssi_level_dbm = rssi_level; - ping_pdc_op_params.last_rx_op_channel = ping_data.cmd_params.channel; + ping_pdc_op_params.rx_channel = ping_data.cmd_params.channel; /* Others from struct dect_phy_commmon_op_pdc_rcv_params are not needed */ - if (length <= sizeof(ping_pdc_op_params.data)) { - memcpy(ping_pdc_op_params.data, p_data, length); + if (evt->len <= sizeof(ping_pdc_op_params.data)) { + memcpy(ping_pdc_op_params.data, evt->data, evt->len); dect_phy_ping_msgq_data_op_add(DECT_PHY_PING_EVENT_RX_PDC_DATA, (void *)&ping_pdc_op_params, sizeof(struct dect_phy_commmon_op_pdc_rcv_params)); } else { printk("Received data is too long to be received by PING TH - discarded (len %d, " "buf size %d)\n", - length, sizeof(ping_pdc_op_params.data)); + evt->len, sizeof(ping_pdc_op_params.data)); } } -static void dect_phy_ping_on_pdc_crc_failure_cb( - uint64_t const *time, struct nrf_modem_dect_phy_rx_pdc_crc_failure const *crc_failure) +static void dect_phy_ping_mdm_pdc_crc_failure_cb( + const struct nrf_modem_dect_phy_pdc_crc_failure_event *evt, + uint64_t *time) { struct dect_phy_common_op_pdc_crc_fail_params pdc_crc_fail_params = { .time = *time, - .crc_failure = *crc_failure, + .crc_failure = *evt, }; - dect_app_modem_time_save(time); dect_phy_ping_msgq_data_op_add(DECT_PHY_PING_EVENT_RX_PDC_CRC_ERROR, (void *)&pdc_crc_fail_params, sizeof(struct dect_phy_common_op_pdc_crc_fail_params)); @@ -729,7 +705,7 @@ static void dect_phy_ping_rssi_done_evt_send(void) } static void dect_phy_ping_rssi_ntf_handle(enum nrf_modem_dect_phy_err status, - struct nrf_modem_dect_phy_rssi_meas const *p_result) + struct nrf_modem_dect_phy_rssi_event const *p_result) { if (status == NRF_MODEM_DECT_PHY_SUCCESS) { __ASSERT_NO_MSG(p_result != NULL); @@ -761,60 +737,13 @@ static void dect_phy_ping_rssi_ntf_handle(enum nrf_modem_dect_phy_err status, } } -static void dect_phy_ping_on_rssi_cb(const uint64_t *time, - const struct nrf_modem_dect_phy_rssi_meas *p_result) +static void dect_phy_ping_mdm_rssi_cb(const struct nrf_modem_dect_phy_rssi_event *evt) { - dect_phy_ping_rssi_ntf_handle(NRF_MODEM_DECT_PHY_SUCCESS, p_result); + dect_phy_ping_rssi_ntf_handle(NRF_MODEM_DECT_PHY_SUCCESS, evt); } /**************************************************************************************************/ -static void dect_phy_ping_link_configuration_cb( - uint64_t const *time, enum nrf_modem_dect_phy_err status) -{ - printk("WARN: Unexpectedly in %s\n", (__func__)); -} - -static void dect_phy_ping_time_query_cb(uint64_t const *time, enum nrf_modem_dect_phy_err status) -{ - printk("WARN: Unexpectedly in %s\n", (__func__)); -} - -static void dect_phy_ping_capability_get_cb(const uint64_t *time, enum nrf_modem_dect_phy_err err, - const struct nrf_modem_dect_phy_capability *capabilities) -{ - dect_app_modem_time_save(time); -} - -static void dect_phy_ping_stf_cover_seq_control_cb( - const uint64_t *time, enum nrf_modem_dect_phy_err err) -{ - printk("WARN: Unexpectedly in %s\n", (__func__)); -} - -extern struct k_sem dect_phy_ctrl_mdm_api_deinit_sema; -static void dect_phy_ping_deinit_cb(const uint64_t *time, enum nrf_modem_dect_phy_err err) -{ - k_sem_give(&dect_phy_ctrl_mdm_api_deinit_sema); -} - -static const struct nrf_modem_dect_phy_callbacks ping_phy_api_config = { - .init = dect_phy_ping_initialize_cb, - .rx_stop = dect_phy_ping_rx_op_stop_cb, - .op_complete = dect_phy_ping_op_complete_cb, - .pcc = dect_phy_ping_rx_pcc_cb, - .pcc_crc_err = dect_phy_ping_pcc_crc_failure_cb, - .pdc = dect_phy_ping_rx_pdc_cb, - .pdc_crc_err = dect_phy_ping_on_pdc_crc_failure_cb, - .rssi = dect_phy_ping_on_rssi_cb, - .link_config = dect_phy_ping_link_configuration_cb, - .time_get = dect_phy_ping_time_query_cb, - .capability_get = dect_phy_ping_capability_get_cb, - .stf_cover_seq_control = dect_phy_ping_stf_cover_seq_control_cb, - .deinit = dect_phy_ping_deinit_cb, -}; - -/**************************************************************************************************/ static void dect_phy_ping_client_tx_all_intervals_done(uint32_t handle) { @@ -1134,12 +1063,13 @@ static int dect_phy_ping_tx_request_results(void) .format = DECT_PHY_HEADER_FORMAT_001, .short_network_id = (uint8_t)(current_settings->common.network_id & 0xFF), .transmitter_identity_hi = (uint8_t)(current_settings->common.transmitter_id >> - 8), /* TODO: use short RD ID */ + 8), .transmitter_identity_lo = (uint8_t)(current_settings->common.transmitter_id & 0xFF), .df_mcs = 0, - .transmit_power = dect_common_utils_next_phy_tx_power_get( - dect_common_utils_dbm_to_phy_tx_power(params->tx_power_dbm)), + .transmit_power = dect_phy_ctrl_utils_mdm_next_supported_phy_tx_power_get( + dect_common_utils_dbm_to_phy_tx_power(params->tx_power_dbm), + params->channel), .receiver_identity_hi = (uint8_t)(params->destination_transmitter_id >> 8), .receiver_identity_lo = (uint8_t)(params->destination_transmitter_id & 0xFF), .feedback.format1.format = 0, @@ -1305,8 +1235,8 @@ static int dect_phy_ping_server_results_tx(char *result_str) .transmitter_identity_lo = (uint8_t)(current_settings->common.transmitter_id & 0xFF), .df_mcs = 1, - .transmit_power = dect_common_utils_next_phy_tx_power_get( - ping_data.rx_metrics.rx_phy_transmit_pwr), + .transmit_power = dect_phy_ctrl_utils_mdm_next_supported_phy_tx_power_get( + ping_data.rx_metrics.rx_phy_transmit_pwr, params->channel), .receiver_identity_hi = (uint8_t)(ping_data.server_data.rx_last_tx_id >> 8), .receiver_identity_lo = (uint8_t)(ping_data.server_data.rx_last_tx_id & 0xFF), .feedback.format1.format = 0, @@ -1632,6 +1562,13 @@ void dect_phy_ping_mdm_op_completed( } else if (mdm_completed_params->handle == DECT_PHY_PING_SERVER_RX_HANDLE) { int64_t z_ticks_rx_scheduled = ping_data.server_data.rx_enabled_z_ticks; int64_t z_delta_ms = k_uptime_delta(&z_ticks_rx_scheduled); + uint64_t time_now = dect_app_modem_time_now(); + uint64_t first_possible_start; + struct dect_phy_settings *current_settings = dect_common_settings_ref_get(); + + first_possible_start = + time_now + + US_TO_MODEM_TICKS(current_settings->scheduler.scheduling_delay_us); dect_phy_ping_server_data_on_going_rx_count_decrease(); @@ -1643,7 +1580,8 @@ void dect_phy_ping_mdm_op_completed( struct dect_phy_ping_params copy_params = ping_data.cmd_params; - dect_phy_ping_start(©_params, RESTART, 0); + dect_phy_ping_start( + ©_params, RESTART, first_possible_start); } } else { /* Let's restart only if failure is not happening very fast which @@ -1656,7 +1594,8 @@ void dect_phy_ping_mdm_op_completed( struct dect_phy_ping_params copy_params = ping_data.cmd_params; - dect_phy_ping_start(©_params, RESTART, 0); + dect_phy_ping_start( + ©_params, RESTART, first_possible_start); } else { desh_error( "ping server RX failed - ping server RX stopped."); @@ -1698,23 +1637,6 @@ static void dect_phy_ping_thread_fn(void) dect_phy_ping_cmd_done(); break; } - case DECT_PHY_PING_EVENT_MDM_INITIALIZED: { - struct dect_phy_common_op_initialized_params *params = - (struct dect_phy_common_op_initialized_params *)event.data; - - if (params->status) { - desh_error("(%s): init failed (time %llu, temperature %d, " - "temp_limit %d): %d", - (__func__), params->time, params->temperature, - params->modem_configuration.temperature_limit, - params->status); - } else { - desh_print("dect phy api initialized for ping command."); - } - k_sem_give(&ping_phy_api_init); - break; - } - case DECT_PHY_PING_EVENT_MDM_OP_COMPLETED: { struct dect_phy_common_op_completed_params *params = (struct dect_phy_common_op_completed_params *)event.data; @@ -1852,9 +1774,11 @@ static void dect_phy_ping_thread_fn(void) } if (cmd_params->debugs) { - desh_print("PCC received (time %llu): status: \"%s\", snr %d, " + desh_print("PCC received (time %llu, handle %d): " + "status: \"%s\", snr %d, " "RSSI-2 %d (RSSI %d), stf_start_time %llu", - params->time, tmp_str, params->pcc_status.snr, + params->time, params->pcc_status.handle, + tmp_str, params->pcc_status.snr, params->pcc_status.rssi_2, rssi_level, params->pcc_status.stf_start_time); desh_print(" phy header:"); @@ -1912,7 +1836,7 @@ static void dect_phy_ping_thread_fn(void) /* NACK: stop current RX, TX a retransmit, * restart RX for a remaining duration. */ - (void)nrf_modem_dect_phy_rx_stop( + (void)nrf_modem_dect_phy_cancel( DECT_PHY_PING_CLIENT_RX_HANDLE); dect_phy_ping_harq_client_nak_handle(); } @@ -1938,12 +1862,13 @@ static void dect_phy_ping_thread_fn(void) .data_length = params->data_length, .data = params->data, }; - struct nrf_modem_dect_phy_rx_pdc_status *p_rx_status = &(params->rx_status); + struct nrf_modem_dect_phy_pdc_event *p_rx_status = &(params->rx_status); int16_t rssi_level = p_rx_status->rssi_2 / 2; - desh_print("PDC received (time %llu): snr %d, RSSI-2 %d " + desh_print("PDC received (time %llu, handle %d): snr %d, RSSI-2 %d " "(RSSI %d), len %d", - params->time, p_rx_status->snr, p_rx_status->rssi_2, rssi_level, + params->time, p_rx_status->handle, + p_rx_status->snr, p_rx_status->rssi_2, rssi_level, params->data_length); if (params->data_length) { @@ -2036,52 +1961,79 @@ static int dect_phy_ping_msgq_non_data_op_add(uint16_t event_id) /**************************************************************************************************/ -static void dect_phy_ping_mdm_init(const struct nrf_modem_dect_phy_init_params *init_params) +void dect_phy_ping_mdm_evt_handler(const struct nrf_modem_dect_phy_event *evt) { - int ret = nrf_modem_dect_phy_callback_set(&ping_phy_api_config); + dect_app_modem_time_save(&evt->time); + + switch (evt->id) { + case NRF_MODEM_DECT_PHY_EVT_COMPLETED: + dect_phy_ping_mdm_op_complete_cb(&evt->op_complete, (uint64_t *)&evt->time); + break; + case NRF_MODEM_DECT_PHY_EVT_PCC: + dect_phy_ping_mdm_pcc_cb(&evt->pcc, (uint64_t *)&evt->time); + break; + case NRF_MODEM_DECT_PHY_EVT_PCC_ERROR: + dect_phy_ping_mdm_pcc_crc_failure_cb(&evt->pcc_crc_err, (uint64_t *)&evt->time); + break; + case NRF_MODEM_DECT_PHY_EVT_PDC: + dect_phy_ping_mdm_pdc_cb(&evt->pdc, (uint64_t *)&evt->time); + break; + case NRF_MODEM_DECT_PHY_EVT_PDC_ERROR: + dect_phy_ping_mdm_pdc_crc_failure_cb(&evt->pdc_crc_err, (uint64_t *)&evt->time); + break; + case NRF_MODEM_DECT_PHY_EVT_RSSI: + dect_phy_ping_mdm_rssi_cb(&evt->rssi); + break; + + /* Callbacks handled by dect_phy_ctrl */ + case NRF_MODEM_DECT_PHY_EVT_RADIO_CONFIG: + dect_phy_ctrl_mdm_radio_config_cb(&evt->radio_config); + break; + case NRF_MODEM_DECT_PHY_EVT_ACTIVATE: + dect_phy_ctrl_mdm_activate_cb(&evt->activate); + break; + case NRF_MODEM_DECT_PHY_EVT_DEACTIVATE: + dect_phy_ctrl_mdm_deactivate_cb(&evt->deactivate); + break; + case NRF_MODEM_DECT_PHY_EVT_CANCELED: + dect_phy_ctrl_mdm_cancel_cb(&evt->cancel); + break; + + default: + printk("%s: WARN: Unexpected event id %d\n", (__func__), evt->id); + break; + } +} - if (ret) { - printk("nrf_modem_dect_phy_callback_set returned: %i\n", ret); - } else { - ret = nrf_modem_dect_phy_init(init_params); +static void dect_phy_ping_mdm_init(void) +{ + int ret = nrf_modem_dect_phy_event_handler_set(dect_phy_ping_mdm_evt_handler); - if (ret) { - printk("nrf_modem_dect_phy_init returned: %i\n", ret); - } else { - ret = nrf_modem_dect_phy_capability_get(); /* asynch: result in callback */ - if (ret) { - printk("nrf_modem_dect_phy_capability_get returned: %i\n", ret); - } - } + if (ret) { + printk("nrf_modem_dect_phy_event_handler_set returned: %i\n", ret); } } int dect_phy_ping_cmd_handle(struct dect_phy_ping_params *params) { - struct dect_phy_settings *current_settings = dect_common_settings_ref_get(); - struct nrf_modem_dect_phy_init_params ping_phy_init_params = { - .harq_rx_expiry_time_us = current_settings->harq.mdm_init_harq_expiry_time_us, - .harq_rx_process_count = current_settings->harq.mdm_init_harq_process_count, - .reserved = 0, - .band4_support = ((current_settings->common.band_nbr == 4) ? 1 : 0), - }; int ret; if (ping_data.on_going) { desh_error("ping command already running"); return -1; } - k_sem_reset(&ping_phy_api_init); - dect_phy_ping_mdm_init(&ping_phy_init_params); + struct dect_phy_settings *current_settings = dect_common_settings_ref_get(); + uint64_t time_now = dect_app_modem_time_now(); + uint64_t first_possible_start; + + first_possible_start = + time_now + (3 * US_TO_MODEM_TICKS(current_settings->scheduler.scheduling_delay_us)); + + dect_phy_ping_mdm_init(); - ret = k_sem_take(&ping_phy_api_init, K_SECONDS(5)); - if (ret) { - desh_error("(%s): nrf_modem_dect_phy_init() timeout.", (__func__)); - return -ETIMEDOUT; - } dect_phy_ping_rssi_curr_data_reset(); - ret = dect_phy_ping_start(params, START, 0); + ret = dect_phy_ping_start(params, START, first_possible_start); if (ret) { ping_data.on_going = false; } @@ -2103,7 +2055,6 @@ void dect_phy_ping_cmd_stop(void) } } else { dect_phy_ping_msgq_non_data_op_add(DECT_PHY_PING_EVENT_SERVER_REPORT); - nrf_modem_dect_phy_rx_stop(DECT_PHY_PING_SERVER_RX_HANDLE); dect_phy_ping_server_data_on_going_rx_count_decrease(); dect_phy_ping_msgq_non_data_op_add(DECT_PHY_PING_EVENT_CMD_DONE); } diff --git a/samples/dect/dect_phy/dect_shell/src/dect/rf_tool/dect_phy_rf_tool.c b/samples/dect/dect_phy/dect_shell/src/dect/rf_tool/dect_phy_rf_tool.c index c4def025aec..ab2abb78fa8 100644 --- a/samples/dect/dect_phy/dect_shell/src/dect/rf_tool/dect_phy_rf_tool.c +++ b/samples/dect/dect_phy/dect_shell/src/dect/rf_tool/dect_phy_rf_tool.c @@ -120,72 +120,42 @@ static bool dect_phy_rf_tool_rx_mode(enum dect_phy_rf_tool_mode mode); /**************************************************************************************************/ #define DECT_PHY_RF_TOOL_EVT_CMD_DONE 1 -#define DECT_PHY_RF_TOOL_EVT_MDM_INITIALIZED 2 -#define DECT_PHY_RF_TOOL_EVT_MDM_DEINITIALIZED 3 -#define DECT_PHY_RF_TOOL_EVT_MDM_OP_COMPLETED 4 -#define DECT_PHY_RF_TOOL_EVT_STATUS_REPORT 5 -#define DECT_PHY_RF_TOOL_EVT_RX_PCC_CRC_ERROR 6 -#define DECT_PHY_RF_TOOL_EVT_RX_PDC_CRC_ERROR 7 -#define DECT_PHY_RF_TOOL_EVT_RX_PCC 8 -#define DECT_PHY_RF_TOOL_EVT_RX_PDC_DATA 9 -#define DECT_PHY_RF_TOOL_EVT_SCHEDULER_ALL_REPETITIONS_DONE 10 +#define DECT_PHY_RF_TOOL_EVT_MDM_OP_COMPLETED 2 +#define DECT_PHY_RF_TOOL_EVT_RX_PCC_CRC_ERROR 3 +#define DECT_PHY_RF_TOOL_EVT_RX_PDC_CRC_ERROR 4 +#define DECT_PHY_RF_TOOL_EVT_RX_PCC 5 +#define DECT_PHY_RF_TOOL_EVT_RX_PDC_DATA 6 +#define DECT_PHY_RF_TOOL_EVT_SCHEDULER_ALL_REPETITIONS_DONE 7 /**************************************************************************************************/ -static void dect_phy_rf_tool_initialize_cb(const uint64_t *time, int16_t temperature, - enum nrf_modem_dect_phy_err status, - const struct nrf_modem_dect_phy_modem_cfg *modem_configuration) -{ - struct dect_phy_common_op_initialized_params initialized_evt_params; - - initialized_evt_params.time = *time; - initialized_evt_params.temperature = temperature; - initialized_evt_params.status = status; - initialized_evt_params.modem_configuration = *modem_configuration; - - dect_app_modem_time_save(time); - dect_phy_rf_tool_msgq_data_op_add(DECT_PHY_RF_TOOL_EVT_MDM_INITIALIZED, - (void *)&initialized_evt_params, - sizeof(struct dect_phy_common_op_initialized_params)); -} - -static void dect_phy_rf_tool_rx_op_stop_cb(uint64_t const *time, enum nrf_modem_dect_phy_err status, - uint32_t handle) -{ - dect_app_modem_time_save(time); -} - -static void dect_phy_rf_tool_op_complete_cb(uint64_t const *time, int16_t temperature, - enum nrf_modem_dect_phy_err status, uint32_t handle) +static void dect_phy_rf_tool_mdm_op_complete_cb( + const struct nrf_modem_dect_phy_op_complete_event *evt, + uint64_t *time) { struct dect_phy_common_op_completed_params rf_tool_op_completed_params = { - .handle = handle, - .temperature = temperature, - .status = status, + .handle = evt->handle, + .temperature = evt->temp, + .status = evt->err, .time = *time, }; - dect_app_modem_time_save(time); - dect_phy_api_scheduler_mdm_op_completed(&rf_tool_op_completed_params); dect_phy_rf_tool_msgq_data_op_add(DECT_PHY_RF_TOOL_EVT_MDM_OP_COMPLETED, (void *)&rf_tool_op_completed_params, sizeof(struct dect_phy_common_op_completed_params)); } -static void dect_phy_rf_tool_rx_pcc_cb(uint64_t const *time, - struct nrf_modem_dect_phy_rx_pcc_status const *p_rx_status, - union nrf_modem_dect_phy_hdr const *p_phy_header) +static void dect_phy_rf_tool_mdm_pcc_cb(const struct nrf_modem_dect_phy_pcc_event *evt, + uint64_t *time) { struct dect_phy_common_op_pcc_rcv_params ctrl_pcc_op_params; - struct dect_phy_header_type2_format0_t *header = (void *)p_phy_header; - - dect_app_modem_time_save(time); + struct dect_phy_header_type2_format0_t *header = (void *)&evt->hdr; - ctrl_pcc_op_params.pcc_status = *p_rx_status; - ctrl_pcc_op_params.phy_header = *p_phy_header; + ctrl_pcc_op_params.pcc_status = *evt; + ctrl_pcc_op_params.phy_header = evt->hdr; ctrl_pcc_op_params.time = *time; - ctrl_pcc_op_params.stf_start_time = p_rx_status->stf_start_time; + ctrl_pcc_op_params.stf_start_time = evt->stf_start_time; ctrl_pcc_op_params.phy_len = header->packet_length; ctrl_pcc_op_params.phy_len_type = header->packet_length_type; @@ -194,118 +164,61 @@ static void dect_phy_rf_tool_rx_pcc_cb(uint64_t const *time, sizeof(struct dect_phy_common_op_pcc_rcv_params)); } -static void dect_phy_rf_tool_pcc_crc_failure_cb( - uint64_t const *time, struct nrf_modem_dect_phy_rx_pcc_crc_failure const *crc_failure) +static void dect_phy_rf_tool_mdm_pcc_crc_failure_cb( + const struct nrf_modem_dect_phy_pcc_crc_failure_event *evt, + uint64_t *time) { struct dect_phy_common_op_pcc_crc_fail_params pdc_crc_fail_params = { .time = *time, - .crc_failure = *crc_failure, + .crc_failure = *evt, }; - dect_app_modem_time_save(time); dect_phy_rf_tool_msgq_data_op_add(DECT_PHY_RF_TOOL_EVT_RX_PCC_CRC_ERROR, (void *)&pdc_crc_fail_params, sizeof(struct dect_phy_common_op_pcc_crc_fail_params)); } -static void dect_phy_rf_tool_rx_pdc_cb(uint64_t const *time, - struct nrf_modem_dect_phy_rx_pdc_status const *p_rx_status, - void const *p_data, uint32_t length) +static void dect_phy_rf_tool_mdm_pdc_cb(const struct nrf_modem_dect_phy_pdc_event *evt, + uint64_t *time) { - int16_t rssi_level = p_rx_status->rssi_2 / 2; - - dect_app_modem_time_save(time); - + int16_t rssi_level = evt->rssi_2 / 2; struct dect_phy_commmon_op_pdc_rcv_params rf_tool_pdc_op_params; - rf_tool_pdc_op_params.rx_status = *p_rx_status; + rf_tool_pdc_op_params.rx_status = *evt; - rf_tool_pdc_op_params.data_length = length; + rf_tool_pdc_op_params.data_length = evt->len; rf_tool_pdc_op_params.time = *time; rf_tool_pdc_op_params.rx_pwr_dbm = 0; /* Taken from PCC */ rf_tool_pdc_op_params.rx_rssi_level_dbm = rssi_level; /* Used from PCC */ - rf_tool_pdc_op_params.last_rx_op_channel = rf_tool_data.cmd_params.channel; + rf_tool_pdc_op_params.rx_channel = rf_tool_data.cmd_params.channel; - if (length <= sizeof(rf_tool_pdc_op_params.data)) { - memcpy(rf_tool_pdc_op_params.data, p_data, length); + if (evt->len <= sizeof(rf_tool_pdc_op_params.data)) { + memcpy(rf_tool_pdc_op_params.data, evt->data, evt->len); dect_phy_rf_tool_msgq_data_op_add( DECT_PHY_RF_TOOL_EVT_RX_PDC_DATA, (void *)&rf_tool_pdc_op_params, sizeof(struct dect_phy_commmon_op_pdc_rcv_params)); } else { printk("Received data is too long to be received by PERF TH - discarded (len %d, " "buf size %d)\n", - length, sizeof(rf_tool_pdc_op_params.data)); + evt->len, sizeof(rf_tool_pdc_op_params.data)); } } -static void dect_phy_rf_tool_on_pdc_crc_failure_cb( - uint64_t const *time, struct nrf_modem_dect_phy_rx_pdc_crc_failure const *crc_failure) +static void dect_phy_rf_tool_mdm_pdc_crc_failure_cb( + const struct nrf_modem_dect_phy_pdc_crc_failure_event *evt, + uint64_t *time) { struct dect_phy_common_op_pdc_crc_fail_params pdc_crc_fail_params = { .time = *time, - .crc_failure = *crc_failure, + .crc_failure = *evt, }; - dect_app_modem_time_save(time); dect_phy_rf_tool_msgq_data_op_add(DECT_PHY_RF_TOOL_EVT_RX_PDC_CRC_ERROR, (void *)&pdc_crc_fail_params, sizeof(struct dect_phy_common_op_pdc_crc_fail_params)); } -static void dect_phy_rf_tool_on_rssi_cb(const uint64_t *time, - const struct nrf_modem_dect_phy_rssi_meas *p_result) -{ - printk("WARN: Unexpectedly in %s\n", (__func__)); -} - -static void dect_phy_rf_tool_link_configuration_cb(uint64_t const *time, - enum nrf_modem_dect_phy_err status) -{ - printk("WARN: Unexpectedly in %s\n", (__func__)); -} - -static void dect_phy_rf_tool_time_query_cb( - uint64_t const *time, enum nrf_modem_dect_phy_err status) -{ -} - -static void dect_phy_rf_tool_capability_get_cb( - const uint64_t *time, enum nrf_modem_dect_phy_err err, - const struct nrf_modem_dect_phy_capability *capabilities) -{ - dect_app_modem_time_save(time); -} - -static void dect_phy_rf_tool_stf_cover_seq_control_cb( - const uint64_t *time, enum nrf_modem_dect_phy_err err) -{ - printk("WARN: Unexpectedly in %s\n", (__func__)); -} - -extern struct k_sem dect_phy_ctrl_mdm_api_deinit_sema; -static void dect_phy_rf_tool_deinit_cb(const uint64_t *time, enum nrf_modem_dect_phy_err err) -{ - k_sem_give(&dect_phy_ctrl_mdm_api_deinit_sema); - dect_phy_rf_tool_msgq_non_data_op_add(DECT_PHY_RF_TOOL_EVT_MDM_DEINITIALIZED); -} - -static const struct nrf_modem_dect_phy_callbacks rf_tool_phy_api_config = { - .init = dect_phy_rf_tool_initialize_cb, - .rx_stop = dect_phy_rf_tool_rx_op_stop_cb, - .op_complete = dect_phy_rf_tool_op_complete_cb, - .pcc = dect_phy_rf_tool_rx_pcc_cb, - .pcc_crc_err = dect_phy_rf_tool_pcc_crc_failure_cb, - .pdc = dect_phy_rf_tool_rx_pdc_cb, - .pdc_crc_err = dect_phy_rf_tool_on_pdc_crc_failure_cb, - .rssi = dect_phy_rf_tool_on_rssi_cb, - .link_config = dect_phy_rf_tool_link_configuration_cb, - .time_get = dect_phy_rf_tool_time_query_cb, - .capability_get = dect_phy_rf_tool_capability_get_cb, - .stf_cover_seq_control = dect_phy_rf_tool_stf_cover_seq_control_cb, - .deinit = dect_phy_rf_tool_deinit_cb, -}; - /**************************************************************************************************/ static bool dect_phy_rf_tool_rx_mode(enum dect_phy_rf_tool_mode mode) { @@ -480,7 +393,7 @@ void dect_phy_rf_tool_print_results(void) static void dect_phy_rf_tool_cmd_done(void) { - dect_phy_rf_tool_msgq_non_data_op_add(DECT_PHY_RF_TOOL_EVT_STATUS_REPORT); + dect_phy_rf_tool_print_results(); /* Mdm phy api deinit is done by dect_phy_ctrl */ dect_phy_ctrl_msgq_non_data_op_add(DECT_PHY_CTRL_OP_RF_TOOL_CMD_DONE); @@ -513,27 +426,6 @@ static void dect_phy_rf_tool_thread_fn(void) dect_phy_rf_tool_cmd_done(); break; } - case DECT_PHY_RF_TOOL_EVT_MDM_INITIALIZED: { - struct dect_phy_common_op_initialized_params *params = - (struct dect_phy_common_op_initialized_params *)event.data; - - if (params->status) { - desh_error("(%s): init failed (time %llu, temperature %d, " - "temp_limit %d): %d", - (__func__), params->time, params->temperature, - params->modem_configuration.temperature_limit, - params->status); - } else { - desh_print("dect phy api initialized for RF tool command."); - } - k_sem_give(&rf_tool_phy_api_init); - break; - } - case DECT_PHY_RF_TOOL_EVT_MDM_DEINITIALIZED: { - desh_print("dect phy api deinitialized for RF tool command."); - desh_print("rf_tool command done."); - break; - } case DECT_PHY_RF_TOOL_EVT_MDM_OP_COMPLETED: { struct dect_phy_common_op_completed_params *params = (struct dect_phy_common_op_completed_params *)event.data; @@ -575,10 +467,6 @@ static void dect_phy_rf_tool_thread_fn(void) } break; } - case DECT_PHY_RF_TOOL_EVT_STATUS_REPORT: { - dect_phy_rf_tool_print_results(); - break; - } case DECT_PHY_RF_TOOL_EVT_RX_PCC_CRC_ERROR: { if (rf_tool_data.on_going) { rf_tool_data.rx_metrics.rx_pcc_crc_error_count++; @@ -875,30 +763,53 @@ static int dect_phy_rf_tool_msgq_non_data_op_add(uint16_t event_id) /**************************************************************************************************/ +void dect_phy_rf_tool_evt_handler(const struct nrf_modem_dect_phy_event *evt) +{ + dect_app_modem_time_save(&evt->time); + + switch (evt->id) { + case NRF_MODEM_DECT_PHY_EVT_PCC: + dect_phy_rf_tool_mdm_pcc_cb(&evt->pcc, (uint64_t *)&evt->time); + break; + case NRF_MODEM_DECT_PHY_EVT_PCC_ERROR: + dect_phy_rf_tool_mdm_pcc_crc_failure_cb(&evt->pcc_crc_err, (uint64_t *)&evt->time); + break; + case NRF_MODEM_DECT_PHY_EVT_PDC: + dect_phy_rf_tool_mdm_pdc_cb(&evt->pdc, (uint64_t *)&evt->time); + break; + case NRF_MODEM_DECT_PHY_EVT_PDC_ERROR: + dect_phy_rf_tool_mdm_pdc_crc_failure_cb(&evt->pdc_crc_err, (uint64_t *)&evt->time); + break; + case NRF_MODEM_DECT_PHY_EVT_COMPLETED: + dect_phy_rf_tool_mdm_op_complete_cb(&evt->op_complete, (uint64_t *)&evt->time); + break; + + /* Callbacks handled by dect_phy_ctrl */ + case NRF_MODEM_DECT_PHY_EVT_RADIO_CONFIG: + dect_phy_ctrl_mdm_radio_config_cb(&evt->radio_config); + break; + case NRF_MODEM_DECT_PHY_EVT_ACTIVATE: + dect_phy_ctrl_mdm_activate_cb(&evt->activate); + break; + case NRF_MODEM_DECT_PHY_EVT_DEACTIVATE: + dect_phy_ctrl_mdm_deactivate_cb(&evt->deactivate); + break; + case NRF_MODEM_DECT_PHY_EVT_CANCELED: + dect_phy_ctrl_mdm_cancel_cb(&evt->cancel); + break; + + default: + printk("%s: WARN: Unexpected event id %d\n", (__func__), evt->id); + break; + } +} + static void dect_phy_rf_tool_phy_init(void) { - struct dect_phy_settings *current_settings = dect_common_settings_ref_get(); - struct nrf_modem_dect_phy_init_params rf_tool_phy_init_params = { - .harq_rx_expiry_time_us = current_settings->harq.mdm_init_harq_expiry_time_us, - .harq_rx_process_count = current_settings->harq.mdm_init_harq_process_count, - .reserved = 0, - .band4_support = ((current_settings->common.band_nbr == 4) ? 1 : 0), - }; - int ret = nrf_modem_dect_phy_callback_set(&rf_tool_phy_api_config); + int ret = nrf_modem_dect_phy_event_handler_set(dect_phy_rf_tool_evt_handler); if (ret) { - printk("nrf_modem_dect_phy_callback_set returned: %i\n", ret); - } else { - ret = nrf_modem_dect_phy_init(&rf_tool_phy_init_params); - - if (ret) { - printk("nrf_modem_dect_phy_init returned: %i\n", ret); - } else { - ret = nrf_modem_dect_phy_capability_get(); /* asynch: result in callback */ - if (ret) { - printk("nrf_modem_dect_phy_capability_get returned: %i\n", ret); - } - } + printk("nrf_modem_dect_phy_event_handler_set returned: %i\n", ret); } } @@ -1072,8 +983,6 @@ static int dect_phy_rf_tool_tx_op_schedule(uint64_t start_time, uint32_t interva static int dect_phy_rf_tool_operations_schedule(uint64_t init_frame_start_time) { - struct dect_phy_settings *current_settings = dect_common_settings_ref_get(); - struct dect_phy_rf_tool_params *cmd_params = &(rf_tool_data.cmd_params); uint64_t frame_start_time = init_frame_start_time; uint64_t time_now = dect_app_modem_time_now(); @@ -1083,8 +992,7 @@ static int dect_phy_rf_tool_operations_schedule(uint64_t init_frame_start_time) if (init_frame_start_time == 0) { /* Initial start */ frame_start_time = - time_now + - (20 * US_TO_MODEM_TICKS(current_settings->scheduler.scheduling_delay_us)); + time_now + MS_TO_MODEM_TICKS(200); } else { frame_start_time = init_frame_start_time; } @@ -1252,11 +1160,22 @@ static int dect_phy_rf_tool_start(struct dect_phy_rf_tool_params *params, bool r rf_tool_data.rx_metrics.rx_op_to_mdm_ok_count++; } } else { - /* Schedule operations right away */ + /* Schedule operations right away if possible in active radio mode */ uint64_t next_possible_frame_time = 0; if (restart) { next_possible_frame_time = dect_phy_rf_tool_next_frame_time_get(restart); + } else { + enum nrf_modem_dect_phy_radio_mode radio_mode; + + ret = dect_phy_ctrl_current_radio_mode_get(&radio_mode); + if (!ret && radio_mode != NRF_MODEM_DECT_PHY_RADIO_MODE_LOW_LATENCY) { + uint64_t time_now = dect_app_modem_time_now(); + + next_possible_frame_time = + time_now + (3 * US_TO_MODEM_TICKS( + current_settings->scheduler.scheduling_delay_us)); + } } ret = dect_phy_rf_tool_operations_schedule(next_possible_frame_time); } @@ -1431,14 +1350,8 @@ int dect_phy_rf_tool_cmd_handle(struct dect_phy_rf_tool_params *params) return -1; } - k_sem_reset(&rf_tool_phy_api_init); dect_phy_rf_tool_phy_init(); - ret = k_sem_take(&rf_tool_phy_api_init, K_SECONDS(5)); - if (ret) { - desh_error("(%s): nrf_modem_dect_phy_init() timeout.", (__func__)); - return -ETIMEDOUT; - } ret = dect_phy_rf_tool_start(params, false); if (ret) { rf_tool_data.on_going = false; diff --git a/samples/dect/dect_phy/dect_shell/src/main.c b/samples/dect/dect_phy/dect_shell/src/main.c index 9dcfc779bc8..cb91a325127 100644 --- a/samples/dect/dect_phy/dect_shell/src/main.c +++ b/samples/dect/dect_phy/dect_shell/src/main.c @@ -204,10 +204,10 @@ int main(void) } #endif - desh_print_version_info(); - /* Resize terminal width and height of the shell to have proper command editing. */ shell_execute_cmd(desh_shell, "resize"); + desh_print_version_info(); + return 0; } diff --git a/samples/dect/dect_phy/dect_shell/src/utils/desh_print.c b/samples/dect/dect_phy/dect_shell/src/utils/desh_print.c index 81e72495b04..e912ea62649 100644 --- a/samples/dect/dect_phy/dect_shell/src/utils/desh_print.c +++ b/samples/dect/dect_phy/dect_shell/src/utils/desh_print.c @@ -149,25 +149,21 @@ int desh_print_help_shell(const struct shell *shell, size_t argc, char **argv) void desh_print_version_info(void) { - /* shell_print() is not used here, because this function is called early during - * application startup and the shell might not be ready yet. - */ - printk("\nDESH version: v%s-%s\n", NCS_VERSION_STRING, NCS_COMMIT_STRING); - + desh_print("DESH version: v%s-%s", NCS_VERSION_STRING, NCS_COMMIT_STRING); #if defined(BUILD_ID) - printk("DESH build id: v%s\n", STRINGIFY(BUILD_ID)); + desh_print("DESH build id: v%s", STRINGIFY(BUILD_ID)); #else - printk("DESH build id: custom\n"); + desh_print("DESH build id: custom"); #endif #if defined(BUILD_VARIANT) #if defined(BRANCH_NAME) - printk("DESH build variant: %s/%s\n", STRINGIFY(BRANCH_NAME), STRINGIFY(BUILD_VARIANT)); + desh_print("DESH build variant: %s/%s", STRINGIFY(BRANCH_NAME), STRINGIFY(BUILD_VARIANT)); #else - printk("DESH build variant: %s\n", STRINGIFY(BUILD_VARIANT)); + desh_print("DESH build variant: %s", STRINGIFY(BUILD_VARIANT)); #endif #else - printk("DESH build variant: dev\n"); + desh_print("DESH build variant: dev"); #endif } From 524885476608ac2a6454ed12ea7867c5979c13dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20J=C3=B8lsgard?= Date: Thu, 16 Jan 2025 10:43:02 +0100 Subject: [PATCH 3/3] samples: dect_phy: hello_dect: modem 1.1 support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updates for libmodem 3.0.0 API changes. Adds support for configuring the band group index for using band 4 with the sample. Signed-off-by: Eivind Jølsgard --- samples/dect/dect_phy/hello_dect/Kconfig | 9 + samples/dect/dect_phy/hello_dect/src/main.c | 275 ++++++++++++++------ 2 files changed, 207 insertions(+), 77 deletions(-) diff --git a/samples/dect/dect_phy/hello_dect/Kconfig b/samples/dect/dect_phy/hello_dect/Kconfig index 8b922e759ff..2a348c650a4 100644 --- a/samples/dect/dect_phy/hello_dect/Kconfig +++ b/samples/dect/dect_phy/hello_dect/Kconfig @@ -11,6 +11,15 @@ config CARRIER The availability of the channels and the exact regulation to use them varies in different countries. See ETSI TS 103 636-2 5.4.2 for the calculation. +config BAND_GROUP_INDEX + int "Band group index" + default 0 + range 0 1 + help + Value 0 refers to RF frequencies operating near 2GHz. + Value 1 to RF frequencies near 1 GHz. + + config NETWORK_ID int "Network ID" range 1 4294967295 diff --git a/samples/dect/dect_phy/hello_dect/src/main.c b/samples/dect/dect_phy/hello_dect/src/main.c index 1b1801a6ce8..6bcb4130543 100644 --- a/samples/dect/dect_phy/hello_dect/src/main.c +++ b/samples/dect/dect_phy/hello_dect/src/main.c @@ -18,6 +18,7 @@ BUILD_ASSERT(CONFIG_CARRIER, "Carrier must be configured according to local regu static bool exit; static uint16_t device_id; +static uint64_t modem_time; /* Header type 1, due to endianness the order is different than in the specification. */ struct phy_ctrl_field_common { @@ -36,12 +37,13 @@ struct phy_ctrl_field_common { /* Semaphore to synchronize modem calls. */ K_SEM_DEFINE(operation_sem, 0, 1); +K_SEM_DEFINE(deinit_sem, 0, 1); + /* Callback after init operation. */ -static void init(const uint64_t *time, int16_t temp, enum nrf_modem_dect_phy_err err, - const struct nrf_modem_dect_phy_modem_cfg *cfg) +static void on_init(const struct nrf_modem_dect_phy_init_event *evt) { - if (err) { - LOG_ERR("Init failed, err %d", err); + if (evt->err) { + LOG_ERR("Init failed, err %d", evt->err); exit = true; return; } @@ -50,118 +52,207 @@ static void init(const uint64_t *time, int16_t temp, enum nrf_modem_dect_phy_err } /* Callback after deinit operation. */ -static void deinit(const uint64_t *time, enum nrf_modem_dect_phy_err err) +static void on_deinit(const struct nrf_modem_dect_phy_deinit_event *evt) { - if (err) { - LOG_ERR("Deinit failed, err %d", err); + if (evt->err) { + LOG_ERR("Deinit failed, err %d", evt->err); + return; + } + + k_sem_give(&deinit_sem); +} + +static void on_activate(const struct nrf_modem_dect_phy_activate_event *evt) +{ + if (evt->err) { + LOG_ERR("Activate failed, err %d", evt->err); + exit = true; return; } k_sem_give(&operation_sem); } -/* Operation complete notification. */ -static void op_complete(const uint64_t *time, int16_t temperature, - enum nrf_modem_dect_phy_err err, uint32_t handle) +static void on_deactivate(const struct nrf_modem_dect_phy_deactivate_event *evt) +{ + + if (evt->err) { + LOG_ERR("Deactivate failed, err %d", evt->err); + return; + } + + k_sem_give(&deinit_sem); +} + +static void on_configure(const struct nrf_modem_dect_phy_configure_event *evt) { - LOG_DBG("op_complete cb time %"PRIu64" status %d", *time, err); + if (evt->err) { + LOG_ERR("Configure failed, err %d", evt->err); + return; + } + k_sem_give(&operation_sem); } -/* Callback after receive stop operation. */ -static void rx_stop(const uint64_t *time, enum nrf_modem_dect_phy_err err, uint32_t handle) +/* Callback after link configuration operation. */ +static void on_link_config(const struct nrf_modem_dect_phy_link_config_event *evt) +{ + LOG_DBG("link_config cb time %"PRIu64" status %d", modem_time, evt->err); +} + +static void on_radio_config(const struct nrf_modem_dect_phy_radio_config_event *evt) { - LOG_DBG("rx_stop cb time %"PRIu64" status %d handle %d", *time, err, handle); + if (evt->err) { + LOG_ERR("Radio config failed, err %d", evt->err); + return; + } + k_sem_give(&operation_sem); } -/* Physical Control Channel reception notification. */ -static void pcc( - const uint64_t *time, - const struct nrf_modem_dect_phy_rx_pcc_status *status, - const union nrf_modem_dect_phy_hdr *hdr) +/* Callback after capability get operation. */ +static void on_capability_get(const struct nrf_modem_dect_phy_capability_get_event *evt) { - struct phy_ctrl_field_common *header = (struct phy_ctrl_field_common *)hdr->type_1; + LOG_DBG("capability_get cb time %"PRIu64" status %d", modem_time, evt->err); +} - LOG_INF("Received header from device ID %d", - header->transmitter_id_hi << 8 | header->transmitter_id_lo); +static void on_bands_get(const struct nrf_modem_dect_phy_band_get_event *evt) +{ + LOG_DBG("bands_get cb status %d", evt->err); } -/* Physical Control Channel CRC error notification. */ -static void pcc_crc_err(const uint64_t *time, - const struct nrf_modem_dect_phy_rx_pcc_crc_failure *crc_failure) +static void on_latency_info_get(const struct nrf_modem_dect_phy_latency_info_event *evt) { - LOG_DBG("pcc_crc_err cb time %"PRIu64"", *time); + LOG_DBG("latency_info_get cb status %d", evt->err); } -/* Physical Data Channel reception notification. */ -static void pdc(const uint64_t *time, - const struct nrf_modem_dect_phy_rx_pdc_status *status, - const void *data, uint32_t len) +/* Callback after time query operation. */ +static void on_time_get(const struct nrf_modem_dect_phy_time_get_event *evt) { - /* Received RSSI value is in fixed precision format Q14.1 */ - LOG_INF("Received data (RSSI: %d.%d): %s", - (status->rssi_2 / 2), (status->rssi_2 & 0b1) * 5, (char *)data); + LOG_DBG("time_get cb time %"PRIu64" status %d", modem_time, evt->err); } -/* Physical Data Channel CRC error notification. */ -static void pdc_crc_err( - const uint64_t *time, const struct nrf_modem_dect_phy_rx_pdc_crc_failure *crc_failure) +static void on_cancel(const struct nrf_modem_dect_phy_cancel_event *evt) { - LOG_DBG("pdc_crc_err cb time %"PRIu64"", *time); + LOG_DBG("on_cancel cb status %d", evt->err); + k_sem_give(&operation_sem); } -/* RSSI measurement result notification. */ -static void rssi(const uint64_t *time, const struct nrf_modem_dect_phy_rssi_meas *status) +/* Operation complete notification. */ +static void on_op_complete(const struct nrf_modem_dect_phy_op_complete_event *evt) { - LOG_DBG("rssi cb time %"PRIu64" carrier %d", *time, status->carrier); + LOG_DBG("op_complete cb time %"PRIu64" status %d", modem_time, evt->err); + k_sem_give(&operation_sem); } -/* Callback after link configuration operation. */ -static void link_config(const uint64_t *time, enum nrf_modem_dect_phy_err err) +/* Physical Control Channel reception notification. */ +static void on_pcc(const struct nrf_modem_dect_phy_pcc_event *evt) { - LOG_DBG("link_config cb time %"PRIu64" status %d", *time, err); + LOG_INF("Received header from device ID %d", + evt->hdr.hdr_type_1.transmitter_id_hi << 8 | evt->hdr.hdr_type_1.transmitter_id_lo); } -/* Callback after time query operation. */ -static void time_get(const uint64_t *time, enum nrf_modem_dect_phy_err err) +/* Physical Control Channel CRC error notification. */ +static void on_pcc_crc_err(const struct nrf_modem_dect_phy_pcc_crc_failure_event *evt) { - LOG_DBG("time_get cb time %"PRIu64" status %d", *time, err); + LOG_DBG("pcc_crc_err cb time %"PRIu64"", modem_time); } -/* Callback after capability get operation. */ -static void capability_get(const uint64_t *time, enum nrf_modem_dect_phy_err err, - const struct nrf_modem_dect_phy_capability *capability) +/* Physical Data Channel reception notification. */ +static void on_pdc(const struct nrf_modem_dect_phy_pdc_event *evt) +{ + /* Received RSSI value is in fixed precision format Q14.1 */ + LOG_INF("Received data (RSSI: %d.%d): %s", + (evt->rssi_2 / 2), (evt->rssi_2 & 0b1) * 5, (char *)evt->data); +} + +/* Physical Data Channel CRC error notification. */ +static void on_pdc_crc_err(const struct nrf_modem_dect_phy_pdc_crc_failure_event *evt) +{ + LOG_DBG("pdc_crc_err cb time %"PRIu64"", modem_time); +} + +/* RSSI measurement result notification. */ +static void on_rssi(const struct nrf_modem_dect_phy_rssi_event *evt) { - LOG_DBG("capability_get cb time %"PRIu64" status %d", *time, err); + LOG_DBG("rssi cb time %"PRIu64" carrier %d", modem_time, evt->carrier); } -static void stf_cover_seq_control(const uint64_t *time, enum nrf_modem_dect_phy_err err) +static void on_stf_cover_seq_control(const struct nrf_modem_dect_phy_stf_control_event *evt) { LOG_WRN("Unexpectedly in %s\n", (__func__)); } -/* Dect PHY callbacks. */ -static struct nrf_modem_dect_phy_callbacks dect_phy_callbacks = { - .init = init, - .deinit = deinit, - .op_complete = op_complete, - .rx_stop = rx_stop, - .pcc = pcc, - .pcc_crc_err = pcc_crc_err, - .pdc = pdc, - .pdc_crc_err = pdc_crc_err, - .rssi = rssi, - .link_config = link_config, - .time_get = time_get, - .capability_get = capability_get, - .stf_cover_seq_control = stf_cover_seq_control, -}; +static void dect_phy_event_handler(const struct nrf_modem_dect_phy_event *evt) +{ + modem_time = evt->time; + + switch (evt->id) { + case NRF_MODEM_DECT_PHY_EVT_INIT: + on_init(&evt->init); + break; + case NRF_MODEM_DECT_PHY_EVT_DEINIT: + on_deinit(&evt->deinit); + break; + case NRF_MODEM_DECT_PHY_EVT_ACTIVATE: + on_activate(&evt->activate); + break; + case NRF_MODEM_DECT_PHY_EVT_DEACTIVATE: + on_deactivate(&evt->deactivate); + break; + case NRF_MODEM_DECT_PHY_EVT_CONFIGURE: + on_configure(&evt->configure); + break; + case NRF_MODEM_DECT_PHY_EVT_RADIO_CONFIG: + on_radio_config(&evt->radio_config); + break; + case NRF_MODEM_DECT_PHY_EVT_COMPLETED: + on_op_complete(&evt->op_complete); + break; + case NRF_MODEM_DECT_PHY_EVT_CANCELED: + on_cancel(&evt->cancel); + break; + case NRF_MODEM_DECT_PHY_EVT_RSSI: + on_rssi(&evt->rssi); + break; + case NRF_MODEM_DECT_PHY_EVT_PCC: + on_pcc(&evt->pcc); + break; + case NRF_MODEM_DECT_PHY_EVT_PCC_ERROR: + on_pcc_crc_err(&evt->pcc_crc_err); + break; + case NRF_MODEM_DECT_PHY_EVT_PDC: + on_pdc(&evt->pdc); + break; + case NRF_MODEM_DECT_PHY_EVT_PDC_ERROR: + on_pdc_crc_err(&evt->pdc_crc_err); + break; + case NRF_MODEM_DECT_PHY_EVT_TIME: + on_time_get(&evt->time_get); + break; + case NRF_MODEM_DECT_PHY_EVT_CAPABILITY: + on_capability_get(&evt->capability_get); + break; + case NRF_MODEM_DECT_PHY_EVT_BANDS: + on_bands_get(&evt->band_get); + break; + case NRF_MODEM_DECT_PHY_EVT_LATENCY: + on_latency_info_get(&evt->latency_get); + break; + case NRF_MODEM_DECT_PHY_EVT_LINK_CONFIG: + on_link_config(&evt->link_config); + break; + case NRF_MODEM_DECT_PHY_EVT_STF_CONFIG: + on_stf_cover_seq_control(&evt->stf_cover_seq_control); + break; + } +} -/* Dect PHY init parameters. */ -static struct nrf_modem_dect_phy_init_params dect_phy_init_params = { - .harq_rx_expiry_time_us = 5000000, +/* Dect PHY config parameters. */ +static struct nrf_modem_dect_phy_config_params dect_phy_config_params = { + .band_group_index = CONFIG_BAND_GROUP_INDEX, .harq_rx_process_count = 4, + .harq_rx_expiry_time_us = 5000000, }; /* Send operation. */ @@ -249,13 +340,13 @@ int main(void) return err; } - err = nrf_modem_dect_phy_callback_set(&dect_phy_callbacks); + err = nrf_modem_dect_phy_event_handler_set(dect_phy_event_handler); if (err) { - LOG_ERR("nrf_modem_dect_phy_callback_set failed, err %d", err); + LOG_ERR("nrf_modem_dect_phy_event_handler_set failed, err %d", err); return err; } - err = nrf_modem_dect_phy_init(&dect_phy_init_params); + err = nrf_modem_dect_phy_init(); if (err) { LOG_ERR("nrf_modem_dect_phy_init failed, err %d", err); return err; @@ -266,6 +357,28 @@ int main(void) return -EIO; } + err = nrf_modem_dect_phy_configure(&dect_phy_config_params); + if (err) { + LOG_ERR("nrf_modem_dect_phy_configure failed, err %d", err); + return err; + } + + k_sem_take(&operation_sem, K_FOREVER); + if (exit) { + return -EIO; + } + + err = nrf_modem_dect_phy_activate(NRF_MODEM_DECT_PHY_RADIO_MODE_LOW_LATENCY); + if (err) { + LOG_ERR("nrf_modem_dect_phy_activate failed, err %d", err); + return err; + } + + k_sem_take(&operation_sem, K_FOREVER); + if (exit) { + return -EIO; + } + hwinfo_get_device_id((void *)&device_id, sizeof(device_id)); LOG_INF("Dect NR+ PHY initialized, device ID: %d", device_id); @@ -288,15 +401,15 @@ int main(void) tx_counter_value++; + /* Wait for TX operation to complete. */ + k_sem_take(&operation_sem, K_FOREVER); + if ((tx_counter_value >= CONFIG_TX_TRANSMISSIONS) && CONFIG_TX_TRANSMISSIONS) { LOG_INF("Reached maximum number of transmissions (%d)", CONFIG_TX_TRANSMISSIONS); break; } - /* Wait for TX operation to complete. */ - k_sem_take(&operation_sem, K_FOREVER); - /** Receiving messages for CONFIG_RX_PERIOD_S seconds. */ err = receive(rx_handle); if (err) { @@ -310,13 +423,21 @@ int main(void) LOG_INF("Shutting down"); + err = nrf_modem_dect_phy_deactivate(); + if (err) { + LOG_ERR("nrf_modem_dect_phy_deactivate failed, err %d", err); + return err; + } + + k_sem_take(&deinit_sem, K_FOREVER); + err = nrf_modem_dect_phy_deinit(); if (err) { LOG_ERR("nrf_modem_dect_phy_deinit() failed, err %d", err); return err; } - k_sem_take(&operation_sem, K_FOREVER); + k_sem_take(&deinit_sem, K_FOREVER); err = nrf_modem_lib_shutdown(); if (err) {