">
赞
踩
测试代码
-
- #include <rtthread.h>
- #include <rtdevice.h>
- #include <dfs_posix.h>
-
- #ifdef RT_USING_DFS
- #include <dfs_fs.h>
- #endif
-
- #define DBG_SECTION_NAME "MAIN"
- #define DBG_COLOR
- #define DBG_LEVEL DBG_INFO
- #include <rtdbg.h>
-
- int main(int argc, char *argv[])
- {
- return 0;
- }
-
- /* Example: nand flash mount fatfs */
- #ifdef RT_USING_DFS
-
- #define NAND_FLASH_NAME "nand0"
- #define TEST_DATA_LEN (512*1024)
-
- void thread1_entry(void *pra)
- {
- int fd, size;
- rt_uint8_t *data_ptr;
- rt_uint8_t *recv_ptr;
-
- rt_uint32_t index = 0;
- rt_uint32_t j = 0;
- rt_uint32_t file_size = 0;
- rt_uint32_t datasize = 0;
-
- char *file_name;
- int i = 0;
-
- file_name = rt_malloc(220);
- for(i=0;i<2;i++)
- {
- sprintf(file_name,"/file%03d.txt",i);
-
- data_ptr = rt_malloc(TEST_DATA_LEN);
- if (data_ptr == RT_NULL)
- {
- rt_kprintf("data ptr out of memory!\n");
- return;
- }
-
- /* prepare write data */
- for (index = 0; index < TEST_DATA_LEN; index ++)
- {
- data_ptr[index] = '0' + j;
- j++;
- if (j > 9)
- {
- j = 0;
- }
- }
-
- /* open "/test.txt" file with (O_WRONLY | O_CREAT | O_APPEND) mode */
- fd = open(file_name, O_WRONLY | O_CREAT | O_APPEND);
- if (fd >= 0)
- {
-
- datasize = write(fd, data_ptr, TEST_DATA_LEN);
- if(datasize != TEST_DATA_LEN)
- {
- rt_kprintf("Write done %s.\n\n",file_name);
- rt_kprintf("Write over.\n");
- return;
- }
- datasize = write(fd, data_ptr, TEST_DATA_LEN);
- if(datasize != TEST_DATA_LEN)
- {
- rt_kprintf("Write done %s.\n\n",file_name);
- rt_kprintf("Write over.\n");
- return;
- }
- file_size = lseek(fd, 0, SEEK_END);
- rt_kprintf("**************************file size is %d.\n", file_size);
- close(fd);
-
- rt_kprintf("Write done %s.\n\n",file_name);
- }
- rt_free(data_ptr);
-
- }
- }
-
- int mnt_init(void)
- {
- rt_thread_t tid1 = RT_NULL;
-
- /* mount fatfs */
- if (dfs_mount(NAND_FLASH_NAME, "/", "elm", 0, 0) == 0)
- {
- rt_kprintf("Mount FatFs file system to root, Done!\n");
- }
- else
- {
- rt_kprintf("Mount FatFs file system failed.\n");
- return 0;
- }
-
- /* Test: read and write file in thread1 */
- tid1 = rt_thread_create("test_thread1", thread1_entry, 0, 4096, 25, 20);
- if (tid1 != RT_NULL)
- {
- rt_thread_startup(tid1);
- }
- return 0;
- }
- INIT_APP_EXPORT(mnt_init);
- #endif
-

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。