我用375B做文件復(fù)制.將一個(gè)U盤中的文件復(fù)制到另一個(gè)目錄中,硬件是S3C44B0X RAM是8M 使用了SaveVariable來保存和恢復(fù)變量,但我在使用中如果將變量備份緩沖區(qū)定義大于80字節(jié)時(shí).輸出!!!ENTER ABRET 如果定義成80字節(jié)的話能復(fù)制但只能復(fù)制第一次讀取的扇區(qū)數(shù)的內(nèi)容第二次讀取的內(nèi)容就變成為亂碼了.也就是說SaveVariable變量的保存和恢復(fù)沒有成功.我用的庫是CH375HFM庫同時(shí)貼上我的代碼 unsigned char mFile0Info[ 80 ]; unsigned char mFile1Info[ 80 ]; int usbtest(void) { UINT16 CH375vSectorSize; UINT8 i, c, SecCount,mReadOver; UINT8 td; UINT16 mFileSize; UINT32 NewSize, count; /* 因?yàn)镽AM容量有限,所以NewSize限制為16位,實(shí)際上如果文件較大,應(yīng)該分幾次讀寫并且將NewSize改為UINT32以便累計(jì) */ UINT8 *pCodeStr; CH375vSectorSize=512; uart_printf("Usb for S3C44B0x\n"); uart_printf("Serial Baud rate is %d\n", SERIAL_BAUD); uart_printf(table_begin); uart_printf("System Initialized.\n"); mDelaymS( 50 ); /* 延時(shí)100毫秒 */ uart_printf( "CH375 IS TEST \n" ); CH375Reset( ); // mDelaymS(50 ); /* 延時(shí)50ms */ xWriteCH375Cmd( 0x06 ); //發(fā)送測試命令 xWriteCH375Data( 0x55 ); td=xReadCH375Data( ); //返回?cái)?shù)據(jù) uart_printf("Scode1 %xh\n", td); xWriteCH375Cmd( 0x06 ); //發(fā)送測試命令 xWriteCH375Data( 0xaa );//發(fā)送測試碼 td=xReadCH375Data( ); //返回?cái)?shù)據(jù) uart_printf("Scode2 %xh\n", td); i = CH375LibInit( ); /* 初始化CH375程序庫和CH375芯片,操作成功返回0 */ mStopIfError( i ); /* 其它電路初始化 */ CH375_PORT_INIT( ); uart_printf("\nCH375_Init over !!"); while ( 1 ) { uart_printf( "\ninput U disk!\n" ); while ( CH375DiskStatus != DISK_CONNECT ) /* 查詢CH375中斷并更新中斷狀態(tài),等待U盤插入 */ mDelaymS( 10 );
/* 檢查U盤是否準(zhǔn)備好,有些U盤不需要這一步,但是某些U盤必須要執(zhí)行這一步才能工作 */ for ( i = 0; i < 10; i ++ ) { /* 有的U盤總是返回未準(zhǔn)備好,不過可以被忽略 */ uart_printf( "Ready ?\n" ); if ( CH375DiskReady( ) == ERR_SUCCESS ) break; /* 查詢磁盤是否準(zhǔn)備好 */ } /* 查詢磁盤物理容量 */ uart_printf( "DiskSize\n" ); i = CH375DiskSize( ); mStopIfError( i ); uart_printf( "TotalSize = %d MB \n", (unsigned int)( mCmdParam.DiskSize.mDiskSizeSec >> 11 ) );
/* 讀取原文件 */ uart_printf( "Open source file\n" ); /* 打開源文件 */ //mCopyCodeStringToIRAM( mCmdParam.Open.mPathName, "\\TEST.C" ); strcpy( (char *)mCmdParam.Open.mPathName, "\\C51\\CH375HFT.C" ); i = CH375FileOpen( ); /* 打開文件 */ mStopIfError( i ); mFileSize = CH375vFileSize; mCmdParam.SaveVariable.mSaveVariable = 0x01; mCmdParam.SaveVariable.mBuffer = &mFile0Info[ 0 ]; CH375SaveVariable( ); /* 保存源文件信息 */ uart_printf( "Create destination file\n" ); /* 創(chuàng)建目標(biāo)文件 */ //mCopyCodeStringToIRAM( mCmdParam.Create.mPathName, "\\TESTSAVE.C" ); strcpy( (char *)mCmdParam.Open.mPathName, "\\C51\\TESTSAVE.C" ); i = CH375FileCreate( ); mStopIfError( i ); mCmdParam.SaveVariable.mSaveVariable = 0x01; mCmdParam.SaveVariable.mBuffer = &mFile1Info[ 0 ]; CH375SaveVariable( ); /* 保存目標(biāo)文件信息 */
mReadOver = 0; while( 1 ) { uart_printf("============================\n"); // uart_printf("restore source file info\n"); mCmdParam.SaveVariable.mSaveVariable = 0x00; mCmdParam.SaveVariable.mBuffer = &mFile0Info[ 0 ]; CH375SaveVariable( ); /* 恢復(fù)源文件信息 */ // uart_printf("read\n"); CH375vFileSize += CH375vSectorSize - 1; /* 默認(rèn)情況下,以扇區(qū)方式讀取數(shù)據(jù)時(shí),無法讀出文件尾部不足1個(gè)扇區(qū)的部分,所以必須臨時(shí)加大文件長度以讀取尾部零頭 */ mCmdParam.ReadX.mSectorCount =16; //讀取16扇 mCmdParam.ReadX.mDataBuffer = &FILE_DATA_BUF[ 0 ]; i = CH375FileReadX( ); mStopIfError( i ); CH375vFileSize -= CH375vSectorSize - 1;
SecCount = mCmdParam.ReadX.mSectorCount; /* 備份實(shí)際讀取的扇區(qū)數(shù) */ if( SecCount < 16 ) mReadOver = 1; // 當(dāng)讀取的扇區(qū)數(shù)小于16時(shí)說明文件己結(jié)束
uart_printf("save source file info\n"); mCmdParam.SaveVariable.mSaveVariable = 0x01; mCmdParam.SaveVariable.mBuffer = &mFile0Info[ 0 ]; CH375SaveVariable( ); /* 保存源文件信息 */ /*==================================================================*/ // uart_printf("restore destination file info\n"); mCmdParam.SaveVariable.mSaveVariable = 0x00; mCmdParam.SaveVariable.mBuffer = &mFile1Info[ 0 ]; CH375SaveVariable( ); /* 恢復(fù)目標(biāo)文件信息 */ // uart_printf("write\n"); mCmdParam.WriteX.mSectorCount = SecCount; mCmdParam.WriteX.mDataBuffer = &FILE_DATA_BUF[ 0 ]; i = CH375FileWriteX( ); mStopIfError( i ); // uart_printf("save destination file info\n"); mCmdParam.SaveVariable.mSaveVariable = 0x01; mCmdParam.SaveVariable.mBuffer = &mFile1Info[ 0 ]; CH375SaveVariable( ); /* 保存目標(biāo)文件信息 */
if( mReadOver ) { uart_printf(" copy file over\n"); CH375vFileSize = mFileSize; mCmdParam.Close.mUpdateLen = 1; i = CH375FileClose( ); mStopIfError( i ); break; } } [Emot]1[/Emot]