Zephyr API Documentation 4.3.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
timer.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Carlo Caione <ccaione@baylibre.com>
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_ARCH_ARM64_TIMER_H_
8#define ZEPHYR_INCLUDE_ARCH_ARM64_TIMER_H_
9
10#ifndef _ASMLANGUAGE
11
12#include <limits.h>
13
15#include <zephyr/types.h>
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21#define ARM_ARCH_TIMER_IRQ ARM_TIMER_VIRTUAL_IRQ
22#define ARM_ARCH_TIMER_PRIO ARM_TIMER_VIRTUAL_PRIO
23#define ARM_ARCH_TIMER_FLAGS ARM_TIMER_VIRTUAL_FLAGS
24
26{
27#ifdef CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME
28 extern unsigned int z_clock_hw_cycles_per_sec;
29 uint64_t cntfrq_el0 = read_cntfrq_el0();
30
31 __ASSERT(cntfrq_el0 < UINT_MAX, "cntfrq_el0 cannot fit in system 'unsigned int'");
32 z_clock_hw_cycles_per_sec = (unsigned int) cntfrq_el0;
33#endif
34}
35
40
41static ALWAYS_INLINE void arm_arch_timer_enable(unsigned char enable)
42{
43 uint64_t cntv_ctl;
44
45 cntv_ctl = read_cntv_ctl_el0();
46
47 if (enable) {
48 cntv_ctl |= CNTV_CTL_ENABLE_BIT;
49 } else {
50 cntv_ctl &= ~CNTV_CTL_ENABLE_BIT;
51 }
52
53 write_cntv_ctl_el0(cntv_ctl);
54}
55
57{
58 uint64_t cntv_ctl;
59
60 cntv_ctl = read_cntv_ctl_el0();
61
62 if (mask) {
63 cntv_ctl |= CNTV_CTL_IMASK_BIT;
64 } else {
65 cntv_ctl &= ~CNTV_CTL_IMASK_BIT;
66 }
67
68 write_cntv_ctl_el0(cntv_ctl);
69}
70
75
76#ifdef __cplusplus
77}
78#endif
79
80#endif /* _ASMLANGUAGE */
81
82#endif /* ZEPHYR_INCLUDE_ARCH_ARM64_TIMER_H_ */
static ALWAYS_INLINE uint64_t read_cntvct_el0(void)
Definition lib_helpers.h:65
static ALWAYS_INLINE uint64_t read_cntfrq_el0(void)
Definition lib_helpers.h:59
static ALWAYS_INLINE uint64_t read_cntv_ctl_el0(void)
Definition lib_helpers.h:63
static ALWAYS_INLINE void write_cntv_ctl_el0(uint64_t val)
Definition lib_helpers.h:63
static ALWAYS_INLINE void write_cntv_cval_el0(uint64_t val)
Definition lib_helpers.h:64
static ALWAYS_INLINE void arm_arch_timer_set_irq_mask(bool mask)
Definition timer.h:56
static ALWAYS_INLINE void arm_arch_timer_enable(unsigned char enable)
Definition timer.h:41
#define CNTV_CTL_ENABLE_BIT
Definition cpu.h:85
#define CNTV_CTL_IMASK_BIT
Definition cpu.h:86
static ALWAYS_INLINE uint64_t arm_arch_timer_count(void)
Definition armv7_v8_timer.h:63
static ALWAYS_INLINE void arm_arch_timer_set_compare(uint64_t val)
Definition armv7_v8_timer.h:28
static ALWAYS_INLINE void arm_arch_timer_init(void)
Definition armv7_v8_timer.h:24
#define ALWAYS_INLINE
Definition common.h:160
__UINT64_TYPE__ uint64_t
Definition stdint.h:91