summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-03-04 17:38:00 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-03-04 17:38:00 +0000
commit68c754f4ee2a45e89b2f8952c1926e73f2147146 (patch)
tree4c7840655e4f2bccac1f8dcf1ae41be17bdd0234 /apps
parent8e1975393114d786b3699f926a416c3945ec3dfd (diff)
downloadnuttx-68c754f4ee2a45e89b2f8952c1926e73f2147146.tar.gz
nuttx-68c754f4ee2a45e89b2f8952c1926e73f2147146.tar.bz2
nuttx-68c754f4ee2a45e89b2f8952c1926e73f2147146.zip
Several fixes to the PIC32 USB device OUT path logic
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4451 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps')
-rw-r--r--apps/examples/usbterm/usbterm.h2
-rw-r--r--apps/examples/usbterm/usbterm_main.c32
2 files changed, 29 insertions, 5 deletions
diff --git a/apps/examples/usbterm/usbterm.h b/apps/examples/usbterm/usbterm.h
index a889c886d..2534c2f3c 100644
--- a/apps/examples/usbterm/usbterm.h
+++ b/apps/examples/usbterm/usbterm.h
@@ -132,6 +132,8 @@ struct usbterm_globals_s
FILE *instream; /* Stream for incoming USB data */
FILE *outstream; /* Stream for outgoing USB data */
pthread_t listener; /* USB terminal listener thread */
+ bool peer; /* True: A peer is connected to the serial port on
+ * the remote host */
/* Buffers for incoming and outgoing data */
diff --git a/apps/examples/usbterm/usbterm_main.c b/apps/examples/usbterm/usbterm_main.c
index ba723e91b..170585624 100644
--- a/apps/examples/usbterm/usbterm_main.c
+++ b/apps/examples/usbterm/usbterm_main.c
@@ -127,15 +127,27 @@ FAR void *usbterm_listener(FAR void *parameter)
message("usbterm_listener: Waiting for remote input\n");
for (;;)
{
- /* Display the prompt string on the remote USB serial connection */
+ /* Display the prompt string on the remote USB serial connection -- only
+ * if we know that there is someone listening at the other end. The
+ * remote side must initiate the the conversation.
+ */
- fputs("\rusbterm> ", g_usbterm.outstream);
- fflush(g_usbterm.outstream);
+ if (g_usbterm.peer)
+ {
+ fputs("\rusbterm> ", g_usbterm.outstream);
+ fflush(g_usbterm.outstream);
+ }
/* Get the next line of input from the remote USB serial connection */
if (fgets(g_usbterm.inbuffer, CONFIG_EXAMPLES_USBTERM_BUFLEN, g_usbterm.instream))
{
+ /* If we receive anything, then we can be assured that there is someone
+ * with the serial driver open on the remote host.
+ */
+
+ g_usbterm.peer = true;
+
/* Echo the line on the local stdout */
fputs(g_usbterm.inbuffer, stdout);
@@ -181,6 +193,10 @@ int MAIN_NAME(int argc, char *argv[])
pthread_attr_t attr;
int ret;
+ /* Initialize global data */
+
+ memset(&g_usbterm, 0, sizeof(struct usbterm_globals_s));
+
/* Initialization of the USB hardware may be performed by logic external to
* this test.
*/
@@ -324,9 +340,11 @@ int MAIN_NAME(int argc, char *argv[])
return 1;
}
#endif
- else
+ /* Is there anyone listening on the other end? */
+
+ else if (g_usbterm.peer)
{
- /* Send the line of input via USB */
+ /* Yes.. Send the line of input via USB */
fputs(g_usbterm.outbuffer, g_usbterm.outstream);
@@ -335,6 +353,10 @@ int MAIN_NAME(int argc, char *argv[])
fputs("\rusbterm> ", g_usbterm.outstream);
fflush(g_usbterm.outstream);
}
+ else
+ {
+ printf("Still waiting for remote peer. Please try again later.\n", ret);
+ }
/* If USB tracing is enabled, then dump all collected trace data to stdout */