diff options
| -rw-r--r-- | firmware/microblaze/apps/txrx_uhd.c | 2 | ||||
| -rw-r--r-- | firmware/microblaze/lib/hal_io.c | 9 | ||||
| -rw-r--r-- | firmware/microblaze/lib/hal_io.h | 1 | ||||
| -rw-r--r-- | firmware/microblaze/lib/hal_uart.c | 11 | ||||
| -rw-r--r-- | firmware/microblaze/lib/hal_uart.h | 7 | 
5 files changed, 29 insertions, 1 deletions
| diff --git a/firmware/microblaze/apps/txrx_uhd.c b/firmware/microblaze/apps/txrx_uhd.c index 9fe17e262..9cf4c163f 100644 --- a/firmware/microblaze/apps/txrx_uhd.c +++ b/firmware/microblaze/apps/txrx_uhd.c @@ -315,7 +315,7 @@ void handle_udp_ctrl_packet(        //executes a readline()-style read, up to num_bytes long, up to and including newline        int num_bytes = ctrl_data_in->data.uart_args.bytes;        if(num_bytes > 20) num_bytes = 20; -      num_bytes = fngets(ctrl_data_in->data.uart_args.dev, (char *) ctrl_data_out.data.uart_args.data, num_bytes); +      num_bytes = fngets_timeout(ctrl_data_in->data.uart_args.dev, (char *) ctrl_data_out.data.uart_args.data, num_bytes);        ctrl_data_out.id = USRP2_CTRL_ID_I_HELLA_READ_THAT_UART_DUDE;        ctrl_data_out.data.uart_args.bytes = num_bytes;        break; diff --git a/firmware/microblaze/lib/hal_io.c b/firmware/microblaze/lib/hal_io.c index 18cc34aaf..0e3754958 100644 --- a/firmware/microblaze/lib/hal_io.c +++ b/firmware/microblaze/lib/hal_io.c @@ -252,6 +252,15 @@ fngets(hal_uart_name_t u, char * const s, int len)  	return (x-s)-1;  } +int +fngets_timeout(hal_uart_name_t u, char * const s, int len) +{ +  char *x = s; +  while(((*x=(char)hal_uart_getc_timeout(u)) != '\n') && ((x-s) < len)) x++; +	*x = 0; +	return (x-s)-1; +} +  char *  gets(char * const s)  { diff --git a/firmware/microblaze/lib/hal_io.h b/firmware/microblaze/lib/hal_io.h index 45e23755f..950f8d591 100644 --- a/firmware/microblaze/lib/hal_io.h +++ b/firmware/microblaze/lib/hal_io.h @@ -28,6 +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);  /*   * ------------------------------------------------------------------------ diff --git a/firmware/microblaze/lib/hal_uart.c b/firmware/microblaze/lib/hal_uart.c index 8f7f83a68..4d754d5e5 100644 --- a/firmware/microblaze/lib/hal_uart.c +++ b/firmware/microblaze/lib/hal_uart.c @@ -19,6 +19,7 @@  #include "memory_map.h"  #include "hal_uart.h"  #include "hal_io.h" +#include "mdelay.h"  //just to save you from going insane, note that firmware/FPGA UARTs [0-2] correspond to serial ports [1-3].  //so in software, we refer to UART_DEBUG as UART0, but it transmits on pin TXD<1>. see the UART assignments in hal_uart.h. @@ -101,6 +102,16 @@ hal_uart_getc(hal_uart_name_t u)    return uart_regs[u].rxchar;  } +int  +hal_uart_getc_timeout(hal_uart_name_t u) +{ +  int timeout = 0; +  while (((uart_regs[u].rxlevel) == 0) && (timeout++ < HAL_UART_TIMEOUT_MS)) +    mdelay(1); + +  return (uart_regs[u].rxlevel == 0) ? 0 : uart_regs[u].rxchar; +} +  int hal_uart_rx_flush(hal_uart_name_t u)  {    char x; diff --git a/firmware/microblaze/lib/hal_uart.h b/firmware/microblaze/lib/hal_uart.h index 051dffe92..b9b0a5e14 100644 --- a/firmware/microblaze/lib/hal_uart.h +++ b/firmware/microblaze/lib/hal_uart.h @@ -27,6 +27,8 @@  #define DEFAULT_UART UART_DEBUG //which UART printf, gets, etc. use +#define HAL_UART_TIMEOUT_MS 100 +  typedef enum {    US_9600   = 0,    US_19200  = 1, @@ -82,6 +84,11 @@ 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 + */ +int hal_uart_getc_timeout(hal_uart_name_t u); +  int hal_uart_rx_flush(hal_uart_name_t u);  #endif /* INCLUDED_HAL_UART_H */ | 
