Browse Source

serial: uart_native_pty_bottom: length parameter

Add a length parameter to the poll in read function so that data can be
read in larger chunks.

Signed-off-by: Jordan Yates <jordan@embeint.com>
pull/89078/head
Jordan Yates 3 months ago committed by Benjamin Cabé
parent
commit
3d344186fc
  1. 6
      drivers/serial/uart_native_pty.c
  2. 9
      drivers/serial/uart_native_pty_bottom.c
  3. 2
      drivers/serial/uart_native_pty_bottom.h

6
drivers/serial/uart_native_pty.c

@ -170,13 +170,11 @@ static int np_uart_stdin_poll_in(const struct device *dev, unsigned char *p_char @@ -170,13 +170,11 @@ static int np_uart_stdin_poll_in(const struct device *dev, unsigned char *p_char
return -1;
}
rc = np_uart_stdin_poll_in_bottom(in_f, p_char);
rc = np_uart_stdin_poll_in_bottom(in_f, p_char, 1);
if (rc == -2) {
disconnected = true;
return -1;
}
return rc;
return rc == 1 ? 0 : -1;
}
/**

9
drivers/serial/uart_native_pty_bottom.c

@ -32,12 +32,13 @@ @@ -32,12 +32,13 @@
*
* @param in_f Input file descriptor
* @param p_char Pointer to character.
* @param len Maximum number of characters to read.
*
* @retval 0 If a character arrived and was stored in p_char
* @retval >0 Number of characters actually read
* @retval -1 If no character was available to read
* @retval -2 if the stdin is disconnected
*/
int np_uart_stdin_poll_in_bottom(int in_f, unsigned char *p_char)
int np_uart_stdin_poll_in_bottom(int in_f, unsigned char *p_char, int len)
{
if (feof(stdin)) {
/*
@ -64,12 +65,12 @@ int np_uart_stdin_poll_in_bottom(int in_f, unsigned char *p_char) @@ -64,12 +65,12 @@ int np_uart_stdin_poll_in_bottom(int in_f, unsigned char *p_char)
ERROR("%s: Error on select ()\n", __func__);
}
n = read(in_f, p_char, 1);
n = read(in_f, p_char, len);
if ((n == -1) || (n == 0)) {
return -1;
}
return 0;
return n;
}
/**

2
drivers/serial/uart_native_pty_bottom.h

@ -20,7 +20,7 @@ extern "C" { @@ -20,7 +20,7 @@ extern "C" {
/* Note: None of these functions are public interfaces. But internal to the native ptty driver */
int np_uart_stdin_poll_in_bottom(int in_f, unsigned char *p_char);
int np_uart_stdin_poll_in_bottom(int in_f, unsigned char *p_char, int len);
int np_uart_slave_connected(int fd);
int np_uart_open_pty(const char *uart_name, const char *auto_attach_cmd,
bool do_auto_attach, bool wait_pts);

Loading…
Cancel
Save