apps/examples/pty_test: Use of POLL must be optional. There are still a few character drivers that do not support it.
This commit is contained in:
parent
8a16e80cf3
commit
126592b85d
@ -21,6 +21,10 @@ config EXAMPLES_PTYTEST_PROGNAME
|
|||||||
This is the name of the program that will be use when the NSH ELF
|
This is the name of the program that will be use when the NSH ELF
|
||||||
program is installed.
|
program is installed.
|
||||||
|
|
||||||
|
config EXAMPLES_PTYTEST_POLL
|
||||||
|
bool "Test poll() with data transfers"
|
||||||
|
default n
|
||||||
|
|
||||||
config EXAMPLES_PTYTEST_SERIALDEV
|
config EXAMPLES_PTYTEST_SERIALDEV
|
||||||
string "Test serial device"
|
string "Test serial device"
|
||||||
default"/dev/ttyS1"
|
default"/dev/ttyS1"
|
||||||
|
@ -96,7 +96,9 @@ struct term_pair_s
|
|||||||
|
|
||||||
static void serial_in(struct term_pair_s *tp)
|
static void serial_in(struct term_pair_s *tp)
|
||||||
{
|
{
|
||||||
|
#ifdef CONFIG_EXAMPLES_PTYTEST_POLL
|
||||||
struct pollfd fdp;
|
struct pollfd fdp;
|
||||||
|
#endif
|
||||||
char buffer[16];
|
char buffer[16];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -106,19 +108,23 @@ static void serial_in(struct term_pair_s *tp)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLES_PTYTEST_POLL
|
||||||
fdp.fd = tp->fd_uart;
|
fdp.fd = tp->fd_uart;
|
||||||
fdp.events = POLLIN;
|
fdp.events = POLLIN;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Run forever */
|
/* Run forever */
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
#ifdef CONFIG_EXAMPLES_PTYTEST_POLL
|
||||||
ret = poll((struct pollfd *)&fdp, 1, POLL_TIMEOUT);
|
ret = poll((struct pollfd *)&fdp, 1, POLL_TIMEOUT);
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
{
|
{
|
||||||
if ((fdp.revents & POLLIN) != 0)
|
if ((fdp.revents & POLLIN) != 0)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
int len;
|
ssize_t len;
|
||||||
|
|
||||||
len = read(tp->fd_uart, buffer, 16);
|
len = read(tp->fd_uart, buffer, 16);
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
@ -138,6 +144,7 @@ static void serial_in(struct term_pair_s *tp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef CONFIG_EXAMPLES_PTYTEST_POLL
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Timeout */
|
/* Timeout */
|
||||||
@ -154,6 +161,7 @@ static void serial_in(struct term_pair_s *tp)
|
|||||||
fprintf(stderr, "ERROR: poll failed: %d\n", errno);
|
fprintf(stderr, "ERROR: poll failed: %d\n", errno);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +175,9 @@ static void serial_in(struct term_pair_s *tp)
|
|||||||
|
|
||||||
static void serial_out(struct term_pair_s *tp)
|
static void serial_out(struct term_pair_s *tp)
|
||||||
{
|
{
|
||||||
|
#ifdef CONFIG_EXAMPLES_PTYTEST_POLL
|
||||||
struct pollfd fdp;
|
struct pollfd fdp;
|
||||||
|
#endif
|
||||||
char buffer[16];
|
char buffer[16];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -177,19 +187,23 @@ static void serial_out(struct term_pair_s *tp)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLES_PTYTEST_POLL
|
||||||
fdp.fd = tp->fd_pty;
|
fdp.fd = tp->fd_pty;
|
||||||
fdp.events = POLLIN;
|
fdp.events = POLLIN;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Run forever */
|
/* Run forever */
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
#ifdef CONFIG_EXAMPLES_PTYTEST_POLL
|
||||||
ret = poll((struct pollfd *)&fdp, 1, POLL_TIMEOUT);
|
ret = poll((struct pollfd *)&fdp, 1, POLL_TIMEOUT);
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
{
|
{
|
||||||
if (fdp.revents & POLLIN)
|
if ((fdp.revents & POLLIN != 0))
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
int len;
|
ssize_t len;
|
||||||
|
|
||||||
len = read(tp->fd_pty, buffer, 16);
|
len = read(tp->fd_pty, buffer, 16);
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
@ -209,6 +223,7 @@ static void serial_out(struct term_pair_s *tp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef CONFIG_EXAMPLES_PTYTEST_POLL
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Timeout */
|
/* Timeout */
|
||||||
@ -225,6 +240,7 @@ static void serial_out(struct term_pair_s *tp)
|
|||||||
fprintf(stderr, "ERROR: poll failed: %d\n", errno);
|
fprintf(stderr, "ERROR: poll failed: %d\n", errno);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user