High Precision Event Timer.
More...
High Precision Event Timer.
- Note
- Since the HPET might be 32bit it could overflow rather quickly, so we implement a system for checking roughly when it will overflow and accumulate the counter into a 64 bit nanosecond counter.
- See also
- OSDev HPET
◆ HPET_CAP_COUNTER_CLK_PERIOD_SHIFT
| #define HPET_CAP_COUNTER_CLK_PERIOD_SHIFT 32 |
The bit offset of the clock period in the capabilities register.
Definition at line 44 of file hpet.c.
◆ HPET_CONF_ENABLE_CNF_BIT
| #define HPET_CONF_ENABLE_CNF_BIT (1 << 0) |
The bit to set to enable the HPET in the configuration register.
Definition at line 49 of file hpet.c.
◆ HPET_CONF_LEG_RT_CNF_BIT
| #define HPET_CONF_LEG_RT_CNF_BIT (1 << 1) |
The bit to set to enable legacy replacement mode in the configuration register.
Definition at line 54 of file hpet.c.
◆ HPET_ADDRESS_SPACE_MEMORY
| #define HPET_ADDRESS_SPACE_MEMORY 0 |
◆ HPET_ADDRESS_SPACE_IO
| #define HPET_ADDRESS_SPACE_IO 1 |
◆ HPET_FEMTOSECONDS_PER_SECOND
| #define HPET_FEMTOSECONDS_PER_SECOND 1000000000000000ULL |
The number of femtoseconds in one second.
Definition at line 69 of file hpet.c.
◆ hpet_register_t
HPET register offsets.
| Enumerator |
|---|
| HPET_REG_GENERAL_CAPABILITIES_ID | |
| HPET_REG_GENERAL_CONFIG | |
| HPET_REG_GENERAL_INTERRUPT | |
| HPET_REG_MAIN_COUNTER_VALUE | |
| HPET_REG_TIMER0_CONFIG_CAP | |
| HPET_REG_TIMER0_COMPARATOR | |
Definition at line 31 of file hpet.c.
◆ hpet_write()
Write to an HPET register.
- Parameters
-
| reg | The register to write to. |
| value | The value to write. |
Definition at line 111 of file hpet.c.
◆ hpet_read()
Read from an HPET register.
- Parameters
-
| reg | The register to read from. |
- Returns
- The value read from the register.
Definition at line 122 of file hpet.c.
◆ hpet_ns_per_tick()
Get the HPET clock period in nanoseconds.
- Returns
- The HPET clock period in nanoseconds.
Definition at line 132 of file hpet.c.
◆ hpet_read_ns_counter()
Safely read the HPET counter value in nanoseconds.
- Returns
- The current value of the HPET counter in nanoseconds.
Definition at line 142 of file hpet.c.
◆ hpet_reset_counter()
Reset the HPET main counter to zero and enable the HPET.
Definition at line 157 of file hpet.c.
◆ hpet_overflow_thread()
Thread function that periodically accumulates the HPET counter to prevent overflow.
- Parameters
-
Definition at line 169 of file hpet.c.
◆ hpet_init()
Initialize the HPET.
- Returns
- On success,
0. On failure, ERR.
Definition at line 204 of file hpet.c.
◆ hpet_deinit()
Deinitialize the HPET.
Definition at line 263 of file hpet.c.
◆ hpet
Pointer to the HPET ACPI table.
Definition at line 94 of file hpet.c.
◆ address
Mapped virtual address of the HPET registers.
Definition at line 95 of file hpet.c.
◆ period
Main counter tick period in femtoseconds (10^-15 s).
Definition at line 96 of file hpet.c.
◆ counter
Accumulated nanosecond counter, used to avoid overflows.
Definition at line 98 of file hpet.c.
◆ counterLock
Seqlock for the accumulated counter.
Definition at line 99 of file hpet.c.
◆ overflowThreadTid
| tid_t overflowThreadTid = 0 |
|
static |
Thread ID of the overflow thread.
Definition at line 101 of file hpet.c.
◆ overflowQueue
Wait queue for the overflow thread.
Definition at line 102 of file hpet.c.
◆ overflowShouldStop
Flag to signal the overflow thread to stop.
Definition at line 103 of file hpet.c.
◆ source
Initial value:= {
.name = "HPET",
.precision = 0,
}
#define NULL
Pointer error value.
static clock_t hpet_read_ns_counter(void)
Safely read the HPET counter value in nanoseconds.
Structure to describe the HPET to the sys time subsystem.
Definition at line 192 of file hpet.c.