@@ -59,7 +59,13 @@ enum sm_gnss_operation {
5959
6060#if defined(CONFIG_NRF_CLOUD_AGNSS )
6161static struct k_work agnss_req_work ;
62- #endif
62+
63+ #if defined(CONFIG_SM_NRF_CLOUD_LOCATION )
64+ static K_SEM_DEFINE (agnss_ncellmeas_sem , 0 , 1 ) ;
65+ static struct lte_lc_cells_info * agnss_net_info ;
66+ #endif /* CONFIG_SM_NRF_CLOUD_LOCATION */
67+ #endif /* CONFIG_SM_NRF_CLOUD */
68+
6369#if defined(CONFIG_NRF_CLOUD_PGPS )
6470static struct k_work pgps_req_work ;
6571static struct k_work pgps_coap_req_work ;
@@ -317,6 +323,16 @@ static int read_agnss_req(struct nrf_modem_gnss_agnss_data_frame *req)
317323#endif /* CONFIG_NRF_CLOUD_AGNSS || CONFIG_NRF_CLOUD_PGPS */
318324
319325#if defined(CONFIG_NRF_CLOUD_AGNSS )
326+
327+ #if defined(CONFIG_SM_NRF_CLOUD_LOCATION )
328+ static void agnss_ncellmeas_done (struct lte_lc_cells_info * cell_data , void * ctx )
329+ {
330+ ARG_UNUSED (ctx );
331+ agnss_net_info = cell_data ;
332+ k_sem_give (& agnss_ncellmeas_sem );
333+ }
334+ #endif /* CONFIG_SM_NRF_CLOUD_LOCATION */
335+
320336static void agnss_requestor (struct k_work * )
321337{
322338 int err ;
@@ -348,7 +364,20 @@ static void agnss_requestor(struct k_work *)
348364 };
349365
350366#if defined(CONFIG_SM_NRF_CLOUD_LOCATION )
351- struct lte_lc_cells_info * net_info = sm_at_nrfcloud_ncellmeas (1 , false);
367+ /* Start async ncellmeas and wait for the result via semaphore.
368+ * agnss_ncellmeas_done() is called from the AT monitor thread
369+ * (not sm_work_q) for the single-phase case, so giving the semaphore
370+ * does not deadlock this work item.
371+ */
372+ struct lte_lc_cells_info * net_info = NULL ;
373+
374+ err = sm_at_nrfcloud_ncellmeas_start (1 , false, agnss_ncellmeas_done , NULL );
375+ if (err == 0 ) {
376+ /* We will wait for 5 seconds for NCELLMEAS to complete. */
377+ k_sem_take (& agnss_ncellmeas_sem , K_SECONDS (5 ));
378+ net_info = agnss_net_info ;
379+ agnss_net_info = NULL ;
380+ }
352381
353382 if (net_info != NULL && net_info -> current_cell .id != LTE_LC_CELL_EUTRAN_ID_INVALID ) {
354383 request .net_info = net_info ;
0 commit comments