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

📄 hpi.lst

📁 CYPRESS SL811相关资料
💻 LST
📖 第 1 页 / 共 3 页
字号:
 286   1      	if(!bXXGFlags.bits.SLAVE_IS_ATTACHED)
 287   1      	{
 288   2      	UartRspBlock.errcode=ERC_NODEVICE;
 289   2      	return FALSE;		
 290   2      	}
 291   1      	if(!ThisFile.bFileOpen)
 292   1      	{
 293   2      	UartRspBlock.errcode=ERC_FILENOTOPENED;
 294   2      	return FALSE;		
 295   2      	}
 296   1      	///////////////////////////////////////////////////////////
 297   1      	ThisFile.bFileOpen=0;
 298   1      	bSuccess=1;
 299   1      	UartRspBlock.len=0;
 300   1      	//lba=GetSecNumFromPointer();
 301   1      	//cluster=GetClusterNumFromSectorNum(lba);
 302   1      	//cluster=ThisFile.StartCluster;
 303   1      	//lba=FirstSectorofCluster(ThisFile.StartCluster);
C51 COMPILER V6.20c  HPI                                                                   08/21/2003 22:51:03 PAGE 6   

 304   1      	//readLength=SwapINT16(UartCmdBlock.CmdBlock.Cmd_ReadFile.readLength);
 305   1      	if(readLength>MAX_READ_LENGTH)
 306   1      		{
 307   2      		UartRspBlock.errcode=ERC_LENGTHEXCEED;
 308   2      		return FALSE;	
 309   2      		}
 310   1      	if(readLength+ThisFile.pointer>ThisFile.LengthInByte)
 311   1      		{
 312   2      		UartRspBlock.errcode=ERC_LENGTHEXCEED;
 313   2      		return FALSE;	
 314   2      		}
 315   1      	////////////////////////////////////////////
 316   1      		
 317   1      		///////////////////////////////////////////////////
 318   1      		while(readLength>0)
 319   1      		{
 320   2      		   if(readLength+ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec)
 321   2      		   	len=DeviceInfo.BPB_BytesPerSec;
 322   2      		   else
 323   2      		   	len=readLength+ThisFile.OffsetofSector;
 324   2      		   
 325   2      		   //////////////////////////////////////////////////////
 326   2      		   if(ThisFile.OffsetofSector>0)
 327   2      		   	{
 328   3      		   	if(RBC_Read(ThisFile.SectorPointer,1,DBUF))
 329   3      		   		{
 330   4      		   		//ThisFile.OffsetofSector=len;
 331   4      		   		len=len-ThisFile.OffsetofSector;
 332   4      		   		for(i=0;i<len;i++)
 333   4      		   			//UARTBUF[i]=DBUF[ThisFile.OffsetofSector+i];
 334   4      		   			*(pBuffer+i)=DBUF[ThisFile.OffsetofSector+i];
 335   4      		   		ThisFile.OffsetofSector=ThisFile.OffsetofSector+len;
 336   4      		   		}
 337   3      		   	else
 338   3      		   		{
 339   4      		   		UartRspBlock.errcode=ERC_DEVICEERR;
 340   4      				return FALSE;	
 341   4      		   		}
 342   3      		   	}
 343   2      		   else
 344   2      		   	{
 345   3      		   		if(!RBC_Read(ThisFile.SectorPointer,1,pBuffer+UartRspBlock.len))
 346   3      		   		{
 347   4      		   		UartRspBlock.errcode=ERC_DEVICEERR;
 348   4      				return FALSE;	
 349   4      		   		}
 350   3      		   		ThisFile.OffsetofSector=len;
 351   3      		   	}
 352   2      		   ////////////////////////////////////////////////////////////
 353   2      		  // if(ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)
 354   2      		  // 	ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
 355   2      		   readLength-=len;
 356   2      		   UartRspBlock.len+=len;
 357   2      		  // ThisFile.OffsetofSector=;
 358   2      		   /////////////////////////////////////////////////////////
 359   2      		   if(ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)
 360   2      		   {	
 361   3      		   	ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
 362   3      		   	ThisFile.SectorofCluster+=1;
 363   3      		   	if(ThisFile.SectorofCluster>DeviceInfo.BPB_SecPerClus-1)
 364   3      		   	{
 365   4      		   		ThisFile.SectorofCluster=0;
C51 COMPILER V6.20c  HPI                                                                   08/21/2003 22:51:03 PAGE 7   

 366   4      		 		 ThisFile.ClusterPointer=GetNextClusterNum(ThisFile.ClusterPointer);
 367   4      		 		 if(ThisFile.ClusterPointer>0xffef)
 368   4      		 		 	{
 369   5      		 		 	   //RspBlockReadFile.errcode=ERC_REACHEND;
 370   5      		   			   //RspBlockReadFile.result=0x0;
 371   5      		   			   UartRspBlock.errcode=ERC_REACHEND;
 372   5      					   return FALSE;	
 373   5      		 		 	}
 374   4      		 		 ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.ClusterPointer); 	
 375   4      		   	}
 376   3      		   	else
 377   3      		   		ThisFile.SectorPointer=ThisFile.SectorPointer+1;
 378   3      		    }
 379   2      		   //////////////////////////////////////////////////////////////////
 380   2      		}//end while
 381   1      	
 382   1      	
 383   1      	ThisFile.bFileOpen=1;
 384   1      	ThisFile.pointer+=UartRspBlock.len;
 385   1      	//////////////////////////////////////////////
 386   1      	RspBlockReadFile.readLength=SwapINT16(UartRspBlock.len);
 387   1      	return TRUE;
 388   1      #undef RspBlockReadFile
 389   1      }
 390          
 391          unsigned char CreateFile(unsigned char *pBuffer)
 392          {
 393   1      #define RspBlockCreateFile UartRspBlock.RspBlock.Rsp_CreateFile
 394   1      	//unsigned long sectorNum;
 395   1      	unsigned int sector,i,j;
 396   1      	unsigned char bstop;
 397   1      	PDIR_INFO pDirInfo;
 398   1      	
 399   1      	if(!bXXGFlags.bits.SLAVE_IS_ATTACHED)
 400   1      	{
 401   2      	UartRspBlock.errcode=ERC_NODEVICE;
 402   2      	return FALSE;		
 403   2      	}
 404   1      	///////////////////////////////////////////////////////////
 405   1      	//RspBlockCreateFile.result=0x1;
 406   1      	//RspBlockCreateFile.errcode=ERC_OK;
 407   1      	pDirInfo=(PDIR_INFO)pBuffer;
 408   1      	///////// Search the file of the same name  ///////////
 409   1      	//UartCmdBlock.CmdBlock.Cmd_CreateFile.filename[j]
 410   1      	//if(!SPC_TestUnit())
 411   1      	//	return FALSE;
 412   1      	//if(!RBC_Read(1,1,DBUF))
 413   1      	//	return FALSE;
 414   1      	//if(!RBC_Write(1,1,DBUF))
 415   1      	//	return FALSE;
 416   1      	//////// Search the fat for a free cluster  ////////////
 417   1      	pDirInfo->startCluster=SwapINT16(GetFreeCusterNum());
 418   1      	
 419   1      	if(pDirInfo->startCluster<0x2)
 420   1      	{
 421   2      	UartRspBlock.errcode=ERC_NODEVICE;
 422   2      	return FALSE;		
 423   2      	}
 424   1      	pDirInfo->length=0;
 425   1      	/////// Search a free space in the root dir space and build the item ///
 426   1      	ThisFile.bFileOpen=0;
 427   1      	bstop=0;
C51 COMPILER V6.20c  HPI                                                                   08/21/2003 22:51:03 PAGE 8   

 428   1      	for(sector=0;sector<DeviceInfo.BPB_RootEntCnt;sector++)
 429   1      	    {   
 430   2      		//////////////////////////////////////////////////
 431   2      		if(!RBC_Read(DeviceInfo.RootStartSector+sector,1,DBUF))
 432   2      			{
 433   3      			
 434   3      			UartRspBlock.errcode=ERC_DEVICEERR;
 435   3      				return FALSE;	
 436   3      			}
 437   2      		///////////////////////////////////////////////////
 438   2      		for(i=0;i<DeviceInfo.BPB_BytesPerSec;i=i+32)
 439   2      			{
 440   3      			if((DBUF[i]==0x00)||(DBUF[i]==0xE5))
 441   3      				{
 442   4      				for(j=0;j<32;j++)
 443   4      					//DBUF[i+j]=UartCmdBlock.CmdBlock.Cmd_CreateFile.item[j];
 444   4      					DBUF[i+j]=*(pBuffer+j);
 445   4      				if(!RBC_Write(DeviceInfo.RootStartSector+sector,1,DBUF))
 446   4      		  	 		{
 447   5      		  	 		UartRspBlock.errcode=ERC_DEVICEERR;
 448   5      					return FALSE;	
 449   5      		  	 		}
 450   4      				bstop=1;
 451   4      				break;
 452   4      				}
 453   3      			}
 454   2      		///////////////////////////////////////////////////////
 455   2      		if(bstop==1)break;
 456   2      		
 457   2      	    }
 458   1      	/////////////////////////////////////////////
 459   1      	//pDirInfo=(PDIR_INFO)RspBlockOpenFile.item;
 460   1      	//ThisFile.FatSectorPointer=ThisFatSecNum(ThisFile.StartCluster);
 461   1      	ThisFile.StartCluster=SwapINT16(pDirInfo->startCluster);
 462   1      	ThisFile.LengthInByte=0;
 463   1      	ThisFile.ClusterPointer=ThisFile.StartCluster;
 464   1      	ThisFile.SectorPointer=FirstSectorofCluster(ThisFile.StartCluster);
 465   1      	ThisFile.OffsetofSector=0;
 466   1      	ThisFile.SectorofCluster=0;
 467   1      	ThisFile.bFileOpen=1;
 468   1      	ThisFile.pointer=0;
 469   1      	ThisFile.FatSectorPointer=0;
 470   1      	//////////////////////////////////////////////
 471   1      	FreeFat.SectorNum=DeviceInfo.FatStartSector;
 472   1      	FreeFat.OldSectorNum=DeviceInfo.FatStartSector;
 473   1      	FreeFat.OffsetofSector=2;
 474   1      	
 475   1      	return TRUE;
 476   1      #undef RspBlockCreateFile
 477   1      }
 478          
 479          unsigned char WriteFile(unsigned int writeLength,unsigned char *pBuffer)
 480          {
 481   1      #define RspBlockWriteFile UartRspBlock.RspBlock.Rsp_WriteFile
 482   1      	unsigned int len,sector,i;
 483   1      	PDIR_INFO pDirInfo;
 484   1      	unsigned char bSuccess,bStop,step;
 485   1      	
 486   1      	if(!bXXGFlags.bits.SLAVE_IS_ATTACHED)	//U盘是否已经连接
 487   1      	{
 488   2      	UartRspBlock.errcode=ERC_NODEVICE;
 489   2      	return FALSE;		
C51 COMPILER V6.20c  HPI                                                                   08/21/2003 22:51:03 PAGE 9   

 490   2      	}
 491   1      	if(!ThisFile.bFileOpen)			//文件是否已经打开
 492   1      	{
 493   2      	UartRspBlock.errcode=ERC_FILENOTOPENED;
 494   2      	return FALSE;		
 495   2      	}
 496   1      	///////////////////////////////////////////////////////////
 497   1      	//if(UartCmdBlock.CmdBlock.Cmd_WriteFile.writeLength>0)
 498   1      	//	{
 499   1      	//	for(i=UartCmdBlock.CmdBlock.Cmd_WriteFile.writeLength;i<MAX_WRITE_LENGTH;i++)
 500   1      	//	UARTBUF[i]=0;
 501   1      	//	}
 502   1      		
 503   1      	///////////////////////////////////////////////////////////
 504   1      	ThisFile.bFileOpen=0;
 505   1      	bSuccess=1;
 506   1      	bStop=0;
 507   1      
 508   1      	UartRspBlock.len=0;
 509   1      	//if(UartCmdBlock.CmdBlock.Cmd_WriteFile.writeLength)
 510   1      	while(writeLength>0)				
 511   1      	{
 512   2      		 //////////////////////////////////////////////////////
 513   2      		 if(ThisFile.OffsetofSector>0)
 514   2      		 	{
 515   3      		 	if(writeLength+ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec)
 516   3      		   		len=DeviceInfo.BPB_BytesPerSec;
 517   3      			else
 518   3      		   		len=writeLength+ThisFile.OffsetofSector;
 519   3      			//////////////////////////////////////////////////
 520   3      		 	if(!RBC_Read(ThisFile.SectorPointer,1,DBUF))
 521   3      				{
 522   4      		   		UartRspBlock.errcode=ERC_DEVICEERR;
 523   4      				return FALSE;	
 524   4      		   		}
 525   3      		   			//ThisFile.OffsetofSector=len;
 526   3      			len=len-ThisFile.OffsetofSector;
 527   3      		   	for(i=0;i<len;i++)
 528   3      		   		//DBUF[ThisFile.OffsetofSector+i]=UARTBUF[i];
 529   3      		   		DBUF[ThisFile.OffsetofSector+i]=*(pBuffer+i);
 530   3      		   	if(!RBC_Write(ThisFile.SectorPointer,1,DBUF))
 531   3      		   			{
 532   4      		   			UartRspBlock.errcode=ERC_DEVICEERR;
 533   4      					return FALSE;	
 534   4      		   			}
 535   3      		  	ThisFile.OffsetofSector=ThisFile.OffsetofSector+len;
 536   3      		   	}
 537   2      		 else
 538   2      		 	{
 539   3      		 	if(writeLength>DeviceInfo.BPB_BytesPerSec)
 540   3      		   		{
 541   4      		   		step=writeLength/DeviceInfo.BPB_BytesPerSec;
 542   4      		   		//step=step-ThisFile.SectorofCluster;
 543   4      		   		if(step>DeviceInfo.BPB_SecPerClus)
 544   4      		   			{
 545   5      		   			step=DeviceInfo.BPB_SecPerClus-ThisFile.SectorofCluster;
 546   5      		   			len=step*DeviceInfo.BPB_BytesPerSec;	
 547   5      		   			}
 548   4      		   		else	
 549   4      		   			{
 550   5      		   			step=step-ThisFile.SectorofCluster;
 551   5      		   			len=step*DeviceInfo.BPB_BytesPerSec;
C51 COMPILER V6.20c  HPI                                                                   08/21/2003 22:51:03 PAGE 10  

 552   5      		   			}
 553   4      		   		}
 554   3      			else
 555   3      		   		{
 556   4      		   		step=1;
 557   4      		   		len=writeLength;
 558   4      		   		}
 559   3      		 	////////////////////////////////////////////
 560   3      		 	if(!RBC_Write(ThisFile.SectorPointer,step,pBuffer+UartRspBlock.len))
 561   3      		   		{
 562   4      		   		UartRspBlock.errcode=ERC_DEVICEERR;
 563   4      				return FALSE;	
 564   4      		   		}
 565   3      		   	ThisFile.OffsetofSector=len;
 566   3      		 	}
 567   2      		 /////////////////////////////////////////////////////
 568   2      		 //if(ThisFile.OffsetofSector>DeviceInfo.BPB_BytesPerSec-1)
 569   2      		 //  	ThisFile.OffsetofSector-=DeviceInfo.BPB_BytesPerSec;
 570   2      		   writeLength-=len;
 571   2      		   UartRspBlock.len+=len;
 572   2      		   //ThisFile.LengthInByte+=len;
 573   2      		/////////////更新文件指针 //////////////////////////////
 574   2      		//改变参数:OffsetofSector,SectorofCluster,SectorPointer,ClusterPointer
 575   2      		  step=ThisFile.OffsetofSector/DeviceInfo.BPB_BytesPerSec;
 576   2      		  
 577   2      		  if(step>0)

⌨️ 快捷键说明

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