Eurobot system lib

Files at this revision

API Documentation at this revision

Comitter:
narshu
Date:
Thu Apr 26 19:40:58 2012 +0000
Commit message:

Changed in this revision

system.cpp Show annotated file Show diff for this revision Revisions of this file
system.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r b35c6c9aad45 system.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/system.cpp	Thu Apr 26 19:40:58 2012 +0000
@@ -0,0 +1,23 @@
+#include "system.h"
+
+//Defining the externs
+DigitalOut     OLED1(LED1);
+DigitalOut     OLED2(LED2);
+DigitalOut     OLED3(LED3);
+DigitalOut     OLED4(LED4);
+
+float cpupercent; //defining the extern
+void measureCPUidle (void const* arg) {
+    
+    Timer timer;
+    cpupercent = 0; //defined in system.h
+    
+    while(1) {
+        timer.reset();
+        timer.start();
+        wait(1);
+        
+        int thistime = timer.read_us()-1000000;
+        cpupercent = thistime;
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r b35c6c9aad45 system.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/system.h	Thu Apr 26 19:40:58 2012 +0000
@@ -0,0 +1,48 @@
+
+#ifndef SYSTEM_H
+#define SYSTEM_H
+
+#include "globals.h"
+#include "rtos.h"
+
+//Declaring the onboard LED's for everyone to use
+extern DigitalOut     OLED1;//(LED1);
+extern DigitalOut     OLED2;//(LED2);
+extern DigitalOut     OLED3;//(LED3);
+extern DigitalOut     OLED4;//(LED4);
+
+//a type which is a pointer to a rtos thread function
+typedef void (*tfuncptr_t)(void const *argument);
+
+//---------------------
+//Signal ticker stuff
+#define SIGTICKARGS(thread, signal) \
+    (tfuncptr_t) (&Signalsetter::callback), osTimerPeriodic, (void*)(new Signalsetter(thread, signal))
+
+class Signalsetter {
+public:
+    Signalsetter(Thread& inthread, int insignal) :
+            thread(inthread) {
+        signal = insignal;
+        //pc.printf("ptr saved as %#x \r\n", (int)(&(inthread)));
+    }
+
+    static void callback(void* thisin) {
+
+        Signalsetter* fthis = (Signalsetter*)thisin;
+        //pc.printf("callback will signal thread object at %#x \r\n", (int)(&(fthis->thread)));
+        fthis->thread.signal_set(fthis->signal);
+        //delete fthis; //this is useful for single fire tickers!
+    }
+
+private:
+    Thread& thread;
+    int signal;
+};
+
+//---------------------
+//cpu usage measurement function
+extern float cpupercent;
+void measureCPUidle (void const* arg);
+
+#endif