blob: ecd639638b1851e0f2bb905bd92662d5b13c0e44 [file] [log] [blame]
Dmitriy Korovkinf51049b2015-04-10 17:16:14 -04001/* Variables needed needed for system clock */
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -07002
3/*
4 * Copyright (c) 2014-2015 Wind River Systems, Inc.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * 2) Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * 3) Neither the name of Wind River Systems nor the names of its contributors
17 * may be used to endorse or promote products derived from this software without
18 * specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33/*
34DESCRIPTION
35
36Declare variables used by both system timer device driver and kernel components
37that use timer functionality.
38*/
39
40#ifndef _CLOCK_VARS__H_
41#define _CLOCK_VARS__H_
42
43#ifndef _ASMLANGUAGE
Dmitriy Korovkinf51049b2015-04-10 17:16:14 -040044#include <stdint.h>
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -070045
46#define sys_clock_ticks_per_sec CONFIG_SYS_CLOCK_TICKS_PER_SEC
47#define sys_clock_hw_cycles_per_sec CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC
48
49/*
50 * sys_clock_us_per_tick global variable represents a number
51 * of microseconds in one OS timer tick
52 */
53extern int sys_clock_us_per_tick;
54
55/*
56 * sys_clock_hw_cycles_per_tick global variable represents a number
57 * of platform clock ticks in one OS timer tick.
58 * sys_clock_hw_cycles_per_tick often represents a value of divider
59 * of the board clock frequency
60 */
61extern int sys_clock_hw_cycles_per_tick;
62
Dmitriy Korovkinf51049b2015-04-10 17:16:14 -040063/* number of nsec per usec */
64#define NSEC_PER_USEC 1000
65
66/* SYS_CLOCK_HW_CYCLES_TO_NS64 converts CPU clock cycles to nanoseconds */
67#define SYS_CLOCK_HW_CYCLES_TO_NS64(X) \
68 (((uint64_t)(X) * sys_clock_us_per_tick * NSEC_PER_USEC) / \
69 sys_clock_hw_cycles_per_tick)
70
71/*
72 * SYS_CLOCK_HW_CYCLES_TO_NS_AVG converts CPU clock cycles to nanoseconds
73 * and calculates the average cycle time
74 */
75#define SYS_CLOCK_HW_CYCLES_TO_NS_AVG(X, NCYCLES) \
76 (uint32_t)(SYS_CLOCK_HW_CYCLES_TO_NS64 (X) / NCYCLES)
77
78#define SYS_CLOCK_HW_CYCLES_TO_NS(X) (uint32_t)(SYS_CLOCK_HW_CYCLES_TO_NS64 (X))
79
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -070080#ifdef CONFIG_NANOKERNEL
Inaky Perez-Gonzalez8ddf82c2015-04-10 16:44:37 -070081extern uint32_t nanoTicks;
82extern struct nano_timer *nanoTimerList;
83#endif /* CONFIG_NANOKERNEL */
84
85#endif /* !_ASMLANGUAGE */
86
87#endif /* _CLOCK_VARS__H_ */