@@ -50,9 +50,9 @@ static struct dect_phy_ctrl_data {
5050
5151 bool scheduler_suspended ;
5252
53- bool perf_on_going ;
54- bool ping_on_going ;
55- bool cert_on_going ;
53+ bool perf_ongoing ;
54+ bool ping_ongoing ;
55+ bool cert_ongoing ;
5656 bool ext_command_running ;
5757
5858 bool rx_cmd_on_going ;
@@ -74,7 +74,7 @@ static struct dect_phy_ctrl_data {
7474 uint8_t last_received_pcc_phy_len ;
7575 enum dect_phy_packet_length_type last_received_pcc_phy_len_type ;
7676
77- bool rssi_scan_on_going ;
77+ bool rssi_scan_ongoing ;
7878 bool rssi_scan_cmd_running ;
7979 struct dect_phy_rssi_scan_params rssi_scan_params ;
8080 dect_phy_ctrl_rssi_scan_completed_callback_t rssi_scan_complete_cb ;
@@ -88,13 +88,14 @@ static struct dect_phy_ctrl_data {
8888
8989K_SEM_DEFINE (rssi_scan_sema , 0 , 1 );
9090
91- K_SEM_DEFINE (phy_api_deinit , 0 , 1 );
92- K_SEM_DEFINE (phy_api_init , 0 , 1 );
91+ K_SEM_DEFINE (dect_phy_ctrl_mdm_api_deinit_sema , 0 , 1 );
92+ K_SEM_DEFINE (dect_phy_ctrl_mdm_api_init_sema , 0 , 1 );
9393
9494/**************************************************************************************************/
9595
9696static void dect_phy_rssi_channel_scan_completed_cb (enum nrf_modem_dect_phy_err phy_status );
9797static void dect_phy_ctrl_on_modem_lib_init (int ret , void * ctx );
98+ static int dect_phy_ctrl_phy_reinit (void );
9899
99100/**************************************************************************************************/
100101
@@ -152,33 +153,27 @@ static void dect_phy_ctrl_msgq_thread_handler(void)
152153 break ;
153154 }
154155 case DECT_PHY_CTRL_OP_PERF_CMD_DONE : {
155- ctrl_data .perf_on_going = false;
156+ ctrl_data .perf_ongoing = false;
156157 dect_phy_ctrl_msgq_non_data_op_add (DECT_PHY_CTRL_OP_DEBUG_ON );
157158
158- /* Deinit was done by perf module:
159- * reinit phy api to have our callbacks back
160- */
161- dect_phy_ctrl_on_modem_lib_init (0 , NULL );
159+ dect_phy_ctrl_phy_reinit ();
160+
161+ desh_print ("perf command done." );
162162 break ;
163163 }
164164 case DECT_PHY_CTRL_OP_PING_CMD_DONE : {
165- ctrl_data .ping_on_going = false;
165+ ctrl_data .ping_ongoing = false;
166166 dect_phy_ctrl_msgq_non_data_op_add (DECT_PHY_CTRL_OP_DEBUG_ON );
167167
168- /* Deinit was done by ping module:
169- * reinit phy api to have our callbacks back
170- */
171- dect_phy_ctrl_on_modem_lib_init (0 , NULL );
168+ dect_phy_ctrl_phy_reinit ();
169+ desh_print ("ping command done." );
172170 break ;
173171 }
174172 case DECT_PHY_CTRL_OP_RF_TOOL_CMD_DONE : {
175- ctrl_data .cert_on_going = false;
173+ ctrl_data .cert_ongoing = false;
176174 dect_phy_ctrl_msgq_non_data_op_add (DECT_PHY_CTRL_OP_DEBUG_ON );
177175
178- /* Deinit was done by rf tool module:
179- * reinit phy api to have our callbacks back
180- */
181- dect_phy_ctrl_on_modem_lib_init (0 , NULL );
176+ dect_phy_ctrl_phy_reinit ();
182177 break ;
183178 }
184179 case DECT_PHY_CTRL_OP_DEBUG_ON : {
@@ -259,7 +254,6 @@ static void dect_phy_ctrl_msgq_thread_handler(void)
259254 params -> modem_configuration .latency .txrx_tx_to_rx );
260255 }
261256 }
262- k_sem_give (& phy_api_init );
263257 break ;
264258 }
265259
@@ -404,7 +398,7 @@ static void dect_phy_ctrl_msgq_thread_handler(void)
404398 case DECT_PHY_CTRL_OP_RSSI_SCAN_RUN : {
405399 int err = 0 ;
406400
407- if (ctrl_data .rssi_scan_on_going ||
401+ if (ctrl_data .rssi_scan_ongoing ||
408402 (ctrl_data .rssi_scan_cmd_running &&
409403 ctrl_data .rssi_scan_params .interval_secs )) {
410404 if (ctrl_data .rssi_scan_params .suspend_scheduler ) {
@@ -461,6 +455,7 @@ static void dect_phy_ctrl_mdm_initialize_cb(const uint64_t *time, int16_t temper
461455 ctrl_data .phy_api_initialized = true;
462456 }
463457
458+ k_sem_give (& dect_phy_ctrl_mdm_api_init_sema );
464459 dect_phy_ctrl_msgq_data_op_add (DECT_PHY_CTRL_OP_PHY_API_MDM_INITIALIZED ,
465460 (void * )& ctrl_op_initialized_params ,
466461 sizeof (struct dect_phy_common_op_initialized_params ));
@@ -634,7 +629,7 @@ static void dect_phy_ctrl_mdm_on_rssi_cb(const uint64_t *time,
634629{
635630 dect_app_modem_time_save (time );
636631
637- if (ctrl_data .rssi_scan_on_going || ctrl_data .rx_cmd_on_going ) {
632+ if (ctrl_data .rssi_scan_ongoing || ctrl_data .rx_cmd_on_going ) {
638633 dect_phy_scan_rssi_cb_handle (NRF_MODEM_DECT_PHY_SUCCESS , p_result );
639634 } else if (ctrl_data .ext_cmd .direct_rssi_cb != NULL ) {
640635 ctrl_data .ext_cmd .direct_rssi_cb (p_result );
@@ -717,7 +712,7 @@ static void dect_phy_ctrl_mdm_on_stf_cover_seq_control_cb(
717712static void dect_phy_ctrl_mdm_on_deinit_cb (const uint64_t * time , enum nrf_modem_dect_phy_err err )
718713{
719714 ctrl_data .phy_api_initialized = false;
720- k_sem_give (& phy_api_deinit );
715+ k_sem_give (& dect_phy_ctrl_mdm_api_deinit_sema );
721716}
722717
723718static const struct nrf_modem_dect_phy_callbacks dect_phy_api_config = {
@@ -1012,7 +1007,7 @@ static void dect_phy_rssi_channel_scan_completed_cb(enum nrf_modem_dect_phy_err
10121007 desh_warn (" RSSI scan failed: %s (%d)" , tmp_str , phy_status );
10131008 }
10141009 dect_phy_api_scheduler_resume ();
1015- ctrl_data .rssi_scan_on_going = false;
1010+ ctrl_data .rssi_scan_ongoing = false;
10161011 if (ctrl_data .rssi_scan_complete_cb ) {
10171012 ctrl_data .rssi_scan_complete_cb (phy_status );
10181013 }
@@ -1028,26 +1023,25 @@ static int dect_phy_ctrl_phy_reinit(void)
10281023{
10291024 int ret ;
10301025
1031- k_sem_reset (& phy_api_deinit );
1032-
1026+ k_sem_reset (& dect_phy_ctrl_mdm_api_deinit_sema );
10331027 ret = nrf_modem_dect_phy_deinit ();
1034-
10351028 if (ret ) {
10361029 desh_error ("nrf_modem_dect_phy_deinit failed, err=%d" , ret );
10371030 return ret ;
10381031 }
10391032
10401033 /* Wait that deinit is done */
1041- ret = k_sem_take (& phy_api_deinit , K_SECONDS (5 ));
1034+ ret = k_sem_take (& dect_phy_ctrl_mdm_api_deinit_sema , K_SECONDS (10 ));
10421035 if (ret ) {
10431036 desh_error ("(%s): nrf_modem_dect_phy_deinit() timeout." , (__func__ ));
10441037 return - ETIMEDOUT ;
10451038 }
10461039
1047- k_sem_reset (& phy_api_init );
1040+ k_sem_reset (& dect_phy_ctrl_mdm_api_init_sema );
10481041 dect_phy_ctrl_phy_init ();
10491042
1050- ret = k_sem_take (& phy_api_init , K_SECONDS (5 ));
1043+ /* Wait that init is done */
1044+ ret = k_sem_take (& dect_phy_ctrl_mdm_api_init_sema , K_SECONDS (60 ));
10511045 if (ret ) {
10521046 desh_error ("(%s): nrf_modem_dect_phy_init() timeout." , (__func__ ));
10531047 return - ETIMEDOUT ;
@@ -1065,14 +1059,14 @@ int dect_phy_ctrl_rssi_scan_start(struct dect_phy_rssi_scan_params *params,
10651059 return - EACCES ;
10661060 }
10671061
1068- if (ctrl_data .rssi_scan_on_going ) {
1062+ if (ctrl_data .rssi_scan_ongoing ) {
10691063 desh_error ("RSSI scan already on going.\n" );
10701064 return - EBUSY ;
10711065 }
10721066
10731067 k_sem_reset (& rssi_scan_sema );
10741068
1075- ctrl_data .rssi_scan_on_going = true;
1069+ ctrl_data .rssi_scan_ongoing = true;
10761070 ctrl_data .rssi_scan_cmd_running = true;
10771071 ctrl_data .rssi_scan_params = * params ;
10781072 ctrl_data .rssi_scan_complete_cb = fp_result_callback ;
@@ -1095,7 +1089,7 @@ int dect_phy_ctrl_rssi_scan_start(struct dect_phy_rssi_scan_params *params,
10951089void dect_phy_ctrl_rssi_scan_stop (void )
10961090{
10971091 ctrl_data .rssi_scan_cmd_running = false;
1098- ctrl_data .rssi_scan_on_going = false;
1092+ ctrl_data .rssi_scan_ongoing = false;
10991093 k_timer_stop (& rssi_scan_timer );
11001094 dect_phy_scan_rssi_stop ();
11011095 k_sem_reset (& rssi_scan_sema );
@@ -1104,17 +1098,41 @@ void dect_phy_ctrl_rssi_scan_stop(void)
11041098
11051099/**************************************************************************************************/
11061100
1101+ static bool dect_phy_ctrl_op_ongoing (void )
1102+ {
1103+ if (ctrl_data .rssi_scan_ongoing ) {
1104+ desh_warn ("RSSI scan ongoing." );
1105+ return true;
1106+ }
1107+ if (ctrl_data .perf_ongoing ) {
1108+ desh_warn ("Performance test ongoing." );
1109+ return true;
1110+ }
1111+ if (ctrl_data .ping_ongoing ) {
1112+ desh_warn ("Ping ongoing." );
1113+ return true;
1114+ }
1115+ if (ctrl_data .cert_ongoing ) {
1116+ desh_warn ("Certification ongoing." );
1117+ return true;
1118+ }
1119+ if (ctrl_data .ext_command_running ) {
1120+ desh_warn ("External command ongoing." );
1121+ return true;
1122+ }
1123+ return false;
1124+ }
1125+
11071126int dect_phy_ctrl_perf_cmd (struct dect_phy_perf_params * params )
11081127{
11091128 int ret ;
11101129
1111- if (ctrl_data .rssi_scan_on_going || ctrl_data .perf_on_going || ctrl_data .ping_on_going ||
1112- ctrl_data .cert_on_going || ctrl_data .ext_command_running ) {
1130+ if (dect_phy_ctrl_op_ongoing ()) {
11131131 desh_error (
11141132 "DECT operation already on going. Stop all before starting running perf." );
11151133 return - EBUSY ;
11161134 }
1117- k_sem_reset (& phy_api_deinit );
1135+ k_sem_reset (& dect_phy_ctrl_mdm_api_deinit_sema );
11181136
11191137 /* We want to have own callbacks for perf command */
11201138 ret = nrf_modem_dect_phy_deinit ();
@@ -1124,14 +1142,14 @@ int dect_phy_ctrl_perf_cmd(struct dect_phy_perf_params *params)
11241142 }
11251143
11261144 /* Wait that deinit is done */
1127- ret = k_sem_take (& phy_api_deinit , K_SECONDS (5 ));
1145+ ret = k_sem_take (& dect_phy_ctrl_mdm_api_deinit_sema , K_SECONDS (10 ));
11281146 if (ret ) {
11291147 desh_error ("(%s): nrf_modem_dect_phy_deinit() timeout." , (__func__ ));
11301148 return - ETIMEDOUT ;
11311149 }
11321150
11331151 dect_phy_ctrl_msgq_non_data_op_add (DECT_PHY_CTRL_OP_DEBUG_OFF );
1134- ctrl_data .perf_on_going = true;
1152+ ctrl_data .perf_ongoing = true;
11351153 ret = dect_phy_perf_cmd_handle (params );
11361154 if (ret ) {
11371155 dect_phy_ctrl_msgq_non_data_op_add (DECT_PHY_CTRL_OP_PERF_CMD_DONE );
@@ -1152,13 +1170,11 @@ void dect_phy_ctrl_perf_cmd_stop(void)
11521170int dect_phy_ctrl_ping_cmd (struct dect_phy_ping_params * params )
11531171{
11541172 int ret ;
1155-
1156- if (ctrl_data .rssi_scan_on_going || ctrl_data .perf_on_going || ctrl_data .ping_on_going ||
1157- ctrl_data .cert_on_going || ctrl_data .ext_command_running ) {
1173+ if (dect_phy_ctrl_op_ongoing ()) {
11581174 desh_error ("Operation already on going. Stop all before starting running ping." );
11591175 return - EBUSY ;
11601176 }
1161- k_sem_reset (& phy_api_deinit );
1177+ k_sem_reset (& dect_phy_ctrl_mdm_api_deinit_sema );
11621178
11631179 /* We want to have own mdm phy api callbacks for ping command */
11641180 ret = nrf_modem_dect_phy_deinit ();
@@ -1168,14 +1184,14 @@ int dect_phy_ctrl_ping_cmd(struct dect_phy_ping_params *params)
11681184 }
11691185
11701186 /* Wait that deinit is done */
1171- ret = k_sem_take (& phy_api_deinit , K_SECONDS (5 ));
1187+ ret = k_sem_take (& dect_phy_ctrl_mdm_api_deinit_sema , K_SECONDS (10 ));
11721188 if (ret ) {
11731189 desh_error ("(%s): nrf_modem_dect_phy_deinit() timeout." , (__func__ ));
11741190 return - ETIMEDOUT ;
11751191 }
11761192
11771193 dect_phy_ctrl_msgq_non_data_op_add (DECT_PHY_CTRL_OP_DEBUG_OFF );
1178- ctrl_data .ping_on_going = true;
1194+ ctrl_data .ping_ongoing = true;
11791195 ret = dect_phy_ping_cmd_handle (params );
11801196 if (ret ) {
11811197 dect_phy_ctrl_msgq_non_data_op_add (DECT_PHY_CTRL_OP_PING_CMD_DONE );
@@ -1193,16 +1209,16 @@ void dect_phy_ctrl_ping_cmd_stop(void)
11931209
11941210/**************************************************************************************************/
11951211
1196- int dect_phy_ctrl_cert_cmd (struct dect_phy_rf_tool_params * params )
1212+ int dect_phy_ctrl_rf_tool_cmd (struct dect_phy_rf_tool_params * params )
11971213{
11981214 int ret ;
11991215
1200- if (ctrl_data .rssi_scan_on_going || ctrl_data .perf_on_going || ctrl_data .ping_on_going ||
1201- ctrl_data .cert_on_going || ctrl_data .ext_command_running ) {
1216+ if (dect_phy_ctrl_op_ongoing ()) {
12021217 desh_error ("Operation already on going. Stop all before starting running rf_tool." );
12031218 return - EBUSY ;
12041219 }
1205- k_sem_reset (& phy_api_deinit );
1220+
1221+ k_sem_reset (& dect_phy_ctrl_mdm_api_deinit_sema );
12061222
12071223 /* We want to have own mdm phy api callbacks for cert command */
12081224 ret = nrf_modem_dect_phy_deinit ();
@@ -1212,14 +1228,14 @@ int dect_phy_ctrl_cert_cmd(struct dect_phy_rf_tool_params *params)
12121228 }
12131229
12141230 /* Wait that deinit is done */
1215- ret = k_sem_take (& phy_api_deinit , K_SECONDS (5 ));
1231+ ret = k_sem_take (& dect_phy_ctrl_mdm_api_deinit_sema , K_SECONDS (10 ));
12161232 if (ret ) {
12171233 desh_error ("(%s): nrf_modem_dect_phy_deinit() timeout." , (__func__ ));
12181234 return - ETIMEDOUT ;
12191235 }
12201236
12211237 dect_phy_ctrl_msgq_non_data_op_add (DECT_PHY_CTRL_OP_DEBUG_OFF );
1222- ctrl_data .cert_on_going = true;
1238+ ctrl_data .cert_ongoing = true;
12231239 ret = dect_phy_rf_tool_cmd_handle (params );
12241240 if (ret ) {
12251241 dect_phy_ctrl_msgq_non_data_op_add (DECT_PHY_CTRL_OP_RF_TOOL_CMD_DONE );
@@ -1228,7 +1244,7 @@ int dect_phy_ctrl_cert_cmd(struct dect_phy_rf_tool_params *params)
12281244 return ret ;
12291245}
12301246
1231- void dect_phy_ctrl_cert_cmd_stop (void )
1247+ void dect_phy_ctrl_rf_tool_cmd_stop (void )
12321248{
12331249 dect_phy_ctrl_msgq_non_data_op_add (DECT_PHY_CTRL_OP_DEBUG_ON );
12341250
@@ -1290,8 +1306,8 @@ int dect_phy_ctrl_ext_command_start(struct dect_phy_ctrl_ext_callbacks ext_callb
12901306 return - EACCES ;
12911307 }
12921308
1293- if (ctrl_data .rssi_scan_on_going ||
1294- ctrl_data .perf_on_going || ctrl_data .ping_on_going ) {
1309+ if (ctrl_data .rssi_scan_ongoing ||
1310+ ctrl_data .perf_ongoing || ctrl_data .ping_ongoing ) {
12951311 desh_error ("(%s): Operation already on going. "
12961312 "Stop all before starting running ext command." ,
12971313 (__func__ ));
@@ -1333,7 +1349,15 @@ static void dect_phy_ctrl_on_modem_lib_init(int ret, void *ctx)
13331349 ARG_UNUSED (ctx );
13341350
13351351 if (!ctrl_data .phy_api_initialized ) {
1352+ k_sem_reset (& dect_phy_ctrl_mdm_api_init_sema );
1353+
13361354 dect_phy_ctrl_phy_init ();
1355+
1356+ /* Wait that init is done */
1357+ ret = k_sem_take (& dect_phy_ctrl_mdm_api_init_sema , K_SECONDS (2 ));
1358+ if (ret ) {
1359+ desh_error ("(%s): nrf_modem_dect_phy_init() timeout." , (__func__ ));
1360+ }
13371361 }
13381362}
13391363
0 commit comments