From 8b6fe7ef860690b07c448bfd7b94a778bdae0c47 Mon Sep 17 00:00:00 2001 From: gaoyang3513 Date: Wed, 24 Jul 2024 00:05:14 +0800 Subject: [PATCH] =?UTF-8?q?[Mod]=20=E8=A7=A3=E5=86=B3GCC=E7=89=88=E6=9C=AC?= =?UTF-8?q?=EF=BC=8C=E4=B8=B2=E5=8F=A3=E6=97=A0=E6=B3=95=E6=8E=A5=E6=94=B6?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NSPE/WIFI_IOT/app/main.c | 20 -------------------- NSPE/WIFI_IOT/bsp/uart.c | 28 +++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/NSPE/WIFI_IOT/app/main.c b/NSPE/WIFI_IOT/app/main.c index 1dce2cb..07e5bc2 100644 --- a/NSPE/WIFI_IOT/app/main.c +++ b/NSPE/WIFI_IOT/app/main.c @@ -147,26 +147,6 @@ void start_task(void *p_arg) app_init(); #endif -#if defined (CONFIG_GY3513) -#if 0 - printf("reading input from file... "); - fflush(stdout); - - filename = "Test.txt"; - LWIP_ASSERT("invalid filename", filename != NULL); - f = fopen(filename, "rb"); - LWIP_ASSERT("open failed", f != NULL); - len = fread(pktbuf, 1, sizeof(pktbuf), f); - len = fwrite(pktbuf, 1, sizeof(pktbuf), f); - fclose(f); - printf("testing file: \"%s\"...\r\n", filename); -#else - fprintf(stdout, "What is your name?\r\n"); - fscanf(stdin, "%s", read_buf); - fprintf(stdout, "\nHello, %s\r\n", read_buf); -#endif -#endif // CONFIG_GY3513 - sys_task_delete(NULL); } diff --git a/NSPE/WIFI_IOT/bsp/uart.c b/NSPE/WIFI_IOT/bsp/uart.c index 5c7b66e..6218bd8 100644 --- a/NSPE/WIFI_IOT/bsp/uart.c +++ b/NSPE/WIFI_IOT/bsp/uart.c @@ -37,6 +37,7 @@ OF SUCH DAMAGE. #include "app_cfg.h" #include "bsp_inc.h" #include "gd32w51x_usart.h" +#include "platform_def.h" #include "uart.h" #include "malloc.h" #include "wifi_netlink.h" @@ -90,6 +91,31 @@ int _write(int fd, char *str, int len) return i; } + +int _read(int handle, char *buffer, int size) +{ + uint8_t ch = 0U; + int actualSize = 0; + + /* This function only reads from "standard in", for all other file handles it returns failure. */ + if (handle != 0) { + return -1; + } + + /* Receive data. */ + for (; size > 0; size--) { + while(RESET == usart_flag_get(LOG_UART, USART_FLAG_RBNE)); + + *buffer++ = (char)usart_data_receive(LOG_UART); + actualSize++; + + if ((ch == 0U) || (ch == (uint8_t)'\n') || (ch == (uint8_t)'\r')) { + break; + } + } + + return (actualSize > 0) ? actualSize : -1; +} #endif /*! @@ -134,7 +160,7 @@ void usart_config(uint32_t usart_periph) usart_baudrate_set(usart_periph, 115200); usart_receive_config(usart_periph, USART_RECEIVE_ENABLE); usart_transmit_config(usart_periph, USART_TRANSMIT_ENABLE); - //usart_interrupt_enable(usart_periph, USART_INT_RBNE); + usart_interrupt_enable(usart_periph, USART_INT_RBNE); usart_enable(usart_periph); }