kernel.h: Header hygine, move clock/timer handling

The kernel.h file had a bunch of internal APIs for timeout/clock
handling mixed in.  Move these to sys_clock.h, which it always
included (in a weird location, so move THAT to kernel_includes.h with
everything else).

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
This commit is contained in:
Andy Ross 2018-09-19 09:35:43 -07:00 committed by Anas Nashif
commit 0d1228af36
3 changed files with 115 additions and 116 deletions

View file

@ -355,21 +355,6 @@ struct __packed _k_thread_stack_element {
};
typedef struct _k_thread_stack_element k_thread_stack_t;
/* timeouts */
struct _timeout;
typedef void (*_timeout_func_t)(struct _timeout *t);
struct _timeout {
sys_dnode_t node;
struct k_thread *thread;
sys_dlist_t *wait_q;
s32_t delta_ticks_from_prev;
_timeout_func_t func;
};
extern s32_t _timeout_remaining_get(struct _timeout *timeout);
/**
* @typedef k_thread_entry_t
* @brief Thread entry point function type.
@ -1235,11 +1220,6 @@ __syscall void k_thread_name_set(k_tid_t thread_id, const char *value);
*/
__syscall const char *k_thread_name_get(k_tid_t thread_id);
/**
* @}
*/
#include <sys_clock.h>
/**
* @addtogroup clock_apis
* @{
@ -1321,81 +1301,6 @@ __syscall const char *k_thread_name_get(k_tid_t thread_id);
* @cond INTERNAL_HIDDEN
*/
/* kernel clocks */
#ifdef CONFIG_SYS_CLOCK_EXISTS
/*
* If timer frequency is known at compile time, a simple (32-bit)
* tick <-> ms conversion could be used for some combinations of
* hardware timer frequency and tick rate. Otherwise precise
* (64-bit) calculations are used.
*/
#if !defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME)
#if (sys_clock_hw_cycles_per_sec % sys_clock_ticks_per_sec) != 0
#define _NEED_PRECISE_TICK_MS_CONVERSION
#elif (MSEC_PER_SEC % sys_clock_ticks_per_sec) != 0
#define _NON_OPTIMIZED_TICKS_PER_SEC
#endif
#endif
#if defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME) || \
defined(_NON_OPTIMIZED_TICKS_PER_SEC)
#define _NEED_PRECISE_TICK_MS_CONVERSION
#endif
#endif
static ALWAYS_INLINE s32_t _ms_to_ticks(s32_t ms)
{
#ifdef CONFIG_SYS_CLOCK_EXISTS
#ifdef _NEED_PRECISE_TICK_MS_CONVERSION
/* use 64-bit math to keep precision */
return (s32_t)ceiling_fraction(
(s64_t)ms * sys_clock_hw_cycles_per_sec,
((s64_t)MSEC_PER_SEC * sys_clock_hw_cycles_per_sec) /
sys_clock_ticks_per_sec);
#else
/* simple division keeps precision */
s32_t ms_per_tick = MSEC_PER_SEC / sys_clock_ticks_per_sec;
return (s32_t)ceiling_fraction(ms, ms_per_tick);
#endif
#else
__ASSERT(ms == 0, "ms not zero");
return 0;
#endif
}
static inline s64_t __ticks_to_ms(s64_t ticks)
{
#ifdef CONFIG_SYS_CLOCK_EXISTS
#ifdef _NEED_PRECISE_TICK_MS_CONVERSION
/* use 64-bit math to keep precision */
return (u64_t)ticks * MSEC_PER_SEC / sys_clock_ticks_per_sec;
#else
/* simple multiplication keeps precision */
u32_t ms_per_tick = MSEC_PER_SEC / sys_clock_ticks_per_sec;
return (u64_t)ticks * ms_per_tick;
#endif
#else
__ASSERT(ticks == 0, "ticks not zero");
return 0;
#endif
}
/* added tick needed to account for tick in progress */
#ifdef CONFIG_TICKLESS_KERNEL
#define _TICK_ALIGN 0
#else
#define _TICK_ALIGN 1
#endif
struct k_timer {
/*
* _timeout structure must be first here if we want to use