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

📄 udisc.c

📁 s3c44b0+sl811读写u盘程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/////////////////////////////////////
#include "..\inc\common.h"
#include "..\inc\SL811.H"
#include "..\inc\TPBULK.H"
#include "..\inc\HAL.H"
//#include "hpi32.H"
#include "fat32.H"
#include "..\inc\hpi.H"
#include "..\inc\fat.H"
#include "..\Target\44blib.H"
#include "..\Target\44b.H"

FLAGS bFlags;
extern unsigned char DBUF[BUFFER_LENGTH];
unsigned char usector;
extern Command_Def   Command;
extern unsigned char UARTBUF[UARTBUF_LENGTH];
unsigned int  DirStartCluster;		
extern SYS_INFO_BLOCK   DeviceInfo;
extern unsigned int mycount,mycount1,mycount2,mycount3,myremove;
extern unsigned int rw_flag;
unsigned char filename[11];
unsigned char content[200];
char current_floder[200];
//unsigned char current_floder[200]={"root>"};
//extern unsigned int ms_sucess;
//unsigned int NowCluster;
/////////////////////////////////////////////////
void create_folder(void);
void create_file(void);
void check_space(void);
void write_file(void);
void read_file(void);
void open_file(void);
void del_f(void);
void turn_folder(void);
void return_up_folder(void);
void return_root(void);
void list(void);
unsigned int Uart_Getfilename(char *string);
unsigned int Uart_GetContent(char *string);
void add_string(char *str1,char *str2);
unsigned int findend(char *str);
unsigned int findright(char *str,unsigned int i);

void * function_sl811[][2]=
{
	(void *)create_folder, 	     "创建子目录            ",
	(void *)turn_folder, 	     "进入目录项            ",
	(void *)return_up_folder, 	 "返回上一级目录        ",
	(void *)return_root,    	 "返回根目录            ",
	(void *)list,             	 "列举根目录下的文件    ",
	(void *)create_file, 	     "创建文件              ",
	(void *)open_file,	         "打开文件              ",
	(void *)write_file,	         "往指定文件中写入字符  ",
	(void *)read_file,	         "读指定文件中的字符    ",
	(void *)check_space,	     "查看剩余空间          ",
	(void *)del_f,	             "删除文件或目录        ",
        0,0
};

//void play_Udisc();

void play_Udisc(void)
{
    int mck,temp,i,uart_temp;
    unsigned long time_count;
//    unsigned int i,j,ii;
	bFlags.bits.bUartInDone=0;	
	SL811_Init();
    DirStartCluster=0;
    
	ChangePllValue(12,0x3,0x1);   //10MHZ  INPUT   20M OUTPUT
	mck=(  (12+8)*10000000  )/(  (3+2)*2  );
	Uart_Init(mck,115200);
    
    Uart_Printf("\nSL811 Host 初始化完毕");
    Uart_Printf("\n请插入USB设备(退出SL811 HOST功能请按任意键)");
   
	do
	{
        time_count++;		
		if (time_count>10000)
			{
			time_count = 0;
			check_usb();
			}
		if(bFlags.bits.SLAVE_FOUND){
			bFlags.bits.SLAVE_FOUND=FALSE;
			Uart_Printf("\n发现USB硬件设备");
			mycount++;
  		    DelayMs(250);
			if(EnumUsbDev(1))				// enumerate USB device, assign USB address = #1
			{
			   	bFlags.bits.SLAVE_ENUMERATED = TRUE;	// Set slave USB device enumerated flag			   	
			    mycount1++;
			   Uart_Printf("\n设置USB地址成功");
			}	
			}
		if(bFlags.bits.SLAVE_REMOVED)
		{
			Uart_Printf("\n移除USB硬件设备\n请插入USB设备(退出SL811 HOST功能请按任意键)");
			bFlags.bits.SLAVE_REMOVED=FALSE;
			bFlags.bits.SLAVE_ENUMERATED = FALSE;
			bFlags.bits.SLAVE_IS_ATTACHED = FALSE;
			myremove++;
	//		ms_sucess=500;
		}

      //20070822
/*	   if(1==RW_flag)
	   {
			bFlags.bits.bUartInDone=0;

			if(DeviceInfo.FAT)	//FAT32
				UartHandler32();
			else
				UartHandler();	//FAT16	
		}
*/

		if(bFlags.bits.bMassDevice)
		{
			bFlags.bits.bMassDevice=FALSE;
			if(EnumMassDev())
				{
			   	  bFlags.bits.SLAVE_IS_ATTACHED = TRUE;
				  mycount2++;
				  Uart_Printf("\n识别为Mass Storage");
				  rw_flag=1;
				  Uart_Printf("\n准备读写");
				//  strcpy(currnet_floder,"dfde")
				  current_floder[0]='r'; current_floder[1]='o'; current_floder[2]='o'; current_floder[3]='t';
				  current_floder[4]='\\';current_floder[5]='\0';
				}
			else
				{
				
				bFlags.bits.SLAVE_IS_ATTACHED = FALSE;
				
				temp=SL811Read(IntStatus);
				if(!(temp & 0x40))	bFlags.bits.SLAVE_FOUND=TRUE;
				
				}		
		}		
		
	//	if(bFlags.bits.SLAVE_IS_ATTACHED&&(DeviceInfo.FAT==0)&&(1==rw_flag))//FAT16=0,FAT32=1;
		if(bFlags.bits.SLAVE_IS_ATTACHED&&(1==rw_flag))//FAT16=0,FAT32=1;
		{
/*		 mycount3++;
	     Command.CLass=0x07;	//space
	     UartHandler32();
	 */ 
//		Command.CLass=0x00;	//List
//	     UartHandler();
         i=0;
         Uart_Printf("\n                             U盘操作选择    \n\n");
	     while(1)
		{   //display sl811 menu
		   
	    	Uart_Printf("%2d:%s",i,function_sl811[i][1]);
	   		i++;
	   	 	if((int)(function_sl811[i][0])==0)
	   	 	{
			Uart_Printf("\n");
			break;
	    	}
	    	if((i%3)==0)
			Uart_Printf("\n");
		}
	    Uart_Printf("\n当前目录或文件:");
	    for(temp=0;(current_floder[temp]!='\0');temp++)
	    	Uart_Printf("%c",current_floder[temp]);
	    Uart_Printf("\n请选择U盘操作功能:(退出对本设备的操作请按ESC键)");
	    i=Uart_GetIntNum_esc();
		//Uart_Printf("\n");
		if(i>=0 && (i<(sizeof(function_sl811)/6)) ) 
	    	( (void (*)(void)) (function_sl811[i][0]) )();
	    if(-1==i)
		{
		 rw_flag=0;
		 Uart_Printf("\nU盘现在可以安全地移除了!"); 
		}
	//	 if(1==mycount3)
	//	 ms_sucess=20;
	//	{
	//	 Uart_Printf("\n读写完毕\n");
	//	 }
/*		

	     Command.CLass=0x02;	//ReadFile
	     Command.len=10;
         UartHandler();  
         
	     Command.CLass=0x03;	//SetFilePointer	     
	     Command.len=0x05;
	     UartHandler();
		 
		 for(ii=0;ii<5;ii++)
         {
           for(i=500;i>0;i--)
            for(j=500;j>0;j--);
           asm("  RSBX  XF ");       
           for(i=500;i>0;i--)
            for(j=500;j>0;j--);
           asm("  SSBX  XF ");   
 
          }
		  	*/
        }
	}while(!(rUTRSTAT0 & 0x1)); //Receive data read
	
	uart_temp=RdURXH0();
	
	ChangePllValue(0x3a,0x3,0x1);   //10MHZ  INPUT   20M OUTPUT
	mck=(  (0x3a+8)*10000000  )/(  (3+2)*2  );
	Uart_Init(mck,115200);
    	
}

/*
void create_folder(void)
{
 	unsigned int temp;
    Command.CLass=0x09;    //Create folder
	Command.len=0;
	Command.Parameter[0]=0x31;Command.Parameter[1]=0x32;Command.Parameter[2]=0x33;Command.Parameter[3]=0x34;
	Command.Parameter[4]=0x35;Command.Parameter[5]=0x20;Command.Parameter[6]=0x20;Command.Parameter[7]=0x20;
	Command.Parameter[8]=0x20;Command.Parameter[9]=0x20;Command.Parameter[10]=0x20;
	Command.Parameter[11]=0x10;Command.Parameter[12]=0x00;Command.Parameter[13]=0xAD;
		 Command.Parameter[14]=0xE0;Command.Parameter[15]=0x14;Command.Parameter[16]=0xBD;
		 Command.Parameter[17]=0x2E;Command.Parameter[18]=0xBD;Command.Parameter[19]=0x2E;
		 Command.Parameter[20]=0x00;Command.Parameter[21]=0x00;Command.Parameter[22]=0xE1;
		 Command.Parameter[23]=0x14;Command.Parameter[24]=0xBD;Command.Parameter[25]=0x2E;
		 Command.Parameter[26]=0x00;Command.Parameter[27]=0x00;Command.Parameter[28]=0x00;
		 Command.Parameter[29]=0x00;Command.Parameter[30]=0x00;Command.Parameter[31]=0x00;
		 if(DeviceInfo.FAT==0)
	     	temp=UartHandler();
	     else
	     	temp=UartHandler32();
	     if(1==temp)
	     	Uart_Printf("操作完毕\n");
	     else
	     	Uart_Printf("操作失败\n"); 
}*/
void create_folder(void)
{
    unsigned int temp,end,i;
   char *string;
   Uart_Printf("\n请输入要创建的文件夹名(字母大写)(可输入汉字)"); 
   Uart_Getfilename(string);
   
   for(temp=0;temp<11;temp++)
    Command.Parameter[temp]=0x20;
   temp=0;
   while('\0'!=filename[temp])
   {
   // Uart_SendByte(filename[temp]);
     Command.Parameter[temp]=filename[temp];
    temp++;
    if(temp>10)
    {
    	Uart_Printf("\n文件夹名过长,仅创建前11个字符的文件夹名");
    	break;
    }
   }
    Command.CLass=0x09;    //Create folder
	Command.len=0;
	//Command.Parameter[0]=0x31;Command.Parameter[1]=0x32;Command.Parameter[2]=0x33;Command.Parameter[3]=0x34;
	//Command.Parameter[4]=0x35;Command.Parameter[5]=0x20;Command.Parameter[6]=0x20;Command.Parameter[7]=0x20;
	//Command.Parameter[8]=0x20;Command.Parameter[9]=0x20;Command.Parameter[10]=0x20;
	//Command.Parameter[11]=0x10;Command.Parameter[12]=0x00;Command.Parameter[13]=0xAD;
		 Command.Parameter[14]=0xE0;Command.Parameter[15]=0x14;Command.Parameter[16]=0xBD;
		 Command.Parameter[17]=0x2E;Command.Parameter[18]=0xBD;Command.Parameter[19]=0x2E;
		 Command.Parameter[20]=0x00;Command.Parameter[21]=0x00;Command.Parameter[22]=0xE1;
		 Command.Parameter[23]=0x14;Command.Parameter[24]=0xBD;Command.Parameter[25]=0x2E;
		 Command.Parameter[26]=0x00;Command.Parameter[27]=0x00;Command.Parameter[28]=0x00;
		 Command.Parameter[29]=0x00;Command.Parameter[30]=0x00;Command.Parameter[31]=0x00;
		 if(DeviceInfo.FAT==0)
	     	temp=UartHandler();
	     else
	     	temp=UartHandler32();
	     if(1==temp)
	     {
	     	Uart_Printf("操作完毕\n");
	     	end=findend(current_floder);
	     	for(i=0;(filename[i]!='\0');i++)
    			current_floder[end+i]=filename[i];
    		current_floder[end+i]='\\';
  			current_floder[end+i+1]='\0'; 
	     }
	     else
	     	Uart_Printf("操作失败\n"); 
}

/*
void create_file1(void)
{
   unsigned int temp;
   Command.CLass=0x04;    //Create file
		 Command.len=0;
	     Command.Parameter[0]=0x31;Command.Parameter[1]=0x32;Command.Parameter[2]=0x33;Command.Parameter[3]=0x20;
	     Command.Parameter[4]=0x20;Command.Parameter[5]=0x20;Command.Parameter[6]=0x20;Command.Parameter[7]=0x20;
	     Command.Parameter[8]=0x54;Command.Parameter[9]=0x58;Command.Parameter[10]=0x54;
	     Command.Parameter[11]=0x20;Command.Parameter[12]=0x10;Command.Parameter[13]=0x62;
		 Command.Parameter[14]=0x57;Command.Parameter[15]=0x4C;Command.Parameter[16]=0xA7;
		 Command.Parameter[17]=0x30;Command.Parameter[18]=0xA7;Command.Parameter[19]=0x30;
		 Command.Parameter[20]=0x00;Command.Parameter[21]=0x00;Command.Parameter[22]=0x09;
		 Command.Parameter[23]=0x35;Command.Parameter[24]=0x32;Command.Parameter[25]=0x24;
		 Command.Parameter[26]=0x00;Command.Parameter[27]=0x00;Command.Parameter[28]=0x00;
		 Command.Parameter[29]=0x00;Command.Parameter[30]=0x00;Command.Parameter[31]=0x00;
		 if(DeviceInfo.FAT==0)
	     	temp=UartHandler();
	     else
	     	temp=UartHandler32();
	     if(1==temp)
	     	Uart_Printf("操作完毕\n");
	     else
	     	Uart_Printf("操作失败\n"); 
}
*/
void create_file(void)
{
   unsigned int temp,temp1,end,i;
   char *string;
   Uart_Printf("\n请输入要创建的文件名(字母大写)(可输入汉字)(主文件名+扩展文件名):"); 
   Uart_Getfilename(string);
   
   for(temp=0;temp<11;temp++)
    Command.Parameter[temp]=0x20;
   temp=0;
   temp1=0;
   while('\0'!=filename[temp])
   {
  //  Uart_SendByte(filename[temp]);
    if('.'!=filename[temp])
    	Command.Parameter[temp1]=filename[temp];
    else
       	temp1=7;
    temp++;
    temp1++;

⌨️ 快捷键说明

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