rsoc/Day5/filesystem.c

100 lines
2.3 KiB
C
Raw Normal View History

// //记得在menuconfig中开启支持旧版本功能Support legacy version
// #include <board.h>
// #include <rtthread.h>
// #include <drv_gpio.h>
// #include <dfs_posix.h>//需要添加软件包进这里
2024-07-30 17:53:43 +08:00
// //定义要写入的内容
// char String[] = "Hello, RT-Thread.Welcom to RSOC!";
2024-07-30 17:53:43 +08:00
// //定义接受文件内容的缓冲区
// char buffer[100] = {};
2024-07-30 17:53:43 +08:00
// void FileSystem_Test(void *parameter)
// {
// //文件描述符
// int fd;
2024-07-30 17:53:43 +08:00
// //用只写方式打开文件,如果没有该文件,则创建一个文件
// fd = open("/fal/FileTest.txt", O_WRONLY | O_CREAT);
2024-07-30 17:53:43 +08:00
// //如果打开成功
// if (fd >= 0)
// {
// //写入文件
// write(fd, String, sizeof(String));
2024-07-30 17:53:43 +08:00
// rt_kprintf("Write done.\n");
2024-07-30 17:53:43 +08:00
// //关闭文件
// close(fd);
// }
// else
// {
// rt_kprintf("File Open Fail.\n");
// }
2024-07-30 17:53:43 +08:00
// //用只读方式打开文件
// fd = open("/fal/FileTest.txt", O_RDONLY);
2024-07-30 17:53:43 +08:00
// if (fd>= 0)
// {
// //读取文件内容
// rt_uint32_t size = read(fd, buffer, sizeof(buffer));
2024-07-30 17:53:43 +08:00
// if (size < 0)
// {
// rt_kprintf("Read File Fail.\n");
// return ;
// }
2024-07-30 17:53:43 +08:00
// //输出文件内容
// rt_kprintf("Read from file test.txt : %s \n", buffer);
2024-07-30 17:53:43 +08:00
// //关闭文件
// close(fd);
// }
// else
// {
// rt_kprintf("File Open Fail.\n");
// }
// }
// //导出命令
// MSH_CMD_EXPORT(FileSystem_Test, FileSystem_Test);
2024-07-30 17:53:43 +08:00
// static void readdir_sample(void)
// {
// DIR *dirp;
// struct dirent *d;
2024-07-30 17:53:43 +08:00
// /* 打开 / dir_test 目录 */
// dirp = opendir("/fal");
// if (dirp == RT_NULL)
// {
// rt_kprintf("open directory error!\n");
// }
// else
// {
// /* 读取目录 */
// while ((d = readdir(dirp)) != RT_NULL)
// {
// rt_kprintf("found %s\n", d->d_name);
// }
2024-07-30 17:53:43 +08:00
// /* 关闭目录 */
// closedir(dirp);
// }
// }
// /* 导出到 msh 命令列表中 */
// MSH_CMD_EXPORT(readdir_sample, readdir sample);
2024-07-30 17:53:43 +08:00
// /*
// #define WIFI_CS GET_PIN(F, 10)
// void WIFI_CS_PULL_DOWM(void)
// {
// rt_pin_mode(WIFI_CS, PIN_MODE_OUTPUT);
// rt_pin_write(WIFI_CS, PIN_LOW);
// }
// INIT_BOARD_EXPORT(WIFI_CS GET_PIN);
// */