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); }