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

📄 hpi.c

📁 ARM的串口源码
💻 C
📖 第 1 页 / 共 4 页
字号:
     case 0x0025: //i.e.  二楼 16F
	 	Command.Parameter[0] = 0x31;
		Command.Parameter[1] = 0x36;
		Command.Parameter[2] = 0x46;
	 	break;
     case 0x0026: //i.e.  二楼 16F
	 	Command.Parameter[0] = 0x31;
		Command.Parameter[1] = 0x36;
		Command.Parameter[2] = 0x46;
	 	break;
     case 0x0027: //i.e.  二楼 16F
	 	Command.Parameter[0] = 0x31;
		Command.Parameter[1] = 0x36;
		Command.Parameter[2] = 0x46;
	 	break;
     case 0x0028: //i.e.  二楼 16F
	 	Command.Parameter[0] = 0x31;
		Command.Parameter[1] = 0x36;
		Command.Parameter[2] = 0x46;
	 	break;
     case 0x0029: //i.e.  二楼 16F
	 	Command.Parameter[0] = 0x31;
		Command.Parameter[1] = 0x36;
		Command.Parameter[2] = 0x46;
	 	break;
     case 0x002a: //i.e.  二楼 16F
	 	Command.Parameter[0] = 0x31;
		Command.Parameter[1] = 0x36;
		Command.Parameter[2] = 0x46;
	 	break;
     case 0x002b: //i.e.  二楼 16F
	 	Command.Parameter[0] = 0x31;
		Command.Parameter[1] = 0x36;
		Command.Parameter[2] = 0x46;
	 	break;
     case 0x002c: //i.e.  二楼 16F
	 	Command.Parameter[0] = 0x31;
		Command.Parameter[1] = 0x36;
		Command.Parameter[2] = 0x46;
	 	break;
     case 0x002d: //i.e.  二楼 16F
	 	Command.Parameter[0] = 0x31;
		Command.Parameter[1] = 0x36;
		Command.Parameter[2] = 0x46;
	 	break;
     case 0x002e: //i.e.  二楼 16F
	 	Command.Parameter[0] = 0x31;
		Command.Parameter[1] = 0x36;
		Command.Parameter[2] = 0x46;
	 	break;
     case 0x002f: //i.e.  二楼 16F
	 	Command.Parameter[0] = 0x31;
		Command.Parameter[1] = 0x36;
		Command.Parameter[2] = 0x46;
	 	break;
     case 0x0030: //i.e.  二楼 16F
	 	Command.Parameter[0] = 0x31;
		Command.Parameter[1] = 0x36;
		Command.Parameter[2] = 0x46;
	 	break;
	 default: 
		nosignal = 1;	//没有对应信号的音乐,则不播放
	 	break;
	}
	switch(code026.special)
	{
		case 1:
			break;
		case 2:
			break;
		case 4:
			break;
		case 8:
			break;
		case 16:
			break;
		case 32:
			break;
		case 64:
			break;
		case 128:
			break;
		default:
			if(nosignal)
					return FALSE;
			else 
					break;
	}
	if(!Findfile()) return FALSE;		//如果U盘中无所要播放文件,则返回错误
	return TRUE;
}

*/
unsigned char Findfile(void)	//寻找U盘中是否有需播放的文件
{
 unsigned char i,j;
 for(i=0;i<Filelist.list.number;i++)	//文件数
 {
  for(j=0;j<9;j++)	//文件名
  {
   if(j==8)return TRUE;
   if(Command.Parameter[j] != Filelist.list.dir[i].name[j])	break;
  }
 }
 return FALSE;
}

unsigned char UartHandler(void)  //顶层应用接口
{
  unsigned short temp = 10;
  union{
 		 unsigned char c[4];
  		 unsigned long add;
	}wavlen;  //每个音频文件的总长度	

  Response.Result=0;Response.len=0;
  while((!Response.Result)&&(temp--))//打开文件,运行5次,如果不成功则退出
  {
	 	Response.Result = OpenFile(Command.Parameter);
  }
  if(!Response.Result)
  {
  	  	return FALSE;
  }
  temp = 10;Response.Result=0;
  while((!Response.Result)&&(temp--))
  	{
  	 Response.Result = SetFilePointer(0x0000003a+setpointer);//设置指针到WAV文档PCM音源处,若是背景音乐,则在断点处继续播放
  	}
  for(temp=0;temp<8;temp++)Command.Parameter[temp]=0x20;  //清空文件名,用于判断新信号

  wavlen.c[3] = UARTBUF[31];	//载入文件长度
  wavlen.c[2] = UARTBUF[30];
  wavlen.c[1] = UARTBUF[29];
  wavlen.c[0] = UARTBUF[28];  

  wavlen.add -= 0x00003a;	//去掉文件头长度
  wavlen.add -= setpointer;  //去掉断点处长度
  WAVreadcount = 0;				//设置P1口指针位置和计数
  WAVdata.sendready = 0x00003E80;	//设置提前填充WAVBUF时间
  WAVdata.sendlen = WAVLEN;	//设置填充BUF的数据量
  if(wavlen.add<WAVLEN)		//若发送字节数小于BUF大小
  {
   WAVdata.sendlen = wavlen.add;
   WAVdata.sendready = WAVdata.sendlen-500;  //当读到sendready位置时通知前台程序继续从头充满BUF
  }
//  ComSendByte(0XEE); //for test
  enable_INT();
  while(wavlen.add) //读取文件
  {
   	   WAVdata.sendover = 0;	//标志BUF未发送完		
	   Response.Result=ReadFile(WAVdata.sendlen,WAVdata.databuf);//填充BUF
	   IO0SET = 1<<OE;			//OE = 1; 打开CPLD,开始向DAC发送数据
  	   VICIntEnable = 1<<VICIntSel_EINT2;			//打开CPLD的中断
	   WAVdata.sendover = 0;	//标志BUF未发送完
	   if(bFlags.bits.bUartInDone==1)		  //若有BCD码,则退出
	   {
		if(BG.BGM)
		{
		 BG.setpointer = ThisFile.pointer;		//设置背景音乐的中断点,以便下次进入背景音乐时断点续播
		 BG.done = 0;		//表示背景音乐未播放完
		}
		BG.BGM = 0;		//表示接下来将进入信号状态,不播放背景音乐
		IO0CLR = 1<<OE;			//OE = 0; 关闭CPLD
  		VICIntEnClr = 1<<VICIntSel_EINT2;			//关闭CPLD的中断
		return TRUE;
	   }
	   if(wavlen.add<WAVLEN)//若发送字节数小于BUF大小
	   {
		WAVdata.sendlen = wavlen.add;
		WAVdata.sendready = WAVdata.sendlen-500;  //当读到sendready位置时通知前台程序继续从头充满BUF
	    if(wavlen.add<500)WAVdata.sendready=0;
	   }
	   while(!WAVdata.sendover);
	   { 
	   	 if(bFlags.bits.bUartInDone)
		 {
			  if(BG.BGM)
			  {
			  BG.setpointer = ThisFile.pointer;		//设置背景音乐的中断点,以便下次进入背景音乐时断点续播
			  BG.done = 0;		//表示背景音乐未播放完
			  }
			  BG.BGM = 0;		//表示接下来将进入信号状态,不播放背景音乐
			  IO0CLR = 1<<OE;			//OE = 0; 关闭CPLD
  			  VICIntEnClr = 1<<VICIntSel_EINT2;			//关闭CPLD的中断
			  return TRUE;
		 }
	   }
	   wavlen.add -= WAVdata.sendlen;  //修正剩余文件长度
  }
  BCDcodeTemp = 0;			//把并口缓存数据清零
  IO0CLR = 1<<OE;			//OE = 0; 关闭CPLD
  VICIntEnClr = 1<<VICIntSel_EINT2;			//关闭CPLD的中断
  BG.BGM = 1;
//  ComSendByte(0XFF);//for test
  return TRUE;  
}

unsigned char List(void)
{
	unsigned short item,i;
	unsigned char k,bstop,sector;
	unsigned char Lcount,Ncount,base;
	if(!bFlags.bits.SLAVE_IS_ATTACHED)
		return FALSE;	
	item=0;
	bstop=0;
	////////////////////////////////////
	Lcount=0;
	for(i=0;i<MaxLFNum;i++)
		{
		ShowFileName[i].LongName[0]=0x00;
		ShowFileName[i].LongName[1]=0x00;
		}
	/////////////////////////////////////
	if(DirStartCluster==0)	//Root Dir
	{
	for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
	    {   
		if(!RBC_Read(DeviceInfo.RootStartSector+sector,1,DBUF))
			return FALSE;			
		for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
			{
			if(DBUF[i]==0x00)
				{bstop=1;
				break;}
			else if(DBUF[i]==0xE5)
				continue;			
			else
				{
				for(k=0;k<32;k++)
					Filelist.value[item*32+k]=DBUF[i+k];
				item=item+1;
				/////////////////////////////////
				if(DBUF[i+11]==0x0F)
					{
					base=((DBUF[i]&0x1F)-1)*26;
					if(base<=224)
					{
					Ncount=0;
					for(k=1;k<11;k++)
						{
						ShowFileName[Lcount].LongName[base+Ncount]=DBUF[i+k];
						Ncount++;
						}
					for(k=14;k<26;k++)
						{
						ShowFileName[Lcount].LongName[base+Ncount]=DBUF[i+k];
						Ncount++;
						}
					for(k=28;k<32;k++)
						{
						ShowFileName[Lcount].LongName[base+Ncount]=DBUF[i+k];
						Ncount++;
						}
					}
					}
				else
					{
					for(k=0;k<32;k++)
						ShowFileName[Lcount].item[k]=DBUF[i+k];
				    Lcount++;					
					}			
				/////////////////////////////////
				}
			}
		
		if(bstop==1)break;		
	    }
	Response.len=item*32;
	return TRUE;
	}
//////////////////////////////////////////////////////////////////   
	else		//Son Dir
	{
		NowCluster=DirStartCluster;		
		do
		{
			NowSector=FirstSectorofCluster(NowCluster);
			for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
	    	{   
				if(!RBC_Read(NowSector+sector,1,DBUF))
					return FALSE;				
				for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
				{
					if(DBUF[i]==0x00)
						{bstop=1;break;}
					else if(DBUF[i]==0xE5)
						continue;			
					else
					{
						for(k=0;k<32;k++)
							Filelist.value[item*32+k]=DBUF[i+k];
						item=item+1;
						/////////////////////////////////
						if(DBUF[i+11]==0x0F)
						{
							base=((DBUF[i]&0x1F)-1)*26;
							if(base<=224)
							{
								Ncount=0;
								for(k=1;k<11;k++)
								{
									ShowFileName[Lcount].LongName[base+Ncount]=DBUF[i+k];
									Ncount++;
								}
								for(k=14;k<26;k++)
								{
									ShowFileName[Lcount].LongName[base+Ncount]=DBUF[i+k];
									Ncount++;
								}
								for(k=28;k<32;k++)
								{
									ShowFileName[Lcount].LongName[base+Ncount]=DBUF[i+k];
									Ncount++;
								}
							}
						}
						else
						{
							for(k=0;k<32;k++)
								ShowFileName[Lcount].item[k]=DBUF[i+k];
				 		   Lcount++;							
						}			
				/////////////////////////////////
					}
				}
				if(bstop==1)break;		
	    	}
			if(bstop==1)break;
	
			NowCluster=GetNextClusterNum(NowCluster); 
			
		}while(NowCluster<=0xffef);

	Response.len=item*32;
	return TRUE;
	}
}

unsigned char OpenFile(unsigned char *pBuffer)
{
	unsigned short i;
	unsigned char j,bstop,sector;
		
	if(!bFlags.bits.SLAVE_IS_ATTACHED)
		return FALSE;
					
	ThisFile.bFileOpen=0;

	if(DirStartCluster==0)	//Root Dir
	{
	for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
	    { 
			if(!RBC_Read(DeviceInfo.RootStartSector+sector,1,DBUF))
			return FALSE;
		for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
			{
			if(DBUF[i]==0x00)
				return FALSE;
			j=0;
			while(DBUF[i+j]==*(pBuffer+j))
				{
				 j=j+1;
				 if(j>10)
				 	break;
				}
			
			if(j>10&&(DBUF[i+11]&0x10)!=0x10)
			    {
			    for(j=0;j<32;j++)
			    	UARTBUF[j]=DBUF[i+j];		    
			    bstop=1;
			    break;
				}
			
			}
		if(bstop==1)break;
		}
	    
	    if(sector>=DeviceInfo.BPB_RootEntCnt)
	    	return FALSE;
	}
///////////////////////////////////////////////////////////////////////////////////////
	else
	{
		NowCluster=DirStartCluster;		
		do
		{
			NowSector=FirstSectorofCluster(NowCluster);
			for(sector=0;sector<DeviceInfo.BPB_SecPerClus;sector++)
	    	{   
				if(!RBC_Read(NowSector+sector,1,DBUF))
					return FALSE;				
				for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
				{
					if(DBUF[i]==0x00)
						return FALSE;
					j=0;
					while(DBUF[i+j]==*(pBuffer+j))
					{
						 j=j+1;
						 if(j>10)
						 	break;
					}
					if(j>10&&(DBUF[i+11]&0x10)!=0x10)
				    	{ 
						for(j=0;j<32;j++)
			    			UARTBUF[j]=DBUF[i+j];			    
			    		bstop=1;
			    		break;
						}
				}
				if(bstop==1)break;		
	    	}
			if(bstop==1)break;	
			NowCluster=GetNextClusterNum(NowCluster);			
		}while(NowCluster<=0xffef);
		
		if(NowCluster>0xffef)
	    	return FALSE;
	}

	ThisFile.bFileOpen=1;
	ThisFile.StartCluster=LSwapINT16(UARTBUF[26],UARTBUF[27]);
	ThisFile.LengthInByte=LSwapINT32(UARTBUF[28],UARTBUF[29],UARTBUF[30],UARTBUF[31]);
	ThisFile.ClusterPointer=ThisFile.StartCluster;	
	ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.StartCluster);
	ThisFile.OffsetofSector=0;
	ThisFile.SectorofCluster=0;	
	ThisFile.FatSectorPointer=0;	
	ThisFile.pointer=0;
	
	Response.len=32;
	return TRUE;	
}

unsigned char ReadFile(unsigned long readLength,unsigned char *pBuffer)
{

	unsigned short len,i;
	unsigned short tlen;	
	unsigned long blen;

	if(!bFlags.bits.SLAVE_IS_ATTACHED)
		return FALSE;		
	if(!ThisFile.bFileOpen)
		return FALSE;

	blen=readLength;

	tlen=0;
	if(readLength>MAX_READ_LENGTH)
		return FALSE;	

⌨️ 快捷键说明

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