Very simple cooperative round-robin task scheduler. See examples.

Dependents:   Garage_Control

Files at this revision

API Documentation at this revision

Comitter:
AjK
Date:
Fri Mar 04 13:10:39 2011 +0000
Parent:
2:974a420997a9
Child:
4:49652acb6806
Commit message:
1.2 See ChangeLog.h

Changed in this revision

ChangeLog.h Show annotated file Show diff for this revision Revisions of this file
Examples/example4.h Show annotated file Show diff for this revision Revisions of this file
STcallback.h Show annotated file Show diff for this revision Revisions of this file
SimpleScheduler.h Show annotated file Show diff for this revision Revisions of this file
--- a/ChangeLog.h	Fri Mar 04 12:40:14 2011 +0000
+++ b/ChangeLog.h	Fri Mar 04 13:10:39 2011 +0000
@@ -1,5 +1,8 @@
 /*
 
+1.2     04/Mar/2011
+        Added extra documentation.
+        
 1.1     04/Mar/2011
         When calling a task pass a pointer to the SimpleTask holding the pointer.
         Missed this as STcallback allowed for passing a null value. That was fixed.
--- a/Examples/example4.h	Fri Mar 04 12:40:14 2011 +0000
+++ b/Examples/example4.h	Fri Mar 04 13:10:39 2011 +0000
@@ -122,7 +122,7 @@
 
 int main() {
     pc.baud(115200);
-    pc.printf("Example3 starting up.\n");
+    pc.printf("Example4 starting up.\n");
     
     clockAccurate = false;
     
--- a/STcallback.h	Fri Mar 04 12:40:14 2011 +0000
+++ b/STcallback.h	Fri Mar 04 13:10:39 2011 +0000
@@ -75,7 +75,7 @@
      *
      * Note, the callback function prototype must be:-
      * @code
-     * uint32_t myCallbackFunction(uint32_t);
+     * void myCallbackFunction(SimpleTask *p);
      * @endcode
      * @param A C function pointer to call.
      */
@@ -88,7 +88,7 @@
      * Note, the callback method prototype must be:-
      * @code
      *     public:
-     *         uint32_t myCallbackFunction(uint32_t);
+     *         void myCallbackFunction(SimpleTask *p);
      * @endcode
      * @param A C++ object pointer.
      * @param A C++ method within the object to call.
@@ -103,7 +103,7 @@
      *
      * call the callback function.
      *
-     * @return uint32_t The value the callback returns.
+     * @param SimpleTask * pointer.
      */
     void call(SimpleTask *arg) {
         if (c_callback != 0) {
--- a/SimpleScheduler.h	Fri Mar 04 12:40:14 2011 +0000
+++ b/SimpleScheduler.h	Fri Mar 04 13:10:39 2011 +0000
@@ -26,6 +26,8 @@
     @author        Andy Kirkham
 */
 
+#ifndef AJK_SIMPLESCHEDULER_H
+#define AJK_SIMPLESCHEDULER_H
 
 #include "mbed.h"
 #include <list>
@@ -41,6 +43,8 @@
  * @see SimpleScheduler
  * @see example1.h
  * @see example2.h
+ * @see example3.h
+ * @see example4.h
  * @see http://mbed.org/cookbook/SimpleScheduler
  *
  * @code
@@ -48,8 +52,14 @@
  *     task->attach(func);
  * @endcode
  * @code
- *     SimpleTask *task = new SimpleTask(100, func);
+ *     SimpleTask *task = new SimpleTask(100, func); // Every 100ms
+ *     SimpleTask *task = new SimpleTask(1.0, func); // Every 1second
  * @endcode
+ * 
+ * When creating new SimpleTasks you pass the time as a frequency
+ * of how often to call the task function. If the time is an integer
+ * then milliseconds is assumed. If the number you pass is a read (double)
+ * number then the time assumed is seconds.
  */
 class SimpleTask {
 public:
@@ -73,8 +83,6 @@
         return prev;
     }
     
-    SimpleTask() { init(); }
-    
     // Constructor with frequency in miliseconds
     SimpleTask(int f) { init(f); }
     
@@ -147,9 +155,11 @@
  * 
  * DigitalOut led1(LED1);
  * DigitalOut led2(LED2);
+ * DigitalOut led3(LED3);
  * 
  * void f1(SimpleTask *task) { led1 = !led1; }
  * void f2(SimpleTask *task) { led2 = !led2; }
+ * void f3(SimpleTask *task) { led3 = !led3; }
  * 
  * SimpleScheduler *scheduler;
  * 
@@ -158,8 +168,9 @@
  *     scheduler = new SimpleScheduler;
  *     
  *     scheduler
- *         ->addTask( new SimpleTask(0,   f1) )
- *         ->addTask( new SimpleTask(200, f2) )
+ *         ->addTask( new SimpleTask(0,   f1) ) // As often as possible
+ *         ->addTask( new SimpleTask(200, f2) ) // Every 200milliseconds
+ *         ->addTask( new SimpleTask(1.0, f3) ) // Once a second
  *     ;
  *     
  *     scheduler->run();    
@@ -207,3 +218,5 @@
 }; // namespace AjK ends.
 
 using namespace AjK;
+
+#endif
\ No newline at end of file