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

📄 test.c

📁 AT91fr40162的FLASH读写程序
💻 C
字号:

#include "dtm_v3.h"
#include "dtm.h"
#include "externdef.h"
#include <stdio.h>
#include <stdlib.h>
#include "flash_40162s.h"

_BYTE TestWriteBIEFBaseInfo(void);
_BYTE TestWriteBIEFTrainInfo(void);
_BYTE TestWriteBIEFTimeInfo(void);


_BYTE  Car[128] = {
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,
	0x43,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x01,0x00,0x00,0x00,0x00,
	0x00,0x03,0x0F,0x0F,0x03,0x03,0x3E,0x76,0xEF,0xDF,0xFF,0xFF,0xFF,0xFF,0xF8,0xFC,
	0xFE,0xFE,0xFE,0xFC,0xF8,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3C,0x7C,0x7C,0x7C,0x00,
	0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0xC0,0xC0,0x80,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0xC0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00
} ;

void TestDispImage()
{
	_BYTE i,j;	
	for (i=0;i<20;i++) {
		for (j=0;j<20;j++) {
		   	DispLCDClearScreen();
			DispOutImageInRow(i,j,32,32,Car,0);
	   		DispRefreshInRow(i,j,32,32);
			Delayms(20);
		}
	}	
}


_BYTE TestWriteBIEFBaseInfo(void)
{
	SBIEF_1 sBaseInfo;
	_BYTE cRetCode;
	_WORD i;
   	_BYTE  cpSample[LENOFMB];									// 内容为指纹评分(1)+指纹长度(2)+指纹数据(<=400)
   	_WORD  wFeatureLength;
   	_BYTE cScore;

	sBaseInfo.dwCardID=0x3333;									// 持卡人编号
	for (i=0;i<128;i++) sBaseInfo.cpName[i]=0xFF;				//gFontBuf[368+i];
	sBaseInfo.cCardType = 0x02;	//0x02;
	sBaseInfo.wMaxItem = 511;

   	for (i=0;i<LENOFMB;i++) cpSample[i]=0x6F;
	sBaseInfo.cFingerScore1 = cScore;
	sBaseInfo.wFingerLength1 = wFeatureLength;
	for (i=0;i<LENOFMB-1;i++) sBaseInfo.cpFingerMB1[i] = cpSample[i];						// 指纹模板一

   	for (i=0;i<LENOFMB;i++) cpSample[i]=0xF6;
	sBaseInfo.cFingerScore2 = cScore;
	sBaseInfo.wFingerLength2 = wFeatureLength;						// 指纹二长度
	for (i=0;i<LENOFMB-1;i++) sBaseInfo.cpFingerMB2[i] = cpSample[i];						// 指纹模板一
	cRetCode = ICReadWriteBIEFBaseInfo(&sBaseInfo,ICWRITE);
	return(cRetCode);
}
 

_BYTE TestWriteBIEFTrainInfo(void)
{
	SBIEF_2 sTrainInfo;
	_BYTE cRetCode;
	_BYTE cCopy = 0;
	sTrainInfo.dwDayFieldTotalTime = 0;					// 日道训累加时间
	sTrainInfo.dwDayFieldTotalMile = 0;					// 日道训累加里程
	sTrainInfo.dwDayRoadTotalTime = 0;					// 日场训累加时间
	sTrainInfo.dwDayRoadTotalMile = 0;					// 日场训累加里程
	sTrainInfo.dwNightFieldTotalTime = 0;				// 夜道训累加时间
	sTrainInfo.dwNightFieldTotalMile = 0;				// 夜道训累加里程
	sTrainInfo.dwNightRoadTotalTime = 0;				// 夜场训累加时间
	sTrainInfo.dwNightRoadTotalMile = 0;				// 夜场训累加里程
	sTrainInfo.wCurrentItem = 0;						// 当前条数
	sTrainInfo.cCrc = 0;								// 校验
	cRetCode = ICReadWriteBIEFTrainInfo(&sTrainInfo,ICWRITE,&cCopy);
	return(cRetCode);
}

_BYTE TestWriteBIEFTimeInfo(void)
{
	SBIEF_3 sTimeInfo;
	_BYTE cRetCode;
	_BYTE cCopy = 0;
	sTimeInfo.wBuyTime = 30*60;								// 买钟总时间								
	sTimeInfo.wBuyDayFieldTime = 10*60;						// 买钟日场训时间
	sTimeInfo.wBuyDayRoadTime = 20*60;						// 买钟日路训时间
	sTimeInfo.wBuyNightFieldTime = 0;					// 买钟夜场训时间
	sTimeInfo.wBuyNightRoadTime = 0;					// 买钟夜路训时间
	sTimeInfo.cCrc = 0;									// 校验
	cRetCode = ICReadWriteBIEFTimeInfo(&sTimeInfo,ICWRITE,&cCopy);
	return(cRetCode);
}





_BYTE TestWriteFlash(void)
{
	_BYTE cRetCode;
	cRetCode = AT91FlashCheckIdentifyID();
	if (cRetCode!=C_OK) return(cRetCode);
	
	cRetCode = AT91ChipErase();   // 写BootLoader
	if (cRetCode!=C_OK) return(cRetCode);
	
	//cRetCode = AT91EraseSector(0x00000);										// 擦除块0-7的64K
	//if (cRetCode!=C_OK)return(cRetCode);

	cRetCode = AT91WriteBlockToFlash((_WORD*)0x20000,(_WORD*)FLASH_BASE,0x02000);// 写块0的8K
	if (cRetCode!=FLASH_OK) return(cRetCode);
	cRetCode = AT91WriteBlockToFlash((_WORD*)0x22000,(_WORD*)(FLASH_BASE+0x2000),0x02000);// 写块1的8K
	if (cRetCode!=FLASH_OK) return(cRetCode);

//	cRetCode = AT91WriteBlockToFlash((_WORD*)0x22000,(_WORD*)(FLASH_BASE+0x1F0000),0x02000);// 写块38的8K
//	if (cRetCode!=FLASH_OK) return(cRetCode);
	return(cRetCode);
}


_BYTE TestFlashReadWriteMB()
{
	_BYTE cpTxBuf[LENOFBIEFBASEINFO],cpRxBuf[LENOFBIEFBASEINFO];
	_BYTE cRetCode;
	_BYTE ErrorCounter,ErrPass,OKPass,ErrFlag;
	_WORD wAdd;
	_WORD i,j;
	
	ErrorCounter = 0;
	ErrPass = 0;
	OKPass = 0;
				
	wAdd = 0x9;
	
	for (j=0;j<10;j++) {
		ErrFlag = 0;
		for (i=0;i<LENOFBIEFBASEINFO;i++)	cpTxBuf[i]=0xAA+i;
		cRetCode = FlashWriteBuf(wAdd,LENOFMB,FLASH_CHIP2,cpTxBuf);
        if (cRetCode!=C_OK) {
			Beep(8);
        	return(cRetCode);
        }	
		for (i=0;i<LENOFMB;i++)	cpRxBuf[i]=0x00;
       	cRetCode = FlashReadBuf(wAdd,LENOFMB,FLASH_CHIP2,cpRxBuf);
        if (cRetCode!=C_OK) {
			Beep(8);
        	return(cRetCode);
        }	
		for (i=0;i<LENOFMB;i++) {
			if (cpTxBuf[i]!=cpRxBuf[i]) {
				ErrorCounter++;
				ErrFlag = 1;
			}
		}
		if (ErrFlag==1) 
			OKPass++;
		else
			ErrPass++;
		cRetCode = ErrorCounter+ErrPass+OKPass+ErrFlag;
	}
	while(1);		
}


_BYTE TestRAM(void)
{
	_WORD i,j;
		
	for(j=0;j<256;j++){
		for(i=0;i<1024;i++)
			wADDRESS[i]=(_BYTE)(i);
	}
		
	Delayms(1);
	for(j=0;j<256;j++){
		for(i=0;i<1024;i++){
			if((_BYTE)(i)!=wADDRESS[i]) return(C_NOTOK);
					
		}
	}
return(C_OK);
}

_BYTE TestEEPROM1(void)
{
  _BYTE testBuff[1024];
  _WORD i,wAddress;
  _BYTE cRetCode;
  
  wAddress=0x0000;
  
  for (i=0; i<=1024; i++ )
    	    testBuff[i]=(_BYTE)(i+1);
    	    
  cRetCode = FlashWriteBuf(wAddress,1024,2,testBuff);
  if(cRetCode!=C_OK) return(C_NOTOK);
   	       
   	
  for (i=0; i<=1024; i++ ) testBuff[i]=0;
    	    	    
  cRetCode= FlashReadBuf(wAddress,1024,1,testBuff);
  if(cRetCode!=C_OK) return(C_NOTOK);
    
  for ( i=0;i<1024;i++){
     if (testBuff[i] !=(_BYTE)(i+1)) return(C_NOTOK);
  }
 
return(C_OK);
}

_BYTE TestEEPROM2(void)
{
  _BYTE testBuff[1024];
  _WORD i,wAddress;
  _BYTE cRetCode;
  
  wAddress=0x0000;
  
  for (i=0; i<=1024; i++ )
    	    testBuff[i]=(_BYTE)(i+2);
    	    
   cRetCode = FlashWriteBuf(wAddress,1024,1,testBuff);
 if(cRetCode!=C_OK) return(C_NOTOK);
    	
  
  for (i=0; i<=1024; i++ ) testBuff[i]=0;
    	    
  cRetCode= FlashReadBuf(wAddress,1024,1,testBuff);
  if(cRetCode!=C_OK) return(C_NOTOK);
     
  for ( i=0;i<1024;i++){
     	if (testBuff[i] !=(_BYTE)(i+2)) return(C_NOTOK);
  }
return(C_OK);
}


_BYTE TestICcard(void)
{
  _BYTE testBuff[1024];
  _WORD i,wAddress;
  _BYTE cRetCode,j;
  ICPower(ON);
  wAddress=0x0000;
  for(j=0;j<2;j++){
  wAddress += j*1024;
 
    	
  for (i=0; i<=1024; i++ )
     	testBuff[i]=(_BYTE)(i);
    	    
  cRetCode = ICWriteBlock(wAddress,1024,testBuff);
  if(cRetCode!=C_OK) return(C_NOTOK);
  	
  for (i=0; i<1024; i++ )
   	testBuff[i]=(_BYTE)(0);
    	    
  cRetCode = ICReadBlock(wAddress,1024,testBuff);
  if(cRetCode!=C_OK) return(C_NOTOK);
  	 
  for ( i=0;i<1024;i++){
  	   	if (testBuff[i] !=(_BYTE)(i)) return(C_NOTOK);
  	   }
  	}
    	
 return(C_OK);
}

⌨️ 快捷键说明

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