diff options
Diffstat (limited to 'firmware/zpu/lib')
-rw-r--r-- | firmware/zpu/lib/hal_io.c | 4 | ||||
-rw-r--r-- | firmware/zpu/lib/hal_io.h | 2 | ||||
-rw-r--r-- | firmware/zpu/lib/hal_uart.c | 11 | ||||
-rw-r--r-- | firmware/zpu/lib/hal_uart.h | 6 |
4 files changed, 11 insertions, 12 deletions
diff --git a/firmware/zpu/lib/hal_io.c b/firmware/zpu/lib/hal_io.c index be4c570c7..1d137943c 100644 --- a/firmware/zpu/lib/hal_io.c +++ b/firmware/zpu/lib/hal_io.c @@ -253,11 +253,11 @@ fngets(hal_uart_name_t u, char * const s, int len) } int -fngets_timeout(hal_uart_name_t u, char * const s, int len) +fngets_noblock(hal_uart_name_t u, char * const s, int len) { char *x = s; - while(((*x=(char)hal_uart_getc_timeout(u)) != '\n') && (*x != -1) && ((x-s) < len)) x++; + while(((*x=(char)hal_uart_getc_noblock(u)) != '\n') && (*x != 255) && ((x-s) < len)) x++; *x = 0; //printf("Returning from fngets() with string %d of length %d\n", s[0], x-s); return (x-s); diff --git a/firmware/zpu/lib/hal_io.h b/firmware/zpu/lib/hal_io.h index 574df7d3e..7a617685c 100644 --- a/firmware/zpu/lib/hal_io.h +++ b/firmware/zpu/lib/hal_io.h @@ -28,7 +28,7 @@ char *gets(char * const s); int fputstr(hal_uart_name_t u, const char *s); int fnputstr(hal_uart_name_t u, const char *s, int len); int fngets(hal_uart_name_t u, char * const s, int len); -int fngets_timeout(hal_uart_name_t u, char * const s, int len); +int fngets_noblock(hal_uart_name_t u, char * const s, int len); /* * ------------------------------------------------------------------------ diff --git a/firmware/zpu/lib/hal_uart.c b/firmware/zpu/lib/hal_uart.c index f0921f4f0..6a37cceb6 100644 --- a/firmware/zpu/lib/hal_uart.c +++ b/firmware/zpu/lib/hal_uart.c @@ -103,12 +103,13 @@ hal_uart_getc(hal_uart_name_t u) } int -hal_uart_getc_timeout(hal_uart_name_t u) +hal_uart_getc_noblock(hal_uart_name_t u) { - int timeout = 0; - while (((uart_regs[u].rxlevel) == 0) && (timeout++ < HAL_UART_TIMEOUT_MS)) - mdelay(1); - return (timeout >= HAL_UART_TIMEOUT_MS) ? -1 : uart_regs[u].rxchar; //return -1 if nothing there, cause fngets to quit +// int timeout = 0; +// while (((uart_regs[u].rxlevel) == 0) && (timeout++ < HAL_UART_TIMEOUT_MS)) +// mdelay(1); + if(uart_regs[u].rxlevel == 0) return 255; + return uart_regs[u].rxchar; } int hal_uart_rx_flush(hal_uart_name_t u) diff --git a/firmware/zpu/lib/hal_uart.h b/firmware/zpu/lib/hal_uart.h index 758c8cb5e..793aface0 100644 --- a/firmware/zpu/lib/hal_uart.h +++ b/firmware/zpu/lib/hal_uart.h @@ -27,8 +27,6 @@ #define DEFAULT_UART UART_DEBUG //which UART printf, gets, etc. use -#define HAL_UART_TIMEOUT_MS 300 - typedef enum { US_9600 = 0, US_19200 = 1, @@ -85,9 +83,9 @@ void hal_uart_putc_nowait(hal_uart_name_t u, int ch); int hal_uart_getc(hal_uart_name_t u); /* - * \brief Blocking read of next char from serial port with timeout + * \brief Non-blocking read of next char from serial port, return -1 if nothing available */ -int hal_uart_getc_timeout(hal_uart_name_t u); +int hal_uart_getc_noblock(hal_uart_name_t u); int hal_uart_rx_flush(hal_uart_name_t u); |