Colour sensors calibrated

Dependencies:   mbed-rtos mbed Servo QEI

Fork of ICRSEurobot13 by Thomas Branch

Revision:
29:4e20b44251c6
Child:
43:6504d85d85b4
diff -r 664e81033846 -r 4e20b44251c6 System/system.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/System/system.cpp	Wed Apr 10 04:20:40 2013 +0000
@@ -0,0 +1,34 @@
+
+#include "rtos.h"
+#include "mbed.h"
+#include "Printing.h"
+
+Timer SystemTime;
+
+Ticker CPUIdleMeasureTicker;
+volatile unsigned int nopctr = 0;
+const float s_per_nopcycle = 1.0f/24000000.0f;
+
+float CpuUsage = 0;
+
+void nopwait(int ms){
+while(ms--)
+    for (volatile int i = 0; i < 24000; i++);
+}
+
+void PostAndResetCPUIdle(){
+    CpuUsage = 1.0f - (s_per_nopcycle * nopctr);
+    Printing::updateval(10,CpuUsage);
+    nopctr = 0;
+}
+
+void measureCPUidle (void const*){
+    
+    osThreadSetPriority (osThreadGetId(), osPriorityIdle);
+    Printing::registerID(10, 1);
+    
+    CPUIdleMeasureTicker.attach(PostAndResetCPUIdle, 1);
+    
+    while(1)
+        nopctr++;
+}