load testing EthernetInterface

Dependencies:   EthernetInterface mbed-rtos mbed

Revision:
0:09101c438a45
Child:
1:321b8f934993
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jan 17 09:12:56 2014 +0000
@@ -0,0 +1,76 @@
+#include "mbed.h"
+#include "rtos.h"
+#include "EthernetInterface.h"
+
+Serial pc(USBTX, USBRX);
+DigitalOut myled(LED1);
+EthernetInterface eth;
+
+volatile int count = 0, num = 0, reset = 0;
+volatile int ref = 0, refreset = 0; // no rtos = 8727224
+
+extern "C"
+void os_idle_demon (void) {
+    for (;;) {
+        if (reset) {
+            count = 0;
+            reset = 0;
+        } else {
+            count ++;
+        }
+    }
+}
+
+void isr_timer () {
+    num = count;
+    reset = 1;
+    refreset = 1;
+    myled = 1;
+}
+
+void real_count (void const *args) {
+    while (!refreset);
+    refreset = 0;
+    for (;;) {
+        if (refreset) {
+            count = 0;
+            refreset = 0;
+            break;
+        } else {
+            ref ++;
+        }
+    }
+}
+
+int main() {
+    Ticker timer;
+
+    pc.baud(115200);
+    pc.printf("LOAD TESTING\r\n");
+    pc.printf("system clock: %d\r\n", SystemCoreClock);
+
+    timer.attach(&isr_timer, 1);
+
+    pc.printf("wait...\r\n");
+    Thread thread(real_count, NULL, osPriorityRealtime);
+    while (! ref);
+    pc.printf("reference count: %d / sec\r\n", ref);
+
+    pc.printf("ethernet...\r\n");
+    eth.init(); //Use DHCP
+    if (eth.connect()) {
+        pc.printf("error\r\n");
+        return -1;
+    }
+    pc.printf("IP: %s\r\n", eth.getIPAddress());
+
+    num = 0;
+    for (;;) {
+        if (num) {
+            pc.printf("idle count: %d / sec (%0.1f %%)\r\n", num, (float)num / ref * 100);
+            num = 0;
+            myled = 0;
+        }
+        Thread::wait(100);
+    }
+}