kernel/sched.c: add k_usleep() API function
Add k_usleep() API, analogous to k_sleep(), excepting that the argument is in microseconds rather than milliseconds. Signed-off-by: Charles E. Youse <charles.youse@intel.com>
This commit is contained in:
parent
b186303cb6
commit
a567831bed
3 changed files with 69 additions and 8 deletions
|
@ -129,6 +129,37 @@ static inline u64_t __ticks_to_ms(s64_t ticks)
|
|||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* These are only currently used by k_usleep(), but they are
|
||||
* defined here for parity with their ms analogs above. Note:
|
||||
* we don't bother trying the 32-bit intermediate shortcuts
|
||||
* possible with ms, because of the magnitudes involved.
|
||||
*/
|
||||
|
||||
static inline s32_t z_us_to_ticks(s32_t us)
|
||||
{
|
||||
#ifdef CONFIG_SYS_CLOCK_EXISTS
|
||||
return (s32_t) ceiling_fraction(
|
||||
(s64_t)us * sys_clock_hw_cycles_per_sec(),
|
||||
((s64_t)USEC_PER_SEC * sys_clock_hw_cycles_per_sec()) /
|
||||
CONFIG_SYS_CLOCK_TICKS_PER_SEC);
|
||||
#else
|
||||
__ASSERT(us == 0, "us not zero");
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline s32_t __ticks_to_us(s32_t ticks)
|
||||
{
|
||||
#ifdef CONFIG_SYS_CLOCK_EXISTS
|
||||
return (s32_t) ((s64_t)ticks * USEC_PER_SEC /
|
||||
(s64_t)CONFIG_SYS_CLOCK_TICKS_PER_SEC);
|
||||
#else
|
||||
__ASSERT(ticks == 0, "ticks not zero");
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* added tick needed to account for tick in progress */
|
||||
#define _TICK_ALIGN 1
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue