📄 progeeprom.c
字号:
/******************************************************************************
Copyright (c) Motorola 2001
File Name : $RCSfile: ProgEeprom.c,v $
Engineer : $Author: estyger $
Location : EKB
Date Created : 05/06/2001
Current Revision : $Revision: 1.1.1.1 $
Notes :
*******************************************************************************
Motorola reserves the right to make changes without further notice to any
product herein to improve reliability, function or design. Motorola does not
assume any liability arising out of the application or use of any product,
circuit, or software described herein; neither does it convey any license
under its patent rights nor the rights of others. Motorola products are not
designed, intended, or authorized for use as components in systems intended for
surgical implant into the body, or other applications intended to support life,
or for any other application in which the failure of the Motorola product
could create a situation where personal injury or death may occur. Should
Buyer purchase or use Motorola products for any such unintended or
unauthorized application, Buyer shall idemnify and hold Motorola and its
officers, employees, subsidiaries, affiliates, and distributors harmless
against all claims costs, damages, and expenses, and reasonable attorney fees
arising out of, directly or indirectly, any claim of personal injury or death
associated with such unintended or unauthorized use, even if such claim alleges
that Motorola was negligent regarding the design or manufacture of the part.
Motorola and the Motorola logo* are registered trademarks of Motorola Ltd.
******************************************************************************/
/************************* System Include Files ******************************/
/************************* Project Include Files *****************************/
#include "stdtypes.h"
#include "mcucfg.h"
#include "s12_eectl.h"
/************************* typedefs ******************************************/
/************************* #Defines ******************************************/
#ifndef ALIGNED_WORD_MASK
#define ALIGNED_WORD_MASK 0x0001
#endif
#ifndef PASS
#define PASS 1
#endif
#ifndef FAIL
#define FAIL 0
#endif
/************************* Global Variables **********************************/
static tEEPROM eeprom @(REG_BASE + 0x110);
/************************* External Variables ********************************/
/******************************************************************************
Function Name : ConfigECLKDIV
Engineer : r27624
Date : 17/9/2001
Arguments : none
Return : none
Notes : This function configures the EEPROM clock prescaler
in preparation for programming.
******************************************************************************/
void
ConfigECLKDIV(void)
{
if(eeprom.eclkdiv.bit.edivld == 0)
{ /* configure EEPROM clock prescaler */
eeprom.eclkdiv.byte = (UINT8)EECLK_PRESCALER;
}
return;
}
/******************************************************************************
Function Name : ProgEeprom
Engineer : r27624
Date : 28/06/2001
Arguments : progAdr Pointer to the start of the destination
EEPROM location to be programmed
bufferPtr Pointer to the start of the source data
size Number of WORDS to be programmed
Return : status FAIL:
if progAdr does not point to an aligned word, or
the ACCERR bit is set during programming sequence, or
the PVIOL bit is set during programming sequence.
PASS:
if not FAIL.
Notes : This function does not check if the EEPROM is erased.
This function does not verify that the data has been
sucessfully programmed.
******************************************************************************/
UINT8
ProgEeprom(UINT16* progAdr, UINT16* bufferPtr, UINT16 size)
{
if(((UINT16)progAdr & ALIGNED_WORD_MASK) != 0) /* Check for aligned word */
{
return(FAIL);
}
/* Clear error flags */
eeprom.estat.byte = (ACCERR | PVIOL);
/* Word to program? */
while(size != 0)
{ /* Is command buffer empty? */
if(eeprom.estat.bit.cbeif == 1)
{
/* Latch data and address */
*progAdr++ = *bufferPtr++;
/* Configure prog command */
eeprom.ecmd.byte = PROG;
/* Launch the command */
eeprom.estat.byte = CBEIF;
/* Was the access error flag set? */
/* Was the protection violation error flags set */
if((eeprom.estat.bit.accerr == 1) ||
(eeprom.estat.bit.pviol == 1))
{
return(FAIL);
}
/* next word */
size--;
}
}
/* Wait for last command to finish */
while(eeprom.estat.bit.ccif != 1)
{
}
/* finished, no errors */
return(PASS);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -