From 9830c45105339840b3fb1b67687567d5a97b03d4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 25 Oct 2013 15:48:11 -0600 Subject: apps/examples/cc3000 updated by David Sidrane --- apps/examples/cc3000/Makefile | 4 +- apps/examples/cc3000/board.c | 2 +- apps/examples/cc3000/cc3000basic.c | 96 ++++++++++++++++++++++++++++++++--- apps/examples/cc3000/shell.c | 9 +++- apps/examples/cc3000/shell.h | 4 +- apps/examples/cc3000/telnetd_daemon.c | 17 ++----- 6 files changed, 107 insertions(+), 25 deletions(-) (limited to 'apps/examples/cc3000') diff --git a/apps/examples/cc3000/Makefile b/apps/examples/cc3000/Makefile index bf6bcc43f..37910b841 100644 --- a/apps/examples/cc3000/Makefile +++ b/apps/examples/cc3000/Makefile @@ -41,11 +41,11 @@ include $(APPDIR)/Make.defs APPNAME = c3b PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 2048 +STACKSIZE = 660 APPNAME1 = shell PRIORITY1 = SCHED_PRIORITY_DEFAULT -STACKSIZE1 = 2048 +STACKSIZE1 = 980 # Hello, World! Example diff --git a/apps/examples/cc3000/board.c b/apps/examples/cc3000/board.c index 009b56663..ff2a3c729 100644 --- a/apps/examples/cc3000/board.c +++ b/apps/examples/cc3000/board.c @@ -169,7 +169,7 @@ void CC3000_Init(void) once = true; } - CC3000_wlan_init( CC3000_AsyncCallback, + cc3000_wlan_init( CC3000_AsyncCallback, SendFirmwarePatch, SendDriverPatch, SendBootloaderPatch); diff --git a/apps/examples/cc3000/cc3000basic.c b/apps/examples/cc3000/cc3000basic.c index 73d8a4272..e72dbecb6 100644 --- a/apps/examples/cc3000/cc3000basic.c +++ b/apps/examples/cc3000/cc3000basic.c @@ -87,14 +87,17 @@ ****************************************************************************/ #include + #include "board.h" #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -127,16 +130,60 @@ void ShowInformation(void); #define US_PER_SEC 1000000 /**************************************************************************** - * Public Variables + * Private Data ****************************************************************************/ -uint8_t isInitialized = false; +static uint8_t isInitialized = false; + +#ifdef CONFIG_EXAMPLE_CC3000_MEM_CHECK +static struct mallinfo mmstart; +static struct mallinfo mmprevious; +#endif /**************************************************************************** - * Public Functions + * Private Functions ****************************************************************************/ -bool wait(long timeoutMs, volatile unsigned long *what, volatile unsigned long is) +#ifndef CONFIG_EXAMPLE_CC3000_MEM_CHECK +# define stkmon_disp() +#else +static void show_memory_usage(struct mallinfo *mmbefore, + struct mallinfo *mmafter) +{ + int diff; + + printf(" total used free largest\n"); + printf("Before:%11d%11d%11d%11d\n", + mmbefore->arena, mmbefore->uordblks, mmbefore->fordblks, mmbefore->mxordblk); + printf("After: %11d%11d%11d%11d\n", + mmafter->arena, mmafter->uordblks, mmafter->fordblks, mmafter->mxordblk); + + diff = mmbefore->uordblks - mmafter->uordblks; + if (diff < 0) + { + printf("Change:%11d allocated\n", -diff); + } + else if (diff > 0) + { + printf("Change:%11d freed\n", diff); + } + + stkmon_disp(); +} + +static void _stkmon_disp(FAR struct tcb_s *tcb, FAR void *arg) +{ +#if CONFIG_TASK_NAME_SIZE > 0 + syslog("%5d %6d %6d %s\n", + tcb->pid, tcb->adj_stack_size, up_check_tcbstack(tcb), tcb->name); +#else + syslog("%5d %6d %6d\n", + tcb->pid, tcb->adj_stack_size, up_check_tcbstack(tcb)); +#endif +} + +static bool wait(long timeoutMs, volatile unsigned long *what, + volatile unsigned long is) { long t_ms; struct timeval end, start; @@ -157,7 +204,8 @@ bool wait(long timeoutMs, volatile unsigned long *what, volatile unsigned long i return true; } -bool wait_on(long timeoutMs, volatile unsigned long *what, volatile unsigned long is,char * msg) +static bool wait_on(long timeoutMs, volatile unsigned long *what, + volatile unsigned long is, char * msg) { printf(msg); printf("..."); @@ -176,6 +224,21 @@ bool wait_on(long timeoutMs, volatile unsigned long *what, volatile unsigned lon return ret; } +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +void stkmon_disp(void) +{ +#if CONFIG_TASK_NAME_SIZE > 0 + syslog("%-5s %-6s %-6s %s\n", "PID", "SIZE", "USED", "THREAD NAME"); +#else + syslog("%-5s %-6s %-6s\n", "PID", "SIZE", "USED"); +#endif + sched_foreach(_stkmon_disp, NULL); +} +#endif + void AsyncEventPrint(void) { printf("\n"); @@ -283,7 +346,16 @@ int execute(int cmd) { Initialize(); } + +#ifdef CONFIG_EXAMPLE_CC3000_MEM_CHECK + mmprevious= mallinfo(); + show_memory_usage(&mmstart,&mmprevious); +#endif shell_main(0, 0); +#ifdef CONFIG_EXAMPLE_CC3000_MEM_CHECK + mmprevious= mallinfo(); + show_memory_usage(&mmstart,&mmprevious); +#endif break; case 'q': @@ -301,6 +373,12 @@ int execute(int cmd) void Initialize(void) { +#ifdef CONFIG_EXAMPLE_CC3000_MEM_CHECK + mmstart = mallinfo(); + memcpy(&mmprevious, &mmstart, sizeof(struct mallinfo)); + show_memory_usage(&mmstart,&mmprevious); +#endif + uint8_t fancyBuffer[MAC_ADDR_LEN]; if (isInitialized) @@ -350,6 +428,11 @@ void Initialize(void) #else isInitialized = true; #endif + +#ifdef CONFIG_EXAMPLE_CC3000_MEM_CHECK + mmprevious = mallinfo(); + show_memory_usage(&mmstart,&mmprevious); +#endif } /* This just shows the compiled size of the transmit & recieve buffers */ @@ -486,7 +569,7 @@ void StartSmartConfig(void) * returns is the socket number it used. So we ignore it. */ - mdnsAdvertiser(1,device_name,strlen(device_name)); + mdnsadvertiser(1, device_name, strlen(device_name)); printf(" Smart Config finished Successfully!\n"); ShowInformation(); @@ -853,6 +936,7 @@ int c3b_main(int argc, char *argv[]) do { helpme(); + stkmon_disp(); ch = getchar(); diff --git a/apps/examples/cc3000/shell.c b/apps/examples/cc3000/shell.c index 590c8b12c..2e8f3d08d 100644 --- a/apps/examples/cc3000/shell.c +++ b/apps/examples/cc3000/shell.c @@ -51,6 +51,7 @@ #include #include "shell.h" +#include /**************************************************************************** * Definitions @@ -121,6 +122,9 @@ static void shell_unknown(int argc, char **argv) static void shell_quit(int argc, char **argv) { printf("Bye!\n"); +#ifdef CONFIG_EXAMPLE_CC3000_MEM_CHECK + stkmon_disp(); +#endif exit(0); } @@ -163,6 +167,9 @@ int shell_session(int argc, char *argv[]) printf("CC3000 command shell -- NuttX style\n"); printf("Type '?' and return for help\n"); +#ifdef CONFIG_EXAMPLE_CC3000_MEM_CHECK + stkmon_disp(); +#endif for(;;) { @@ -210,7 +217,7 @@ int shell_main(int argc, char *argv[]) config.d_stacksize = CONFIG_EXAMPLES_TELNETD_DAEMONSTACKSIZE; config.t_priority = CONFIG_EXAMPLES_TELNETD_CLIENTPRIO; config.t_stacksize = CONFIG_EXAMPLES_TELNETD_CLIENTSTACKSIZE; - config.t_entry = shell_session; + config.t_entry = nsh_consolemain; /* Start the telnet daemon */ diff --git a/apps/examples/cc3000/shell.h b/apps/examples/cc3000/shell.h index aa8152a70..c25da9c0e 100644 --- a/apps/examples/cc3000/shell.h +++ b/apps/examples/cc3000/shell.h @@ -59,7 +59,7 @@ #endif #ifndef CONFIG_EXAMPLES_TELNETD_DAEMONSTACKSIZE -# define CONFIG_EXAMPLES_TELNETD_DAEMONSTACKSIZE 768 +# define CONFIG_EXAMPLES_TELNETD_DAEMONSTACKSIZE 580 #endif #ifndef CONFIG_EXAMPLES_TELNETD_CLIENTPRIO @@ -70,6 +70,8 @@ # define CONFIG_EXAMPLES_TELNETD_CLIENTSTACKSIZE 990 #endif +#undef CONFIG_EXAMPLE_CC3000_MEM_CHECK + /* Other definitions ********************************************************/ #define SHELL_PROMPT "CC3000 1.0> " diff --git a/apps/examples/cc3000/telnetd_daemon.c b/apps/examples/cc3000/telnetd_daemon.c index 353a63404..a149f7abe 100644 --- a/apps/examples/cc3000/telnetd_daemon.c +++ b/apps/examples/cc3000/telnetd_daemon.c @@ -70,7 +70,7 @@ * Public Data ****************************************************************************/ -/* This structure is used to passed information to telnet daemon when it +/* This structure is used to passed information to telnet daemon when it * started. */ @@ -159,15 +159,8 @@ static int telnetd_daemon(int argc, char *argv[]) ndbg("listen failure %d\n", errno); goto errout_with_socket; } -#if defined(CC3000_SOCKETS) - short nonBlocking=SOCK_OFF; - if (setsockopt(listensd, SOL_SOCKET, SOCKOPT_ACCEPT_NONBLOCK, &nonBlocking, sizeof(nonBlocking)) < 0) - { - ndbg("setsockopt failure %d\n", errno); - goto errout_with_socket; - } -#endif - /* Now go silent. Only the lldbg family of debug functions should + + /* Now go silent. Only the lldbg family of debug functions should * be used after this point because these do not depend on stdout * being available. */ @@ -259,10 +252,6 @@ static int telnetd_daemon(int argc, char *argv[]) close(0); close(1); close(2); -#if defined(CC3000_SOCKETS_ST) - /* We can not do more then one accept in Single treaded version */ - break; -#endif } errout_with_acceptsd: -- cgit v1.2.3