Colin Hogben / Mbed OS k64f-net-leak

Files at this revision

API Documentation at this revision

Comitter:
Colin Hogben
Date:
Mon Oct 24 12:42:04 2016 +0100
Parent:
0:7bf6075ca76a
Commit message:
First version

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Oct 24 10:49:11 2016 +0000
+++ b/main.cpp	Mon Oct 24 12:42:04 2016 +0100
@@ -1,3 +1,70 @@
-int main(void) {
-    return 0;
-}
\ No newline at end of file
+//=======================================================================
+//      Demonstrate memory leak in k64f ethernet driver
+//=======================================================================
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "lwip/stats.h"
+
+// Configuration
+#define DEST_IP "192.168.3.1"           // Where to send UDP packets
+#define DEST_PORT 4009
+#define NBIG 8                         // How many big packets in burst
+#define NSMALL 12                       // How many small packets in burst
+
+EthernetInterface eth;
+SocketAddress dest;
+UDPSocket sock;
+char data[1400] = {0};
+
+// Send a burst of COUNT packets, each of SIZE bytes
+// Return number sent before memory error
+int burst(int count, size_t size) {
+    int num;
+    for (num = 0; num < count; num++) {
+        int err = sock.sendto(dest, data, size);
+        if (err == NSAPI_ERROR_NO_MEMORY) {
+            break;
+        } else if (err < 0) {
+            printf("sendto(%u): %d\n", size, err);
+            break;
+        }
+        data[0] ++;
+    }
+    return num;
+}
+
+int main() {
+    printf("k64f-net-leak\n");
+    int err = eth.connect();
+    if (err < 0) {
+        printf("eth.connect: %d\n", err);
+        return 1;
+    }
+
+    err = sock.open(&eth);
+    if (err < 0) {
+        printf("sock.open: %d\n", err);
+        return 1;
+    }
+
+    dest = SocketAddress(DEST_IP, DEST_PORT);
+
+#if PRIME_ARP
+    // First packet is slightly special, since ARP request needed first
+    burst(1, 10);
+#endif
+
+    //wait_ms(20);
+
+    while (1) {
+        // If enabled by macros in mbed_app.json, show lwip memory usage
+        MEM_STATS_DISPLAY();
+
+        // Stuff some big packets into the ring buffer
+        int big = burst(NBIG, 1400);
+        // See if we can overwrite them
+        int small = burst(NSMALL, 20);
+        printf("big=%d small=%d\n", big, small);
+        wait(1.0);
+    }
+}
--- a/mbed-os.lib	Mon Oct 24 10:49:11 2016 +0000
+++ b/mbed-os.lib	Mon Oct 24 12:42:04 2016 +0100
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/mbed-os/#a6f3fd1a60d5df59246d7caf3f108c4d34e1808e
+https://github.com/ARMmbed/mbed-os/#de41409830b3b0a254723ee6bc7e994b3ea13980
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json	Mon Oct 24 12:42:04 2016 +0100
@@ -0,0 +1,11 @@
+{
+    "macros": ["LWIP_DEBUG", "LWIP_STATS=1", "LWIP_STATS_DISPLAY=1"],
+    "config": {
+	"NB": "Version breakage below: use core.* for 5.1, platform.* for 5.2"
+    },
+    "target_overrides": {
+	"*": {
+	    "platform.stdio-convert-newlines": true
+	}
+    }
+}