⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 arm7 的音乐播放程序
💻 C
字号:

#include "option.h"
#include "def.h"
#include "44b.h"
#include "44blib.h"
#include "Nand.h"
#include "uda1431.h"

#define TESTSIZE 2000000			//Music Size
///////
enum AddrType {
PageAddr = 0,
BlockAddr = 1
};

//static U8 Dst[512];			//Reading Nandflash Page to this
static U8 Buf[512];			//Writing the NandFlash Page

static U8 Music_Buf[TESTSIZE];		//Music just inside
U32 downloadAddress;				//Music begin Address

////////
void Fill_Buf(void);
void Show_Buff(const U8 *Temp);
void ISR_Init(void);
U32 WhichAddr(enum AddrType eAddrT);
void EraseBlock(void);
void ReadPage(U8 *pcDst);
void WritePage(const U8 *pcSrc);
void ChkBadBlock(void);
void ChkAllBlock(void);
void Write_song(U8 *pcMuc);
void Rec_song(void);
void Playing_song(void);

////
void Main(void)
{		
	U8 Nand_State;
	
    rSYSCFG = CACHECFG;   // Using 8KB Cache// 
     
    ISR_Init(); 
    Port_Init();
    Uart_Init(0,115200);
	
	Uart_Printf("Nandflash Working Test By cazy\n\n");
	
	NandFlashInit();	//Show the ID and Size of NANDFLASH	
		
	Nand_State=NFReadStat();
	Uart_Printf("The State of NandFlash is 0x%x\n",Nand_State);	
	
//Erase all the block
	EraseBlock();
	
	
//Writing the page
/*
	Uart_Printf("Now Filling the Buffer...\n");
	Fill_Buf();
	Uart_Printf("The Address of Reading_Buffer is 0x%x\n",Buf);
	WritePage(Buf);
		
//Reading the page
	Uart_Printf("The Address of Reading_Buffer is 0x%x\n",Dst);
	ReadPage(Dst);
	
	Uart_Printf("Now Showing the content of the Buffer:\n");
	Show_Buff(Dst);	
*/
//Checking the 	BadBlock
	//ChkBadBlock();
	
//Checking all the Block
	//ChkAllBlock();

/*Real Part*/

//Moving the WAV file to the SDRAM
	downloadAddress= (U32) (&Music_Buf);
	Uart_Printf("The Address should input: 0x%x \n",downloadAddress);
	
	Uart_SendString("Select Your File and Press 'OK' button ,it may take some minutes\n"); 
    Uart_SendString("When you fininsh Load ,Input 'c' to continue..\n\n");
    
    while( Uart_Getch() != 'c' )0;
  	//Now We put the WAV file to the  downloadAddress In SDRAM

//Writing the SDRAM to the Nandflash
	Uart_SendString("Now Writing file to NandFlash...\n\n");   
    Write_song(Music_Buf);
 	
//Getting the Music File From NandFlash To    Music_Buf
	Uart_SendString("Now Reading file to SDRAM...\n");
 	Rec_song();
 
//Playing the Music  In   Music_Buf
   
   	Playing_song();
	
    while(1);
 }

void Fill_Buf(void)
{
	U32 i;	
	for(i=0;i<10;i++)
   {
     Buf[i]=7; 				//Fill the Buffer with 7
   }

}

void Show_Buff(const U8 *Temp)
{
	U32 i;
	for(i=0;i<10;i++)
	{
	Uart_Printf("%x   ",Temp[i]);
	}
}

void ISR_Init(void)
{
	rINTCON=0x5;	  // Non-vectored,IRQ enable,FIQ disable   
    rINTMOD=0x0;	  // All=IRQ mode
    rINTMSK=BIT_GLOBAL;	  // All interrupt is masked.
}


U32 WhichAddr(enum AddrType eAddrT)
{
    U32 uiAddr;
    
    if (eAddrT == PageAddr)
    {
        Uart_SendString("Please Input Page Address (A9~A23):");
    
        uiAddr = 0x7fff & Uart_GetIntNum();			
    /*
    将页作为其基本的  记数单位
    有效的数值 只是A9~A23
    */
    
        Uart_Printf("The Page Address You Input is : 0x%x\n",uiAddr);
    }
    else 
    {
        Uart_SendString("Please Input Block Address A9~A23(Only A14~A23 is useful):");
    
        uiAddr = 0x7fe0 & Uart_GetIntNum();   //Getting the A14~A23
  	
    	//uiAddr	+=1<<14;		//Jump to next Block
    	
        Uart_Printf("The Block Address You Input is : 0x%x\n",uiAddr);
    }
    
    return uiAddr;
}

void EraseBlock(void)
{
	U32 BlockNum;
	U32 BlockAdd;
	U32 BlockCount;
	
	BlockNum=0;
	BlockAdd=0;
	BlockCount=1<<7;	//要擦除 2的7次方个 块
	
    Uart_SendString("Now Erase 2#7 Blocks ....\n");
     
    //NFEraseBlock(0);
	//NFEraseBlock(0x20);
     
    for(BlockNum=0;BlockNum<BlockCount;BlockNum++)
    {
    	if(NFEraseBlock(BlockAdd)==1)
    	{
    	Uart_Printf("\nEraseBlock No: %d is Failed...\n",BlockNum);
    	return;
    	}
    	
    	BlockAdd+=1<<5;
    }
    
    
    Uart_SendString("\nErase All the Block  Ok!\n");
    
}


void ReadPage(U8 *pcDst)
{
   NFReadPage( WhichAddr(PageAddr), pcDst);   
}


void WritePage(const U8 *pcSrc)
{
    Uart_SendString("WritePage ....\n");
    
    if ( NFWritePage(WhichAddr(PageAddr), pcSrc) ==0)
    {
        Uart_SendString("\nOk!\n");
    }
    else
    {
        Uart_SendString("\nFailed...\n");
    }
}

void ChkBadBlock(void)
{
	Uart_SendString("Checking the BadBlock...\n");
	
	if ( NFChkBadBlk(WhichAddr(BlockAddr)) ==0)
    {
        Uart_SendString("\nThis Block is good!\n");
    }
    else
    {
        Uart_SendString("\nThis Block is Bed!\n");
    }
}


void ChkAllBlock(void)
{
	U32 BlockNum,BlockAdds;
	BlockAdds=0;
	Uart_Printf("Checking all the Block...\n");
	for (BlockNum=0   ;BlockNum<1024  ;BlockNum++)
	{
		if (NFChkBadBlk(BlockAdds)==1)
		{ 
		Uart_Printf("The No: %d is BadBlock !!!\n",BlockNum); 
		return;
		}
		else 
		{
		BlockAdds=BlockAdds+1<<14;		//Jump to next Block
		}
	}
	Uart_SendString("All block is OK!!!");
}


/*Waiting for The Test*/

void Write_song(U8 *pcMuc)
{
	U32 PageNum;		//Page Number
	U32	PageAdd;		//Page Begin Address
	U32 NeedPage;		//Need page Numbers

	U8  *Music_pt;		//Music Writing Point
	
	NeedPage=1<<12;		//7+5 page Get 2mb Buffer
	
	PageNum=0;
	PageAdd=0;
			
	Music_pt=pcMuc;
	
	Uart_SendString("Now Sending Music to NandFlash\n");
	
//Writing One page (PageAddr,SouceFile) 
/*	
	PageAdd=1;
	
	if ( NFWritePage(PageAdd,Music_pt) ==0)
    {
        Uart_SendString("\nWriting page0 Ok!\n");
    }
    else
    {
        Uart_SendString("\nWriting page0 Failed...\n");
    } 
*/	
	
//Writing all the Music to the NandFlash
    
    for ( PageNum=0; PageNum<NeedPage; PageNum++)
    {
    	
    	if (NFWritePage(PageAdd,Music_pt)==1)	//Writing Process
    	{
    		Uart_Printf("Writing Page:%d Failed...\n",PageNum);
    		return;
    	}
    	
    	Music_pt=Music_pt+512;				//Music_pt Operation
    	PageAdd=PageAdd+1;					//PageAdd  Operation
    }
		Uart_SendString("Writing All page Success!...\n");

}


void Rec_song(void)
{
	U32 PageNum;		//Page Number
	U32	PageAdd;		//Page Begin Address
	U32 NeedPage;		//Need page Numbers
	
	U8  *Music_pt;		//Music Point
	
	Music_pt=Music_Buf;
	
	PageNum=0;
	PageAdd=0;
	NeedPage=1<<12;		//7+5  Get 2mb Buffer
	
	
///Getting the Music File
	for( PageNum=0; PageNum<NeedPage; PageNum++)
	{	
	NFReadPage(PageAdd, Music_pt);
	Music_pt=Music_pt+512;				//Music_pt Operation
    PageAdd=PageAdd+1;				//PageAdd  Operation
	}
	
	Uart_SendString("Getting Music File to Music_Buffer\n");
}

void Playing_song(void)
{
 	Uart_SendString("Now Playing the Music , Enjoy...\n"); 
	Play_Wave(Music_Buf);
}



















⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -