UINT8 CH376WriteReqBlock( PUINT8 buff ) /* 向內(nèi)部指定緩沖區(qū)寫入請求的數(shù)據(jù)塊,返回長度 */ { UINT8 s, l; xWriteCH376Cmd( CMD01_WR_REQ_DATA ); s = l = xReadCH376Data( ); /* 長度 */ if ( l ) { do { xWriteCH376Data( *buff ); buff ++; } while ( -- l ); } // xEndCH376Cmd( ); return( s ); }
UINT8 CH376ByteWrite( PUINT8 buff, int ReqCount, PUINT16 RealCount ) /* 以字節(jié)為單位向當(dāng)前位置寫入數(shù)據(jù)塊 */ { UINT8 i,s; xWriteCH376Cmd( CMD2H_BYTE_WRITE ); /* 0x3C 主機文件模式: 以字節(jié)為單位向當(dāng)前位置寫入數(shù)據(jù)塊 */ xWriteCH376Data( (UINT8)ReqCount ); xWriteCH376Data( (UINT8)(ReqCount>>8) ); // xEndCH376Cmd( ); if ( RealCount ) *RealCount = 0; while ( 1 ) { s = Wait376Interrupt( ); if ( s == USB_INT_DISK_WRITE ) /* 0x1E USB存儲器請求數(shù)據(jù)寫入 */ { s = CH376WriteReqBlock( buff ); /* 向內(nèi)部指定緩沖區(qū)寫入請求的數(shù)據(jù)塊,返回長度 */ xWriteCH376Cmd( CMD0H_BYTE_WR_GO ); // xEndCH376Cmd( ); buff += s; if ( RealCount ) *RealCount += s; } /* else if ( s == USB_INT_SUCCESS ) return( s );*/ /* 結(jié)束 */ else return( s ); /* 錯誤 */ } }
void main() {
unsigned char PutIn[10]={'A','B','C','D','E','F','G','H','I','J'} PUINT8 buff; s = mInitCH376Host(); /* 初始化CH376 */ mStopIfError(s);
DelayUS(1); s = CKECK_connect(); /* 檢查連接 */ mStopIfError(s);
DelayUS(1); s = CH376DiskMount(); /* U盤初始化 */ mStopIfError(s);
s = CH376DirCreate( "6-20" ); mStopIfError(s);
s = CH376FileCreate( "T.TXT" ); mStopIfError(s);
buff = &PutIn[0]; s = CH376ByteWrite( buff, sizeof(PutIn), NULL ); mStopIfError(s); }