StuBS
LAPIC::Timer Namespace Reference

Local Timer (for each LAPIC / CPU) More...

Classes

union  ControlRegister
 LAPIC-Timer Control Register. More...
 

Enumerations

enum  DeliveryStatus
 Timer Delivery Status.
 
enum  TimerMode
 Timer Mode.
 
enum  Mask
 Timer Mask.
 

Functions

uint32_t ticks (void)
 Determines the LAPIC timer frequency. More...
 
void set (uint32_t counter, uint8_t divide, uint8_t vector, bool periodic, bool masked=false)
 Set the LAPIC timer. More...
 
void setMasked (bool masked)
 Set the LAPIC-timer interrupt mask. More...
 
Register getClockDiv (uint8_t div)
 Calculate the bit mask for the LAPIC-timer divider. More...
 

Detailed Description

Local Timer (for each LAPIC / CPU)

See also
ISDMv3 10.5.4 APIC Timer

Function Documentation

◆ getClockDiv()

Register LAPIC::Timer::getClockDiv ( uint8_t  div)

Calculate the bit mask for the LAPIC-timer divider.

Parameters
divDivider, must be power of two: 1, 2, 4, 8, 16, 32, 64, 128
Returns
Bit mask for LAPIC::setTimer() or 0xff if div is invalid.

◆ set()

void LAPIC::Timer::set ( uint32_t  counter,
uint8_t  divide,
uint8_t  vector,
bool  periodic,
bool  masked = false 
)

Set the LAPIC timer.

Parameters
counterInitial counter value; decremented on every LAPIC timer tick
divideDivider (power of 2, i.e., 1 2 4 8 16 32...) used as prescaler between bus frequency and LAPIC timer frequency: LAPIC timer frequency = divide * bus frequency. divide is a numerical parameter, the conversion to the corresponding bit mask is done internally by calling getClockDiv().
vectorInterrupt vector number to be triggered on counter expiry
periodicIf set, the interrupt will be issued periodically
maskedIf set, interrupts on counter expiry are suppressed

◆ setMasked()

void LAPIC::Timer::setMasked ( bool  masked)

Set the LAPIC-timer interrupt mask.

Parameters
maskedIf set, interrupts are suppressed on counter expiry.

◆ ticks()

uint32_t LAPIC::Timer::ticks ( void  )

Determines the LAPIC timer frequency.

This function will calculate the number of LAPIC-timer ticks passing in the course of one millisecond. To do so, this function will rely on PIT timer functionality and measure the tick delta between start and end of waiting for a predefined period.

For measurement, the LAPIC-timer single-shot mode (without interrupts) is used; after measurement, the timer is disabled again.

Note
The timer is counting towards zero.
Returns
Number of LAPIC-timer ticks per millisecond