⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_fs.c

📁 基于S3C2440处理器的sd卡驱动程序
💻 C
字号:
#include <string.h>
#include <assert.h>
#include "drv_extr.h"
#include "fs_extr.h"
#include "diskio.h"

DWORD get_fattime(void)
{
	return 0;
}
void FS_Load_FS(void)
{
	if( RES_OK != f_mountdrv() )
	{
		Uart_Printf("\r\nLoad Fail\r\n");
	}
	else
	{
		Uart_Printf("\r\nLoad OK\r\n");
	}
}


//BYTE Buff[2048];			/* Working buffer */

static	FRESULT scan_files (char* path)
{
	DIR dirs;
	FRESULT res;
	BYTE i;
	FILINFO finfo;
	DWORD acc_size;				/* Work register for fs command */
	WORD acc_files, acc_dirs;


	if ((res = f_opendir(&dirs, path)) == FR_OK) 
	{
		i = strlen(path);
		while (((res = f_readdir(&dirs, &finfo)) == FR_OK) && finfo.fname[0])
		{
			if (finfo.fattrib & AM_DIR)
			{
				acc_dirs++;
				Uart_Printf("\r\nDir Name:%s\r\n", finfo.fname);
				*(path+i) = '/'; 
				strcpy(path+i+1, &finfo.fname[0]);
				res = scan_files(path);
				*(path+i) = '\0';
				if (res != FR_OK) break;
			}
			else
			{
				Uart_Printf("\r\nFile Name:%s\\%s\r\n",path, finfo.fname);
				acc_files++;
				acc_size += finfo.fsize;
			}
		}
	}

	return res;
}

void FS_Scan_Dir(void)
{
	scan_files("");
	//Uart_Printf("\r\n Another dir \r\n");
	//scan_files("MISC");
}

void FS_Read_File()
{
	FIL fp;
	unsigned char *buf, *pointer ;
	STATUS status;
	DWORD len;

	memset(&fp, 0, sizeof(FIL));
	{
		status = NU_Allocate_Memory(&system_memory,  &pointer,  0xfffff, NU_NO_SUSPEND);
		assert(status == NU_SUCCESS);
	}
	buf = pointer;
	if( RES_OK ==  f_open(&fp, "/MYSD~1/WATERL~1.JPG",FA_OPEN_EXISTING | FA_READ) )
	{
		if( RES_OK == f_read(&fp, buf, fp.fsize, &len) )
		{
			int i;
			Uart_Printf("\r\n");
			for(i=0; i<len; i++)
			{
				Uart_Printf("0x%02x ", buf[i] );
				if( (i&0xf) == 0)
				Uart_Printf("\r\n");					
			}
		}
	}

	status = NU_Deallocate_Memory(pointer);
	assert(status == NU_SUCCESS);
}
void *funs[][2] = 
{
	(void*)FS_Load_FS,			"Load File System ",
	(void*)FS_Scan_Dir,			"Scan Folder	  ",
	(void*)FS_Read_File,		"Read One File	  ",
	0,0
};

void Print_Help(void)
{
	int i=0;
	Uart_Printf("\r\n-----FS Test-----\r\n\r\n");
	while(1)
	{   //display menu
	    Uart_Printf("%2d:%s\r\n",i,funs[i][1]);
		i++;
	    if((int)(funs[i][0])==0)
	    {
			 Uart_Printf("\r\n");
			 break;
	    }
	   // if((i%4)==0) Uart_Printf("\r\n");
	}
	Uart_Printf("Select(-1 exit):");
}

void Test_FS(void)
{
	int i;
	FATFS fs;
	FatFs = &fs;
	while(1)
	{
		Print_Help();
		i = Uart_GetIntNum();
		Uart_Printf("\r\n");
		if( i == -1 )
			break;
		if(i>=0 && (i<(sizeof(funs)/8 -1)) ) 
	    	( (void (*)(void))(funs[i][0]) )();	// execute selected function.		
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -