FreeNOS
Data Structures | Public Types | Public Member Functions | Data Fields | Protected Attributes
Timer Class Reference

Represents a configurable timer device. More...

#include <Timer.h>

Inheritance diagram for Timer:
ARMTimer BroadcomTimer IntelAPIC IntelPIT KernelTimer

Data Structures

struct  Info
 Timer information structure. More...
 

Public Types

enum  Result { Success, NotFound, IOError, InvalidFrequency }
 Result codes. More...
 

Public Member Functions

struct Timer::Info ALIGN (8) Info
 Timer information structure. More...
 
 Timer ()
 Constructor. More...
 
Size getInterrupt () const
 Get timer interrupt number. More...
 
Size getFrequency () const
 Get timer frequency. More...
 
virtual Result setFrequency (Size hertz)
 Set timer frequency. More...
 
virtual Result getCurrent (Info *info, const Size msecOffset=0)
 Get current timer info. More...
 
virtual Result initialize ()
 Initialize the timer. More...
 
virtual Result start ()
 Start the timer. More...
 
virtual Result stop ()
 Stop the timer. More...
 
virtual Result tick ()
 Process timer tick. More...
 
virtual Result wait (u32 microseconds) const
 Busy wait a number of microseconds. More...
 
bool isExpired (const Info &info) const
 Check if a timer value is expired. More...
 

Data Fields

enum Timer::Result ALIGN
 

Protected Attributes

Size m_ticks
 The current timer ticks. More...
 
Size m_frequency
 Frequency of the Timer. More...
 
Size m_int
 Timer interrupt number. More...
 

Detailed Description

Represents a configurable timer device.

Definition at line 35 of file Timer.h.

Member Enumeration Documentation

◆ Result

Result codes.

Enumerator
Success 
NotFound 
IOError 
InvalidFrequency 

Definition at line 52 of file Timer.h.

Constructor & Destructor Documentation

◆ Timer()

Timer::Timer ( )

Constructor.

Definition at line 21 of file Timer.cpp.

Member Function Documentation

◆ ALIGN()

struct Timer::Info Timer::ALIGN ( )

Timer information structure.

◆ getCurrent()

Timer::Result Timer::getCurrent ( Info info,
const Size  msecOffset = 0 
)
virtual

Get current timer info.

Parameters
infoTimer Info object pointer for output.
msecOffsetOptional offset in milliseconds to add
Returns
Result code.

Definition at line 44 of file Timer.cpp.

References Timer::Info::frequency, m_frequency, m_ticks, Success, and Timer::Info::ticks.

Referenced by ARP::lookupAddress(), ProcessCtlHandler(), ARP::sendRequest(), and FileSystemClient::waitFile().

◆ getFrequency()

Size Timer::getFrequency ( ) const

Get timer frequency.

Returns
Frequency of the timer in hertz.

Definition at line 33 of file Timer.cpp.

References m_frequency.

Referenced by IntelKernel::IntelKernel(), and IntelAPIC::start().

◆ getInterrupt()

Size Timer::getInterrupt ( ) const

Get timer interrupt number.

Returns
Interrupt number.

Definition at line 28 of file Timer.cpp.

References m_int.

Referenced by IntelKernel::clocktick(), IntelKernel::enableIRQ(), and IntelKernel::IntelKernel().

◆ initialize()

Timer::Result Timer::initialize ( )
virtual

Initialize the timer.

Returns
Result code.

Reimplemented in IntelAPIC.

Definition at line 59 of file Timer.cpp.

References Success.

◆ isExpired()

bool Timer::isExpired ( const Info info) const

Check if a timer value is expired.

Parameters
infoTimer info value to compare
Returns
True if expired, false otherwise
Bug:
This function does not take into account a potential wrap-around of the m_ticks member (integer overflow)

Definition at line 85 of file Timer.cpp.

References Timer::Info::frequency, m_ticks, and Timer::Info::ticks.

Referenced by ARP::lookupAddress(), ProcessManager::schedule(), and FileSystemServer::waitFileHandler().

◆ setFrequency()

Timer::Result Timer::setFrequency ( Size  hertz)
virtual

Set timer frequency.

Parameters
hertzFrequency of the timer in hertz.
Returns
Result code.

Reimplemented in IntelPIT, BroadcomTimer, and ARMTimer.

Definition at line 38 of file Timer.cpp.

References m_frequency, and Success.

Referenced by ARMTimer::setFrequency().

◆ start()

Timer::Result Timer::start ( )
virtual

Start the timer.

This function lets the timer run. The timer will generate interrupts on the configured frequency.

Returns
Result code.

Reimplemented in IntelAPIC.

Definition at line 64 of file Timer.cpp.

References Success.

◆ stop()

Timer::Result Timer::stop ( )
virtual

Stop the timer.

This function brings the timer to a halt. The timer will not generate any interrupts.

Returns
Result code.

Reimplemented in IntelAPIC.

Definition at line 69 of file Timer.cpp.

References Success.

◆ tick()

Timer::Result Timer::tick ( )
virtual

Process timer tick.

Should be called on each Timer interrupt to keep the m_info variable synchronized with the actual hardware.

Returns
Result code

Reimplemented in BroadcomTimer, ARMTimer, and KernelTimer.

Definition at line 74 of file Timer.cpp.

References m_ticks, and Success.

Referenced by IntelKernel::clocktick(), SunxiKernel::interrupt(), RaspberryKernel::interrupt(), ARMTimer::tick(), and BroadcomTimer::tick().

◆ wait()

Timer::Result Timer::wait ( u32  microseconds) const
virtual

Busy wait a number of microseconds.

Parameters
microsecondsThe number of microseconds to wait at minimum.
Returns
Result code.

Reimplemented in IntelAPIC.

Definition at line 80 of file Timer.cpp.

References Success.

Field Documentation

◆ ALIGN

enum Timer::Result Timer::ALIGN

◆ m_frequency

Size Timer::m_frequency
protected

◆ m_int

Size Timer::m_int
protected

◆ m_ticks

Size Timer::m_ticks
protected

The current timer ticks.

Definition at line 159 of file Timer.h.

Referenced by getCurrent(), isExpired(), KernelTimer::tick(), and tick().


The documentation for this class was generated from the following files: