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

📄 64m_16e.c

📁 SLICION7的Flash驱动程序
💻 C
📖 第 1 页 / 共 3 页
字号:
#ifdef	SW_LOCK_RELEASE
	unsigned char BlockAddress;
#endif

	while(pProgStart <= pProgStop){
		pProgStatus = pProgStart;
#ifdef	SW_LOCK_RELEASE
											/* A15 - A21 get */
		BlockAddress = 
			(unsigned char)(((unsigned long)pProgStart&0x007f0000)>>16);
		*pProgStart = 0x60;
		*pProgStart = BlockAddress;			/* A15 - A21 */
		*pProgStart = 0xac;
		*pProgStart = (~BlockAddress)&0x7f;	/* #A15 - #A21 */
		*pProgStart = 0x7b;
#endif	
		*pProgStart = 0x41;					/* Output of Page Program Command */

		/***** 128-words Data Output *****/
		for(DataNum = 0;DataNum < 128;DataNum++){
			*pProgStart = *pDataStart;		/* Output of Program Data */
			pProgStart++;					/* Flash Memory Pointer+1 */
			pDataStart++;					/* Data Pointer to be transmitted+1 */
		}
		
		/***** Status Polling *****/
		while((*pProgStatus & 0x80) != 0x80);/* Status Data Confirmation */

		if ((*pProgStatus & 0x38) != 0x00) {/* Check of Error */
			Errflg = FALSE;					/* Set of Error Flag */
			*pProgStatus = 0x50;			/* Clear Status */
			break;
		}
	}/* End of while(pProgStart <= ...) */

	/***** Completion of Page Program *****/
	*pProgStatus = 0xff;					/* Output of Read Array Command */
	return Errflg;
}

/*****************************************************************************
*  FmSingleDataLoadtoPageBuffer()  Single Data Load to Page Buffer
*  ---------------------------------------------------------------------------
*  Declaration  int FmSingleDataLoadtoPageBuffer(unsigned short *pProgAdr, 
*                                                unsigned short *pData,
*                                                unsigned short num)
*  ---------------------------------------------------------------------------
*  Description  1-word data is loaded to a page buffer by this command.
*  ---------------------------------------------------------------------------
*  Parameter    unsigned short *pProgAdr; Program address
*               unsigned short *pData;    Program data address
*               unsigned short num;       Number of program data
*  ---------------------------------------------------------------------------
*  No Related Function
*  ---------------------------------------------------------------------------
*  Version      Ver. 0.10.00 '03/03/07 First release
*****************************************************************************/
void FmSingleDataLoadtoPageBuffer(unsigned short *pProgAdr, 
									unsigned short *pData, unsigned short num)
{
	unsigned short *pProgStart;
	unsigned short DataNum;
#ifdef	SW_LOCK_RELEASE
	unsigned char BlockAddress;
#endif

	pProgStart = pProgAdr;

	for(DataNum = 0;DataNum < num;DataNum++) {
#ifdef	SW_LOCK_RELEASE
											/* A15 - A21 get */
		BlockAddress = 
			(unsigned char)(((unsigned long)pProgAdr&0x007f0000)>>16);
		*pProgAdr = 0x60;
		*pProgAdr = BlockAddress;			/* A15 - A21 */
		*pProgAdr = 0xac;
		*pProgAdr = (~BlockAddress)&0x7f;	/* #A15 - #A21 */
		*pProgAdr = 0x7b;
#endif

		*pProgStart = 0x74;		/* Single Data Load to Page Buffer Command */
		*pProgAdr   = *pData;	/* Data Load to Page Buffer */
		pProgAdr++;				/* Address buffer pointer+1 */
		pData++;				/* Data buffer pointer+1 */
	}
}

/*****************************************************************************
*  FmPageBuffertoFlash()     Page Buffer to Flash
*  ---------------------------------------------------------------------------
*  Declaration  int FmPageBuffertoFlash(unsigned short *pProgStart)
*  ---------------------------------------------------------------------------
*  Description  Loaded data to page buffer is programed by this command.
*               It is necessary to erase the data of the address to program.
*  ---------------------------------------------------------------------------
*  Parameter    unsigned char *pProgStart; Program start address
*  ---------------------------------------------------------------------------
*  Return Value int Errflg;
*                TRUE : Program normal stop
*                FALSE: Program abnormal stop
*  ---------------------------------------------------------------------------
*  No Related Function	
*  ---------------------------------------------------------------------------
*  Notes
*  ---------------------------------------------------------------------------
*  Version      Ver. 0.10.00 '01/10/15 First release
*               Ver. 0.11.00 '01/11/05 Add the confirm command after clear
*                                      Page Buffer Command
*               Ver. 0.40.00 '03/03/20 Change some comments.
*****************************************************************************/
int FmPageBuffertoFlash(unsigned short *pProgStart)
{
	int Errflg = TRUE;						/* Error Flag */
	unsigned short	DataNum;				
#ifdef	SW_LOCK_RELEASE
	unsigned char BlockAddress;
#endif

#ifdef	SW_LOCK_RELEASE
											/* A15 - A21 get */
	BlockAddress = 
		(unsigned char)(((unsigned long)pProgStart&0x007f0000)>>16);
	*pProgStart = 0x60;
	*pProgStart = BlockAddress;				/* A15 - A21 */
	*pProgStart = 0xac;
	*pProgStart = (~BlockAddress)&0x7f;		/* #A15 - #A21 */
	*pProgStart = 0x7b;
#endif

	/***** Output of Page Buffer to Flash Command *****/
	*pProgStart = 0x0E;						/* 1st Bus Cycle */
	*pProgStart = 0xD0;						/* 2nd Bus Cycle */
	/*==== Status Polling ====*/
	while((*pProgStart & 0x80) != 0x80) ;	/* Status Data Confirmation */

	if ((*pProgStart & 0x38) != 0x00) {		/* Check of Error */
		Errflg = FALSE;						/* Set of Error Flag */
		*pProgStart = 0x50;					/* Clear Status */
	}

	*pProgStart = 0xff;						/* Output of Read Array Command */
	return Errflg;
}

/*****************************************************************************
*  FmFlashtoPageBuffer()     Flash to Page Buffer
*  ---------------------------------------------------------------------------
*  Declaration  void FmFlashtoPageBuffer(unsigned short *pBankAdr)
*  ---------------------------------------------------------------------------
*  Description  Array data load to the page buffer is perfomed by this command.
*  ---------------------------------------------------------------------------
*  Parameter    unsigned char *pBankAdr; Read address
*  ---------------------------------------------------------------------------
*  No Related Function
*  ---------------------------------------------------------------------------
*  Version      Ver. 0.10.00 '03/03/13 First release
*****************************************************************************/
void FmFlashtoPageBuffer(unsigned short *pBankAdr)
{
	/***** Output of Flash to Page Buffer Command *****/
	*pBankAdr = 0xF1;						/* 1st Bus Cycle */
	*pBankAdr = 0xD0;						/* 2nd Bus Cycle */
}

/******************************************************************************
*  FmPBClear()  Page Buffer Clear
*  ---------------------------------------------------------------------------
*  Declaration  void FmPBClear(unsigned short *pBankAdrs)
*  ---------------------------------------------------------------------------
*  Description  Loaded data to page buffer is cleared by this command
*  ---------------------------------------------------------------------------
*  Parameter    unsigned short *pBankAdrs; Address of the page buffer to clear
*  ---------------------------------------------------------------------------
*  No Related Function
*  ---------------------------------------------------------------------------
*  Version      Ver. 0.10.00 '01/10/15 First release
*               Ver. 0.11.00 '01/11/05 Add the confirm command
*               Ver. 0.30.01 '03/03/07 Change some comments.
*******************************************************************************/
void FmPBClear(unsigned short *pBankAdrs)
{
#ifdef	SW_LOCK_RELEASE
	unsigned char BlockAddress;
#endif
	
#ifdef	SW_LOCK_RELEASE
											/* A15 - A21 get */
	BlockAddress = 
			(unsigned char)(((unsigned long)pBankAdrs&0x007f0000)>>16);
	*pBankAdrs = 0x60;
	*pBankAdrs = BlockAddress;				/* A15 - A21 get */
	*pBankAdrs = 0xac;
	*pBankAdrs = (~BlockAddress)&0x7f;		/* #A15 - #21 get */
	*pBankAdrs = 0x7b;
#endif

	*pBankAdrs = 0x55;						/* 1st Bus Cycle */
	*pBankAdrs = 0xD0;						/* 2nd Bus Cycle */
}

/******************************************************************************
*  FmReadArray()     Read Array of M6MG3B/T641
*  ---------------------------------------------------------------------------
*  Declaration  void FmReadArray(unsigned short *pBankAdrs)
*  ---------------------------------------------------------------------------
*  Description  The device operation transfers to read status mode.
*               When reading the data of a flah memory, mode of operation has
*               the necessity for read array mode. This command is used when
*               transferring to read array mode from status mode.
*               When teh device is initialized, the deviice operation becomes
*               read array mode automatically. Therefore, it is not necessary
*               to output this command when performaing only read-out.
*  ---------------------------------------------------------------------------
*  Parameter    unsigned short *pBankAdrs; Bank address
*  ---------------------------------------------------------------------------
*  No Related Function	
*  ---------------------------------------------------------------------------
*  Version      Ver. 0.10.00 '03/03/07 First release
*******************************************************************************/
void FmReadArray(unsigned short *pBankAdrs)
{
	*pBankAdrs = 0xff;						/* 1st Bus Cycle */
}

/******************************************************************************
*  FmIdRead()   ID Read operation
*  ---------------------------------------------------------------------------
*  Declaration  unsigned short FmIdRead(unsigned short *pBankAdrs)
*  ---------------------------------------------------------------------------
*  Description  The device identifier(ID) code is read.
*  ---------------------------------------------------------------------------
*  Parameter    unsigned short *pBankAdrs; Bank address
*  ---------------------------------------------------------------------------
*  Return Value unsigned short Code;
*                Upper 8bit Manufacture's code
*                Lower 8bit Device code
*  ---------------------------------------------------------------------------
*  No Related Function	
*  ---------------------------------------------------------------------------
*  Version       Ver. 0.10.00 '03/03/07 First release
*******************************************************************************/
unsigned short FmIdRead(unsigned short *pBankAdrs)
{
	unsigned short	MakerCode, DeviceCode, Code;
	
	pBankAdrs = (unsigned short *)((unsigned long)pBankAdrs & 0xFFFFFFFCL);
	
	*pBankAdrs = 0x90;				/* 1st Bus Cycle */
	MakerCode = *pBankAdrs;			/* Output of Manufacture's Code */
	pBankAdrs++;
	DeviceCode = *pBankAdrs;		/* Output od Device Code */
	Code = (MakerCode << 8) | (DeviceCode & 0x00FF);
	*pBankAdrs = 0xFF;				/* Output of Read Array Command */
	
	return Code;
}

/******************************************************************************
*  FmReadStatusRegister()     Read Status Register
*  ---------------------------------------------------------------------------
*  Declaration  void FmReadStatusRegister(unsigned short *pBankAdrs)
*  ---------------------------------------------------------------------------
*  Description  The device operation transfers to read status mode.
*               Usually, The device transfers to status mode automatically
*               after some command execution. Therefora, it is not necessary
*               to output this command.
*  ---------------------------------------------------------------------------
*  Parameter    unsigned short *pBankAdrs; BANK address
*  ---------------------------------------------------------------------------
*  No Related Function
*  ---------------------------------------------------------------------------
*  Version      Ver. 0.10.00 '03/03/07 First release
*******************************************************************************/
void FmReadStatusRegister(unsigned short *pBankAdrs)
{
	*pBankAdrs = 0x70;						/* 1st Bus Cycle */
}

/******************************************************************************
*  FmClrStatusRegister()     Clear Status Register
*  ---------------------------------------------------------------------------
*  Declaration  void FmClrStatusRegister(unsigned short *pBankAdrs)
*  ---------------------------------------------------------------------------
*  Description  Execute clear status register
*  ---------------------------------------------------------------------------
*  Parameter    unsigned short *pBankAdrs; BANK address
*  ---------------------------------------------------------------------------
*  No Related Function
*  ---------------------------------------------------------------------------
*  Version      Ver. 0.10.00 '03/03/07 First release
*******************************************************************************/
void FmClrStatusRegister(unsigned short *pBankAdrs)
{
	*pBankAdrs = 0x50;						/* 1st Bus Cycle */
}

⌨️ 快捷键说明

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