From 9f0a316c6db3c80588905d2d90a340158b4e2feb Mon Sep 17 00:00:00 2001 From: zhujiarui666 Date: Mon, 27 Jun 2022 16:27:12 +0800 Subject: [PATCH] =?UTF-8?q?xiuos\Ubiquitous\RT-Thread=5FFusion=5FXiUOS\aii?= =?UTF-8?q?t=5Fboard\xidatong-arm32\applications\main.c=EF=BC=9A=201.?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0usb=E6=B5=8B=E8=AF=95=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xidatong-arm32/applications/main.c | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/applications/main.c b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/applications/main.c index dc9f23b9c..4c54c8355 100644 --- a/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/applications/main.c +++ b/Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-arm32/applications/main.c @@ -48,3 +48,68 @@ static void sdram_test2(void) } MSH_CMD_EXPORT(sdram_test2, sdram test2); #endif + +#ifdef BSP_USB1_HOST +#include +static char test_data[120], buffer[120]; +#define TEST_FN "/testusb.c" +void readwrite(const char* filename) +{ + int fd; + int index, length; + + fd = open(TEST_FN, O_WRONLY | O_CREAT | O_TRUNC, 0); + if (fd < 0) + { + rt_kprintf("open file for write failed\n"); + return; + } + + for (index = 0; index < sizeof(test_data); index ++) + { + test_data[index] = index + 27; + } + + length = write(fd, test_data, sizeof(test_data)); + if (length != sizeof(test_data)) + { + rt_kprintf("write data failed\n"); + close(fd); + return; + } + + close(fd); + + fd = open(TEST_FN, O_RDONLY, 0); + if (fd < 0) + { + rt_kprintf("check: open file for read failed\n"); + return; + } + + length = read(fd, buffer, sizeof(buffer)); + if (length != sizeof(buffer)) + { + rt_kprintf("check: read file failed\n"); + close(fd); + return; + } + + for (index = 0; index < sizeof(test_data); index ++) + { + if (test_data[index] != buffer[index]) + { + rt_kprintf("check: check data failed at %d\n", index); + close(fd); + return; + } + } + + rt_kprintf("usb host read/write udisk successful\r\n"); + + close(fd); +} + +MSH_CMD_EXPORT(readwrite, usb host read write test); + +#endif \ No newline at end of file