PikeAero::CTaskTimeBase Class Reference

#include <ctasktimebase.h>

Inheritance diagram for PikeAero::CTaskTimeBase:

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

Collaboration graph
[legend]

Public Member Functions

 CTaskTimeBase (CMachine::InterruptVector vector, TB_TypeDef *TBx, CMachine::ubit32 usec)
virtual CMachine::bit32 fault ()
 The CTaskScheduler will call the fault() method when a fault code was returned by any of the task's other methods.
virtual void irq (CMachine::InterruptVector v)
 receive a hardware interrupt
virtual const char * name ()
 returns a CString containing an human readable name for the task
virtual CMachine::bit32 run ()
 called exactly once. perform task initialization such as initializing private variable. Other tasks are not guaranteed so do not interract with other tasks at this stage.
bool running ()
 determin the running state of the time base. return true of time base is running.
bool set (CMachine::ubit32 usec)
 set the timebase period in microseconds.
virtual CMachine::bit32 start ()
 initialize the class.
virtual CMachine::bit32 stop ()
 The CTaskScheduler will call the stop () method after the task was scheduled for cancelation.
 ~CTaskTimeBase ()

Private Attributes

CMachine::ubit64 mLastTicks
TB_TypeDefmTB
CMachine::ubit64 mTicks
CMachine::ubit32 mUSec

Detailed Description

Impliments a timebase task
Author:
Michael Sharkey <mike@pikeaero.com>

Definition at line 31 of file ctasktimebase.h.


Constructor & Destructor Documentation

PikeAero::CTaskTimeBase::CTaskTimeBase ( CMachine::InterruptVector  vector,
TB_TypeDef TBx,
CMachine::ubit32  usec 
)

Definition at line 26 of file ctasktimebase.cpp.

References PikeAero::CMachine::installVectorIRQ(), and stop().

00027  : ITask()
00028  , mTB(TBx)
00029  , mUSec(usec)
00030  , mTicks(0)
00031  , mLastTicks(0)
00032 {
00033     stop();
00034     CMachine::installVectorIRQ(vector,this);
00035 }

Here is the call graph for this function:

PikeAero::CTaskTimeBase::~CTaskTimeBase (  ) 

stop counting.

Remove self from interrupt vector

Definition at line 38 of file ctasktimebase.cpp.

References PikeAero::CMachine::removeVectorIRQ(), and stop().

00039 {
00040     /** stop counting. **/
00041     stop();
00042     /** Remove self from interrupt vector */
00043     CMachine::removeVectorIRQ(this);
00044 }

Here is the call graph for this function:


Member Function Documentation

CMachine::bit32 PikeAero::CTaskTimeBase::fault (  )  [virtual]

The CTaskScheduler will call the fault() method when a fault code was returned by any of the task's other methods.

Reimplemented from PikeAero::ITask.

Definition at line 108 of file ctasktimebase.cpp.

References PikeAero::CObject::errOK.

00109 {
00110     return errOK;
00111 }

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

receive a hardware interrupt

receive a hardware interrupt [ top half ]

increment hi rez tick count

wake up the bottom half

clear the End of Count flag

Reimplemented from PikeAero::CObject.

Definition at line 148 of file ctasktimebase.cpp.

References mTB, mTicks, PikeAero::ITask::setSleeping(), PikeAero::TB_TypeDef::SR, and TB_EC.

00149 {
00150     if ( mTB->SR & TB_EC )
00151     {
00152         /** increment hi rez tick count */
00153         ++mTicks;
00154         /** wake up the bottom half */
00155         setSleeping(false);
00156         /** clear the End of Count flag **/
00157         mTB->SR &= ~TB_EC;
00158     }
00159 }

Here is the call graph for this function:

virtual const char* PikeAero::CTaskTimeBase::name (  )  [inline, virtual]

returns a CString containing an human readable name for the task

Reimplemented from PikeAero::ITask.

Definition at line 38 of file ctasktimebase.h.

00038 {return "CTaskTimeBase";}

CMachine::bit32 PikeAero::CTaskTimeBase::run (  )  [virtual]

called exactly once. perform task initialization such as initializing private variable. Other tasks are not guaranteed so do not interract with other tasks at this stage.

called periodically by CTaskScheduler to do a piece of work. [ bottom half ]

Returns:
0 on success.

Dispatch a wall clock event approximately every 1/10th second.

disable interrupts on this time base channel.

enable interrupts on this time base channel.

put the task back to sleep

Reimplemented from PikeAero::ITask.

Definition at line 69 of file ctasktimebase.cpp.

References disableInterrupts, PikeAero::CObject::dispatch(), enableInterrupts, PikeAero::CObject::errOK, PikeAero::CObject::event(), mLastTicks, PikeAero::TB_TypeDef::MR, mTB, mTicks, PikeAero::ITask::setSleeping(), and TB_ECM.

00070 {
00071     /**
00072     ** Dispatch a wall clock event approximately every 1/10th second.
00073     */
00074     if ( mLastTicks <= mTicks )
00075     {
00076         CEventTick* event = new CEventTick(this);
00077         mTB->MR &= ~TB_ECM;             /** disable interrupts on this time base channel. */
00078         event->setTicks(mTicks);
00079         mTB->MR |= TB_ECM;              /** enable interrupts on this time base channel. */
00080         dispatch( event );
00081         disableInterrupts();
00082         mLastTicks = mTicks;
00083         enableInterrupts();
00084     }
00085     setSleeping(true);                  /** put the task back to sleep */
00086     return errOK;
00087 }

Here is the call graph for this function:

bool PikeAero::CTaskTimeBase::running (  ) 

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

Reimplemented from PikeAero::ITask.

Definition at line 140 of file ctasktimebase.cpp.

References PikeAero::TB_TypeDef::CR, PikeAero::TB_TypeDef::MR, mTB, TB_ECM, and TB_SC.

00141 {
00142     return ( (mTB->MR&TB_ECM)!=0 && (mTB->CR&TB_SC)!=0 );
00143 }

bool PikeAero::CTaskTimeBase::set ( CMachine::ubit32  usec  ) 

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.
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. TODO - include prescaler tweeking for finer resolution - currently assumes maximum prescaler period.

set the default period

Definition at line 122 of file ctasktimebase.cpp.

References PikeAero::CMachine::fpMCLK(), mTB, PikeAero::TB_TypeDef::PR, and PikeAero::TB_TypeDef::VR.

00123 {
00124     CMachine::ubit32 min = mTB->PR * 1 * static_cast<CMachine::bit32>(CMachine::fpMCLK()) / 1000;
00125     CMachine::ubit32 max = mTB->PR * 65536 * static_cast<CMachine::bit32>(CMachine::fpMCLK()) / 1000;
00126     if ( usec >= min && usec <= max )
00127     {
00128         mTB->VR = static_cast<CMachine::ubit16>(65536/(max/(usec)));
00129         return true;
00130     }
00131     /** set the default period */
00132     mTB->VR = 0xFFFF;
00133     return false;
00134 }

Here is the call graph for this function:

CMachine::bit32 PikeAero::CTaskTimeBase::start (  )  [virtual]

initialize the class.

load the default prescaler.

enable interrupts on this time base channel.

start counting

Reimplemented from PikeAero::ITask.

Definition at line 49 of file ctasktimebase.cpp.

References PikeAero::TB_TypeDef::CR, PikeAero::CObject::errOK, PikeAero::CObject::errOutOfRange, PikeAero::TB_TypeDef::MR, mTB, mUSec, PikeAero::TB_TypeDef::PR, PikeAero::ITask::setSleeping(), TB_ECM, and TB_SC.

00050 {
00051     setSleeping(true);
00052     if ( set( mUSec ) )
00053     {
00054         /** load the default prescaler. */
00055         mTB->PR = 0x00FF;
00056         /** enable interrupts on this time base channel. */
00057         mTB->MR |= TB_ECM;
00058         /** start counting */
00059         mTB->CR = TB_SC;
00060         return errOK;
00061     }
00062     return errOutOfRange;
00063 }

Here is the call graph for this function:

CMachine::bit32 PikeAero::CTaskTimeBase::stop (  )  [virtual]

The CTaskScheduler will call the stop () method after the task was scheduled for cancelation.

Returns:
0 on success.

stop and select fMCLK as clock source.

disable interrupts on this time base channel.

clear the End of Count flag

Reimplemented from PikeAero::ITask.

Definition at line 93 of file ctasktimebase.cpp.

References PikeAero::TB_TypeDef::CR, PikeAero::CObject::errOK, PikeAero::TB_TypeDef::MR, mTB, PikeAero::ITask::setSleeping(), PikeAero::TB_TypeDef::SR, TB_EC, TB_ECM, and TB_SC.

Referenced by CTaskTimeBase(), and ~CTaskTimeBase().

00094 {
00095     setSleeping(true);
00096     /** stop and select fMCLK as clock source. */
00097     mTB->CR &= ~TB_SC;
00098     /** disable interrupts on this time base channel. */
00099     mTB->MR &= ~TB_ECM;
00100     /** clear the End of Count flag **/
00101     mTB->SR &= ~TB_EC;
00102     return errOK;
00103 }

Here is the call graph for this function:

Here is the caller graph for this function:


Field Documentation

Definition at line 77 of file ctasktimebase.h.

Referenced by run().

Definition at line 74 of file ctasktimebase.h.

Referenced by irq(), run(), running(), set(), start(), and stop().

Definition at line 76 of file ctasktimebase.h.

Referenced by irq(), and run().

Definition at line 75 of file ctasktimebase.h.

Referenced by start().


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

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