Pont Architecture Time Triggered OS

Dependencies:   mbed ITG3200

Files at this revision

API Documentation at this revision

Comitter:
Lachrymosa
Date:
Thu Oct 27 22:01:30 2011 +0000
Commit message:
Incomplete Time Triggered OS

Changed in this revision

Constants.h Show annotated file Show diff for this revision Revisions of this file
Debug.h Show annotated file Show diff for this revision Revisions of this file
Globals.h Show annotated file Show diff for this revision Revisions of this file
Gyrotask.c Show annotated file Show diff for this revision Revisions of this file
Gyrotask.h Show annotated file Show diff for this revision Revisions of this file
ITG3200.lib Show annotated file Show diff for this revision Revisions of this file
Ledtask.c Show annotated file Show diff for this revision Revisions of this file
Ledtask.h Show annotated file Show diff for this revision Revisions of this file
OS.c Show annotated file Show diff for this revision Revisions of this file
OS.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 823a9a4db739 Constants.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Constants.h	Thu Oct 27 22:01:30 2011 +0000
@@ -0,0 +1,6 @@
+#ifndef CONSTANT_H_GUARD
+#define CONSTANT_H_GUARD
+#define NumTask (1) // change for number of array spaces.
+#define ArrayFull (-1) //If SCHAddTask runs out of room before adding task.
+#define NothingFound (-2) //If the remove fails due to lack of something to remove.
+#endif
\ No newline at end of file
diff -r 000000000000 -r 823a9a4db739 Debug.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Debug.h	Thu Oct 27 22:01:30 2011 +0000
@@ -0,0 +1,5 @@
+#ifndef DEBUG_H_GUARD
+#define DEBUG_H_GUARD
+#include "mbed.h"
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 823a9a4db739 Globals.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Globals.h	Thu Oct 27 22:01:30 2011 +0000
@@ -0,0 +1,6 @@
+#ifndef GLOBALS_H_GUARD
+#define GLOBALS_H_GUARD
+float GyroX;
+float GyroY;
+float GyroZ;
+#endif
\ No newline at end of file
diff -r 000000000000 -r 823a9a4db739 Gyrotask.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Gyrotask.c	Thu Oct 27 22:01:30 2011 +0000
@@ -0,0 +1,16 @@
+//#ifndef GYROTASK_C_GUARD
+//#define GYROTASK_C_GUARD
+#include "Gyrotask.h"
+extern Serial debug;
+void Gyrotask()
+{
+    debug.printf("Now starting ITG-3200... \n");
+
+     float GyroX = gyro.getGyroX()/0.0612; //+- the offset then / 0.0612 for divisions of voltage to = degrees/second.
+     float GyroY = gyro.getGyroY()/0.0612;
+     float GyroZ = gyro.getGyroZ()/0.0612;
+     
+     //debug.printf("%i, %i, %i\n", gyro.getGyroX(),
+     //gyro.getGyroY(), gyro.getGyroZ());
+}
+//#endif
\ No newline at end of file
diff -r 000000000000 -r 823a9a4db739 Gyrotask.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Gyrotask.h	Thu Oct 27 22:01:30 2011 +0000
@@ -0,0 +1,6 @@
+#ifndef GYROTASK_H_GUARD
+#define GYROTASK_H_GUARD
+#include "ITG3200.h"
+ITG3200 gyro(p9, p10);
+void Gyrotask();
+#endif
\ No newline at end of file
diff -r 000000000000 -r 823a9a4db739 ITG3200.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ITG3200.lib	Thu Oct 27 22:01:30 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/aberk/code/ITG3200/#b098d99dd81e
diff -r 000000000000 -r 823a9a4db739 Ledtask.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Ledtask.c	Thu Oct 27 22:01:30 2011 +0000
@@ -0,0 +1,19 @@
+//#ifndef LEDTASK_C_GUARD
+//#define LEDTASK_C_GUARD
+#include "mbed.h"
+
+extern Serial debug;
+DigitalOut Led1(LED1);
+void Led1Run(void);
+
+void Led1Init()
+{
+    Led1 = 0;
+}
+
+void Led1Run()
+{
+    Led1 = !Led1;
+    debug.printf("LED Switched \n \r");
+}
+//#endif
\ No newline at end of file
diff -r 000000000000 -r 823a9a4db739 Ledtask.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Ledtask.h	Thu Oct 27 22:01:30 2011 +0000
@@ -0,0 +1,5 @@
+#ifndef LEDTASK_H_GUARD
+#define LEDTASK_H_GUARD
+void Led1Init(void);
+void Led1Run(void);
+#endif
\ No newline at end of file
diff -r 000000000000 -r 823a9a4db739 OS.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OS.c	Thu Oct 27 22:01:30 2011 +0000
@@ -0,0 +1,67 @@
+#include "mbed.h"
+#include "Constants.h"
+#include "OS.h"
+extern Serial debug;
+
+pTask TaskList[NumTask];
+
+int SCHAddTask(void(*fP)(void), int P, int D)
+{
+    int i = 0;
+    while(i <= NumTask && TaskList[i].fP != 0)
+    { 
+        i++;
+    }
+    if (i > NumTask)
+    {
+        return ArrayFull;
+    }
+    TaskList[i].fP = fP;
+    TaskList[i].Delay = D;
+    TaskList[i].Period = P;
+    TaskList[i].RunMe = 0;
+    
+    return i;
+}
+
+int SCHRemoveTask(int i)
+{
+    if (TaskList[i].fP == 0)
+    {
+        return NothingFound;
+    }
+    TaskList[i].fP = 0;
+    TaskList[i].Delay = 0;
+    TaskList[i].Period = 0;
+    TaskList[i].RunMe = 0;
+    return i;
+}
+
+void SCHDispatch()
+{
+debug.printf("Entered Dispatch");
+int i = 0;
+    for (i = 0; i <NumTask; i++)
+    {
+        if (TaskList[i].RunMe > 0)
+        {
+            TaskList[i].fP();
+            TaskList[i].RunMe--;
+        }
+    }
+} 
+
+void SCHUpdate()
+{
+debug.printf("Interrupted \n \r");
+int i = 0;
+for (i = 0; i < NumTask; i++) //run through the whole tasklist array.
+    {
+        TaskList[i].Delay--;
+        if (TaskList[i].Delay <=0)
+            {
+                TaskList[i].RunMe++; //Add 1 to runme per timeout.
+                TaskList[i].Delay = TaskList[i].Period; //reset the timeout to the period.
+            }
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 823a9a4db739 OS.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OS.h	Thu Oct 27 22:01:30 2011 +0000
@@ -0,0 +1,15 @@
+#ifndef OS_H_GUARD
+#define OS_H_GUARD
+#include "mbed.h"
+typedef struct {
+   void(*fP)(void);
+   int    Delay;
+   int    Period;
+   int    RunMe;
+}pTask; //The Task List array structure
+
+void SCHUpdate();
+void SCHDispatch();
+int SCHRemoveTask(int i);
+int SCHAddTask(void(*fP)(void), int P, int D);
+#endif
\ No newline at end of file
diff -r 000000000000 -r 823a9a4db739 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Oct 27 22:01:30 2011 +0000
@@ -0,0 +1,34 @@
+#include "mbed.h"
+//#include "ITG3200.h"
+Serial debug(USBTX, USBRX); // tx, rx
+//#include "Debug.h"
+//#include "Globals.h"
+#include "Constants.h"
+#include "Ledtask.h"
+//#include "Ledtask.c"
+//#include "Gyrotask.h"
+//#include "Gyrotask.c"
+#include "OS.h"
+//#include "OS.c"
+
+
+Ticker interrupt;
+
+
+int main() 
+{
+debug.printf("ticker start");
+void Led1Init();
+debug.printf("LED1InitComplete \n \r");
+interrupt.attach(&SCHUpdate, 1); //Starting up the ticker for SCHUpdate.
+debug.printf("Interrupt Started \n \r");
+SCHAddTask(Led1Run,1,1); //adding our LED task.
+//SCHAddTask(Gyrotask,0.2,0.2); //adding the Gyro Task.
+debug.printf("Task Added \n \r");
+    
+    while(1) 
+    {
+        SCHDispatch();
+    }
+}
+
diff -r 000000000000 -r 823a9a4db739 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Oct 27 22:01:30 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912