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

📄 mbm29lv160.c

📁 1针对三星44B0的开发程序2对于网卡的驱动程序3程序采用C语言编程4采用ARM指令集5全部代码在 ADS1.2 中编译调试
💻 C
字号:
#include "../inc/def.h"
#include "../inc/config.h"
#include "../inc/utils.h"
#include "../inc/board.h"

#ifdef	MBM29LV160_SUPPORT

#undef	outport
#undef	inport

#ifdef	MODE_16BITS
#define	FL_OP_ADDR1	((0x555<<1)+ROM_BASE)
#define	FL_OP_ADDR2	((0x2aa<<1)+ROM_BASE)

#define	outport	outportw
#define	inport	inportw

#define	EnterQuery()	outportw(0x98, 0x55*2+ROM_BASE)
#define	ExitQuery()		outportw(0xf0, 0x100+ROM_BASE)

#else
#define	FL_OP_ADDR1	(0xaaa+ROM_BASE)
#define	FL_OP_ADDR2	(0x555+ROM_BASE)

#define	outport	outportb
#define	inport	inportb

#define	EnterQuery()	outportb(0x98, 0xaa+ROM_BASE)
#define	ExitQuery()		outportb(0xf0, 0x100+ROM_BASE)

#endif

static U16 support, flash_type;

static int EraseSector(U32 sector)
{
	U32 tm;
	
	sector += ROM_BASE;

	outport(0xaa, FL_OP_ADDR1);
	outport(0x55, FL_OP_ADDR2);
	outport(0x80, FL_OP_ADDR1);
	outport(0xaa, FL_OP_ADDR1);
	outport(0x55, FL_OP_ADDR2);
	outport(0x30, sector);

		//Delay(2000);
		//printf("%x\n", inport(sector));
		//return 0;
	tm = 400000;
	while(1) {
		if((inport(sector)^inport(sector))&0x40) {	//D6 == D6
			tm--;
			if(tm)
				continue;
			return -1;
		}
		
		if(inport(sector)&0x80) {
		//	printf("tm=%d\n", tm);
			return 0;
		}
		return -1;
	}
}

#define	CHECK_DELAY	10000

static int ProgProc(U32 fl_addr, U32 buf_addr, U32 len)
{
	U32 tm;	
	int err = 0;
	
	fl_addr += ROM_BASE;
	
	while(len) {
#ifdef	MODE_16BITS
		U16 dat = *(U16 *)buf_addr;
#else
		U8 dat = *(U8 *)buf_addr;
#endif			
		outport(0xaa, FL_OP_ADDR1);			
		outport(0x55, FL_OP_ADDR2);
		outport(0xa0, FL_OP_ADDR1);
		outport(dat, fl_addr);		
		
		//Delay(1);
		
		tm = CHECK_DELAY;
		while(--tm) {			
			if((inport(fl_addr)^inport(fl_addr))&(0x40))	//D6 == D6				
				continue;

			if(inport(fl_addr)==dat)
				break;
		}
		if(!tm)
			err = 1;

#ifdef	MODE_16BITS
		fl_addr  += 2;
		buf_addr += 2;
		len -=2;
#else
		fl_addr++;
		buf_addr++;
		len--;
#endif		
	}
	
	return err;
}

void NorFlashInit(void)
{
	U32 i;

	support = 0;
		
	EnterQuery();
	
	if(inport(0x20+ROM_BASE)=='Q')
		if(inport(0x22+ROM_BASE)=='R')
			if(inportb(0x24+ROM_BASE)=='Y') {
				ExitQuery();
				outport(0xaa, FL_OP_ADDR1);			
				outport(0x55, FL_OP_ADDR2);
				outport(0x90, FL_OP_ADDR1);
				i = inport(ROM_BASE+2);
				i &= 0xff;
				if(i==0xc4) {
					flash_type = 'T';
					support = 1;
				}
				if(i==0x49) {
					flash_type = 'B';
					support = 1;
				}
			}
	
	ExitQuery();
}

void NorFlashStatusRep(void)
{
	if(support) {
		printf("29LV160 Found, type-%c\n", flash_type);
	} else
		printf("No 29LV160 Found\n");
}

void NorFlashProg(U32 addr, U32 buf, U32 len)
{
	U32 size, sector_size;
	U8 dat[SIZE_64K];
	
	if(!support)
		return;
	
#ifdef	MODE_16BITS
	addr &= ~1;
	len  &= ~1;
#endif	

	if((addr+len)>=ROM_SIZE) {
		printf("Address error!\n");
		return;
	}
	
	while(len) {
		if(flash_type=='B') {
			if(addr<0x4000)
				sector_size = SIZE_16K;
			else if(addr<0x8000)
				sector_size = SIZE_8K;
			else if(addr<0x10000)
				sector_size = SIZE_32K;
			else
				sector_size = SIZE_64K;
		} else {
			if(addr>=0x1fc000)
				sector_size = SIZE_16K;
			else if(addr>=0x1f8000)
				sector_size = SIZE_8K;
			else if(addr>=0x1f0000)
				sector_size = SIZE_32K;
			else
				sector_size = SIZE_64K;
		}

		size = sector_size-(addr&(sector_size-1));
				
		if(size>len)
			size = len;
			
		if(size<sector_size) {
			NorFlashRead(dat, addr&~(sector_size-1), sector_size);			
			memcpy(dat+(addr&(sector_size-1)), (char *)buf, size);
		} else {
			memcpy(dat, (char *)buf, size);
		}
		
		/*{
			int i;
			
			putch('\n');
			for(i=0;i<16;i++)
				printf("%4x", dat[(addr&(sector_size-1))+i]);
		}*/
		
		EraseSector(addr&~(sector_size-1));
		Delay(10);
		printf("Sector %x erased...", addr&~(sector_size-1));
		printf("program 0x%x, len %d...", addr, size);
		if(ProgProc(addr&~(sector_size-1), (U32)dat, sector_size))
			printf("Fail\n");
		else
			printf("Ok\n");
		addr += size;
		buf  += size;
		len  -= size;
	}
}

#endif

⌨️ 快捷键说明

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