diff --git a/03_m1284p_WIZNET_loopback_STATIC_IP/Application/loopback/loopback.c b/03_m1284p_WIZNET_loopback_STATIC_IP/Application/loopback/loopback.c index a921092..8396cf7 100644 --- a/03_m1284p_WIZNET_loopback_STATIC_IP/Application/loopback/loopback.c +++ b/03_m1284p_WIZNET_loopback_STATIC_IP/Application/loopback/loopback.c @@ -24,13 +24,13 @@ int32_t loopback_tcps(uint8_t sn, uint8_t* buf, uint16_t port) getSn_DIPR(sn, destip); destport = getSn_DPORT(sn); - printf("%d:Connected - %d.%d.%d.%d : %d\r\n",sn, destip[0], destip[1], destip[2], destip[3], destport); + PRINTF("%d:Connected - %d.%d.%d.%d : %u\r\n",sn, destip[0], destip[1], destip[2], destip[3], destport); #endif setSn_IR(sn,Sn_IR_CON); } if((size = getSn_RX_RSR(sn)) > 0) // Don't need to check SOCKERR_BUSY because it doesn't not occur. { - if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE; + if(size > LOOPBACK_DATA_BUF_SIZE) size = LOOPBACK_DATA_BUF_SIZE; ret = recv(sn, buf, size); if(ret <= 0) return ret; // check SOCKERR_BUSY & SOCKERR_XXX. For showing the occurrence of SOCKERR_BUSY. @@ -55,12 +55,12 @@ int32_t loopback_tcps(uint8_t sn, uint8_t* buf, uint16_t port) #endif if((ret = disconnect(sn)) != SOCK_OK) return ret; #ifdef _LOOPBACK_DEBUG_ - printf("%d:Socket Closed\r\n", sn); + PRINTF("%d:Socket Closed\r\n", sn); #endif break; case SOCK_INIT : #ifdef _LOOPBACK_DEBUG_ - printf("%d:Listen, TCP server loopback, port [%d]\r\n", sn, port); + PRINTF("%d:Listen, TCP server loopback, port [%u]\r\n", sn, port); #endif if( (ret = listen(sn)) != SOCK_OK) return ret; break; @@ -102,7 +102,7 @@ int32_t loopback_tcpc(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destpo if(getSn_IR(sn) & Sn_IR_CON) // Socket n interrupt register mask; TCP CON interrupt = connection with peer is successful { #ifdef _LOOPBACK_DEBUG_ - printf("%d:Connected to - %d.%d.%d.%d : %d\r\n",sn, destip[0], destip[1], destip[2], destip[3], destport); + PRINTF("%d:Connected to - %d.%d.%d.%d : %u\r\n",sn, destip[0], destip[1], destip[2], destip[3], destport); #endif setSn_IR(sn, Sn_IR_CON); // this interrupt should be write the bit cleared to '1' } @@ -112,7 +112,7 @@ int32_t loopback_tcpc(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destpo ////////////////////////////////////////////////////////////////////////////////////////////// if((size = getSn_RX_RSR(sn)) > 0) // Sn_RX_RSR: Socket n Received Size Register, Receiving data length { - if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE; // DATA_BUF_SIZE means user defined buffer size (array) + if(size > LOOPBACK_DATA_BUF_SIZE) size = LOOPBACK_DATA_BUF_SIZE; // LOOPBACK_DATA_BUF_SIZE means user defined buffer size (array) ret = recv(sn, buf, size); // Data Receive process (H/W Rx socket buffer -> User's buffer) if(ret <= 0) return ret; // If the received data length <= 0, receive failed and process end @@ -140,13 +140,13 @@ int32_t loopback_tcpc(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destpo #endif if((ret=disconnect(sn)) != SOCK_OK) return ret; #ifdef _LOOPBACK_DEBUG_ - printf("%d:Socket Closed\r\n", sn); + PRINTF("%d:Socket Closed\r\n", sn); #endif break; case SOCK_INIT : #ifdef _LOOPBACK_DEBUG_ - printf("%d:Try to connect to the %d.%d.%d.%d : %d\r\n", sn, destip[0], destip[1], destip[2], destip[3], destport); + PRINTF("%d:Try to connect to the %d.%d.%d.%d : %u\r\n", sn, destip[0], destip[1], destip[2], destip[3], destport); #endif if( (ret = connect(sn, destip, destport)) != SOCK_OK) return ret; // Try to TCP connect to the TCP server (destination) break; @@ -181,12 +181,12 @@ int32_t loopback_udps(uint8_t sn, uint8_t* buf, uint16_t port) case SOCK_UDP : if((size = getSn_RX_RSR(sn)) > 0) { - if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE; + if(size > LOOPBACK_DATA_BUF_SIZE) size = LOOPBACK_DATA_BUF_SIZE; ret = recvfrom(sn, buf, size, destip, (uint16_t*)&destport); if(ret <= 0) { #ifdef _LOOPBACK_DEBUG_ - printf("%d: recvfrom error. %ld\r\n",sn,ret); + PRINTF("%d: recvfrom error. %ld\r\n",sn,ret); #endif return ret; } @@ -198,7 +198,7 @@ int32_t loopback_udps(uint8_t sn, uint8_t* buf, uint16_t port) if(ret < 0) { #ifdef _LOOPBACK_DEBUG_ - printf("%d: sendto error. %ld\r\n",sn,ret); + PRINTF("%d: sendto error. %ld\r\n",sn,ret); #endif return ret; } @@ -213,7 +213,7 @@ int32_t loopback_udps(uint8_t sn, uint8_t* buf, uint16_t port) if((ret = socket(sn, Sn_MR_UDP, port, 0x00)) != sn) return ret; #ifdef _LOOPBACK_DEBUG_ - printf("%d:Opened, UDP loopback, port [%d]\r\n", sn, port); + PRINTF("%d:Opened, UDP loopback, port [%u]\r\n", sn, port); #endif break; default : diff --git a/03_m1284p_WIZNET_loopback_STATIC_IP/Application/loopback/loopback.h b/03_m1284p_WIZNET_loopback_STATIC_IP/Application/loopback/loopback.h index 8f5a3d6..5df3cff 100644 --- a/03_m1284p_WIZNET_loopback_STATIC_IP/Application/loopback/loopback.h +++ b/03_m1284p_WIZNET_loopback_STATIC_IP/Application/loopback/loopback.h @@ -6,13 +6,15 @@ extern "C" { #endif #include +#include +#include "../../globals.h" /* Loopback test debug message printout enable */ #define _LOOPBACK_DEBUG_ /* DATA_BUF_SIZE define for Loopback example */ -#ifndef DATA_BUF_SIZE - #define DATA_BUF_SIZE 2048 +#ifndef LOOPBACK_DATA_BUF_SIZE + #define LOOPBACK_DATA_BUF_SIZE 512 #endif /************************/ diff --git a/03_m1284p_WIZNET_loopback_STATIC_IP/globals.h b/03_m1284p_WIZNET_loopback_STATIC_IP/globals.h index e71ae1d..25410eb 100644 --- a/03_m1284p_WIZNET_loopback_STATIC_IP/globals.h +++ b/03_m1284p_WIZNET_loopback_STATIC_IP/globals.h @@ -29,9 +29,11 @@ static FATFS Fatfs; //File system object for each logical drive. >= 2 //******************************* Fat FS declare related: END -#define HTTPD_MAX_BUF_SIZE 2048 //For Mega1284p(16kb RAM)/Mega2560(8kb RAM) +//#define HTTPD_MAX_BUF_SIZE 2048 //For Mega1284p(16kb RAM)/Mega2560(8kb RAM) //#define HTTPD_MAX_BUF_SIZE MAX_URI_SIZE+10 //For Mega644p(4kb RAM)/Mega128(4kb RAM) (ie. 512+10=522 bytes look at httpParser.h <_st_http_request> definition) +#define LOOPBACK_DATA_BUF_SIZE 512 + #define PRINTF_EN 1 #if PRINTF_EN #define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args) @@ -66,4 +68,7 @@ extern const char str_prog_name[] PROGMEM; extern wiz_NetInfo netInfo; +#define CHK_RAM_LEAKAGE +#define CHK_UPTIME + #endif /* GLOBALS_H_ */ diff --git a/03_m1284p_WIZNET_loopback_STATIC_IP/main.c b/03_m1284p_WIZNET_loopback_STATIC_IP/main.c index 690a7b0..931700c 100644 --- a/03_m1284p_WIZNET_loopback_STATIC_IP/main.c +++ b/03_m1284p_WIZNET_loopback_STATIC_IP/main.c @@ -210,7 +210,7 @@ uint16_t adc_read(uint8_t channel) #define PORT_TCPS 5000 #define PORT_UDPS 3000 -#define ETH_MAX_BUF_SIZE 2048 +#define ETH_MAX_BUF_SIZE LOOPBACK_DATA_BUF_SIZE unsigned char ethBuf0[ETH_MAX_BUF_SIZE]; unsigned char ethBuf1[ETH_MAX_BUF_SIZE]; @@ -329,6 +329,7 @@ int main() /* Loopback Test: TCP Server and UDP */ // Test for Ethernet data transfer validation uint32_t timer_link_1sec = millis(); + uint32_t timer_uptime_60sec = millis(); while(1) { //Here at least every 1sec @@ -358,6 +359,20 @@ int main() } } + if((millis()-timer_uptime_60sec)> 60000) + { + //here every 60 sec + timer_uptime_60sec = millis(); +#ifdef CHK_RAM_LEAKAGE + //Printout RAM usage every 1 minute + PRINTF(">> Free RAM is: %d bytes\r\n", freeRam()); +#endif + +#ifdef CHK_UPTIME + //Printout RAM usage every 1 minute + PRINTF(">> Uptime %lu sec\r\n", millis()/1000); +#endif + } } return 0; } diff --git a/04_m1284p_WIZNET_loopback_DHCP/main.c b/04_m1284p_WIZNET_loopback_DHCP/main.c index 8699cdb..21772d8 100644 --- a/04_m1284p_WIZNET_loopback_DHCP/main.c +++ b/04_m1284p_WIZNET_loopback_DHCP/main.c @@ -298,8 +298,8 @@ void my_ip_assign(void) // Display_Net_Conf(); print_network_information(); #if 1 - printf("DHCP LEASED TIME : %ld Sec.\r\n", getDHCPLeasetime()); - printf("\r\n"); + PRINTF("DHCP LEASED TIME : %ld Sec.\r\n", getDHCPLeasetime()); + PRINTF("\r\n"); #endif } @@ -395,6 +395,7 @@ int main() //Every 1min print-out DHCP leased time elapse #ifdef _DHCP_LEASED_TIME_DEBUG_ PRINTF("DHCP LEASED TIME elapse: %lu Sec.\r\n", timer_dhcp_1sec_count ); + PRINTF("DHCP LEASED TIME : %ld Sec.\r\n", getDHCPLeasetime()); #endif } }