StuBS
HPET Namespace Reference

Abstraction of the HPET existing in "modern" computers (since ~2005) More...

Classes

struct  ConfigurationRegister.__unnamed44__
 

Typedefs

typedef uint64_t InterruptStatusRegister
 Global state register for interrupts. More...
 

Enumerations

enum  RegisterOffset : uint16_t {
  CAPABILITIES_AND_ID = 0x000 ,
  CONFIGURATION = 0x010 ,
  INTERRUPT_STATUS = 0x020 ,
  MAIN_COUNTER = 0x0f0
}
 Register Offsets. More...
 
enum  CounterSize {
  SIZE_32BIT = 0x0 ,
  SIZE_64BIT = 0x1
}
 Size of the global counter and the comparators.
 

Functions

bool init ()
 Initializes the HPET system from ACPI Table. More...
 
void delay (uint64_t usecs)
 Delays the caller's execution by approx. More...
 
bool isEnabled ()
 Checks whether the HPET system is enabled. More...
 
void reset ()
 Reset the global counter to zero. More...
 
uint64_t get ()
 
void enable ()
 Activate the HPET system. More...
 
void disable ()
 Deactivate the HPET system. More...
 
size_t countComparators ()
 Retrieve the number of HPET comparators. More...
 
ComparatorgetComparator (size_t n)
 Returns a pointer to the nth timer comparator. More...
 

Constants

uintptr_t base_address = 0
 

Detailed Description

Abstraction of the HPET existing in "modern" computers (since ~2005)

Today's systems contain, in addition to the old Programmable Interval Timer (PIT), several additional timers, the "High Precision Event Timers" (HPET). Those timers, developed by Intel and Microsoft, are intended as replacement for both the PIT and the CMOS Real Time Clock in the long run.

Unlike the PIT, the HPETs are in a well-define state at system boot, are configured via Memory Mapped IO, have a significantly higher precision, and support up to 256 independent comparators (depending on the architecture).

The HPET timers are implemented using a single counter and several comparators. The counter increments at a fixed frequency that is independent of the CPUs current frequency (which might change due to CPU power management). The only cause for reading a value smaller than previous values is a intermittent counter overflow.

After system boot, the HPET is in the following state:

  1. The global counter is set to 0 and stopped.
  2. The comparators' value registers are set to their maximum value.
  3. All interrupts are disabled:
    • The global activation bit is 0.
    • Every comparators' interrupt-enable bit is set to 0
    • The legacy mode is disabled
See also
IA-PC HPET (High Precision Event Timers) Specification 1.0a

Class Documentation

◆ HPET::ConfigurationRegister.__unnamed44__

struct HPET::ConfigurationRegister.__unnamed44__
Class Members
uint64_t enabled: 1 Enables/disables the HPET.
uint64_t legacy_routing: 1 if 1, legacy routing is enabled
uint64_t __pad0__: 62

Typedef Documentation

◆ InterruptStatusRegister

Global state register for interrupts.

This register is only required for level-triggered interrupts – it provides information about the comparator that issued an interrupt. To acknowledge the interrupt, the software is required to write 1 to the corresponding bit (writes of 0 have no effect).

For edge-triggered interrupts, the corresponding bit is always set to 0 and should be ignored.

See also
IA-PC HPET - 2.3.6 General Interrupt Status Register

Enumeration Type Documentation

◆ RegisterOffset

enum HPET::RegisterOffset : uint16_t

Register Offsets.

See also
IA-PC HPET - 2.3.1 Register Overview
Enumerator
CAPABILITIES_AND_ID 

CapabilitiesAndIdRegister

CONFIGURATION 

ConfigurationRegister

INTERRUPT_STATUS 

InterruptStatusRegister

MAIN_COUNTER 

global counter

Function Documentation

◆ init()

bool HPET::init ( )

Initializes the HPET system from ACPI Table.

Returns
true on success, false on error

◆ delay()

void HPET::delay ( uint64_t  usecs)

Delays the caller's execution by approx.

Actively waits by polling the main counter until at least the given micro seconds have passed

Parameters
usecstime to wait in micro seconds.

◆ isEnabled()

bool HPET::isEnabled ( )

Checks whether the HPET system is enabled.

Checks whether the HPET system is activated globally, i.e. the global counter is running and the comparators could send interrupts (if configured to do so).

Returns
true if enabled, false if disabled

◆ reset()

void HPET::reset ( )

Reset the global counter to zero.

See also
IA-PC HPET - 2.3.7 Main Counter Register

◆ enable()

void HPET::enable ( )

Activate the HPET system.

Activate the HPET system globally by enabling the global counter and, thereby, enabling all (previously configured) interrupts.

◆ disable()

void HPET::disable ( )

Deactivate the HPET system.

Deactivates the HPET system globally by disabling the global counter and, thereby, disabling all interrupts.

◆ countComparators()

size_t HPET::countComparators ( )

Retrieve the number of HPET comparators.

Returns
number of comparators.

◆ getComparator()

Comparator * HPET::getComparator ( size_t  n)

Returns a pointer to the nth timer comparator.

Returns
A pointer to the timer comperator, or nullptr if invalid timer.