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

📄 eeprom.c

📁 TC35i收发短信的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 System : EEPROM emulation
 Module name : EEPROM emulation control processing
 File name : EEPROMCtrlEx.c
 Version name : 1.00
 Target CPU : uPD78F0547(78K0/KF2)
 Last updated : 2005/08/31
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma section @@CODE SLF_CTRL
#include "ext_var.h"
#include "Eeprom.h"


/****************************************************************************
**
**  Abstract:
**	enable flmd0
**
**  Parameters:
**	None
**
**  Returns:
**	none
**
****************************************************************************/
void EnableFLMD( void )
{
	P6.3 = 1;
	NOP();
	NOP();
}

/****************************************************************************
**
**  Abstract:
**	disable flmd0
**
**  Parameters:
**	None
**
**  Returns:
**	none
**
****************************************************************************/
void DisableFLMD( void )
{
	P6.3 = 0;
	NOP();
	NOP();
}

/*-------------------------------------------------------------
Function name : ucUseProhibitionBlock
Arguments : usFlagAdr: Flag Address
Return value : 1 / 0
Summary : examine it whether it is a ban on use block
-------------------------------------------------------------*/
uchar ucUseProhibitionBlock(uchar *p)
{
	if((p[0] == 0x0) && (p[1] == 0x0) && (p[2] == 0x0) && (p[3] == 0x0))
	{
		return(TRUE);
	}
	return(FALSE);
}

/*-------------------------------------------------------------
Function name : ucEffectiveBlock
Arguments : usFlagAdr: Flag Address
Return value : 1 / 0
Summary : examine whether I block it effectively
-------------------------------------------------------------*/
uchar ucEffectiveBlock(uchar *p)
{
	if((p[0] == 0x55) && (p[1] == 0xAA) && (p[2] == 0x55) && (p[3] == 0xAA))
	{
		return(TRUE);
	}
	return(FALSE);
}

/*-------------------------------------------------------------
Function name : IsBlockValid
Arguments : usFlagAdr: Flag Address
Return value : 1 / 0
Summary : examine whether I block it effectively
-------------------------------------------------------------*/
uchar IsBlockValid(uchar ucBlock)
{
	ushort usFlagAdr;
	uchar ucResult;

	usFlagAdr = BLOCK_TO_ADDRESS(ucEEPROM_BLOCK[ucBlock]);

	ucResult = BLOCK_IS_EFFECTIVE((uchar *)usFlagAdr);

	return (ucResult);
}



/*-------------------------------------------------------------
Function name : ucBlankBlock
Arguments : usFlagAdr: Flag Address
Return value : 1 / 0
Summary : examine it whether it is a blank block
-------------------------------------------------------------*/
uchar ucBlankBlock(uchar *p)
{
	if((p[0] == 0xFF) && (p[1] == 0xFF) && (p[2] == 0xFF) && (p[3] == 0xFF)) 
	{
		return(TRUE);
	}
	return(FALSE);
}

/*-------------------------------------------------------------
Function name : SelfFlashModeOn
APPENDIX A SAMPLE PROGRAM LIST (C LANGUAGE VERSION)
Application Note U17517EJ2V0AN 107
Arguments : None
Return value : None
Summary : Sets self rewriting mode (A1).
-------------------------------------------------------------*/
/*--- Processing to switch from normal mode to self programming mode */
void SelfFlashModeOn(void)
{
	EnableFLMD();

	DI();
	FlashStart(); /* Self programing start library call */
	EI();
	return;
}
/*-------------------------------------------------------------
Function name : SelfFlashModeOff
Arguments : None
Return value : None
Summary : Releases self rewriting mode.
-------------------------------------------------------------*/
/*--- Processing to switch from self programming mode to normal mode */
void SelfFlashModeOff(void)
{
	DI();
	FlashEnd(); /* Self programing end library call */
	EI();

	DisableFLMD();

	return;
}
/*-------------------------------------------------------------
 Function name : ucSelfFlashInitialize
 Arguments : None
 Return value : Normal completion (TRUE: 0x0) /
 Abnormal completion (FALSE: 0xff)
 Summary : Initializes self programming firmware for EEPROM emulation.
 Initializes flash firmware (sets operating frequency)
 Checks FLMD pin [because programming may be disabled depending on the FLMD
 pin's status]
 -------------------------------------------------------------*/
/*Flash memory self programming initialization processing */
uchar ucSelfFlashInitialize(void)
{
	FlashEnv((ushort )&ucEntryRAM);      /* Initializes internal flash firmware */
	if(CheckFLMD() != LIB_NORMAL_END)    //LIB_NORMAL_END = 0;y寔4幓z弙-桹--normal,!0---error
	{                                   /* Obtains FLMD pin information */
		return(FALSE);
	}
	return(TRUE);
}
/*-------------------------------------------------------------
Function name : ucSelfFlashBlockErase
Arguments : ucEraseStartBlock: Erase block number
Return value : Normal completion (TRUE: 0x0) /
Abnormal completion (FALSE: 0xFF)
Summary : Erases specified block.
-------------------------------------------------------------*/
/*--- Flash memory block erase processing -------------------*/
uchar ucSelfFlashBlockErase(uchar ucBank,uchar ucBlock)
{
	uchar ucStatus;

	while(1) 
	{
                                     /* Flash memory blank check library call */
		DI();
		ucStatus = FlashBlockBlankCheck(ucBank,ucBlock);
		EI();

		if(ucStatus == LIB_BLKCHK_ERR) 
		{                            /* Blank check error (Blank check error) */
                                     /* Flash memorry erase library call */
			DI();
			ucStatus = FlashBlockErase(ucBank,ucBlock);
			EI();
                                    /* States other than discontinuation error and nomarl error */
                                    /* (parameter / protect / erase error) */
			if((ucStatus != LIB_NORMAL_END) && (ucStatus != LIB_STATE_INT)) 
			{
				return(FALSE);
			}
		} 
		else if (ucStatus == LIB_NORMAL_END) 
		{                          /* Blank check normal end */
			FlashEnv((ushort )&ucEntryRAM);
			return(TRUE);
		} 
		else if(ucStatus != LIB_STATE_INT) 
		{
                                  /* States other than discontinuation error (parameter error) */
			return(FALSE);
		}
	}
}
/*-------------------------------------------------------------
Function name : ucSelfFlashEEPROMWrite
Arguments : ucBank: Bank number
ucNum : Data number
usAddr: Writes start address
Return value : Normal completion (TRUE: 0x0) /
Abnormal completion (FALSE: 0xFF)
Summary : write data to EEPROM
-------------------------------------------------------------*/
/*--- Flash memory data write processing --------------------*/
uchar ucSelfFlashEEPROMWrite(uchar ucBank,ushort usAddr,uchar ucNum)
{
	uchar ucStatus;
	WordAddr.WriteAddress = usAddr;
	WordAddr.WriteBank = ucBank;

	while(1) 
	{
                                 /* Flash memory EEPROM write library call */
		DI();
		ucStatus = EEPROMWrite(&WordAddr,(uchar )((ucNum / 4) + 1),(ushort )(&ucDataBuf[0]));
		EI();
		if(ucStatus == LIB_NORMAL_END) 
		{                         /* Word write normal end */
			return(TRUE);
		} 
		else if(ucStatus != LIB_STATE_INT) 
		{
                                 /* States other than discontinuation error (parameter/protect/write error) */
			return(ucStatus);
		}
	}
}
/*-------------------------------------------------------------
Function name : ucSelfFlashWordWrite
Arguments : usSetAdr:
usDataAdr:
Return value : Normal completion (TRUE: 0x0) /
Abnormal completion (FALSE: 0xFF)
Summary : write word data to EEPROM
-------------------------------------------------------------*/
/*--- Flash memory word data write processing ---------------*/
uchar ucSelfFlashWordWrite(uchar ucBank,ushort usSetAdr,uchar ucNum)
{
   uchar ucStatus;
   WordAddr.WriteAddress = usSetAdr;
   WordAddr.WriteBank = ucBank;
   while(1) 
   {
                                 /* Word write library call */
      DI();
      ucStatus = FlashWordWrite(&WordAddr,(uchar )((((ushort )ucNum - 1) / 4) + 1),
      (ushort )(&ucDataBuf[0]));
      EI();
      if(ucStatus == LIB_NORMAL_END) 
       {                         /* Word write normal end */
             return(TRUE);
       } 
      else if (ucStatus != LIB_STATE_INT) 
       {
                                 /* States other than discontinuation error (parameter/protect/write error) */
             return(FALSE);
       }
   }
}
/*-------------------------------------------------------------
Function name : usBlockToAddress
Arguments : ucBlock:Block number
Return value : Address Data
Summary : A block number is changed into an address.
--------------------------------------------------------------*/
ushort usBlockToAddress(ushort usBlock)
{
	return((usBlock << 2) * 0x100);
}


/****************************************************************************
**
**  Abstract:

⌨️ 快捷键说明

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