Example #1
0
//打开多级目录下的文件并读
uint8_t  Byte_OPEN_READ_PATH (const char * BUF_Name , uint32_t Addr , uint8_t * bufread , uint32_t offset )
{
	bus_SPI_mutex_apply();
	strcpy( (char *)TarName,  BUF_Name );
	CH376FileOpenPath( TarName );/* 打开多级目录下的文件或者目录(文件夹),支持多级目录路径,支持路径分隔符,路径长度不超过255个字符 */
	//bufoffset =	CH376GetFileSize( );
	CH376ByteLocate( Addr );
	s = CH376ByteRead(  bufread , offset ,NULL );/* 以字节为单位从当前位置读取数据块 */
	CH376FileClose( TRUE ); /* 关闭文件,对于字节读写建议自动更新文件长度 */
	memset( TarName, 0, 100 );
	memset( buf, 0, 100 );
	bus_SPI_mutex_release();	
	return s;
}
Example #2
0
//以扇区为单位填充
BOOL SecFill( const char * BUF_Name , uint32_t Addr , uint8_t size)
{										//		文件名称 			写起始地址					要写的数量	
	bus_SPI_mutex_apply();
	strcpy( (char *)TarName,  BUF_Name );
	CH376FileOpenPath( TarName );/* 打开多级目录下的文件或者目录(文件夹),支持多级目录路径,支持路径分隔符,路径长度不超过255个字符 */
	CH376ByteLocate( Addr );	
	memset( buf, 0xaa, 100 );
	s = CH376ByteWrite( buf, size, NULL ); /* 以字节为单位向当前位置写入数据块 */
	CH376FileClose( TRUE ); /* 关闭文件,对于字节读写建议自动更新文件长度 */
	memset( TarName, 0, 100 );
	memset( buf, 0, 100 );
	bus_SPI_mutex_release();
	if( s == USB_INT_SUCCESS )
		return TRUE;  
	else 
	if(s == USB_INT_BUF_OVER)
	{
		beep();
		return FALSE;
	}
	else
		return FALSE; 	
}
Example #3
0
//*****************************************************************************
//
//! \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");

}
Example #4
0
int main( void )
{
    int i;
    int j;
    UINT8	res;
    UINT8	s;
    UINT8	NameBuf[20] = {0};
    UINT8       CountT = 0;
    UINT32      U_D;
    PUINT32     pU_D;
    pU_D = &U_D;
    // Stop watchdog timer to prevent time out reset
    WDTCTL = WDTPW + WDTHOLD;
    P1DIR_bit.P1DIR0 = 1;
    P1OUT_bit.P1OUT0 = 1;

    UartInit();
code_start:
    CountT ++;
    for(i = 0;i<30000;i++);
    printk("Code Start !\r\n");
    printk("程序开始 !\r\n");
    
    do{
        for(i = 0;i<30000;i++);
        res = mInitCH376Host();
    }while(res != USB_INT_SUCCESS);
    printk("USB_INT_SUCCESS !\r\n");
    
    do{
        for(i = 0;i<30000;i++);
        res = CH376DiskConnect( ); /* 查询U盘是否连接,返回USB_INT_SUCCESS则说明当前已连接 */ 
    }while(res!=USB_INT_SUCCESS);
    printk("  Connect SUCCESS\r\n");
    
    do{
        for(i = 0;i<30000;i++);
        res = CH376DiskMount( ); /* 查询U盘或SD卡是否准备好,有些U盘可能需多次调用才能成功 */ 
    }while(res!=USB_INT_SUCCESS);
    printk("  U is OK !\r\n");

    s = CH376DiskCapacity(pU_D);
    mStopIfError( s );
    printk("  U盘大小:");
    printHex((unsigned int)U_D);
    printHex((unsigned int)(U_D>>16));
    printk("\r\n");
    
    s = CH376DiskQuery(pU_D);
    mStopIfError( s );
    printk("  剩余大小:");
    printHex((unsigned int)U_D);
    printHex((unsigned int)(U_D>>16));
    printk("\r\n");
    strcpy( NameBuf, "\\2012.TXT" );  /* 目标文件名 */
    
#if 0
    
    printf( "Open\r\n" );
    s = CH376FileOpenPath( NameBuf );
    mStopIfError( s );
    if ( s == ERR_MISS_FILE ){
        printf( "Create\r\n" );
        s = CH376FileCreatePath( NameBuf );  /* 新建多级目录下的文件,支持多级目录路径,输入缓冲区必须在RAM中 */
        mStopIfError( s );
    }
    
    printf( "CH376ByteLocate\r\n" );
    s = CH376ByteLocate(0xFFFFFFFF);
    mStopIfError( s );
    
    printf( "Write\r\n" );
    strcpy( buf, "时间        数据  ---\xd\n" );
    s = CH376ByteWrite( buf, strlen(buf), NULL );  /* 以字节为单位向当前位置写入数据块 */
    mStopIfError( s );
    
    strcpy( buf, "2012-12-01  01    ---\xd\n" );
    buf[9] = '0' + CountT;
    
    for(i = 0; i < 100;i ++){
        buf[12] = '0' + i/10;
        buf[13] = '0' + i%10;
        printf( "Write %s" ,buf);
        s = CH376ByteWrite( buf, strlen(buf), NULL );  /* 以字节为单位向当前位置写入数据块 */
        mStopIfError( s );            
    }
    
    printf( "Close\r\n" );
    s = CH376FileClose( TRUE );  /* 关闭文件,对于字节读写建议自动更新文件长度 */
    mStopIfError( s );
#endif
/* 如果MY_ADC.TXT文件已经存在则添加数据到尾部,如果不存在则新建文件 */
        printf( "Open\n" );
        s = CH376FileOpen( NameBuf );  /* 打开文件,该文件在根目录下 */
        if ( s == USB_INT_SUCCESS ) {  /* 文件存在并且已经被打开,移动文件指针到尾部以便添加数据 */
                printf( "File size = %ld\n", CH376GetFileSize( ) );  /* 读取当前文件长度 */
                printf( "Locate tail\n" );
                s = CH376ByteLocate( 0xFFFFFFFF );  /* 移到文件的尾部 */
                mStopIfError( s );
        }
        else if ( s == ERR_MISS_FILE ) {  /* 没有找到文件,必须新建文件 */
                printf( "Create\n" );
                s = CH376FileCreate( NULL );  /* 新建文件并打开,如果文件已经存在则先删除后再新建,不必再提供文件名,刚才已经提供给CH376FileOpen */
                mStopIfError( s );
        }
        else mStopIfError( s );  /* 打开文件时出错 */
        printf( "Write begin\n" );
        s = sprintf( buf, "此前文件长度= %ld 字节\xd\xa", CH376GetFileSize( ) );  /* 注意字符串长度不能溢出buf,否则加大缓冲区或者分多次写入 */
        s = CH376ByteWrite( buf, s, NULL );  /* 以字节为单位向文件写入数据 */
        mStopIfError( s );
        printf( "Write ADC data\n" );
        printf( "Current offset ( file point ) is :        ");
        for(i = 0;i<1000;i++){
            s = sprintf( buf, "%02d.%02d.%02d.%d\xd\xa", 2012 + i/365, 1 + (i / 30) % 12, 1 + i % 30, i );  
            /* 将二制制数据格式为一行字符串 */
            s = CH376ByteWrite( buf, s, NULL );  /* 以字节为单位向文件写入数据 */
            /* 有些U盘可能会要求在写数据后等待一会才能继续操作,
            所以,如果在某些U盘中发生数据丢失现象,
            建议在每次写入数据后稍作延时再继续 */
            for(j = 0;j<30;j++);
            mStopIfError( s );
            printf( "\b\b\b\b\b\b" );
            printf( "%6ld", CH376ReadVar32( VAR_CURRENT_OFFSET ) );  
            /* 读取当前文件指针 */
        }
        
        printf( "Write end\n" );
        strcpy( buf, "今天的ADC数据到此结束\xd\xa" );
        s = CH376ByteWrite( buf, strlen( buf ), NULL );  /* 以字节为单位向文件写入数据 */
        mStopIfError( s );
/* 如果实际产品中有实时时钟,可以根据需要将文件的日期和时间修改为实际值,参考EXAM10用CH376DirInfoRead/CH376DirInfoSave实现 */
        printf( "Close\n" );
        s = CH376FileClose( TRUE );  /* 关闭文件,自动计算文件长度,以字节为单位写文件,建议让程序库关闭文件以便自动更新文件长度 */
        mStopIfError( s );

        
    do{
        for(i = 0;i<30000;i++);
        P1OUT_bit.P1OUT0 = 1;
        for(i = 0;i<30000;i++);
        P1OUT_bit.P1OUT0 = 0;            
        res = CH376DiskConnect( ); /* 查询U盘是否连接,返回USB_INT_SUCCESS则说明当前已连接 */ 
        
    }while(res!=ERR_DISK_DISCON);
    printk("  ERR_DISK_DISCON\r\n");
    goto code_start;

}
Example #5
0
//*****************************************************************************
//
//! \brief VS1003 Example.
//!
//! \param None.
//!
//! This function is to give an example of using VS10xx to play audio file.
//! we use VS1003 as the decoder. This chip can decode WAV,MP3,WMA,MIDI audio
//! files and also can record audio. But we don't give out the record functions
//! since it relates much to file manipulation and seldom used. If you need this
//! function, please refer to VS10xx datasheet on VLSI's official page.
//!
//! \return None.
//
//*****************************************************************************
void VS10xxExample(void)
{
	unsigned char i,s;
	unsigned short usDataCnt, usAudioDecTime = 0;
	unsigned int ulFileSize = 0, ulFileCursor = 0;
	AudioFileInfo tFLIF;
    xSysCtlClockSet(72000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ);
    xSysCtlDelay( 1000000 );
    PeriphInit();
    VS10xxSineTest(0x24, 5000000);
    VS10xxSineTest(0x85, 5000000);
    //
    // Open MP3 file
    //
    s = CH376FileOpen("/01.MP3");
    mStopIfError(s);
    //
    // Set start volume, balance and Bass Treble Enhancement
    //
    VS10xxSetVolume( 77 );
    VS10xxSetBalance( 0 );
    VS10xxBassTrebleEnhance(0, 12, 0, 10);
    //
    // Get file size. (Optional)
    //
    ulFileSize = CH376GetFileSize( );
    //
    // Single song loop
    //
    while( 1 )
    {
    	CH376ByteRead( ucBuff, 512, &usDataCnt );
    	//
    	// Send audio stream to VS1003
    	//
    	for(i=0;i<16;i++)
    	{
    		VS10xxWriteData( ucBuff + i*32 );
    	}
    	ulFileCursor += usDataCnt;
    	if(ulFileCursor == 4096)
    	{
    		//
    		// Get and print file information
    		//
    		VS10xxGetAudioInfo(&tFLIF);
    		printf("\n\rFile type: %d\n\rBit rate: %d kbps\n\rSample rate: %dHz",
    				tFLIF.eFileType, tFLIF.usBitRate, tFLIF.ucSampleRate);
    		printf("\n\rMP3 ID: %d\n\rMP3 layer: %d\n\rOther information: %x\n\r",
    				tFLIF.ucMp3ID, tFLIF.ucMp3Layer, tFLIF.ucOtherInfo);
    	}
    	if((ulFileCursor % 10240) == 0)
    	{
    		//
    		// Get and print decode time
    		//
    		usAudioDecTime = VS10xxGetDecodeTime();
    		printf("\rplayed time: %2d:%2ds", usAudioDecTime/60, usAudioDecTime%60);
    	}
    	//
    	// If file come to the end.
    	//
    	if( usDataCnt==0 )
    	{
    		ulFileCursor=0;
    		//
    		// Move file pointer to the beginning of the file
    		//
    		CH376ByteLocate( 0 );
    		//
    		// Reset decode time
    		//
    		VS10xxResetDecodeTime();
    	}
    	//
    	// Key scan
    	//
    	switch(JoystickKeyRead())
    	{
    		case JOYSTICK_KEY_SELECT:
    			ucKeySelFlag = !ucKeySelFlag;
    			if(ucKeySelFlag) xGPIOSPinWrite( LED_PIN, 1 );
    			else xGPIOSPinWrite( LED_PIN, 0 );
    			break;
    		case JOYSTICK_KEY_UP:
    			if(!ucKeySelFlag)
    			{
    				//
    				// Volume increase
    				//
    				if(sucVolLevel<9)
    					sucVolLevel++;
    				VS10xxSetVolume(ucVolumeLevel[sucVolLevel]);
    			}
    			else
    			{
    				//
    				// Treble increase
    				//
    				if(ssTrebleA < 7) ssTrebleA++;
    				VS10xxBassTrebleEnhance(ssTrebleA, 12, ssBassA, 10);
    			}
    			break;
    		case JOYSTICK_KEY_DOWN:
    			if(!ucKeySelFlag)
    			{
    				//
    				// Volume decrease
    				//
    				if(sucVolLevel!=0)
    					sucVolLevel--;
    				VS10xxSetVolume(ucVolumeLevel[sucVolLevel]);
    			}
    			else
    			{
    				//
    				// Treble decrease
    				//
    				if(ssTrebleA > -8)
    					ssTrebleA--;
    				VS10xxBassTrebleEnhance(ssTrebleA, 12, ssBassA, 10);
    			}
    			break;
    		case JOYSTICK_KEY_LEFT:
    			if(!ucKeySelFlag)
    			{
    				//
    				// Balance decrease
    				//
    				if(ssVolBalance>-254)
    					ssVolBalance--;
    				VS10xxSetBalance(ssVolBalance);
    			}
    			else
    			{
    				//
    				// bass decrease
    				//
    				if(ssBassA>0)
    					ssBassA--;
    				VS10xxBassTrebleEnhance(ssTrebleA, 12, ssBassA, 10);
    			}
    			break;
    		case JOYSTICK_KEY_RIGHT:
    			if(!ucKeySelFlag)
    			{
    				//
    				// balance increase
    				//
    				if(ssVolBalance<254) ssVolBalance++;
    				VS10xxSetBalance(ssVolBalance);
    			}
    			else
    			{
    				//
    				// Bass increase
    				//
    				if(ssBassA<15)
    				     ssBassA++;
    				VS10xxBassTrebleEnhance(ssTrebleA, 12, ssBassA, 10);
    			}
    			break;
    		default :
    			break;
    	}
    }
//    CH376FileClose(FALSE);
}