📄 s12_eectl.h
字号:
/******************************************************************************
Copyright (c) Motorola 2001
File Name : $RCSfile: s12_eectl.h,v $
Engineer : $Author: estyger $
Location : EKB
Date Created : 28/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.
******************************************************************************/
#ifndef EECTL_H
#define EECTL_H
/************************* System Include Files ******************************/
/************************* Project Include Files *****************************/
#include "stdtypes.h"
/************************* typedefs ******************************************/
typedef union uECLKDIV
{
UINT8 byte;
struct
{
UINT8 ediv :6; /*clk divider */
UINT8 ediv8 :1; /*clk /8 prescaler enable */
UINT8 edivld :1; /*clock divider loaded flag */
}bit;
}tECLKDIV;
typedef union uECNFG
{
UINT8 byte;
struct
{
UINT8 :4; /*not used */
UINT8 eswai :1; /*eeprom stopped in wait mode */
UINT8 :1; /*not used */
UINT8 ccie :1; /*command complete interrupt enable */
UINT8 cbeie :1; /*command buffer empty interrupt enable */
}bit;
}tECNFG;
typedef union uEPROT
{
UINT8 byte;
struct
{
UINT8 ep :3; /*protection block size: (ep+1)*64 bytes */
UINT8 epdis :1; /*protection disable */
UINT8 :3; /*contain value of equivalent bits in protection byte */
UINT8 eopen :1; /*open block for program/erase */
}bit;
}tEPROT;
typedef union uESTAT
{
UINT8 byte;
struct
{
UINT8 :2; /*not used */
UINT8 blank :1; /*blank verify flag */
UINT8 :1; /*not used */
UINT8 accerr :1; /*access error flag */
UINT8 pviol :1; /*protection violation flag */
UINT8 ccif :1; /*command complete interrupt flag */
UINT8 cbeif :1; /*command buffer empty interrupt flag */
}bit;
}tESTAT;
typedef union uECMD
{
UINT8 byte;
struct
{
UINT8 mass :1; /*mass erase enable */
UINT8 :1; /*not used */
UINT8 erver :1; /*erase verify enable */
UINT8 :2; /*not used */
UINT8 prog :1; /*word programming */
UINT8 erase :1; /*erase control */
UINT8 :1; /*not used */
}bit;
}tECMD;
typedef struct /*eeprom datastructure */
{
volatile tECLKDIV eclkdiv; /*eeprom clock divider register */
UINT8 rsvee1[2]; /*reserved */
volatile tECNFG ecnfg; /*eeprom configuration register */
volatile tEPROT eprot; /*eeprom protection register */
volatile tESTAT estat; /*eeprom status register */
volatile tECMD ecmd; /*eeprom command buffer & status register */
UINT8 rsvee2[5]; /*reserved */
}tEEPROM;
/************************* Extern Variables **********************************/
/************************* #Defines ******************************************/
#define EDIV8 0x40 /*bit masks */
#define EDIVLD 0x80
#define ESWAI 0x10 /*bit masks */
#define CCIE 0x40
#define CCBIE 0x80
#define EP0 0x01 /*bit masks */
#define EP1 0x02
#define EP2 0x04
#define EP 0x07 /*ep block mask */
#define EPDIS 0x08
#define EOPEN 0x80
#define BLANK 0x04 /*bit masks */
#define ACCERR 0x10
#define PVIOL 0x20
#define CCIF 0x40
#define CBEIF 0x80
#define MASS 0x01 /*bit masks */
#define ERVER 0x04
#define PROG 0x20
#define ERASE 0x40
/************************* Macros ********************************************/
/* Macro that generates the EEPROM clock precaler as per data book.
If the crystal frequency is above 12.8MHz then the EDIV bit must
be set, this divides the OSCCLK frequency by 8 before the prescaler. */
#if (OSCCLK_FREQ_KHZ > 12800)
/* This macro calculates the prescaler, but also implements the EDIV8 bit */
#if ((OSCCLK_FREQ_KHZ * (BUSCLK_FREQ_KHZ + 200)) % (1600 * BUSCLK_FREQ_KHZ) == 0)
#define EECLK_PRESCALER ((OSCCLK_FREQ_KHZ * (BUSCLK_FREQ_KHZ + 200) / (1600 * BUSCLK_FREQ_KHZ)) + EDIV8 - 1)
#else
#define EECLK_PRESCALER ((OSCCLK_FREQ_KHZ * (BUSCLK_FREQ_KHZ + 200) / (1600 * BUSCLK_FREQ_KHZ)) + EDIV8)
#endif /* OSCCLK_FREQ_KHZ * (BUSCLK_FREQ_KHZ + 200) % (1600 * BUSCLK_FREQ_KHZ) == 0 */
/* Make sure EECLK is within specified range. */
#define EECLK_FREQ_KHZ (OSCCLK_FREQ_KHZ / (8 * (1 + EECLK_PRESCALER)))
#if ((EECLK_FREQ_KHZ < 150) || (EECLK_FREQ_KHZ > 200) || (EECLK_PRESCALER > 0x7F))
#error EEPROM prescaler or clock out of range.
#endif /* Incorrect EECLK frequency. */
#else
/* This macro calculates the prescaler. */
#if ((OSCCLK_FREQ_KHZ * (BUSCLK_FREQ_KHZ + 200)) % (200 * BUSCLK_FREQ_KHZ) == 0)
#define EECLK_PRESCALER ((OSCCLK_FREQ_KHZ * (BUSCLK_FREQ_KHZ + 200) / (200 * BUSCLK_FREQ_KHZ)) - 1)
#else
#define EECLK_PRESCALER (OSCCLK_FREQ_KHZ * (BUSCLK_FREQ_KHZ + 200) / (200 * BUSCLK_FREQ_KHZ))
#endif /* OSCCLK_FREQ_KHZ * (BUSCLK_FREQ_KHZ + 200) % (200 * BUSCLK_FREQ_KHZ) == 0 */
/* Make sure ECLK is within specified range. */
#define EECLK_FREQ_KHZ (OSCCLK_FREQ_KHZ / (1 + EECLK_PRESCALER))
#if ((EECLK_FREQ_KHZ < 150) || (EECLK_FREQ_KHZ > 200) || (EECLK_PRESCALER > 0x3F))
#error EEPROM prescaler or clock out of range.
#endif /* Incorrect EECLK frequency. */
#endif /* OSCCLK_FREQ_KHZ > 12800 */
/************************* Prototypes ****************************************/
void ConfigECLKDIV(void);
UINT8 ProgEeprom(UINT16*, UINT16*, UINT16);
#endif /* End of Header file !defined */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -