37
37
38
38
LOG_MODULE_REGISTER (nrf_dm , CONFIG_DM_MODULE_LOG_LEVEL );
39
39
40
- #ifdef CONFIG_NRF_DM_TIMER0
41
- #define NRF_DM_TIMER NRF_TIMER0
40
+ #ifdef CONFIG_DM_TIMER0
41
+ #define DM_TIMER NRF_TIMER0
42
42
#endif
43
- #ifdef CONFIG_NRF_DM_TIMER1
44
- #define NRF_DM_TIMER NRF_TIMER1
43
+ #ifdef CONFIG_DM_TIMER1
44
+ #define DM_TIMER NRF_TIMER1
45
45
#endif
46
- #ifdef CONFIG_NRF_DM_TIMER2
47
- #define NRF_DM_TIMER NRF_TIMER2
46
+ #ifdef CONFIG_DM_TIMER2
47
+ #define DM_TIMER NRF_TIMER2
48
48
#endif
49
- #ifdef CONFIG_NRF_DM_TIMER3
50
- #define NRF_DM_TIMER NRF_TIMER3
49
+ #ifdef CONFIG_DM_TIMER3
50
+ #define DM_TIMER NRF_TIMER3
51
51
#endif
52
- #ifdef CONFIG_NRF_DM_TIMER4
53
- #define NRF_DM_TIMER NRF_TIMER4
52
+ #ifdef CONFIG_DM_TIMER4
53
+ #define DM_TIMER NRF_TIMER4
54
54
#endif
55
55
56
56
#define PPI_CH_COUNT 2
57
57
58
58
#define MPSL_THREAD_PRIO CONFIG_MPSL_THREAD_COOP_PRIO
59
- #define STACKSIZE CONFIG_MAIN_STACK_SIZE
60
- #define DM_THREAD_PRIORITY K_HIGHEST_APPLICATION_THREAD_PRIO
59
+ #define MPSL_THREAD_STACK_SIZE CONFIG_MAIN_STACK_SIZE
60
+ #define DM_THREAD_PRIORITY 0
61
61
#define TIMESLOT_TIMEOUT_STEP_MS 120000
62
62
63
+ #if CONFIG_DM_HIGH_PRECISION_CALC && !defined(NRF5340_XXAA )
64
+ #define DM_THREAD_STACK_SIZE 2560
65
+ #else
66
+ #define DM_THREAD_STACK_SIZE 1536
67
+ #endif
68
+
63
69
#define DM_TIMESLOT_OVERHEAD_US 400
64
70
#define DM_REFLECTOR_OVERHEAD_US 2000
65
71
@@ -176,6 +182,7 @@ static mpsl_timeslot_signal_return_param_t *mpsl_timeslot_callback(
176
182
dm_io_set (DM_IO_RANGING );
177
183
178
184
if (atomic_get (& timeslot_ctx .state ) == TIMESLOT_STATE_EARLY_PENDING ) {
185
+ dm_io_clear (DM_IO_RANGING );
179
186
return p_ret_val ;
180
187
}
181
188
@@ -258,7 +265,7 @@ static void mpsl_nonpreemptible_thread(void)
258
265
}
259
266
}
260
267
261
- static void process_data (const nrf_dm_report_t * data )
268
+ static void process_data (const nrf_dm_report_t * data , float high_precision_estimate )
262
269
{
263
270
if (!data ) {
264
271
result .status = false;
@@ -287,6 +294,9 @@ static void process_data(const nrf_dm_report_t *data)
287
294
result .dist_estimates .mcpd .best = data -> distance_estimates .mcpd .best ;
288
295
result .dist_estimates .mcpd .rssi_openspace =
289
296
data -> distance_estimates .mcpd .rssi_openspace ;
297
+ #ifdef CONFIG_DM_HIGH_PRECISION_CALC
298
+ result .dist_estimates .mcpd .high_precision = high_precision_estimate ;
299
+ #endif
290
300
}
291
301
}
292
302
@@ -350,11 +360,6 @@ static void dm_start_ranging(void)
350
360
timeslot_queue_remove_first ();
351
361
352
362
uint32_t distance = time_distance_get (timeslot_ctx .last_start , req -> start_time );
353
- uint32_t distance_now = time_distance_get (timeslot_ctx .last_start , time_now ());
354
-
355
- if (distance_now > distance ) {
356
- goto out ;
357
- }
358
363
359
364
atomic_set (& timeslot_ctx .state , TIMESLOT_STATE_PENDING );
360
365
err = timeslot_request (TICKS_TO_US (distance ));
@@ -378,7 +383,7 @@ static void dm_reschedule(void)
378
383
timeslot_len_us = timeslot_ctx .curr_req .timeslot_length_us ;
379
384
380
385
err = timeslot_queue_append (& timeslot_ctx .curr_req .dm_req ,
381
- timeslot_ctx . last_start , window_len_us , timeslot_len_us );
386
+ time_now () , window_len_us , timeslot_len_us );
382
387
if (err ) {
383
388
LOG_DBG ("Timeslot allocator failed (err %d)" , err );
384
389
}
@@ -400,11 +405,17 @@ static void calculation(void)
400
405
}
401
406
} else {
402
407
static nrf_dm_report_t report ;
408
+ float high_precision_estimate = 0 ;
403
409
404
410
nrf_dm_populate_report (& report );
405
411
nrf_dm_calc (& report );
406
- process_data (& report );
407
412
413
+ #ifdef CONFIG_DM_HIGH_PRECISION_CALC
414
+ if (report .ranging_mode == NRF_DM_RANGING_MODE_MCPD ) {
415
+ high_precision_estimate = nrf_dm_high_precision_calc (& report );
416
+ }
417
+ #endif
418
+ process_data (& report , high_precision_estimate );
408
419
if (dm_context .cb -> data_ready != NULL ) {
409
420
dm_context .cb -> data_ready (& result );
410
421
}
@@ -506,7 +517,7 @@ int dm_init(struct dm_init_param *init_param)
506
517
ppi_ch [i ] = (uint8_t )channel ;
507
518
}
508
519
509
- nrf_dm_init (& ppi_conf , & ant_conf , NRF_DM_TIMER );
520
+ nrf_dm_init (& ppi_conf , & ant_conf , DM_TIMER );
510
521
511
522
ver = nrf_dm_version_string_get ();
512
523
LOG_DBG ("Initialized NRF_DM version %s" , ver );
@@ -522,7 +533,8 @@ int dm_init(struct dm_init_param *init_param)
522
533
return 0 ;
523
534
}
524
535
525
- K_THREAD_DEFINE (dm_thread_id , STACKSIZE , dm_thread , NULL , NULL , NULL , DM_THREAD_PRIORITY , 0 , 0 );
536
+ K_THREAD_DEFINE (dm_thread_id , DM_THREAD_STACK_SIZE ,
537
+ dm_thread , NULL , NULL , NULL , DM_THREAD_PRIORITY , 0 , 0 );
526
538
527
- K_THREAD_DEFINE (mpsl_nonpreemptible_thread_id , STACKSIZE ,
539
+ K_THREAD_DEFINE (mpsl_nonpreemptible_thread_id , MPSL_THREAD_STACK_SIZE ,
528
540
mpsl_nonpreemptible_thread , NULL , NULL , NULL , K_PRIO_COOP (MPSL_THREAD_PRIO ), 0 , 0 );
0 commit comments