UINT8 CH376WriteReqBlock( PUINT8 buff ) /* 向内部指定缓冲区写入请求的数据块,返回长度 */ { 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 ) /* 以字节为单位向当前位置写入数据块 */ { UINT8 i,s; xWriteCH376Cmd( CMD2H_BYTE_WRITE ); /* 0x3C 主机文件模式: 以字节为单位向当前位置写入数据块 */ xWriteCH376Data( (UINT8)ReqCount ); xWriteCH376Data( (UINT8)(ReqCount>>8) ); // xEndCH376Cmd( ); if ( RealCount ) *RealCount = 0; while ( 1 ) { s = Wait376Interrupt( ); if ( s == USB_INT_DISK_WRITE ) /* 0x1E USB存储器请求数据写入 */ { s = CH376WriteReqBlock( buff ); /* 向内部指定缓冲区写入请求的数据块,返回长度 */ xWriteCH376Cmd( CMD0H_BYTE_WR_GO ); // xEndCH376Cmd( ); buff += s; if ( RealCount ) *RealCount += s; } /* else if ( s == USB_INT_SUCCESS ) return( s );*/ /* 结束 */ 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); }