The Pedigree Project  0.1
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Rtc Class Reference

#include <Rtc.h>

+ Inheritance diagram for Rtc:
+ Collaboration diagram for Rtc:

Classes

class  Alarm
 
struct  periodicIrqInfo_t
 

Public Member Functions

virtual bool registerHandler (TimerHandler *handler)
 
virtual bool unregisterHandler (TimerHandler *handler)
 
virtual void addAlarm (class Event *pEvent, size_t alarmSecs, size_t alarmUsecs=0)
 
virtual void removeAlarm (class Event *pEvent)
 
virtual size_t removeAlarm (class Event *pEvent, bool bRetZero)
 
virtual size_t getYear ()
 
virtual uint8_t getMonth ()
 
virtual uint8_t getDayOfMonth ()
 
virtual uint8_t getDayOfWeek ()
 
virtual uint8_t getHour ()
 
virtual uint8_t getMinute ()
 
virtual uint8_t getSecond ()
 
virtual uint64_t getNanosecond ()
 
virtual uint64_t getTickCount ()
 
virtual uint64_t getTickCountNano ()
 
bool initialise1 () INITIALISATION_ONLY
 
bool initialise2 () INITIALISATION_ONLY
 
virtual void synchronise (bool tohw=false)
 
void uninitialise ()
 
- Public Member Functions inherited from Timer
virtual Time::Timestamp getUnixTimestamp ()
 

Static Public Member Functions

static Rtcinstance ()
 

Protected Member Functions

 Rtc () INITIALISATION_ONLY
 
virtual ~Rtc ()
 
- Protected Member Functions inherited from Timer
 Timer ()
 
virtual ~Timer ()
 

Private Member Functions

 Rtc (const Rtc &)
 
Rtcoperator= (const Rtc &)
 
virtual bool irq (irq_id_t number, InterruptState &state)
 
void setIndex (uint8_t index)
 
void waitForUpdateCompletion (uint8_t index)
 
void enableRtcUpdates (bool enable)
 
uint8_t read (uint8_t index)
 
void write (uint8_t index, uint8_t value)
 
virtual ~IrqHandler ()
 

Private Attributes

IoPort m_IoPort
 
irq_id_t m_IrqId
 
size_t m_PeriodicIrqInfoIndex
 
bool m_bBCD
 
size_t m_Year
 
uint8_t m_Month
 
uint8_t m_DayOfMonth
 
uint8_t m_Hour
 
uint8_t m_Minute
 
uint8_t m_Second
 
uint64_t m_Nanosecond
 
uint64_t m_TickCount
 
TimerHandlerm_Handlers [MAX_TIMER_HANDLERS]
 
List< Alarm * > m_Alarms
 
Spinlock m_Lock
 
uint64_t m_TscTicksPerNanosecond
 
uint64_t m_Tsc0
 

Static Private Attributes

static periodicIrqInfo_t periodicIrqInfo [12]
 
static Rtc m_Instance
 

Detailed Description

Class for the Real-time clock / CMOS implementing the Timer interface

Definition at line 42 of file Rtc.h.

Constructor & Destructor Documentation

Rtc::Rtc ( )
protected

The default constructor

Definition at line 405 of file Rtc.cc.

References g_FreePages.

Referenced by ~Rtc().

+ Here is the caller graph for this function:

virtual Rtc::~Rtc ( )
inlineprotectedvirtual

The destructor

Definition at line 84 of file Rtc.h.

References enableRtcUpdates(), irq(), operator=(), read(), Rtc(), setIndex(), waitForUpdateCompletion(), and write().

Rtc::Rtc ( const Rtc )
private

The copy-constructor

Note
NOT implemented

Member Function Documentation

void Rtc::addAlarm ( class Event pEvent,
size_t  alarmSecs,
size_t  alarmUsecs = 0 
)
virtual

Dispatches the Event pEvent to the current thread in alarmSecs time.

Parameters
pEventEvent to dispatch.
alarmSecsNumber of seconds to wait.

Implements Timer.

Definition at line 72 of file Rtc.cc.

References Processor::information(), m_Alarms, m_Lock, and m_TickCount.

void Rtc::enableRtcUpdates ( bool  enable)
private

Dis/Enable the RTC updates

Parameters
[in]indexthe index we want to access / have accessed
[in]enableDo we want to enable or disable?

Definition at line 575 of file Rtc.cc.

References m_IoPort, IoPort::read8(), setIndex(), and IoPort::write8().

Referenced by synchronise(), and ~Rtc().

+ Here is the caller graph for this function:

uint8_t Rtc::getDayOfMonth ( )
virtual

Get the current day of month

Returns
the current day of month

Implements Timer.

Definition at line 182 of file Rtc.cc.

References m_DayOfMonth.

uint8_t Rtc::getDayOfWeek ( )
virtual

Get the current day of week

Returns
the current day of week

Implements Timer.

Definition at line 186 of file Rtc.cc.

References m_DayOfMonth, m_Month, and m_Year.

uint8_t Rtc::getHour ( )
virtual

Get the current hour

Returns
the current hour

Implements Timer.

Definition at line 201 of file Rtc.cc.

References m_Hour.

uint8_t Rtc::getMinute ( )
virtual

Get the current minute

Returns
the current minute

Implements Timer.

Definition at line 205 of file Rtc.cc.

References m_Minute.

uint8_t Rtc::getMonth ( )
virtual

Get the current month

Returns
the current month

Implements Timer.

Definition at line 178 of file Rtc.cc.

References m_Month.

uint64_t Rtc::getNanosecond ( )
virtual

Get the current nanosecond

Returns
the current nanosecond

Implements Timer.

Definition at line 213 of file Rtc.cc.

References m_Nanosecond.

uint8_t Rtc::getSecond ( )
virtual

Get the current second

Returns
the current second

Implements Timer.

Definition at line 209 of file Rtc.cc.

References m_Second.

uint64_t Rtc::getTickCount ( )
virtual

Get the Tick count (time elapsed since system bootup)

Returns
the tick count in milliseconds

Implements Timer.

Definition at line 217 of file Rtc.cc.

References getTickCountNano().

Referenced by removeAlarm().

+ Here is the caller graph for this function:

uint64_t Rtc::getTickCountNano ( )
virtual

Get the Tick count (time elapsed since system bootup) in nanosconds.

Returns
the tick count in nanoseconds

Reimplemented from Timer.

Definition at line 221 of file Rtc.cc.

References m_Tsc0, and m_TscTicksPerNanosecond.

Referenced by getTickCount().

+ Here is the caller graph for this function:

size_t Rtc::getYear ( )
virtual

Get the current year

Returns
the current year

Implements Timer.

Definition at line 174 of file Rtc.cc.

References m_Year.

bool Rtc::initialise1 ( )

Initialises the class

Returns
true, if successful, false otherwise

Definition at line 234 of file Rtc.cc.

References IoPort::allocate(), m_bBCD, m_DayOfMonth, m_Handlers, m_Hour, m_IoPort, m_IrqId, m_Minute, m_Month, m_PeriodicIrqInfoIndex, m_Second, m_Year, NOTICE, periodicIrqInfo, Rtc::periodicIrqInfo_t::rateBits, read(), and write().

Referenced by Pc::initialise().

+ Here is the caller graph for this function:

bool Rtc::initialise2 ( )

Initialises the RTC's IRQ.

Definition at line 288 of file Rtc.cc.

References Processor::getInterrupts(), Processor::haltUntilInterrupt(), m_IrqId, m_TickCount, m_Tsc0, m_TscTicksPerNanosecond, NOTICE, read(), IrqManager::registerIsaIrqHandler(), Processor::setInterrupts(), and write().

Referenced by Pc::initialise().

+ Here is the caller graph for this function:

bool Rtc::irq ( irq_id_t  number,
InterruptState &  state 
)
privatevirtual

Called when the handler is registered with the irq manager and the irq occurred

Note
If this function returns false you have to call IrqManager::acknowledgeIrq() when you removed the interrupt reason.
Parameters
[in]numberthe irq number
Returns
should return true, if the interrupt reason was removed, or false otherwise
Todo:
figure out how best to handle this

Implements IrqHandler.

Definition at line 415 of file Rtc.cc.

References Process::description(), g_FreePages, Process::getHeapUsage(), Process::getId(), Scheduler::getNumProcesses(), Scheduler::getProcess(), Machine::getSerial(), Scheduler::instance(), m_Alarms, m_DayOfMonth, m_Handlers, m_Hour, m_Lock, m_Minute, m_Month, m_Nanosecond, m_PeriodicIrqInfoIndex, m_Second, m_TickCount, m_Year, Rtc::periodicIrqInfo_t::ns, periodicIrqInfo, read(), Thread::sendEvent(), IrqManager::tick(), TimerHandler::timer(), UNLIKELY, and WARNING.

Referenced by ~Rtc().

+ Here is the caller graph for this function:

Rtc& Rtc::operator= ( const Rtc )
private

The assignment operator

Note
NOT implemented

Referenced by ~Rtc().

+ Here is the caller graph for this function:

uint8_t Rtc::read ( uint8_t  index)
private

Read the value in the CMOS at a specific index

Parameters
[in]indexthe index
Returns
the value at the index

Definition at line 584 of file Rtc.cc.

References m_IoPort, IoPort::read8(), setIndex(), and waitForUpdateCompletion().

Referenced by initialise1(), initialise2(), irq(), synchronise(), uninitialise(), and ~Rtc().

+ Here is the caller graph for this function:

void Rtc::removeAlarm ( class Event pEvent)
virtual

Removes the event pEvent from the alarm queue.

Parameters
pEventEvent to remove alarm for.

Implements Timer.

Definition at line 86 of file Rtc.cc.

References m_Alarms, and m_Lock.

size_t Rtc::removeAlarm ( class Event pEvent,
bool  bRetZero 
)
virtual

Removes the event pEvent from the alarm queue.

Parameters
pEventEvent to remove alarm for.
bRetZeroIf true, returns zero rather the time until firing
Returns
The number of seconds before the event would have fired, or zero if bRetZero is true.
Todo:
clarify units

Implements Timer.

Definition at line 105 of file Rtc.cc.

References getTickCount(), m_Alarms, m_Handlers, and m_Lock.

void Rtc::setIndex ( uint8_t  index)
private

Set the index register

Parameters
[in]indexthe new index

Definition at line 561 of file Rtc.cc.

References m_IoPort, IoPort::read8(), and IoPort::write8().

Referenced by enableRtcUpdates(), read(), waitForUpdateCompletion(), write(), and ~Rtc().

+ Here is the caller graph for this function:

void Rtc::synchronise ( bool  tohw = false)
virtual

Synchronise the time/date with the hardware

Reimplemented from Timer.

Definition at line 336 of file Rtc.cc.

References enableRtcUpdates(), m_bBCD, m_DayOfMonth, m_Hour, m_Minute, m_Month, m_Second, m_Year, read(), and write().

Referenced by uninitialise().

+ Here is the caller graph for this function:

void Rtc::uninitialise ( )

Uninitialises the class

Definition at line 389 of file Rtc.cc.

References IoPort::free(), m_IoPort, m_IrqId, read(), synchronise(), IrqManager::unregisterHandler(), and write().

void Rtc::waitForUpdateCompletion ( uint8_t  index)
private

Wait until the Update of the RTC entries in the CMOS is complete, if we want to access one of those entries

Parameters
[in]indexthe index we want to access afterwards

Definition at line 566 of file Rtc.cc.

References m_IoPort, IoPort::read8(), and setIndex().

Referenced by read(), write(), and ~Rtc().

+ Here is the caller graph for this function:

void Rtc::write ( uint8_t  index,
uint8_t  value 
)
private

Write the value to the CMOS at a specific index

Parameters
[in]indexthe index
[in]valuethe value

Definition at line 595 of file Rtc.cc.

References m_IoPort, setIndex(), waitForUpdateCompletion(), and IoPort::write8().

Referenced by initialise1(), initialise2(), synchronise(), uninitialise(), and ~Rtc().

+ Here is the caller graph for this function:

Member Data Documentation

List<Alarm *> Rtc::m_Alarms
private

List of alarms.

Definition at line 189 of file Rtc.h.

Referenced by addAlarm(), irq(), and removeAlarm().

bool Rtc::m_bBCD
private

BCD mode? (otherwise in binary mode)

Definition at line 131 of file Rtc.h.

Referenced by initialise1(), and synchronise().

uint8_t Rtc::m_DayOfMonth
private

The current day of month

Definition at line 138 of file Rtc.h.

Referenced by getDayOfMonth(), getDayOfWeek(), initialise1(), irq(), and synchronise().

TimerHandler* Rtc::m_Handlers[MAX_TIMER_HANDLERS]
private

All timer handlers installed

Definition at line 169 of file Rtc.h.

Referenced by initialise1(), irq(), and removeAlarm().

uint8_t Rtc::m_Hour
private

The current hour

Definition at line 140 of file Rtc.h.

Referenced by getHour(), initialise1(), irq(), and synchronise().

Rtc Rtc::m_Instance
staticprivate

The Rtc class instance

Definition at line 166 of file Rtc.h.

IoPort Rtc::m_IoPort
private

The CMOS/Real-time Clock I/O port range

Definition at line 122 of file Rtc.h.

Referenced by enableRtcUpdates(), initialise1(), read(), setIndex(), uninitialise(), waitForUpdateCompletion(), and write().

irq_id_t Rtc::m_IrqId
private

The IRQ Identifier

Definition at line 125 of file Rtc.h.

Referenced by initialise1(), initialise2(), and uninitialise().

Spinlock Rtc::m_Lock
private

Protects m_Alarms.

Definition at line 191 of file Rtc.h.

Referenced by addAlarm(), irq(), and removeAlarm().

uint8_t Rtc::m_Minute
private

The current minute

Definition at line 142 of file Rtc.h.

Referenced by getMinute(), initialise1(), irq(), and synchronise().

uint8_t Rtc::m_Month
private

The current month

Definition at line 136 of file Rtc.h.

Referenced by getDayOfWeek(), getMonth(), initialise1(), irq(), and synchronise().

uint64_t Rtc::m_Nanosecond
private

The current nanosecond

Definition at line 146 of file Rtc.h.

Referenced by getNanosecond(), and irq().

size_t Rtc::m_PeriodicIrqInfoIndex
private

Index into the periodicIrqInfo table

Definition at line 128 of file Rtc.h.

Referenced by initialise1(), and irq().

uint8_t Rtc::m_Second
private

The current second

Definition at line 144 of file Rtc.h.

Referenced by getSecond(), initialise1(), irq(), and synchronise().

uint64_t Rtc::m_TickCount
private

The current tick count in nanoseconds

Definition at line 149 of file Rtc.h.

Referenced by addAlarm(), initialise2(), and irq().

uint64_t Rtc::m_Tsc0
private

Initial TSC value.

Definition at line 197 of file Rtc.h.

Referenced by getTickCountNano(), and initialise2().

uint64_t Rtc::m_TscTicksPerNanosecond
private

Tracks the number of nanoseconds per TSC tick.

Definition at line 194 of file Rtc.h.

Referenced by getTickCountNano(), and initialise2().

size_t Rtc::m_Year
private

The current year

Definition at line 134 of file Rtc.h.

Referenced by getDayOfWeek(), getYear(), initialise1(), irq(), and synchronise().

Rtc::periodicIrqInfo_t Rtc::periodicIrqInfo
staticprivate
Initial value:
= {
{4, 0x0e, {250000000ULL, 250000000ULL}},
{8, 0x0d, {125000000ULL, 125000000ULL}},
{16, 0x0c, {62500000ULL, 62500000ULL}},
{32, 0x0b, {31250000ULL, 31250000ULL}},
{64, 0x0a, {15625000ULL, 15625000ULL}},
{128, 0x09, {7812500ULL, 7812500ULL}},
{256, 0x08, {3906250ULL, 3906250ULL}},
{512, 0x07, {1953125ULL, 1953125ULL}},
{1024, 0x06, {976562ULL, 976563ULL}},
{2048, 0x05, {488281ULL, 488281ULL}},
{4096, 0x04, {244140ULL, 244141ULL}},
{8192, 0x03, {122070ULL, 122070ULL}},
}

Information about the RTC's periodic irq

Definition at line 163 of file Rtc.h.

Referenced by initialise1(), and irq().


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