Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: PicoTCP lpc1768-picotcp-eth mbed-rtos mbed
Revision 6:e7d71e575d37, committed 2013-10-07
- Comitter:
- tass
- Date:
- Mon Oct 07 10:43:36 2013 +0000
- Parent:
- 5:7a73a14f5e85
- Commit message:
- Added new memory and stack measure mechanism.
Changed in this revision
--- a/PicoTCP.lib Fri Sep 06 10:11:46 2013 +0000 +++ b/PicoTCP.lib Mon Oct 07 10:43:36 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/daniele/code/PicoTCP/#734099a8df4e +http://mbed.org/users/daniele/code/PicoTCP/#478be2fd92ac
--- a/main.cpp Fri Sep 06 10:11:46 2013 +0000
+++ b/main.cpp Mon Oct 07 10:43:36 2013 +0000
@@ -1,87 +1,55 @@
+/*
+* To enable stack measurement go to pico_mbed.h and add
+* #define PICO_MEASURE_STACK
+* to read the current number of free stack words (integers) call stack_get_free_words
+*
+* To enable memory measurement go to pico_mbed.h and add
+* #define MEMORY_MEASURE
+*/
+
#include <mbed.h>
#include <stdarg.h>
#include "EthernetInterface.h"
+extern "C"
+{
+ #include "pico_mbed.h"
+#ifdef MEMORY_MEASURE
+ uint32_t max_mem;
+ uint32_t cur_mem;
+#endif
+}
+
#define ECHO_SERVER_PORT 7
#define BUFFER_QUANTITY (1024*1024)
-struct MemoryUsage
-{
- uint32_t curFreeRam;
- uint32_t minFreeRam;
- uint32_t maxFreeRam;
- uint32_t avgFreeRam;
- uint32_t stackPointer;
- uint32_t cntSamples;
-};
+//#define printf(...) do{}while(0)
-struct MemoryUsage memoryStats = {0,0xFFFFFFFF,0,0,0};
-
-int fakePrintf(void* pvHeapInfo, char const* pFormatString, ...)
+void printMemoryStats(void)
{
- struct MemoryUsage * memStat = (struct MemoryUsage *)pvHeapInfo;
- static const char* freeRamFormat = "%d bytes in";
- va_list valist;
-
- if(memcmp(pFormatString,freeRamFormat,strlen(freeRamFormat)) == 0)
- {
- va_start(valist, pFormatString);
- unsigned long freeSize = va_arg(valist, unsigned long);
- memStat->curFreeRam = freeSize;
- if(memStat->minFreeRam > freeSize)
- memStat->minFreeRam = freeSize;
-
- if(memStat->maxFreeRam < freeSize)
- memStat->maxFreeRam = freeSize;
-
- memStat->avgFreeRam = ((memStat->avgFreeRam * memStat->cntSamples) + freeSize)/(++memStat->cntSamples);
- }
- else
- {
- // ignore format
- }
- return 0;
-}
+#ifdef PICO_MEASURE_STACK
+ printf("******** Stack Statistics\n");
+ printf("Current free stack : %d bytes\n",stack_get_free_words()*sizeof(int));
+ printf("Total stack size : %d bytes\n",STACK_TOTAL_WORDS*sizeof(int));
+ printf("Used : %.2f %%\n",100.0*(float)(STACK_TOTAL_WORDS-stack_get_free_words())/STACK_TOTAL_WORDS);
+#endif
-void inline printMemoryStats(void)
-{
- if(memoryStats.cntSamples == 1)
- printf("\n\n***** Initial Memory Report *****\n");
- else
- printf("\n\n********* Memory Report *********\n");
-
- printf("Current free memory : %d bytes\n",memoryStats.curFreeRam);
- printf("Maximum free memory : %d bytes\n",memoryStats.maxFreeRam);
- printf("Minimum free memory : %d bytes\n",memoryStats.minFreeRam);
- printf("Average free memory : %d bytes\n",memoryStats.avgFreeRam);
- printf("Stack pointer address : %d\n",memoryStats.stackPointer);
- printf("****************************\n");
-}
-
-void inline memoryStamp(void)
-{
- __heapstats((__heapprt)fakePrintf, &memoryStats);
-}
-
-void inline stackPtrSnapshot(void)
-{
- memoryStats.stackPointer = __current_sp();
+#ifdef MEMORY_MEASURE
+ printf("******** Memory Statistics\n");
+ printf("Current used memory : %d bytes\n",cur_mem);
+ printf("Maximum used memory : %d bytes\n",max_mem);
+#endif
}
int main() {
printf("Ethernet Interface memory test....\n");
- // Initial memory status
- memoryStamp();
- stackPtrSnapshot(); // snapshot of the stack pointer before starting benchmark to see the SP.
- printMemoryStats();
-
EthernetInterface eth;
int connections = 0;
- //eth.init("192.168.100.12","255.255.255.0","192.168.100.2"); //Use DHCP
eth.init();
- eth.connect();
+ printf("Waiting for DHCP to give IP\n");
+ while(eth.connect() != 0);
printf("IP Address %s\n", eth.getIPAddress());
TCPSocketServer server;
@@ -101,7 +69,6 @@
int dataReceived = 0;
int dataSent = 0;
- printf("\n\n\nStarting the receiving part...\n");
while(dataReceived < BUFFER_QUANTITY)
{
int n = client.receive(buffer, sizeof(buffer));
@@ -110,21 +77,15 @@
break;
}
dataReceived += n;
- memoryStamp();
}
-
- printf("Received : %d bytes\nExpected : %d bytes\n",dataReceived,BUFFER_QUANTITY);
if(dataReceived < BUFFER_QUANTITY)
{
printf("Receiving part of the test has failed. Exiting connection.\n");
+ printf("Received : %d bytes\nExpected : %d bytes\n",dataReceived,BUFFER_QUANTITY);
break;
}
- else{
- printf("Receiving has passed...\n");
- }
- printf("\n\n\nStarting the sending part...\n");
while(dataSent < BUFFER_QUANTITY)
{
int n = client.send_all(buffer, sizeof(buffer));
@@ -133,22 +94,16 @@
break;
}
dataSent += n;
- memoryStamp();
}
- printf("Sent : %d bytes\nExpected : %d bytes\n",dataSent,BUFFER_QUANTITY);
if(dataSent < BUFFER_QUANTITY)
{
printf("Sending part of the test has failed. Exiting connection.\n");
+ printf("Sent : %d bytes\nExpected : %d bytes\n",dataSent,BUFFER_QUANTITY);
+
break;
}
- else
- {
- printf("Sending test has passed...\n");
- }
-
- printf("\n\n\nStarting echo part...\n");
dataReceived = dataSent = 0;
while((dataReceived+dataSent) < 2*BUFFER_QUANTITY)
{
@@ -165,20 +120,17 @@
break;
}
dataSent += n;
- memoryStamp();
}
- printf("Echo size : %d bytes\nExpected : %d bytes\n",(dataReceived+dataSent),2*BUFFER_QUANTITY);
if((dataReceived+dataSent) < 2*BUFFER_QUANTITY)
{
+ printf("Echo size : %d bytes\nExpected : %d bytes\n",(dataReceived+dataSent),2*BUFFER_QUANTITY);
printf("Echo test has failed.Exiting connection...\n");
}
- else
- {
- printf("Echo test has passed...\n");
- }
+
break;
}
+
client.close();
printf("Test was finished...\n");
printMemoryStats();
--- a/mbed-rtos.lib Fri Sep 06 10:11:46 2013 +0000 +++ b/mbed-rtos.lib Mon Oct 07 10:43:36 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/#869ef732a8a2 +http://mbed.org/users/mbed_official/code/mbed-rtos/#ee87e782d34f
