コード例 #1
0
void Sec_CREAT_CON_DIR(const char * BUF_Name)
{	
	bus_SPI_mutex_apply();
	strcpy( (char *)TarName,  BUF_Name );
	s=CH376DirCreate( TarName ); /* 在根目录下新建目录(文件夹)并打开,如果目录已经存在那么直接打开 */
	CH376FileClose( TRUE ); /* 关闭文件,对于字节读写建议自动更新文件长度 */
	memset( TarName, 0, 100 );
	bus_SPI_mutex_release();	
}
コード例 #2
0
ファイル: CH376_Test.c プロジェクト: AlexGora/cox
//*****************************************************************************
//
//! \brief CH376 test execute main body.
//!
//! \return None.
//
//*****************************************************************************
static void CH376Execute(void)
{
    unsigned char s;
    UINT16 usDataCnt;
    unsigned int ulFileSize, ulSetcorCnt;


    //waiting for USB device get ready
    for ( s = 0; s < 10; s ++ )
    {
        mDelaymS( 50 );
        printf( "Ready ?\n\r" );
        //
        // Initialize disk and check if disk is ready
        //
        if ( CH376DiskMount( ) == USB_INT_SUCCESS ) break;
    }
    s = CH376ReadBlock( ucReadData );
    TestAssert((s == sizeof( INQUIRY_DATA )), "CH376 API \"CH376ReadBlock()\"error!");
    if ( s == sizeof( INQUIRY_DATA ) )
    {
        //
        // get device information
        //
    	ucReadData[ s ] = 0;
        printf( "UdiskInfo: %s\n\r", ((P_INQUIRY_DATA)ucReadData)->VendorIdStr);
    }
    s = CH376DiskCapacity(&ulSetcorCnt);
    TestAssert((s == USB_INT_SUCCESS), "CH376 API \"CH376DiskCapacity()\"error!");
    printf("Capacity of U-disk: %dMB\n\r", ulSetcorCnt / (1048576 / DEF_SECTOR_SIZE));
    s = CH376DiskQuery(&ulSetcorCnt);
    TestAssert((s == USB_INT_SUCCESS), "CH376 API \"CH376DiskCapacity()\"error!");
    printf("Available capacity: %dMB\n\r", ulSetcorCnt / (1048576 / DEF_SECTOR_SIZE));

    s = CH376FileOpenPath("/CH376TST/TST.TXT");
    if ( s != USB_INT_SUCCESS )
    {
        //
        // if file path not found, firstly create the folder then create the file
        //
        s = CH376DirCreate("/CH376TST");
        TestAssert((s == USB_INT_SUCCESS), "CH376 API \"CH376DirCreate()\"error!");
        s = CH376FileCreate("TST.TXT");
        TestAssert((s == USB_INT_SUCCESS), "CH376 API \"CH376FileCreate()\"error!");
        s = CH376ByteWrite(ucWriteData, 35, &usDataCnt);
        TestAssert((s == USB_INT_SUCCESS), "CH376 API \"CH376ByteWrite()\"error!");
        //
        // After modifying a file, the parameter of CH376FileClose() must be TRUE to update
        // file size or you will find the file not available when you open the file on computer.
        //
        CH376FileClose(TRUE);
    }
    else
    {
        //
        // if file found, move file pointer to the end of file, then append data to the file
        //
        CH376ByteLocate(0x0);
        s = CH376ByteWrite(ucWriteData, 35, &usDataCnt);
        TestAssert((s == USB_INT_SUCCESS), "CH376 API \"CH376ByteWrite()\"error!");
        //
        // enable auto update file size
        //
        CH376FileClose(TRUE);
    }
    CH376FileOpenPath("/CH376TST/TST.TXT");
    ulFileSize = CH376GetFileSize();
    CH376ByteRead(ucReadData, 512, &usDataCnt);
    for(s = 0; s < ulFileSize; s++)
    {
        TestAssert((ucReadData[s] == ucWriteData[s]), "CH376 API \"CH376ByteRead()\"error!");
    }
    CH376FileClose(FALSE);
    printf("\n\r All test over!\n\r");

}