PikeAero::CTaskScheduler Class Reference

Implements the cooperative multitasking functionality. More...

#include <ctaskscheduler.h>

Collaboration diagram for PikeAero::CTaskScheduler:

Collaboration graph
[legend]

Static Public Member Functions

static CMachine::bit32 append (ITask *task)
 append a task to the task queue.
static ITaskat (CMachine::bit32 id)
 fetch the pointer to the task indexed by task id.
static CMachine::ubit32 count ()
static ITaskcurrent ()
static ITaskfind (const char *name)
 find a task by name
static void initialize ()
 initialize the static class.
static void iowait ()
 Call this function from within a task who is waiting on I/O.
static void resetTaskSlices ()
static void run ()
 Run each task slice forever...
static CMachine::ubit32 tasksEventDriven ()
 return number of stopped processes...
static CMachine::bit32 taskSlices ()
static CMachine::ubit32 tasksRunning ()
 return number of processes running.
static CMachine::ubit32 tasksSleeping ()
 return number of sleeping processes...
static void yield ()
 yield the current task - run some other tasks for one cycle through all task priorities.

Static Private Member Functions

static CMachine::ubit32 mTaskSlices __attribute__ ((aligned))
static CMachine::bit32 run1 ()
 Run one task slice - run1() can be reentered in the case of a task I/O blocking or one which yields CPU.
static void start ()
 Start the task scheduler - never returns.

Static Private Attributes

static bool mRunning
static ITaskmTask
static CTaskQueue mTaskQueue

Detailed Description

Implements the cooperative multitasking functionality.

Author:
Michael Sharkey <mike@pikeaero.com>

Definition at line 33 of file ctaskscheduler.h.


Member Function Documentation

static CMachine::ubit32 mTaskSlices PikeAero::CTaskScheduler::__attribute__ ( (aligned)   )  [static, private]

CMachine::bit32 PikeAero::CTaskScheduler::append ( ITask task  )  [static]

append a task to the task queue.

Definition at line 124 of file ctaskscheduler.cpp.

References PikeAero::CObjectList::append(), PikeAero::CObjectList::indexOf(), PikeAero::ITask::init(), and mTaskQueue.

Referenced by main().

00125 {
00126     mTaskQueue.append(task);
00127     task->init();
00128     return mTaskQueue.indexOf(task);
00129 }

Here is the call graph for this function:

Here is the caller graph for this function:

ITask * PikeAero::CTaskScheduler::at ( CMachine::bit32  id  )  [static]

fetch the pointer to the task indexed by task id.

Definition at line 116 of file ctaskscheduler.cpp.

References PikeAero::CObjectList::at(), and mTaskQueue.

Referenced by main(), PikeAero::CTaskConsole::monitor(), and PikeAero::CTaskAggregator::perSecond().

00117 {
00118     return (ITask*)mTaskQueue.at(id);
00119 }

Here is the call graph for this function:

Here is the caller graph for this function:

static CMachine::ubit32 PikeAero::CTaskScheduler::count (  )  [inline, static]

Definition at line 43 of file ctaskscheduler.h.

References PikeAero::CObjectList::count(), and mTaskQueue.

Referenced by PikeAero::CTaskConsolePacket::monitor(), PikeAero::CTaskConsole::monitor(), PikeAero::CTaskAggregator::perSecond(), tasksEventDriven(), tasksRunning(), and tasksSleeping().

00043 {return mTaskQueue.count();}

Here is the call graph for this function:

Here is the caller graph for this function:

static ITask* PikeAero::CTaskScheduler::current (  )  [inline, static]

Definition at line 45 of file ctaskscheduler.h.

References mTask.

Referenced by iowait().

00045 {return mTask;}

Here is the caller graph for this function:

ITask * PikeAero::CTaskScheduler::find ( const char *  name  )  [static]

find a task by name

true once task scheduler is running

Definition at line 35 of file ctaskscheduler.cpp.

References PikeAero::CObjectList::at(), PikeAero::CObjectList::count(), mTaskQueue, PikeAero::ITask::name(), strcmp, and yield().

Referenced by PikeAero::CTaskFuelInjection::start(), and PikeAero::CTaskConsoleBase::start().

00036 {
00037     for( CMachine::ubit32 n=0; n < mTaskQueue.count(); n++ )
00038     {
00039         ITask* task = (ITask*)mTaskQueue.at(n);
00040         yield();
00041         if ( strcmp((const char*)name,(const char*)task->name()) == 0 )
00042         {
00043             return task;
00044         }
00045     }
00046     return NULL;
00047 }

Here is the call graph for this function:

Here is the caller graph for this function:

void PikeAero::CTaskScheduler::initialize ( void   )  [static]

initialize the static class.

Definition at line 106 of file ctaskscheduler.cpp.

References mRunning, and mTask.

Referenced by main().

00107 {
00108     mTaskSlices=0;
00109     mTask=NULL;
00110     mRunning=false;
00111 }

Here is the caller graph for this function:

void PikeAero::CTaskScheduler::iowait (  )  [static]

Call this function from within a task who is waiting on I/O.

test for running here because some initializers may indirectly call yield() before task schduler is initialized

Definition at line 162 of file ctaskscheduler.cpp.

References current(), PikeAero::ITask::iowait(), mRunning, and run1().

00163 {
00164 
00165     /** test for running here because some initializers may indirectly call yield() before task schduler is initialized */
00166     if ( mRunning )
00167     {
00168         ITask* task = current();
00169         while( task->iowait() )
00170         {
00171             run1();
00172         }
00173     }
00174 }

Here is the call graph for this function:

static void PikeAero::CTaskScheduler::resetTaskSlices (  )  [inline, static]

Definition at line 49 of file ctaskscheduler.h.

Referenced by PikeAero::CTaskAggregator::perSecond().

00049 {mTaskSlices=0;}

Here is the caller graph for this function:

void PikeAero::CTaskScheduler::run (  )  [static]

Run each task slice forever...

Run one task slice

Definition at line 179 of file ctaskscheduler.cpp.

References PikeAero::CTaskQueue::initialize(), mRunning, mTaskQueue, run1(), and start().

Referenced by main().

00180 {
00181     start();
00182     mTaskQueue.initialize();
00183     mRunning=true;
00184     while (mRunning)
00185     {
00186         run1();         /** Run one task slice */
00187     }
00188 }

Here is the call graph for this function:

Here is the caller graph for this function:

CMachine::bit32 PikeAero::CTaskScheduler::run1 (  )  [static, private]

Run one task slice - run1() can be reentered in the case of a task I/O blocking or one which yields CPU.

Returns:
integer from last task run.

Interrupts must be initially enabled.

get the next task for current priority that's not already running and is not sleeping...

Tell watchdog we are still running

Definition at line 194 of file ctaskscheduler.cpp.

References enableInterrupts, PikeAero::ITask::incrementSlices(), mTask, mTaskQueue, PikeAero::CTaskQueue::next(), PikeAero::CMachine::resetWatchDog(), PikeAero::ITask::run(), PikeAero::ITask::running(), PikeAero::ITask::setFault(), PikeAero::ITask::setRunning(), and PikeAero::ITask::sleeping().

Referenced by iowait(), run(), and yield().

00195 {
00196     CMachine::bit32 rc=0;
00197     ITask* task;
00198     enableInterrupts();                                 /** Interrupts must be initially enabled. */
00199     do {
00200         mTask = task = mTaskQueue.next();               /** get the next task for current priority that's not already running and is not sleeping... */
00201         CMachine::resetWatchDog();                      /** Tell watchdog we are still running */
00202     } while ( task->sleeping() || task->running() );
00203     ++mTaskSlices;
00204     task->setRunning(true);
00205     task->incrementSlices();
00206     if ( ( rc = task->run() ) )
00207     {
00208         task->setFault( rc );
00209     }
00210     task->setRunning(false);
00211     return rc;
00212 }

Here is the call graph for this function:

Here is the caller graph for this function:

void PikeAero::CTaskScheduler::start (  )  [static, private]

Start the task scheduler - never returns.

Tell watchdog we are still running

start/initialize the task

Definition at line 134 of file ctaskscheduler.cpp.

References PikeAero::CObjectList::at(), PikeAero::CObjectList::count(), mTaskQueue, PikeAero::CMachine::resetWatchDog(), and PikeAero::ITask::start().

Referenced by run().

00135 {
00136     for( CMachine::ubit32 n=0; n<mTaskQueue.count(); n++ )
00137     {
00138         ITask* task = static_cast<ITask*>(mTaskQueue.at(n));
00139         CMachine::resetWatchDog();      /** Tell watchdog we are still running */
00140         task->start();                  /** start/initialize the task */
00141     }
00142 }

Here is the call graph for this function:

Here is the caller graph for this function:

CMachine::ubit32 PikeAero::CTaskScheduler::tasksEventDriven (  )  [static]

return number of stopped processes...

Definition at line 88 of file ctaskscheduler.cpp.

References PikeAero::CObjectList::at(), PikeAero::CObjectList::count(), count(), mTaskQueue, PikeAero::ITask::priority(), PikeAero::ITask::PriorityEvent, and yield().

Referenced by PikeAero::CTaskConsole::monitor().

00089 {
00090     CMachine::ubit32 count=0;
00091     for( CMachine::ubit32 n=0; n < mTaskQueue.count(); n++ )
00092     {
00093         ITask* task = (ITask*)mTaskQueue.at(n);
00094         yield();
00095         if ( task->priority() == ITask::PriorityEvent )
00096         {
00097             ++count;
00098         }
00099     }
00100     return count;
00101 }

Here is the call graph for this function:

Here is the caller graph for this function:

static CMachine::bit32 PikeAero::CTaskScheduler::taskSlices (  )  [inline, static]

Definition at line 48 of file ctaskscheduler.h.

Referenced by PikeAero::CTaskAggregator::perSecond().

00048 {return mTaskSlices;}

Here is the caller graph for this function:

CMachine::ubit32 PikeAero::CTaskScheduler::tasksRunning (  )  [static]

return number of processes running.

Definition at line 52 of file ctaskscheduler.cpp.

References PikeAero::CObjectList::at(), PikeAero::CObjectList::count(), count(), mTaskQueue, PikeAero::ITask::priority(), PikeAero::ITask::PriorityEvent, PikeAero::ITask::sleeping(), and yield().

Referenced by PikeAero::CTaskConsole::monitor().

00053 {
00054     CMachine::ubit32 count=0;
00055     for( CMachine::ubit32 n=0; n < mTaskQueue.count(); n++ )
00056     {
00057         ITask* task = (ITask*)mTaskQueue.at(n);
00058         yield();
00059         if ( !task->sleeping() && task->priority() < ITask::PriorityEvent )
00060         {
00061             ++count;
00062         }
00063     }
00064     return count;
00065 }

Here is the call graph for this function:

Here is the caller graph for this function:

CMachine::ubit32 PikeAero::CTaskScheduler::tasksSleeping (  )  [static]

return number of sleeping processes...

Definition at line 70 of file ctaskscheduler.cpp.

References PikeAero::CObjectList::at(), PikeAero::CObjectList::count(), count(), mTaskQueue, PikeAero::ITask::priority(), PikeAero::ITask::PriorityEvent, PikeAero::ITask::sleeping(), and yield().

Referenced by PikeAero::CTaskConsole::monitor().

00071 {
00072     CMachine::ubit32 count=0;
00073     for( CMachine::ubit32 n=0; n < mTaskQueue.count(); n++ )
00074     {
00075         ITask* task = (ITask*)mTaskQueue.at(n);
00076         yield();
00077         if ( task->sleeping() && task->priority() < ITask::PriorityEvent )
00078         {
00079             ++count;
00080         }
00081     }
00082     return count;
00083 }

Here is the call graph for this function:

Here is the caller graph for this function:

void PikeAero::CTaskScheduler::yield (  )  [static]

yield the current task - run some other tasks for one cycle through all task priorities.

test for running here because some initializers may indirectly call yield() before task schduler is initialized

Definition at line 147 of file ctaskscheduler.cpp.

References PikeAero::CObjectList::count(), mRunning, mTaskQueue, and run1().

Referenced by PikeAero::CSPIEEPROM::_write(), PikeAero::CTaskAggregator::calculateRPM(), PikeAero::CSPI::clearReceiver(), PikeAero::CCommandHandler::execute(), find(), PikeAero::CString::fromUbit32(), PikeAero::CMutexLock::lock(), PikeAero::CSPIEEPROM::read(), PikeAero::CSPI::rx(), PikeAero::CString::sprintf(), tasksEventDriven(), tasksRunning(), tasksSleeping(), PikeAero::CString::toBit32(), PikeAero::CString::toHex(), PikeAero::CString::toUBit32(), PikeAero::CSPI::tx(), PikeAero::CCommunicationUART::tx(), PikeAero::CCommunicationPacket::tx(), and PikeAero::CCommunication::tx().

00148 {
00149     /** test for running here because some initializers may indirectly call yield() before task schduler is initialized */
00150     if ( mRunning )
00151     {
00152         for( CMachine::bit8 cycles = mTaskQueue.count(); cycles > 0 ; cycles-- )
00153         {
00154             run1();
00155         }
00156     }
00157 }

Here is the call graph for this function:

Here is the caller graph for this function:


Field Documentation

bool PikeAero::CTaskScheduler::mRunning [static, private]

task switches per second

For measuring task slices vs. time

Definition at line 61 of file ctaskscheduler.h.

Referenced by initialize(), iowait(), run(), and yield().

Definition at line 58 of file ctaskscheduler.h.

Referenced by current(), initialize(), and run1().

Currently running task

Definition at line 59 of file ctaskscheduler.h.

Referenced by append(), at(), count(), find(), run(), run1(), start(), tasksEventDriven(), tasksRunning(), tasksSleeping(), and yield().


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

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