@@ -74,7 +74,6 @@ static struct dect_phy_ctrl_data {
7474 bool rssi_scan_on_going ;
7575 bool rssi_scan_cmd_running ;
7676 struct dect_phy_rssi_scan_params rssi_scan_params ;
77- struct dect_phy_rssi_channel_scan_result_t rssi_scan_results ;
7877 dect_phy_ctrl_rssi_scan_completed_callback_t rssi_scan_complete_cb ;
7978
8079 /* Registered callbacks for ext command usage */
@@ -91,8 +90,7 @@ K_SEM_DEFINE(phy_api_init, 0, 1);
9190
9291/**************************************************************************************************/
9392
94- static void dect_phy_rssi_channel_scan_callback (
95- struct dect_phy_rssi_channel_scan_result_t * p_scan_results );
93+ static void dect_phy_rssi_channel_scan_completed_cb (enum nrf_modem_dect_phy_err phy_status );
9694static void dect_phy_ctrl_on_modem_lib_init (int ret , void * ctx );
9795
9896/**************************************************************************************************/
@@ -386,21 +384,30 @@ static void dect_phy_ctrl_msgq_thread_handler(void)
386384 }
387385
388386 case DECT_PHY_CTRL_OP_RSSI_SCAN_RUN : {
387+ int err = 0 ;
388+
389389 if (ctrl_data .rssi_scan_on_going ||
390390 (ctrl_data .rssi_scan_cmd_running &&
391391 ctrl_data .rssi_scan_params .interval_secs )) {
392392 if (ctrl_data .rssi_scan_params .suspend_scheduler ) {
393393 dect_phy_api_scheduler_suspend ();
394394 }
395- dect_phy_scan_rssi_start (& ctrl_data .rssi_scan_params ,
396- dect_phy_rssi_channel_scan_callback );
395+ err = dect_phy_scan_rssi_start (
396+ & ctrl_data .rssi_scan_params ,
397+ dect_phy_rssi_channel_scan_completed_cb );
398+ if (err ) {
399+ desh_error ("RSSI scan start failed: %d" , err );
400+ dect_phy_ctrl_rssi_scan_stop ();
401+ }
397402 }
398403 break ;
399404 }
400405 case DECT_PHY_CTRL_OP_PHY_API_MDM_RSSI_CB_ON_RX_OP : {
401406 if (ctrl_data .rx_cmd_on_going || ctrl_data .ext_command_running ) {
402407 dect_phy_scan_rssi_finished_handle (NRF_MODEM_DECT_PHY_SUCCESS );
403- dect_phy_scan_rssi_data_reinit_with_current_params ();
408+ if (dect_phy_scan_rssi_data_reinit_with_current_params ()) {
409+ desh_error ("Cannot reinit rssi scan data" );
410+ }
404411 }
405412 break ;
406413 }
@@ -613,7 +620,7 @@ static void dect_phy_ctrl_mdm_on_rssi_cb(const uint64_t *time,
613620{
614621 dect_app_modem_time_save (time );
615622
616- if (ctrl_data .rssi_scan_on_going ) {
623+ if (ctrl_data .rssi_scan_on_going || ctrl_data . rx_cmd_on_going ) {
617624 dect_phy_scan_rssi_cb_handle (NRF_MODEM_DECT_PHY_SUCCESS , p_result );
618625 } else if (ctrl_data .ext_cmd .direct_rssi_cb != NULL ) {
619626 ctrl_data .ext_cmd .direct_rssi_cb (p_result );
@@ -782,13 +789,18 @@ int dect_phy_ctrl_rx_start(struct dect_phy_rx_cmd_params *params)
782789
783790 struct dect_phy_rssi_scan_params rssi_params = {
784791 .channel = params -> channel ,
792+ .result_verdict_type = DECT_PHY_RSSI_SCAN_RESULT_VERDICT_TYPE_ALL ,
785793 .busy_rssi_limit = params -> busy_rssi_limit ,
786794 .free_rssi_limit = params -> free_rssi_limit ,
787795 .interval_secs = params -> rssi_interval_secs ,
788796 };
789797
790798 ctrl_data .rx_cmd_params = * params ;
791- dect_phy_scan_rssi_data_init (& rssi_params );
799+ err = dect_phy_scan_rssi_data_init (& rssi_params );
800+ if (err ) {
801+ desh_error ("RSSI scan data init failed: err" , err );
802+ return err ;
803+ }
792804
793805 err = dect_phy_rx_msgq_data_op_add (DECT_PHY_RX_OP_START , (void * )params ,
794806 sizeof (struct dect_phy_rx_cmd_params ));
@@ -865,48 +877,88 @@ void dect_phy_ctrl_status_get_n_print(void)
865877
866878/**************************************************************************************************/
867879
880+ int dect_phy_ctrl_rssi_scan_results_print_and_best_channel_get (bool print_results )
881+ {
882+ struct dect_phy_rssi_scan_channel_results scan_results ;
883+ int err = dect_phy_scan_rssi_channel_results_get (& scan_results );
884+ int best_channel = - ENODATA ;
885+
886+ if (err ) {
887+ desh_error ("RSSI scan results not available." );
888+ return - ENODATA ;
889+ }
890+ best_channel = dect_phy_scan_rssi_results_based_best_channel_get ();
891+
892+ if (print_results ) {
893+ desh_print ("--------------------------------------------------------------"
894+ "---------------" );
895+ desh_print (" RSSI scan done. Found %d free, %d possible and "
896+ "%d busy channels." ,
897+ scan_results .free_channels_count , scan_results .possible_channels_count ,
898+ scan_results .busy_channels_count );
899+ }
900+
901+ if (best_channel <= 0 ) {
902+ desh_print (" No best channel found." );
903+ return - ENODATA ;
904+ }
905+
906+ char final_verdict_str [10 ];
907+ struct dect_phy_rssi_scan_data_result scan_result ;
908+
909+ if (print_results ) {
910+ desh_print (" Best channel: %d" , best_channel );
911+ }
912+
913+ err = dect_phy_scan_rssi_results_get_by_channel (best_channel , & scan_result );
914+ if (err ) {
915+ desh_warn (" No scan result found for best channel." );
916+ return best_channel ;
917+ }
918+
919+ if (print_results ) {
920+ dect_phy_rssi_scan_result_verdict_to_string (scan_result .result , final_verdict_str );
921+
922+ desh_print (" Final verdict: %s" , final_verdict_str );
923+
924+ if (ctrl_data .rssi_scan_params .result_verdict_type ==
925+ DECT_PHY_RSSI_SCAN_RESULT_VERDICT_TYPE_SUBSLOT_COUNT ) {
926+ desh_print (" Free subslots: %d" ,
927+ scan_result .subslot_count_type_results .free_subslot_count );
928+ desh_print (" Possible subslots: %d" ,
929+ scan_result .subslot_count_type_results .possible_subslot_count );
930+ desh_print (" Busy subslots: %d" ,
931+ scan_result .subslot_count_type_results .busy_subslot_count );
932+ }
933+ }
934+ return best_channel ;
935+ }
936+
868937static void dect_phy_ctrl_rssi_scan_timer_handler (struct k_timer * timer_id )
869938{
870939 dect_phy_ctrl_msgq_non_data_op_add (DECT_PHY_CTRL_OP_RSSI_SCAN_RUN );
871940}
872941K_TIMER_DEFINE (rssi_scan_timer , dect_phy_ctrl_rssi_scan_timer_handler , NULL );
873942
874- static void dect_phy_rssi_channel_scan_callback (
875- struct dect_phy_rssi_channel_scan_result_t * p_scan_results )
943+ static void dect_phy_rssi_channel_scan_completed_cb (enum nrf_modem_dect_phy_err phy_status )
876944{
877- memcpy (ctrl_data .rssi_scan_results .free_channels , p_scan_results -> free_channels ,
878- p_scan_results -> free_channels_count * sizeof (uint16_t ));
879- ctrl_data .rssi_scan_results .free_channels_count = p_scan_results -> free_channels_count ;
880-
881- memcpy (ctrl_data .rssi_scan_results .possible_channels , p_scan_results -> possible_channels ,
882- p_scan_results -> possible_channels_count * sizeof (uint16_t ));
883- ctrl_data .rssi_scan_results .possible_channels_count =
884- p_scan_results -> possible_channels_count ;
885-
886- memcpy (ctrl_data .rssi_scan_results .busy_channels , p_scan_results -> busy_channels ,
887- p_scan_results -> busy_channels_count * sizeof (uint16_t ));
888- ctrl_data .rssi_scan_results .busy_channels_count = p_scan_results -> busy_channels_count ;
889-
890- desh_print (" RSSI scan done. Found %d free, %d possible and %d busy channels." ,
891- ctrl_data .rssi_scan_results .free_channels_count ,
892- ctrl_data .rssi_scan_results .possible_channels_count ,
893- ctrl_data .rssi_scan_results .busy_channels_count );
945+ (void )dect_phy_ctrl_rssi_scan_results_print_and_best_channel_get (true);
894946
895- if (p_scan_results -> phy_status == NRF_MODEM_DECT_PHY_SUCCESS ) {
947+ if (phy_status == NRF_MODEM_DECT_PHY_SUCCESS ) {
896948 k_sem_give (& rssi_scan_sema );
897949 } else {
898950 char tmp_str [128 ] = {0 };
899951
900952 dect_common_utils_modem_phy_err_to_string (
901- p_scan_results -> phy_status , NRF_MODEM_DECT_PHY_TEMP_NOT_MEASURED , tmp_str );
953+ phy_status , NRF_MODEM_DECT_PHY_TEMP_NOT_MEASURED , tmp_str );
902954
903955 k_sem_reset (& rssi_scan_sema ); /* -EAGAIN should be returned from k_sem_take() */
904- desh_warn (" RSSI scan failed: %s (%d)" , tmp_str , p_scan_results -> phy_status );
956+ desh_warn (" RSSI scan failed: %s (%d)" , tmp_str , phy_status );
905957 }
906958 dect_phy_api_scheduler_resume ();
907959 ctrl_data .rssi_scan_on_going = false;
908960 if (ctrl_data .rssi_scan_complete_cb ) {
909- ctrl_data .rssi_scan_complete_cb (p_scan_results -> phy_status );
961+ ctrl_data .rssi_scan_complete_cb (phy_status );
910962 }
911963 if (ctrl_data .rssi_scan_cmd_running && ctrl_data .rssi_scan_params .interval_secs ) {
912964 k_timer_start (& rssi_scan_timer , K_SECONDS (ctrl_data .rssi_scan_params .interval_secs ),
@@ -1177,8 +1229,16 @@ bool dect_phy_ctrl_phy_api_scheduler_suspended(void)
11771229
11781230int dect_phy_ctrl_ext_command_start (struct dect_phy_ctrl_ext_callbacks ext_callbacks )
11791231{
1180- if (!dect_phy_ctrl_mdm_phy_api_initialized () || ctrl_data .rssi_scan_on_going ||
1232+ if (!dect_phy_ctrl_mdm_phy_api_initialized ()) {
1233+ desh_error ("(%s): Phy api not initialized" , (__func__ ));
1234+ return - EACCES ;
1235+ }
1236+
1237+ if (ctrl_data .rssi_scan_on_going ||
11811238 ctrl_data .perf_on_going || ctrl_data .ping_on_going ) {
1239+ desh_error ("(%s): Operation already on going. "
1240+ "Stop all before starting running ext command." ,
1241+ (__func__ ));
11821242 return - EBUSY ;
11831243 }
11841244 ctrl_data .ext_cmd = ext_callbacks ;
0 commit comments