load testing EthernetInterface

Dependencies:   EthernetInterface mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
okini3939
Date:
Fri Jan 17 13:58:36 2014 +0000
Parent:
0:09101c438a45
Commit message:
fix reference count

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Jan 17 09:12:56 2014 +0000
+++ b/main.cpp	Fri Jan 17 13:58:36 2014 +0000
@@ -7,7 +7,7 @@
 EthernetInterface eth;
 
 volatile int count = 0, num = 0, reset = 0;
-volatile int ref = 0, refreset = 0; // no rtos = 8727224
+volatile int ref = 123456; // no rtos = 8727224
 
 extern "C"
 void os_idle_demon (void) {
@@ -24,21 +24,14 @@
 void isr_timer () {
     num = count;
     reset = 1;
-    refreset = 1;
     myled = 1;
 }
 
-void real_count (void const *args) {
-    while (!refreset);
-    refreset = 0;
+void dummy_task (const void *args) {
+    volatile int w;
     for (;;) {
-        if (refreset) {
-            count = 0;
-            refreset = 0;
-            break;
-        } else {
-            ref ++;
-        }
+        for (w = 0; w < 10000; w ++);
+        Thread::wait(10);
     }
 }
 
@@ -52,9 +45,20 @@
     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);
+    while (!num) {
+        Thread::wait(100);
+    }
+    pc.printf("   dummy %d%0.1f dummy      \r\n", num, (float)num / ref * 100);
+    num = 0;
+    for (;;) {
+        if (num) {
+            pc.printf("reference count: %d /sec\r\n", num);
+            ref = num;
+            num = 0;
+            break;
+        }
+        Thread::wait(100);
+    }
 
     pc.printf("ethernet...\r\n");
     eth.init(); //Use DHCP
@@ -64,10 +68,12 @@
     }
     pc.printf("IP: %s\r\n", eth.getIPAddress());
 
+//    Thread thread1(dummy_task);
+
     num = 0;
     for (;;) {
         if (num) {
-            pc.printf("idle count: %d / sec (%0.1f %%)\r\n", num, (float)num / ref * 100);
+            pc.printf("idle count: %d /sec (%0.1f %%)\r\n", num, (float)num / ref * 100);
             num = 0;
             myled = 0;
         }