program to test a possible memory leak when using NTP
Dependencies: NetServices mbed
main.cpp@0:3986c9f76b09, 2010-12-22 (annotated)
- Committer:
- hlipka
- Date:
- Wed Dec 22 10:10:39 2010 +0000
- Revision:
- 0:3986c9f76b09
- Child:
- 1:07158ff709d6
initial version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hlipka | 0:3986c9f76b09 | 1 | #include "mbed.h" |
hlipka | 0:3986c9f76b09 | 2 | |
hlipka | 0:3986c9f76b09 | 3 | #include "EthernetNetIf.h" |
hlipka | 0:3986c9f76b09 | 4 | #include "NTPClient.h" |
hlipka | 0:3986c9f76b09 | 5 | |
hlipka | 0:3986c9f76b09 | 6 | #include "AvailableMemory.h" |
hlipka | 0:3986c9f76b09 | 7 | |
hlipka | 0:3986c9f76b09 | 8 | LocalFileSystem local("local"); |
hlipka | 0:3986c9f76b09 | 9 | |
hlipka | 0:3986c9f76b09 | 10 | void updateTime() |
hlipka | 0:3986c9f76b09 | 11 | { |
hlipka | 0:3986c9f76b09 | 12 | time_t ctTime; |
hlipka | 0:3986c9f76b09 | 13 | time(&ctTime); |
hlipka | 0:3986c9f76b09 | 14 | printf("Current time is (UTC): %s\n", ctime(&ctTime)); |
hlipka | 0:3986c9f76b09 | 15 | |
hlipka | 0:3986c9f76b09 | 16 | NTPClient ntp; |
hlipka | 0:3986c9f76b09 | 17 | Host server(IpAddr(), 123, "0.de.pool.ntp.org"); |
hlipka | 0:3986c9f76b09 | 18 | ntp.setTime(server); |
hlipka | 0:3986c9f76b09 | 19 | |
hlipka | 0:3986c9f76b09 | 20 | printf("set time ok\n"); |
hlipka | 0:3986c9f76b09 | 21 | time(&ctTime); |
hlipka | 0:3986c9f76b09 | 22 | printf("Current time is (UTC): %s\n", ctime(&ctTime)); |
hlipka | 0:3986c9f76b09 | 23 | |
hlipka | 0:3986c9f76b09 | 24 | } |
hlipka | 0:3986c9f76b09 | 25 | |
hlipka | 0:3986c9f76b09 | 26 | int main() { |
hlipka | 0:3986c9f76b09 | 27 | printf("calculate free mem 1\n"); |
hlipka | 0:3986c9f76b09 | 28 | int i=AvailableMemory(1,0x8000,false); |
hlipka | 0:3986c9f76b09 | 29 | printf("free mem=%i\n",i); |
hlipka | 0:3986c9f76b09 | 30 | |
hlipka | 0:3986c9f76b09 | 31 | // void* p1=malloc(8000); |
hlipka | 0:3986c9f76b09 | 32 | // void* p2=malloc(8000); |
hlipka | 0:3986c9f76b09 | 33 | |
hlipka | 0:3986c9f76b09 | 34 | printf("calculate free mem 2\n"); |
hlipka | 0:3986c9f76b09 | 35 | i=AvailableMemory(1,0x8000,false); |
hlipka | 0:3986c9f76b09 | 36 | printf("free mem=%i\n",i); |
hlipka | 0:3986c9f76b09 | 37 | |
hlipka | 0:3986c9f76b09 | 38 | printf("setup\n"); |
hlipka | 0:3986c9f76b09 | 39 | EthernetNetIf eth; |
hlipka | 0:3986c9f76b09 | 40 | EthernetErr ethErr; |
hlipka | 0:3986c9f76b09 | 41 | printf("Setting up...\n"); |
hlipka | 0:3986c9f76b09 | 42 | do { |
hlipka | 0:3986c9f76b09 | 43 | ethErr = eth.setup(); |
hlipka | 0:3986c9f76b09 | 44 | if (ethErr) printf("waiting for network...\n", ethErr); |
hlipka | 0:3986c9f76b09 | 45 | } while (ethErr != ETH_OK); |
hlipka | 0:3986c9f76b09 | 46 | |
hlipka | 0:3986c9f76b09 | 47 | printf("setup ok\n"); |
hlipka | 0:3986c9f76b09 | 48 | |
hlipka | 0:3986c9f76b09 | 49 | printf("calculate free mem 3\n"); |
hlipka | 0:3986c9f76b09 | 50 | i=AvailableMemory(1,0x8000,false); |
hlipka | 0:3986c9f76b09 | 51 | printf("free mem=%i\n",i); |
hlipka | 0:3986c9f76b09 | 52 | printf("calculate free mem 3\n"); |
hlipka | 0:3986c9f76b09 | 53 | i=AvailableMemory(1,0x8000,false); |
hlipka | 0:3986c9f76b09 | 54 | printf("free mem=%i\n",i); |
hlipka | 0:3986c9f76b09 | 55 | |
hlipka | 0:3986c9f76b09 | 56 | updateTime(); |
hlipka | 0:3986c9f76b09 | 57 | |
hlipka | 0:3986c9f76b09 | 58 | // free(p1); |
hlipka | 0:3986c9f76b09 | 59 | // free(p2); |
hlipka | 0:3986c9f76b09 | 60 | printf("calculate free mem 4\n"); |
hlipka | 0:3986c9f76b09 | 61 | i=AvailableMemory(1,0x100,false); |
hlipka | 0:3986c9f76b09 | 62 | printf("free mem=%i\n",i); |
hlipka | 0:3986c9f76b09 | 63 | } |