diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h index a9b17b49935b39b261fb9309e560ebf824ee80ce..a5bde091f7fb237a09594b52141996384fe0bbcb 100644 --- a/epicardium/epicardium.h +++ b/epicardium/epicardium.h @@ -31,7 +31,7 @@ typedef unsigned int size_t; #define API_SYSTEM_EXEC 0x2 /* TODO */ #define API_UART_WRITE_STR 0x3 #define API_UART_READ_CHAR 0x4 -#define API_UART_READ_STR 0x5 /* TODO */ +#define API_UART_READ_STR 0x5 #define API_STREAM_READ 0x6 #define API_INTERRUPT_ENABLE 0x7 #define API_INTERRUPT_DISABLE 0x8 @@ -136,14 +136,27 @@ API(API_UART_WRITE_STR, void epic_uart_write_str( )); /** + * Try reading a single character from any connected serial device. * - * Try reading a single character from any connected serial device. If nothing - * is available, :c:func:`epic_uart_read_char` returns ``(-1)``. + * If nothing is available, :c:func:`epic_uart_read_char` returns ``(-1)``. * * :return: The byte or ``(-1)`` if no byte was available. */ API(API_UART_READ_CHAR, int epic_uart_read_char(void)); +/** + * Read as many characters as possible from the UART queue. + * + * :c:func:`epic_uart_read_str` will not block if no new data is available. For + * an example, see :c:func:`epic_isr_uart_rx`. + * + * :param char* buf: Buffer to be filled with incoming data. + * :param size_t cnt: Size of ``buf``. + * :returns: Number of bytes read. Can be ``0`` if no data was available. + * Might be a negative value if an error occured. + */ +API(API_UART_READ_STR, int epic_uart_read_str(char *buf, size_t cnt)); + /** * **Interrupt Service Routine** * diff --git a/epicardium/modules/serial.c b/epicardium/modules/serial.c index ac5737573a71d89b00067cf41dea3572f6323ce7..8cffa3ac40f8a66ddcd7dc0c5491cc4b5d8b59f8 100644 --- a/epicardium/modules/serial.c +++ b/epicardium/modules/serial.c @@ -43,6 +43,22 @@ int epic_uart_read_char(void) return (-1); } +/* + * API-call to read data from the queue. + */ +int epic_uart_read_str(char *buf, size_t cnt) +{ + int i = 0; + + for (i = 0; i < cnt; i++) { + if (xQueueReceive(read_queue, &buf[i], 0) != pdTRUE) { + break; + } + } + + return i; +} + /* Interrupt handler needed for SDK UART implementation */ void UART0_IRQHandler(void) {