@@ -468,13 +468,63 @@ static inline int z_impl_counter_capture_disable(const struct device *dev,
468
468
__syscall uint32_t counter_us_to_ticks (const struct device * dev , uint64_t us );
469
469
470
470
static inline uint32_t z_impl_counter_us_to_ticks (const struct device * dev ,
471
- uint64_t us )
471
+ uint64_t us )
472
472
{
473
473
uint64_t ticks = (us * z_impl_counter_get_frequency (dev )) / USEC_PER_SEC ;
474
474
475
475
return (ticks > (uint64_t )UINT32_MAX ) ? UINT32_MAX : ticks ;
476
476
}
477
477
478
+ /**
479
+ * @brief Function to convert microseconds to ticks with 64 bits.
480
+ *
481
+ * @param[in] dev Pointer to the device structure for the driver instance.
482
+ * @param[in] us Microseconds.
483
+ *
484
+ * @return Converted ticks.
485
+ */
486
+ __syscall uint64_t counter_us_to_ticks_64 (const struct device * dev , uint64_t us );
487
+
488
+ static inline uint64_t z_impl_counter_us_to_ticks_64 (const struct device * dev ,
489
+ uint64_t us )
490
+ {
491
+ return (us * z_impl_counter_get_frequency (dev )) / USEC_PER_SEC ;
492
+ }
493
+
494
+ /**
495
+ * @brief Function to convert nanoseconds to ticks.
496
+ *
497
+ * @param[in] dev Pointer to the device structure for the driver instance.
498
+ * @param[in] ns Nanoseconds.
499
+ *
500
+ * @return Converted ticks. Ticks will be saturated if exceed 32 bits.
501
+ */
502
+ __syscall uint32_t counter_ns_to_ticks (const struct device * dev , uint64_t ns );
503
+
504
+ static inline uint32_t z_impl_counter_ns_to_ticks (const struct device * dev ,
505
+ uint64_t ns )
506
+ {
507
+ uint64_t ticks = (ns * z_impl_counter_get_frequency (dev )) / NSEC_PER_SEC ;
508
+
509
+ return (ticks > (uint64_t )UINT32_MAX ) ? UINT32_MAX : ticks ;
510
+ }
511
+
512
+ /**
513
+ * @brief Function to convert nanoseconds to ticks with 64 bits.
514
+ *
515
+ * @param[in] dev Pointer to the device structure for the driver instance.
516
+ * @param[in] ns Nanoseconds.
517
+ *
518
+ * @return Converted ticks.
519
+ */
520
+ __syscall uint64_t counter_ns_to_ticks_64 (const struct device * dev , uint64_t ns );
521
+
522
+ static inline uint64_t z_impl_counter_ns_to_ticks_64 (const struct device * dev ,
523
+ uint64_t ns )
524
+ {
525
+ return (ns * z_impl_counter_get_frequency (dev )) / NSEC_PER_SEC ;
526
+ }
527
+
478
528
/**
479
529
* @brief Function to convert ticks to microseconds.
480
530
*
@@ -486,11 +536,43 @@ static inline uint32_t z_impl_counter_us_to_ticks(const struct device *dev,
486
536
__syscall uint64_t counter_ticks_to_us (const struct device * dev , uint32_t ticks );
487
537
488
538
static inline uint64_t z_impl_counter_ticks_to_us (const struct device * dev ,
489
- uint32_t ticks )
539
+ uint32_t ticks )
490
540
{
491
541
return ((uint64_t )ticks * USEC_PER_SEC ) / z_impl_counter_get_frequency (dev );
492
542
}
493
543
544
+ /**
545
+ * @brief Function to convert ticks to nanoseconds.
546
+ *
547
+ * @param[in] dev Pointer to the device structure for the driver instance.
548
+ * @param[in] ticks Ticks.
549
+ *
550
+ * @return Converted nanoseconds.
551
+ */
552
+ __syscall uint64_t counter_ticks_to_ns (const struct device * dev , uint32_t ticks );
553
+
554
+ static inline uint64_t z_impl_counter_ticks_to_ns (const struct device * dev ,
555
+ uint32_t ticks )
556
+ {
557
+ return ((uint64_t )ticks * NSEC_PER_SEC ) / z_impl_counter_get_frequency (dev );
558
+ }
559
+
560
+ /**
561
+ * @brief Function to convert ticks to nanoseconds.
562
+ *
563
+ * @param[in] dev Pointer to the device structure for the driver instance.
564
+ * @param[in] ticks Ticks.
565
+ *
566
+ * @return Converted nanoseconds.
567
+ */
568
+ __syscall uint64_t counter_ticks_to_ns_64 (const struct device * dev , uint64_t ticks );
569
+
570
+ static inline uint64_t z_impl_counter_ticks_to_ns_64 (const struct device * dev ,
571
+ uint64_t ticks )
572
+ {
573
+ return (ticks * NSEC_PER_SEC ) / z_impl_counter_get_frequency (dev );
574
+ }
575
+
494
576
/**
495
577
* @brief Function to retrieve maximum top value that can be set.
496
578
*
0 commit comments