PikeAero::CTimeBase Class Reference

#include <ctimebase.h>

Inheritance diagram for PikeAero::CTimeBase:

Inheritance graph
[legend]
Collaboration diagram for PikeAero::CTimeBase:

Collaboration graph
[legend]

Public Member Functions

 CTimeBase (CMachine::InterruptVector vector, TB_TypeDef *TBx, CMachine::ubit32 usec=0, CMachine::ubit8 prescaler=255)
virtual void irq (CMachine::InterruptVector v)
 receive a hardware interrupt
bool load (CMachine::ubit32 usec)
 set the timebase period in microseconds.
void loadPrescaler (CMachine::ubit8 prescaler)
 load the prescaler
bool running ()
 determin the running state of the time base. return true of time base is running.
void start (CMachine::ubit32 usec)
void start ()
 the timebase is not running until the start() method is called.
void stop ()
 stop the time base but remember the period.
CMachine::ubit32 ticks ()
 at every time base period, a tick register is incremented.
virtual ~CTimeBase ()

Protected Member Functions

TB_TypeDeftb ()

Private Attributes

CMachine::ubit32 mMax
CMachine::ubit32 mMin
TB_TypeDefmTB
CMachine::ubit32 mTick
CMachine::ubit32 mUSec

Detailed Description

Implements a Time Base object.
Author:
Michael Sharkey <mike@pikeaero.com>

Definition at line 31 of file ctimebase.h.


Constructor & Destructor Documentation

PikeAero::CTimeBase::CTimeBase ( CMachine::InterruptVector  vector,
TB_TypeDef TBx,
CMachine::ubit32  usec = 0,
CMachine::ubit8  prescaler = 255 
)

stop counting.

calculate min and max timer values

select fMCLK as clock source.

enable interrupts from timer

Install self on interrupt vector chain.

Definition at line 24 of file ctimebase.cpp.

References PikeAero::TB_TypeDef::CR, PikeAero::CMachine::fpMCLK(), PikeAero::CMachine::installVectorIRQ(), load(), loadPrescaler(), mMax, mMin, PikeAero::TB_TypeDef::MR, PikeAero::TB_TypeDef::PR, stop(), tb(), TB_ECM, and TB_EE.

00025  : CObject()
00026  , mTB(TBx)
00027  , mTick(0)
00028  , mUSec(usec)
00029 {
00030     /** stop counting. **/
00031     stop();
00032 
00033     /** calculate min and max timer values */
00034     mMin = tb()->PR * 1 * static_cast<CMachine::bit32>(CMachine::fpMCLK()) / 1000;
00035     mMax = tb()->PR * 65536 * static_cast<CMachine::bit32>(CMachine::fpMCLK()) / 1000;
00036 
00037     /** select fMCLK as clock source. */
00038     tb()->CR &= ~TB_EE;
00039 
00040     loadPrescaler(prescaler);
00041     load(usec);
00042 
00043     /** enable interrupts from timer */
00044     tb()->MR |= TB_ECM;
00045 
00046     /** Install self on interrupt vector chain. */
00047     CMachine::installVectorIRQ(vector,this);
00048 }

Here is the call graph for this function:

PikeAero::CTimeBase::~CTimeBase (  )  [virtual]

stop counting.

Disable Interrupts

Remove self from interrupt vector

Definition at line 51 of file ctimebase.cpp.

References PikeAero::TB_TypeDef::MR, PikeAero::CMachine::removeVectorIRQ(), stop(), tb(), and TB_ECM.

00052 {
00053     /** stop counting. **/
00054     stop();
00055     /** Disable Interrupts */
00056     tb()->MR &= ~TB_ECM;
00057     /** Remove self from interrupt vector */
00058     CMachine::removeVectorIRQ(this);
00059 }

Here is the call graph for this function:


Member Function Documentation

void PikeAero::CTimeBase::irq ( CMachine::InterruptVector  v  )  [virtual]

receive a hardware interrupt

clear the End of Count flag

Increment the tick count

Reimplemented from PikeAero::CObject.

Reimplemented in PikeAero::CTimeBaseOneShot.

Definition at line 65 of file ctimebase.cpp.

References mTick, PikeAero::TB_TypeDef::SR, tb(), and TB_EC.

00066 {
00067     if ( tb()->SR & TB_EC )
00068     {
00069         /** clear the End of Count flag **/
00070         tb()->SR &= ~TB_EC;
00071         /** Increment the tick count */
00072         ++mTick;
00073     }
00074 }

Here is the call graph for this function:

bool PikeAero::CTimeBase::load ( CMachine::ubit32  usec  )  [inline]

set the timebase period in microseconds.

Parameters:
usec specifies the timer period in microseconds or 0 to use the default full duration.
Returns:
true if sucessful, false if out of range (default period is then set). The time (us) needed to reach end of period is given by [ (TB->PR+1)*(TB->TV+1)*fMCLK/1000 == (period usecs) ]. For example, if fMCLK = 32MHz (31.25 nanosec) then the default (max) period is 256*65536*31.25/1000 = 524,288 usec. Minimum period (without altering prescaler) is 256*1*31.25/1000 = 8 usec.

set the default period

Definition at line 69 of file ctimebase.h.

References mMax, mMin, tb(), and PikeAero::TB_TypeDef::VR.

Referenced by CTimeBase(), PikeAero::CInputTimingToothCounter::irq(), and start().

00070         {
00071             if ( usec >= mMin && usec <= mMax )
00072             {
00073                 tb()->VR = static_cast<CMachine::ubit16>(65536/(mMax/usec));
00074                 return true;
00075             }
00076             /** set the default period */
00077             tb()->VR = 0xFFFF;
00078             return false;
00079         }

Here is the call graph for this function:

Here is the caller graph for this function:

void PikeAero::CTimeBase::loadPrescaler ( CMachine::ubit8  prescaler  )  [inline]

load the prescaler

Definition at line 59 of file ctimebase.h.

References PikeAero::TB_TypeDef::PR, and tb().

Referenced by CTimeBase().

00059 { tb()->PR = prescaler; }

Here is the call graph for this function:

Here is the caller graph for this function:

bool PikeAero::CTimeBase::running (  )  [inline]

determin the running state of the time base. return true of time base is running.

Definition at line 54 of file ctimebase.h.

References tb(), TB_ECM, and TB_SC.

00054 { return ( ( tb()->MR & TB_ECM )!=0 && ( tb()->CR & TB_SC )!=0 ); }

Here is the call graph for this function:

void PikeAero::CTimeBase::start ( CMachine::ubit32  usec  )  [inline]

Definition at line 42 of file ctimebase.h.

References load(), and start().

Referenced by start().

00042 { load(usec); start(); }

Here is the call graph for this function:

Here is the caller graph for this function:

void PikeAero::CTimeBase::start (  )  [inline]

the timebase is not running until the start() method is called.

Returns:
true if sucessful, false if out of range.

Definition at line 41 of file ctimebase.h.

References PikeAero::TB_TypeDef::CR, tb(), and TB_SC.

Referenced by PikeAero::CInputTimingToothCounter::irq().

00041 { tb()->CR = TB_SC; }

Here is the call graph for this function:

Here is the caller graph for this function:

void PikeAero::CTimeBase::stop (  )  [inline]

stop the time base but remember the period.

Definition at line 47 of file ctimebase.h.

References PikeAero::TB_TypeDef::CR, PikeAero::TB_TypeDef::SR, tb(), TB_EC, and TB_SC.

Referenced by CTimeBase(), PikeAero::CTimeBaseOneShot::irq(), PikeAero::CInputTimingToothCounter::irq(), and ~CTimeBase().

00047 { tb()->CR &= ~TB_SC; tb()->SR &= ~TB_EC; }

Here is the call graph for this function:

Here is the caller graph for this function:

TB_TypeDef* PikeAero::CTimeBase::tb (  )  [inline, protected]

Definition at line 94 of file ctimebase.h.

References mTB.

Referenced by CTimeBase(), PikeAero::CTimeBaseOneShot::irq(), irq(), load(), loadPrescaler(), running(), start(), stop(), and ~CTimeBase().

00094 {return mTB;}

Here is the caller graph for this function:

CMachine::ubit32 PikeAero::CTimeBase::ticks (  )  [inline]

at every time base period, a tick register is incremented.

Returns:
the value of the tick register, i.e. number of time base periods elapsed.

Definition at line 85 of file ctimebase.h.

References mTick.

00085 {return mTick;}


Field Documentation

Definition at line 101 of file ctimebase.h.

Referenced by CTimeBase(), and load().

Definition at line 100 of file ctimebase.h.

Referenced by CTimeBase(), and load().

Definition at line 97 of file ctimebase.h.

Referenced by tb().

Definition at line 98 of file ctimebase.h.

Referenced by irq(), and ticks().

Definition at line 99 of file ctimebase.h.


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

Generated on Sun Oct 25 14:00:31 2009 for stingray3 by  doxygen 1.5.8