Main Page   Hardware Class Hierarchy   Hardware API     Mapping Class Hierarchy  Mapping API 

oSchedule Class Reference

A class for providing a mechanism for providing simple interrupts using the SIM periodic Interrupt Timer (PIT). More...

#include <oschedule.h>

Inheritance diagram for oSchedule:

OOMRM oTPU

Static Public Member Functions

unsigned period (MILLISECOND r)
 Set the period between events (measured in milliseconds).

float period (void)
 Return current period.

void PITR (word)
 Directly assign the PIT register for those who need to.

void syncronize (void)
 Reestablish period if PITR changes.

void shutdown (void)
 Stops the PIT regardless.

uint8 slices (void)
 Returns maximum number of slices set.

unsigned int timestamp (void)
 Return current time stamp in scheduler ticks.

bool operate (bool b=true)
 Activates oEvent object.

int add (foo, void *data=NULL)
 Returns event handle for turning individual events on/off. (-1 on error).

bool drop (foo)
 Deletes event list permanently.

void run (int id=1)
 Turns on event with handle "id".

void stop (int id)
 Turns off event with handle "id".

void executeon (int id, uint8 s)
 Sets slice number in which function should execute (0=every interrupt).

void error (foo)
 Add optional error routine to trigger if time overflow.

uint8 error (void)
 Return error code. (0 for no error).

void reset (void)
void callback (foovoid f)
int TCR1 (void)
void TMCR (int iarb)
bool HSQR (int chan, int val)
 Configures the host sequence register.

bool HSRR (int chan, int val)
 Configures the host sequence request register.

bool CPR (int chan, int val)
 Configures the channel priority register (Ref. TPU Channel Utilization).

bool CIER (int chan, int cie)
 Configures the channel interrupt enable register.

int CISR (int chan)
 Returns the channel interrupt status register.

void CISR_clear (int chan)
 Clears the channel interrupt status register for the channel.

bool TICR (int cirl, int cibv)
 Configures the TPU interrupt configuration register.

int tpu_vector (IOLINE channel)
 Given a channel, returns the vector number to use for an interrupt.


Detailed Description

A class for providing a mechanism for providing simple interrupts using the SIM periodic Interrupt Timer (PIT).

Note:
technically, the user could do this outside of the object, but this provides a cleaner interface.
Operation
This class utilizes the periodic interrupt timer (PIT) of the system intergration module (SIM) to schedule function calls at a regular interval. Currently this is about 10 milli-seconds. Added functions must return void and have no arguments.
Because some classes may use the scheduler unknown to other classes, it was needed to make the scheduler immune to accidental premature shutdown. Thus, the scheduler will automatically activate (by setting operate to true) if any function is set to run. Also, it will ignore an operate command to true if nothing is running, and vice-versa, it will ignore a operate command to false if something is still running. Therefore, the only way to shut off the scheduler is to stop/drop all functions.

Warning:
Before program exit, as of version 2.4, execute new method shutdown on oScheduler. This will eliminate having to reset the MRM as it guarantees disabling of the PIT.

Rumor has it, ROM loaded programs the static data does not get reinitialized. So be sure to call shutdown to mark the scheduler as needing initialization on next boot.

For uC/OS-II use, callback(OSTickISR) must be called either manually or via a library os function (OS_Init).

Remarks
Currently, the maximum number of functions that can be added is governed by FooMAX. Be careful if you use the PITR method, as there is no error checking to see if it makes sense.
It turns out after more thorough testing, previous to 2.5 the scheduler would never allow another interrupt as the priority was not increased. The new approach is less elegant but more practical as it puts the burden of testing for scheduler overflows on the end user.

Note that you can add an optional error routine to run if an time overrun occurs. This may prove useful for visual feedback as the main program will not gain the CPU again until after the routines have all finished. Refer to sample code below for detailed example.

Sample Code
#include <hardware/oencoder.h>
#include <oconsole.h>
#include <oled.h>
#include <oprocessor.h>
#include <hardware/odio1.h>
#include <hardware/oschedule.h>
oDI1_TPU onoff(15);             // start/stop toggle switch
oConsole console;               // log events...
oGreenLED green;
oRedLED red;
oSchedule events;
bool powerup = false;           // true when toggle button pressed...
// Prototypes
void EventError(void);          // Function to call when schedule overflow occurs.
void setup(void);               // sets up toggle switch.
void Delay(long);               // general time delay...
void shutdown(void);            // exit program.
void speedit(void);             // scheduled function that will exceed time allowed.
// -----------------------------------------
// MAIN
// -----------------------------------------
int main()
{
  green.on();
  events.period(10);
  setup(); // waits for startbutton to be pushed...
  events.error(EventError);
  int SpeedID = events.add(speedit);
  if (SpeedID == -1)
  {
    console.echo("speedit failed\n");
    shutdown();
  } else
    events.run(SpeedID); 

  while (true)
  {
    console.echo("looping...\n");
    if ((events.error()))       // do something creative to fix problem or just exit and increase period ;)
    { 
      if (!events.drop(speedit) )       // for now, just drop function I know is causing problem
        console.echo("Failed to drop speedit\n");
      else
        console.echo("\nfixed!\n");
      events.reset();           // MUST be after error processing or will execute again...
      red.off();
    }
    Delay(50000);
  }
  shutdown();   // never really gets here, but seems weird to not exit after main :)
}
// ====================
// ONEVENT: EVENTERROR; executed if the scheduler has an overflow...
// ====================
void EventError()
{
  red.on();
}
// ====================
// SHUTDOWN: exit gracefully
// ====================
void shutdown()
{
  events.shutdown();
  exit(0);
}
// ====================
// Scheduled: STARTIF - wait for start button to be pressed; then powerup.  
// ====================
void startif()
{
  if (onoff.value() == ON)
  {
    powerup = true;
  }
}
// ====================
// Scheduled: SPEEDIT
// ====================
void speedit()
{  // way too long.......for 10ms 
console.echo("In speedit:much rejoicing?\n");
Delay(100000);
}
// ====================
// Scheduled: EXITIF; executed if button pushed after initial powerup.
// ====================
void exitif()
{
  if (onoff.value() == ON)
  {
     events.shutdown();
     shutdown();
  }
}
// ====================
// DELAY
// ====================
void Delay(long d)
{
  for (long l=0; l<=d; l++) ;
}
// ====================
// SETUP
// ====================
void setup()
{
  int StartID = events.add(startif);
  if (StartID == -1)
  {
    console.echo("startif failed\n");
    shutdown();
  } else
    events.run(StartID);

  while (!powerup) ;    // sit idle until toggle switch hit (function startif).

  Delay(100000);        // !!! MUST DELAY LONG ENOUGH TO DEBOUNCE THE START BUTTON OR WILL TERMINATE AFTER ~20MS!!!
  events.drop(startif);

  int ExitID = events.add(exitif);
  if (ExitID == -1)
  {
    console.echo("exitif failed\n");
    shutdown();
  } else
    events.run(ExitID);
}

Sample Output
CPU32Bug Debugger/Diagnostics - Version  1.00                                  
 (C) Copyright 1991 by Motorola Inc.                       

Booting from address $90010             <- awaiting start/stop toggle button...begins
looping...
In speedit:much rejoicing?              <- red LED goes on; slight pause. PIT disabled, finnally finishes...
looping...                              <- continues

fixed!                                  <- but now, the error trapped and fixed. red LED off.
looping...
looping...
looping...
looping...
looping...
looping...                              <- start/stop toggle button hit again
CPU32Bug>


Member Function Documentation

void callback foovoid  f  )  [static]
 

Note:
: Round robin function set by default.

bool CIER int  chan,
int  cie
[static, inherited]
 

Configures the channel interrupt enable register.

Parameters:
int: channel
int: 1 enables; 0 disables

bool CPR int  chan,
int  val
[static, inherited]
 

Configures the channel priority register (Ref. TPU Channel Utilization).

Parameters:
int: channel
int: priority

bool HSQR int  chan,
int  val
[static, inherited]
 

Configures the host sequence register.

Parameters:
int: channel
int dependent upon function (CFSR) selected

bool HSRR int  chan,
int  val
[static, inherited]
 

Configures the host sequence request register.

Parameters:
int: channel
int: dependend upon function

void reset void   )  [static]
 

Set/reset internal error trap after being handled. Used to set correct callback for RTOS (uC/OS-II as OSTickISR).

int TCR1 void   )  [static, inherited]
 

misnomer--should be TCR1 divisor--return number of clocks (PSCK,TCR1P modifications) Globally available object. Can be used in combination with TPU_REGISTER definition to say TPU_REGISTER->CFSR.BITS...

void TMCR int  iarb  )  [static, inherited]
 

was tpu_init Configures the channel function select register


The documentation for this class was generated from the following file:
Generated on Mon Oct 8 19:32:45 2007 for OOMRM Hardware API by doxygen1.3