From 61e3259f22391e8fdd8546829b5d4672a185dae0 Mon Sep 17 00:00:00 2001 From: houwenxiang Date: Tue, 26 May 2020 20:30:09 +0800 Subject: [PATCH] Driver(UART): fix uart_read_byte and uart_write_byte different in buffer type issue. --- components/driver/include/driver/uart.h | 6 +++--- components/driver/uart.c | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/components/driver/include/driver/uart.h b/components/driver/include/driver/uart.h index ef7508738..732780809 100644 --- a/components/driver/include/driver/uart.h +++ b/components/driver/include/driver/uart.h @@ -514,7 +514,7 @@ int uart_tx_chars(uart_port_t uart_num, const char* buffer, uint32_t len); * - (-1) Parameter error * - OTHERS (>=0) The number of bytes pushed to the TX FIFO */ -int uart_write_bytes(uart_port_t uart_num, const char* src, size_t size); +int uart_write_bytes(uart_port_t uart_num, const void* src, size_t size); /** * @brief Send data to the UART port from a given buffer and length, @@ -536,7 +536,7 @@ int uart_write_bytes(uart_port_t uart_num, const char* src, size_t size); * - (-1) Parameter error * - OTHERS (>=0) The number of bytes pushed to the TX FIFO */ -int uart_write_bytes_with_break(uart_port_t uart_num, const char* src, size_t size, int brk_len); +int uart_write_bytes_with_break(uart_port_t uart_num, const void* src, size_t size, int brk_len); /** * @brief UART read bytes from UART buffer @@ -550,7 +550,7 @@ int uart_write_bytes_with_break(uart_port_t uart_num, const char* src, size_t si * - (-1) Error * - OTHERS (>=0) The number of bytes read from UART FIFO */ -int uart_read_bytes(uart_port_t uart_num, uint8_t* buf, uint32_t length, TickType_t ticks_to_wait); +int uart_read_bytes(uart_port_t uart_num, void* buf, uint32_t length, TickType_t ticks_to_wait); /** * @brief Alias of uart_flush_input. diff --git a/components/driver/uart.c b/components/driver/uart.c index be2575528..15c4961c8 100644 --- a/components/driver/uart.c +++ b/components/driver/uart.c @@ -1112,7 +1112,7 @@ static int uart_tx_all(uart_port_t uart_num, const char* src, size_t size, bool return original_size; } -int uart_write_bytes(uart_port_t uart_num, const char* src, size_t size) +int uart_write_bytes(uart_port_t uart_num, const void* src, size_t size) { UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", (-1)); UART_CHECK((p_uart_obj[uart_num] != NULL), "uart driver error", (-1)); @@ -1120,7 +1120,7 @@ int uart_write_bytes(uart_port_t uart_num, const char* src, size_t size) return uart_tx_all(uart_num, src, size, 0, 0); } -int uart_write_bytes_with_break(uart_port_t uart_num, const char* src, size_t size, int brk_len) +int uart_write_bytes_with_break(uart_port_t uart_num, const void* src, size_t size, int brk_len) { UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", (-1)); UART_CHECK((p_uart_obj[uart_num]), "uart driver error", (-1)); @@ -1146,7 +1146,7 @@ static bool uart_check_buf_full(uart_port_t uart_num) return false; } -int uart_read_bytes(uart_port_t uart_num, uint8_t* buf, uint32_t length, TickType_t ticks_to_wait) +int uart_read_bytes(uart_port_t uart_num, void* buf, uint32_t length, TickType_t ticks_to_wait) { UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", (-1)); UART_CHECK((buf), "uart data null", (-1)); @@ -1184,7 +1184,7 @@ int uart_read_bytes(uart_port_t uart_num, uint8_t* buf, uint32_t length, TickTyp } else { len_tmp = p_uart_obj[uart_num]->rx_cur_remain; } - memcpy(buf + copy_len, p_uart_obj[uart_num]->rx_ptr, len_tmp); + memcpy((uint8_t *)buf + copy_len, p_uart_obj[uart_num]->rx_ptr, len_tmp); UART_ENTER_CRITICAL(&(uart_context[uart_num].spinlock)); p_uart_obj[uart_num]->rx_buffered_len -= len_tmp; uart_pattern_queue_update(uart_num, len_tmp);