Skip to content

Commit bca62b6

Browse files
JiafeiPanjhedberg
authored andcommitted
counter: add counter_ticks_to_ns()
Add new API to get nanosecond from counter ticks. Signed-off-by: Jiafei Pan <[email protected]>
1 parent 08ffc97 commit bca62b6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

include/zephyr/drivers/counter.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,22 @@ static inline uint64_t z_impl_counter_ticks_to_us(const struct device *dev,
338338
return ((uint64_t)ticks * USEC_PER_SEC) / z_impl_counter_get_frequency(dev);
339339
}
340340

341+
/**
342+
* @brief Function to convert ticks to nanoseconds.
343+
*
344+
* @param[in] dev Pointer to the device structure for the driver instance.
345+
* @param[in] ticks Ticks.
346+
*
347+
* @return Converted nanoseconds.
348+
*/
349+
__syscall uint64_t counter_ticks_to_ns(const struct device *dev, uint32_t ticks);
350+
351+
static inline uint64_t z_impl_counter_ticks_to_ns(const struct device *dev,
352+
uint32_t ticks)
353+
{
354+
return ((uint64_t)ticks * NSEC_PER_SEC) / z_impl_counter_get_frequency(dev);
355+
}
356+
341357
/**
342358
* @brief Function to retrieve maximum top value that can be set.
343359
*

0 commit comments

Comments
 (0)