Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
system_timer.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Wind River Systems, Inc.
3 * Copyright (c) 2019 Intel Corporation
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
14
15#ifndef ZEPHYR_INCLUDE_DRIVERS_SYSTEM_TIMER_H_
16#define ZEPHYR_INCLUDE_DRIVERS_SYSTEM_TIMER_H_
17
18#include <stdbool.h>
19#include <zephyr/types.h>
20#include <zephyr/spinlock.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26#define SYS_CLOCK_MAX_WAIT (IS_ENABLED(CONFIG_SYSTEM_CLOCK_SLOPPY_IDLE) \
27 ? K_TICKS_FOREVER : INT_MAX)
28
34
70#if defined(CONFIG_SMP) || defined(CONFIG_SPIN_VALIDATE)
72#else
73/*
74 * When actual spinlocks are not needed (UP without CONFIG_SPIN_VALIDATE),
75 * k_spin_lock() reduces to arch_irq_lock() and the lock argument is
76 * ignored. Inline this to avoid the overhead of an extra function
77 * call for legacy drivers using sys_clock_announce().
78 */
79static inline k_spinlock_key_t sys_clock_lock(void)
80{
82
83 /* If this fires, a new config grew real spinlock content and
84 * the #if guard above needs updating.
85 */
86 BUILD_ASSERT(sizeof(struct k_spinlock) <= 1);
87
88 key.key = arch_irq_lock();
89 return key;
90}
91#endif
92
103#if defined(CONFIG_SMP) || defined(CONFIG_SPIN_VALIDATE)
105#else
106static inline void sys_clock_unlock(k_spinlock_key_t key)
107{
108 arch_irq_unlock(key.key);
109}
110#endif
111
157void sys_clock_set_timeout(int32_t ticks, bool idle);
158
172
194
205static inline void sys_clock_announce(int32_t ticks)
206{
208}
209
222
231
254
273
274#if defined(CONFIG_SYSTEM_CLOCK_HW_CYCLES_PER_SEC_RUNTIME_UPDATE) || defined(__DOXYGEN__)
302void z_sys_clock_hw_cycles_per_sec_update(uint32_t new_hz);
303#endif /* defined(CONFIG_SYSTEM_CLOCK_HW_CYCLES_PER_SEC_RUNTIME_UPDATE) || defined(__DOXYGEN__) */
304
308
309#ifdef __cplusplus
310}
311#endif
312
313#endif /* ZEPHYR_INCLUDE_DRIVERS_SYSTEM_TIMER_H_ */
static ALWAYS_INLINE unsigned int arch_irq_lock(void)
Disable all interrupts on the local CPU.
Definition irq.h:168
static ALWAYS_INLINE void arch_irq_unlock(unsigned int key)
Definition irq.h:176
uint64_t sys_clock_cycle_get_64(void)
64 bit hardware cycle counter
uint32_t sys_clock_cycle_get_32(void)
Hardware cycle counter.
void sys_clock_disable(void)
Disable system timer.
void sys_clock_idle_exit(void)
Timer idle exit notification.
void sys_clock_set_timeout(int32_t ticks, bool idle)
Set system clock timeout.
void sys_clock_announce_locked(int32_t ticks, k_spinlock_key_t key)
Announce time progress to the kernel.
static void sys_clock_announce(int32_t ticks)
Announce time progress to the kernel (legacy wrapper).
Definition system_timer.h:205
uint32_t sys_clock_elapsed(void)
Ticks elapsed since last sys_clock_announce() call.
k_spinlock_key_t sys_clock_lock(void)
Lock the system clock.
void sys_clock_unlock(k_spinlock_key_t key)
Unlock the system clock.
struct z_spinlock_key k_spinlock_key_t
Spinlock key type.
Definition spinlock.h:126
#define BUILD_ASSERT(EXPR, MSG...)
Definition llvm.h:51
Public interface for spinlocks.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INT32_TYPE__ int32_t
Definition stdint.h:74
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
Kernel Spin Lock.
Definition spinlock.h:45