📄 iee1.c
字号:
** Addr - EEPROM Address
** * Data - A pointer to the returned 8-bit data
** Returns :
** --- - Error code, possible codes:
** - ERR_OK - OK
** - ERR_BUSY - device is busy
** - ERR_RANGE - parameter Addr is out of range
** ===================================================================
*/
byte IEE1_GetByte(IEE1_TAddress Addr,byte *Data)
{
if((Addr < IEE1_AREA_START) || (Addr > IEE1_AREA_END)) { /* Is given address out of EEPROM area array ? */
return ERR_RANGE; /* If yes then error */
}
if((ESTAT & 192) != 192) { /* Is reading from EEPROM possible? */
return ERR_BUSY; /* If no then error */
}
*Data = *((volatile byte *) Addr); /* Return data from given address */
return ERR_OK; /* OK */
}
/*
** ===================================================================
** Method : IEE1_SetWord (bean IntEEPROM)
**
** Description :
** This method writes a given word (2 bytes) to the specified
** address in EEPROM. The method also sets address pointer for
** <SetActByte> and <GetActByte> methods (applicable only if
** these methods are enabled). The pointer is set to address
** passed as the parameter + 1.
** Parameters :
** NAME - DESCRIPTION
** Addr - Address to EEPROM
** Data - Data to write
** Returns :
** --- - Error code, possible codes:
** - ERR_OK - OK
** - ERR_SPEED - the bean does not work in the
** active speed mode
** - ERR_BUSY - device is busy
** - ERR_VALUE - verification of written data
** failed (read value does not match with
** written value)
** - ERR_NOTAVAIL - other device-specific
** error
** - ERR_RANGE - selected address out of the
** selected address range
** ===================================================================
*/
byte IEE1_SetWord(IEE1_TAddress Addr,word Data)
{
if((Addr < IEE1_AREA_START) || (Addr > IEE1_AREA_END)) { /* Is given address out of EEPROM area array ? */
return ERR_RANGE; /* If yes then error */
}
if (Addr & 0x0001) { /* Aligned address ? */
return ERR_NOTAVAIL;
}
if((ESTAT & 192) != 192) { /* Is reading from EEPROM possible? */
return ERR_BUSY; /* If no then error */
}
if (*(volatile word *)(Addr) == 65535) { /* Is given EEPROM row erased ? */
return (WriteWord(Addr,Data)); /* Write new content */
} else { /* Is given address non-erased ? */
if (Addr & 2) { /* Is given address from high part of the sector ? */
return (WriteSector(Addr & 65532,(dword)Data | ((*(dword *)(Addr & 65532) & 4294901760))));
}
else { /* Is given address from low part of the sector ? */
return (WriteSector(Addr,((dword)Data << 16) | (*(volatile word *)(Addr + 2))));
}
}
}
/*
** ===================================================================
** Method : IEE1_GetWord (bean IntEEPROM)
**
** Description :
** This method reads a word (2 bytes) from the specified EEPROM
** address. The method also sets address pointer for
** <SetActByte> and <GetActByte> methods (applicable only if
** these methods are enabled). The pointer is set to address
** passed as the parameter + 1.
** Parameters :
** NAME - DESCRIPTION
** Addr - Address to EEPROM
** * Data - Pointer to returned 16-bit data
** Returns :
** --- - Error code, possible codes:
** - ERR_OK - OK
** - ERR_BUSY - device is busy
** - ERR_RANGE - selected address out of the
** selected address range
** ===================================================================
*/
byte IEE1_GetWord(IEE1_TAddress Addr,word *Data)
{
if((Addr < IEE1_AREA_START) || (Addr > IEE1_AREA_END)) { /* Is given address out of EEPROM area array ? */
return ERR_RANGE; /* If yes then error */
}
if((ESTAT & 192) != 192) { /* Is reading from EEPROM possible? */
return ERR_BUSY; /* If no then error */
}
*Data = *(volatile word *)(Addr); /* Return data from given address */
return ERR_OK; /* OK */
}
/*
** ===================================================================
** Method : IEE1_EraseEeprom (bean IntEEPROM)
**
** Description :
** The method mass erases all EEPROM memory. The method also
** sets address pointer for <SetActByte> and <GetActByte>
** methods (applicable only if these methods are enabled). The
** pointer is set to address passed as the parameter - 1.
** Parameters :
** NAME - DESCRIPTION
** Addr - Pass any valid EEPROM address. EEPROM
** module in some CPU families don't require
** address for mass erase, then the parameter
** is ignored.
** Returns :
** --- - Error code, possible codes:
** - ERR_OK - OK
** - ERR_SPEED - the bean does not work in the
** active speed mode
** - ERR_BUSY - device is busy
** - ERR_NOTAVAIL - other device-specific error
** ===================================================================
*/
byte IEE1_EraseEeprom(IEE1_TAddress Addr)
{
if((ESTAT & 192) != 192) { /* Is reading from EEPROM possible? */
return ERR_BUSY; /* If no then error */
}
/* ESTAT: PVIOL=1,ACCERR=1 */
ESTAT = 48; /* Clear error flags */
*(volatile word *)(Addr) = 0; /* Array address */
/* ECMD: ??=0,CMDB6=1,CMDB5=0,??=0,??=0,CMDB2=0,??=0,CMDB0=0 */
ECMD = 65; /* Mass erase command */
ESTAT = 128; /* Clear flag command buffer empty */
if ((ESTAT_PVIOL == 1) || (ESTAT_ACCERR == 1)) { /* Is protection violation or acces error detected ? */
return ERR_NOTAVAIL; /* If yes then error */
}
return ERR_OK; /* OK */
}
/*
** ===================================================================
** Method : IEE1_Init (bean IntEEPROM)
**
** Description :
** Initializes the associated peripheral(s) and the bean internal
** variables. The method is called automatically as a part of the
** application initialization code.
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void IEE1_Init(void)
{
ECLKDIV = 74; /* Set up Clock Divider Register */
}
/* END IEE1. */
/*
** ###################################################################
**
** This file was created by UNIS Processor Expert 2.98 [03.98]
** for the Freescale HCS12 series of microcontrollers.
**
** ###################################################################
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -