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

📄 flashdrv.c

📁 microwindows移植到S3C44B0的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
			WRITE_SHORT(FLASH_BASE_ADDRESS + 2, FirstData);#ifdef BE			s = data;#else			s = (data >> 16);#endif			WRITE_SHORT(FLASH_BASE_ADDRESS + offset + 2, s);			/* polling on writing action => when done break. */			while (true) {				WRITE_SHORT(FLASH_BASE_ADDRESS + 2,					    data70);				regValue =				    READSHORT(FLASH_BASE_ADDRESS + 2);				if ((regValue & data80) == data80)					break;			}			/* Reading STATUS Register for Writing Verification */			WRITE_CHAR(FLASH_BASE_ADDRESS, data70);			regValue = READCHAR(FLASH_BASE_ADDRESS);			if ((regValue & data10) == data10)				return false;	/* Write failure */			flashReset();			return true;		case 4:		case 8:			if (FLASH_MODE == X16) {	/* Case of one X16 bit device */				FirstData = 0x00100010;	/* Data for the First  Cycle  */			} else {	/* (FLASH_MODE == 8) ==> Case of two X8 bit devices */				FirstData = 0x10101010;	/* Data for the First  Cycle  */			}			/* Writing First two Bytes */			WRITE_WORD(FLASH_BASE_ADDRESS +				   offset % FLASH_WIDTH, FirstData);#ifdef BE			s = (data >> 16);#else			s = data;#endif			/* writing the 32-bit data to flash. */			WRITE_WORD(FLASH_BASE_ADDRESS + offset, data);			if (FLASH_MODE == X16) {				data70 = 0x0070;				data80 = 0x0080;				data10 = 0x0010;			} else {	/* (FLASH_MODE == 8) */				data70 = 0x7070;				data80 = 0x8080;				data10 = 0x1010;			}			while (true) {				WRITE_SHORT(FLASH_BASE_ADDRESS +					    offset % FLASH_WIDTH, data70);				regValue = READSHORT(FLASH_BASE_ADDRESS);				if ((regValue & data80) == data80)					break;			}			/* Reading STATUS Register for Writing Verification */			WRITE_CHAR(FLASH_BASE_ADDRESS, data70);			regValue = READCHAR(FLASH_BASE_ADDRESS);			if ((regValue & data10) == data10)				return false;	/* Write failure */			/* Writing Last two Bytes */#ifdef BE			s = data;#else			s = (data >> 16);#endif			while (true) {				WRITE_SHORT(FLASH_BASE_ADDRESS +					    offset % FLASH_WIDTH + 2,					    data70);				regValue =				    READSHORT(FLASH_BASE_ADDRESS +					      offset % FLASH_WIDTH + 2);				if ((regValue & data80) == data80)					break;			}			/* Reading STATUS Register for Writing Verification */			WRITE_CHAR(FLASH_BASE_ADDRESS, data70);			regValue = READCHAR(FLASH_BASE_ADDRESS);			if ((regValue & data10) == data10)				return false;	/* Write failure */			flashReset();			return true;		default:			flashReset();			return false;		}	}	flashReset();	return true;}/********************************************************************* flashReadWord - Read 32Bit from the FLASH memory at a given offset *                 from the FLASH base address.* 				  address 0 = 0x00000000 !!*                 The function takes care of Big/Little endian conversion* INPUTS:  offset,the offset from the flash`s base address* RETURNS: data*********************************************************************/unsigned int flashReadWord(unsigned int offset){	unsigned int regValue;	flashReset();	READ_WORD(FLASH_BASE_ADDRESS + offset, &regValue);	return regValue;}/********************************************************************* flashInWhichSector - Returns the sector`s number at which offset is at.** INPUTS:  Offset* RETURNS: Sector number,or 0xffffffff in case the address is out of range or *          flash wasn't initialize.*********************************************************************/unsigned int flashInWhichSector(unsigned int offset){	unsigned int sectorNumber, numberOfDevices;	unsigned int accMemory = 0;	if ((FLASH_MODE == PURE8) || (FLASH_MODE == X8)) {		numberOfDevices = FLASH_WIDTH;	} else {		/* X16 mode */		numberOfDevices = FLASH_WIDTH / 2;	}	for (sectorNumber = 0;	     sectorNumber < flashTypes[NUMBER_OF_SECTORS]; sectorNumber++) {		accMemory =		    accMemory + flashTypes[FIRST_SECTOR_SIZE +					   sectorNumber];		if (offset < accMemory * numberOfDevices * 1024)			return sectorNumber;	}	return 0xffffffff;}/********************************************************************* flashGetSectorSize - When given a Valid sector Number returns its Size.** INPUTS:  unsigned int sectorNumber.* RETURNS: Sector size. (if Sector number isn't valid or flash wasn't *          initialize return 0.)*********************************************************************/unsigned int flashGetSectorSize(unsigned int sectorNumber){	if (sectorNumber >= flashTypes[NUMBER_OF_SECTORS])		return 0;	else {		if (FLASH_MODE != PURE8)			return (flashTypes				[FIRST_SECTOR_SIZE +				 sectorNumber] * _1K * (FLASH_WIDTH * 8 /							FLASH_MODE));		else		/* in case of PUR8 */			return (flashTypes				[FIRST_SECTOR_SIZE +				 sectorNumber] * _1K * FLASH_WIDTH);	}}/********************************************************************* getFlashSize - Return Total flash size.** INPUTS:  N/A.* RETURNS: Flash size. (If flash wasn't initialize return 0)*********************************************************************/unsigned int flashGetSize(){	unsigned int sectorNum;	unsigned int totalSize = 0;	if (POINTER_TO_FLASH == 0)		return 0;	/* case of flash not initialize */	for (sectorNum = 0; sectorNum < flashTypes[NUMBER_OF_SECTORS];	     sectorNum++) {		totalSize += flashGetSectorSize(sectorNum);	}	return (totalSize);}/********************************************************************* flashGetSectorOffset - Returns sector base address.** INPUTS:  unsigned int sectorNum.* RETURNS: Sector Base Address.*********************************************************************/unsigned int flashGetSectorOffset(unsigned int sectorNum){	unsigned int i;	unsigned int sectorBaseAddress = 0;	unsigned int numOfDevices;	if (sectorNum > (flashParametrs[NUMBER_OF_SECTORS] - 1))		return 0xffffffff;	for (i = 0; i < sectorNum; i++) {		sectorBaseAddress =		    sectorBaseAddress + flashTypes[FIRST_SECTOR_SIZE + i];	}	if (FLASH_MODE == X16)		numOfDevices = FLASH_WIDTH * 8 / FLASH_MODE;	else		numOfDevices = FLASH_WIDTH;	return (_1K * sectorBaseAddress * numOfDevices);}/********************************************************************* flashWriteBlock - Write block of chars to flash.** INPUTS:  unsigned int offset - flash destination address.*          unsigned int numOfByte - block size.*          unsigned char * blockAddress - block source address.* RETURNS: Number of Bytes written.*********************************************************************/unsigned int flashWriteBlock(unsigned int offset, unsigned int numOfByte,			     unsigned char *blockAddress){	register unsigned int flashWrite;	register unsigned int align;	register unsigned int num;	register unsigned int i;	if ((offset + numOfByte) > flashGetSize())		numOfByte = flashGetSize() - offset;	/* getting to flash boundary. */	num = numOfByte;	align = offset % 4;	/* alignment toward flash.    */	/* writes chars until the offset toward flash will be align. */	for (i = align; (i < 4) && (numOfByte > 0) && (align != 0); i++) {		flashWriteChar(offset, blockAddress[0]);		numOfByte--;		offset++;		blockAddress++;	}	while (numOfByte > 3) {#ifdef LE		flashWrite = blockAddress[0] | (blockAddress[1] << 8) |		    (blockAddress[2] << 16) | (blockAddress[3] << 24);#else		flashWrite = blockAddress[3] | (blockAddress[2] << 8) |		    (blockAddress[1] << 16) | (blockAddress[0] << 24);#endif		if (flashWrite != 0xffffffff)	/* for optimization. */			flashWriteWord(offset, flashWrite);		numOfByte -= 4;		blockAddress += 4;		offset += 4;	}	while (numOfByte > 0) {		flashWriteChar(offset, blockAddress[0]);		numOfByte--;		blockAddress++;		offset++;	}	return num;}/********************************************************************* flashReadBlock - Read block of chars from flash.** INPUTS:  unsigned int offset - flash source address.*          unsigned int numOfByte - block size.*          unsigned char * blockAddress - block destination address.* RETURNS: Number of Bytes written.*********************************************************************/unsigned int flashReadBlock(unsigned int offset, unsigned int numOfByte,			    unsigned char *blockAddress){	unsigned int i;	for (i = 0; i < numOfByte; i++) {		blockAddress[i] = flashReadChar(offset + i);	}	return numOfByte;}/********************************************************************* flashReadChar - read one charecter form given flash offset.** INPUTS:  unsigned int offset - required offset to be read from.* RETURNS: read charecter.*********************************************************************/unsigned char flashReadChar(unsigned int offset){	unsigned char regValue;	flashReset();	READ_CHAR(FLASH_BASE_ADDRESS + offset, &regValue);	return regValue;}/********************************************************************* flashReadShort - read 16bit form given flash offset.** INPUTS:  unsigned int offset - required offset to be read from.* RETURNS: 16bit data.*********************************************************************/unsigned short flashReadShort(unsigned int offset){	unsigned short regValue;	flashReset();	READ_SHORT(FLASH_BASE_ADDRESS + offset, &regValue);	return regValue;}/********************************************************************* flashWriteShort - write 16bit data to a given flash offset.*                  It reads the whole word 32bit wide, modify the  short *                  and write back the word.** INPUTS:  unsigned int offset - required offset to be write to.*          unsigned short sdata - data to be written.* RETURNS: true if writting successesed false otherwise.*********************************************************************/bool flashWriteShort(unsigned int offset, unsigned short sdata){	unsigned int align;	unsigned int flashWrite;	unsigned int flashRead;	align = offset % 4;	if ((align == 1) || (align == 3))		return false;	/* offset misaligned. */	flashRead = flashReadWord(offset - align);	if (align == 0)#ifdef BE		flashWrite = (flashRead & 0x0000ffff) | (sdata << 16);#else		flashWrite = (flashRead & 0xffff0000) | sdata;#endif	else			/* (align == 2) */#ifdef BE		flashWrite = (flashRead & 0xffff0000) | sdata;#else		flashWrite = (flashRead & 0x0000ffff) | (sdata << 16);#endif	flashWriteWord(offset - align, flashWrite);	return true;}/********************************************************************* flashWriteChar - write one charecter (8 bit) to a given flash offset.*                  It reads the whole word 32bit wide, modify the charecter *                  and write back the word.** INPUTS:  unsigned int offset - required offset to be write to.*          unsigned short sdata - data to be written.* RETURNS: true if writting successed.*********************************************************************/bool flashWriteChar(unsigned int offset, unsigned char cdata){	unsigned int align;	unsigned int flashWrite;	unsigned int flashRead;	align = offset % 4;	flashRead = flashReadWord(offset - align);#ifdef BE	flashWrite = (flashRead & ~(0xff000000 >> (8 * align))) |	    (cdata << (8 * (3 - align)));#else	flashWrite = (flashRead & ~(0xff000000 << (8 * align))) |	    (cdata << (8 * align));#endif	flashWriteWord(offset - align, flashWrite);	return true;}/********************************************************************* flashGetNumOfSectors - write one charecter (8 bit) to a given flash offset.*                        It reads the whole word 32bit wide, modify the  *                        charecter and write back the word.** INPUTS:  N/A.* RETURNS: Number of sectors.*********************************************************************/unsigned int flashGetNumOfSectors(void){	return (flashTypes[NUMBER_OF_SECTORS]);}

⌨️ 快捷键说明

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