libnx
v4.2.0
include
switch
arm
counter.h
Go to the documentation of this file.
1
/**
2
* @file counter.h
3
* @brief AArch64 system counter-timer.
4
* @author fincs
5
* @copyright libnx Authors
6
*/
7
#pragma once
8
#include "../types.h"
9
10
/**
11
* @brief Gets the current system tick.
12
* @return The current system tick.
13
*/
14
static
inline
u64
armGetSystemTick
(
void
) {
15
u64
ret;
16
__asm__ __volatile__ (
"mrs %x[data], cntpct_el0"
: [data]
"=r"
(ret));
17
return
ret;
18
}
19
20
/**
21
* @brief Gets the system counter-timer frequency
22
* @return The system counter-timer frequency, in Hz.
23
*/
24
static
inline
u64
armGetSystemTickFreq
(
void
) {
25
u64
ret;
26
__asm__ (
"mrs %x[data], cntfrq_el0"
: [data]
"=r"
(ret));
27
return
ret;
28
}
29
30
/**
31
* @brief Converts from nanoseconds to CPU ticks unit.
32
* @param ns Time in nanoseconds.
33
* @return Time in CPU ticks.
34
*/
35
static
inline
u64
armNsToTicks
(
u64
ns) {
36
return
(ns * 12) / 625;
37
}
38
39
/**
40
* @brief Converts from CPU ticks unit to nanoseconds.
41
* @param tick Time in ticks.
42
* @return Time in nanoseconds.
43
*/
44
static
inline
u64
armTicksToNs
(
u64
tick) {
45
return
(tick * 625) / 12;
46
}
armGetSystemTickFreq
static u64 armGetSystemTickFreq(void)
Gets the system counter-timer frequency.
Definition:
counter.h:24
armTicksToNs
static u64 armTicksToNs(u64 tick)
Converts from CPU ticks unit to nanoseconds.
Definition:
counter.h:44
u64
uint64_t u64
64-bit unsigned integer.
Definition:
types.h:22
armGetSystemTick
static u64 armGetSystemTick(void)
Gets the current system tick.
Definition:
counter.h:14
armNsToTicks
static u64 armNsToTicks(u64 ns)
Converts from nanoseconds to CPU ticks unit.
Definition:
counter.h:35
Generated by
1.8.17