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