#define schedVer 1 #define schedRev 0 /**************************************************************************** * * Copyright (c) 2008 Matt Bateman * Robotics4Fun http://www.laughingsky.com/hobbies/robotics/ * (please link back if you use this code!) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * Alternatively, this software may be distributed under the terms of BSD * license. * ****************************************************************************/ /**************************************************************************** * Version Notes * * 1.0 10/28/2008 Initial release ****************************************************************************/ //#define schedDebug 1 // Turn on debug output #define schedShowInitStatus 1 // Display init status and version info typedef void (*PFV)(void); // Pointer to void function #define maxSched 16 // Max number of scheduled functions struct { // Structure for scheduled function info uint16_t period; // Period between runs in mS uint16_t last; // Time stamp of last run PFV proc; // Pointer to function uint16_t max; // Max time function took to run in mS } sched[maxSched]; #ifndef getNow() // ******************************************************* // Timer functions using timer2. By default on the Axon, // the overflow of timer2 is ~1ms. Be sure to init timer2 // somewhere prior to calling any of the avrCam functions. // // timer2Init(); // // These defines are in a misc module, but are included // here in case that module is not loaded. These are used // to handle timeouts when communicating with the camera. // ******************************************************* #define getNow() timer2GetOverflowCount() #define getTimeDiff(now,last) ((last>now)?(65535-last+now):(now-last)) #endif void schedDel (PFV proc) { // ******************************************************* // Delete function from schedule list // ******************************************************* for (register uint8_t i=0;i=sched[i].period) { // Needs to run #ifdef schedDebug // Calculate if time is over more than 40% too long // since last run. If so and debugging is turned on, // print debug message with time info. tmpPeriod=sched[i].period; tmpPeriod*=140; tmpPeriod/=100; // Starvation is 40% over requested if (diff>tmpPeriod) { // Check for starvation rprintf("ERROR: Starvation on process %d ",i); rprintf("(%d):\t",sched[i].period); rprintf("Time = %d\r\n",diff); } #endif sched[i].last=now; // Save current run timestamp sched[i].proc(); // Run the function diff=getTimeDiff(getNow(),sched[i].last); // Calculate how long it took to run sched[i].max=(sched[i].max