#include <oschedule.h>
Inheritance diagram for oSchedule:

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. | |
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).
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.
#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>
|
|
|
|
||||||||||||
|
Configures the channel interrupt enable register.
|
|
||||||||||||
|
Configures the channel priority register (Ref. TPU Channel Utilization).
|
|
||||||||||||
|
Configures the host sequence register.
|
|
||||||||||||
|
Configures the host sequence request register.
|
|
|
Set/reset internal error trap after being handled. Used to set correct callback for RTOS (uC/OS-II as OSTickISR). |
|
|
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... |
|
|
was tpu_init Configures the channel function select register |
1.3