kernel: Add new uniform time unit conversion API
Zephyr has always had an ad hoc collection of time unit macros and conversion routines in a selection of different units, precisions, rounding modes and naming conventions. This adds a single optimized generator to produce any such conversion, and enumerates it to produce a collection of 48 utilities in all useful combinations as a single supported kernel API going forward. Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
This commit is contained in:
parent
28fb42643a
commit
370c39516b
2 changed files with 1034 additions and 22 deletions
|
@ -22,6 +22,8 @@
|
|||
#include <toolchain.h>
|
||||
#include <zephyr/types.h>
|
||||
|
||||
#include <time_units.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -31,26 +33,6 @@ extern int _sys_clock_always_on;
|
|||
extern void z_enable_sys_clock(void);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME)
|
||||
__syscall int z_clock_hw_cycles_per_sec_runtime_get(void);
|
||||
|
||||
static inline int z_impl_z_clock_hw_cycles_per_sec_runtime_get(void)
|
||||
{
|
||||
extern int z_clock_hw_cycles_per_sec;
|
||||
|
||||
return z_clock_hw_cycles_per_sec;
|
||||
}
|
||||
#endif /* CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME */
|
||||
|
||||
static inline int sys_clock_hw_cycles_per_sec(void)
|
||||
{
|
||||
#if defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME)
|
||||
return z_clock_hw_cycles_per_sec_runtime_get();
|
||||
#else
|
||||
return CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Note that some systems with comparatively slow cycle counters
|
||||
* experience precision loss when doing math like this. In the
|
||||
* general case it is not correct that "cycles" are much faster than
|
||||
|
@ -243,6 +225,4 @@ struct _timeout {
|
|||
}
|
||||
#endif
|
||||
|
||||
#include <syscalls/sys_clock.h>
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_SYS_CLOCK_H_ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue