9
0
Fork 0

Add option to use C buffered I/O in examples/serloop

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@1274 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2008-11-17 23:59:16 +00:00
parent 24c4654a6a
commit 2197c62693
2 changed files with 27 additions and 2 deletions

View File

@ -120,7 +120,12 @@ examples/serloop
^^^^^^^^^^^^^^^^
This is a mindlessly simple loopback test on the console. Useful
for testing new serial drivers.
for testing new serial drivers. Configuration options include:
* CONFIG_EXAMPLES_SERLOOP_BUFIO
Use C buffered I/O (getchar/putchar) vs. raw console I/O
(read/read). The behavior of the NuttX getchar() call is
very hostile unless you also set CONFIG_STDIO_BUFFER_SIZE=0.
examples/udp
^^^^^^^^^^^^

View File

@ -38,6 +38,8 @@
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <unistd.h>
/****************************************************************************
@ -71,6 +73,23 @@ void user_initialize(void)
int user_start(int argc, char *argv[])
{
#ifdef CONFIG_EXAMPLES_SERLOOP_BUFIO
int ch;
for (;;)
{
ch = getchar();
if (ch < 1)
{
ch = '!';
}
else if ((ch < 0x20 || ch > 0x7e) && ch != '\n')
{
ch = '.';
}
putchar(ch);
}
#else
ubyte ch;
int ret;
@ -81,12 +100,13 @@ int user_start(int argc, char *argv[])
{
ch = '!';
}
else if (ch < 0x20 || ch > 0x7e)
else if ((ch < 0x20 || ch > 0x7e) && ch != '\n')
{
ch = '.';
}
ret = write(1, &ch, 1);
}
#endif
return 0;
}