📄 s12_fectlne64.h
字号:
/******************************************************************************
Copyright (c) Motorola 2000
File Name : $RCSfile: s12_fectl.h,v $
Engineer : $Author: r27624 $
Location : EKB
Date Created : 09/01/01
Current Revision : $Revision: 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 FECTL_H
#define FECTL_H
/************************* System Include Files ******************************/
/************************* Project Include Files *****************************/
#include "stdtypes.h"
#include "datatypes.h"
/*#include "MC9S12NE64.h"*/
/************************* typedefs ******************************************/
#if 1
/*
#define UINT8 unsigned char
#define UINT16 unsigned int*/
typedef union uFCLKDIV
{
UINT8 byte;
struct
{
UINT8 fdiv :6; /*clk divider */
UINT8 fdiv8 :1; /*clk /8 prescaler enable */
UINT8 fdivld :1; /*clock divider loaded flag */
}bit;
}tFCLKDIV;
typedef union uFSEC
{
UINT8 byte;
struct
{
UINT8 sec0 :2; /*memory security bit */
UINT8 nv :5; /*user non volatile flag bits */
UINT8 keyen :1; /*security key access enable */
}bit;
}tFSEC;
typedef union uFCNFG
{
UINT8 byte;
struct
{
#if 0
UINT8 bksel :2; /*register bank select xpgong2006.01.04*/
#endif
UINT8 :5; /*not used */
UINT8 keyacc :1; /*security key writing enable */
UINT8 ccie :1; /*command complete interrupt enable */
UINT8 cbeie :1; /*command buffer empty interrupt enable */
}bit;
}tFCNFG;
typedef union uFPROT
{
UINT8 byte;
struct
{
UINT8 fpls :2; /*flash protection lower address size */
UINT8 fpldis :1; /*flash protection lower address range disable */
UINT8 fphs :2; /*flash protection higher address size */
UINT8 fphdis :1; /*flash protection higher address range disable */
#if 0
UINT8 :1; /*contains value of equivalent bit in protection byte */
#endif
UINT8 nv :1; /*user non volatile flag bits* xpgong for ne64 2006.01.04*/
#if 0
UINT8 fopen :1; /*open block for program/erase control */
#endif
UINT8 fpopen :1; /*open block for program/erase control .xpgong 2006.01.04*/
}bit;
}tFPROT;
typedef union uFSTAT
{
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;
}tFSTAT;
#if 0
typedef union uFCMD
{
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;
}tFCMD;
#endif
typedef union uFCMD
{
UINT8 byte;
struct
{
UINT8 cmdb0 :1; /* */
UINT8 :1; /*not used */
UINT8 cmdb2 :1; /* */
UINT8 :2; /*not used */
UINT8 cmdb5 :1; /* */
UINT8 cmdb6 :1; /* */
UINT8 :1; /*not used */
}bit;
}tFCMD;
typedef struct /*flash datastructure */
{
volatile tFCLKDIV fclkdiv; /*flash clock divider register */
volatile tFSEC fsec; /*flash security register */
UINT8 rsvfee1; /*reserved */
tFCNFG fcnfg; /*flash configuration register */
volatile tFPROT fprot; /*flash protection register */
volatile tFSTAT fstat; /*flash status register */
tFCMD fcmd; /*flash command buffer & status register */
volatile UINT8 rsvfee2[9]; /*reserved */
}tFLASH;
#if 0
typedef struct /*flash datastructure */
{
volatile FCLKDIVSTR fclkdiv; /*flash clock divider register */
volatile FSECSTR fsec; /*flash security register */
UINT8 rsvfee1; /*reserved */
FCNFGSTR fcnfg; /*flash configuration register */
volatile FPROTSTR fprot; /*flash protection register */
volatile FSTATSTR fstat; /*flash status register */
FCMDSTR fcmd; /*flash command buffer & status register */
volatile UINT8 rsvfee2[9]; /*reserved */
}tFLASH;
#endif
#endif /*xpgong 06.01.05*/
/************************* Extern Variables **********************************/
/************************* #Defines ******************************************/
#if 1
#define FDIV8 0x40 /*bit masks */
#define FDIVLD 0x80
#define SEC00 0x01 /*bit masks */
#define SEC01 0x02
#define NV2 0x04
#define NV3 0x08
#define NV4 0x10
#define NV5 0x20
#define NV6 0x40
#define KEYEN 0x80
#define BKSEL0 0x01 /*bit masks */
#define BKSEL1 0x02
#define BKSEL 0x03 /*bank select mask */
#define KEYACC 0x20
#define CCIE 0x40
#define CCBIE 0x80
#define FPLS0 0x01 /*bit masks */
#define FPLS1 0x02
#define FPLS 0x03 /*fpls block size mask */
#define FPLDIS 0x04
#define FPHS0 0x08
#define FPHS1 0x10
#define FPHS 0x18 /*fphs block size mask */
#define FPHDIS 0x20
#define FOPEN 0x80
#define BLANK 0x04 /*bit masks */
#define ACCERR 0x10
#define PVIOL 0x20
#define CCIF 0x40
#define CBEIF 0x80
#endif /*xpgong 06.01.05*/
/* Oscillator frequency in kHz */
#define OSCCLK_FREQ_KHZ 25000L /* must have "L" appended for F/ECLK_PRESCALER macro modified by xpgong for NE64 */
//#define OSCCLK_FREQ_KHZ 4000L
/* Bus frequency in kHz */
#define BUSCLK_FREQ_KHZ (OSCCLK_FREQ_KHZ*(/*SYNR+*/1)/(/*REFDV+*/1))
#define MASS 0x41
#define PROG 0x20
#define ERASE 0x40
#define ERVER 0x05 /*added by xpgong for NE64 2006.01.04*/
#define PRDIV8 0x40
/*LIJIE############################*/
#define Successful 1
#define Flash_Odd_Access 2
#define Flash_Not_Erased 3
#define Access_Error 4
#define Protection_Error 5
#define Not_StartofSector_Error 6
#define Flash_Sector_Size /*32*/512
//#define FCLK_PRESCALER 0xFD
/************************* Macros ********************************************/
#if 1
/* Macro that generates the FLASH clock precaler as per data book.
If the crystal frequency is above 12.8MHz then the FDIV 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 FDIV8 bit */
#if ((OSCCLK_FREQ_KHZ * (BUSCLK_FREQ_KHZ + 200)) % (1600 * BUSCLK_FREQ_KHZ) == 0)
#define FCLK_PRESCALER ((OSCCLK_FREQ_KHZ * (BUSCLK_FREQ_KHZ + 200) / (1600 * BUSCLK_FREQ_KHZ)) +PRDIV8 - 1)
#else
#define FCLK_PRESCALER ((OSCCLK_FREQ_KHZ * (BUSCLK_FREQ_KHZ + 200) / (1600 * BUSCLK_FREQ_KHZ)) +PRDIV8 )
#endif /* OSCCLK_FREQ_KHZ * (BUSCLK_FREQ_KHZ + 200) % (1600 * BUSCLK_FREQ_KHZ) == 0 */
/* Make sure FCLK is within specified range. */
#define FCLK_FREQ_KHZ (OSCCLK_FREQ_KHZ / (8 * (1 + FCLK_PRESCALER - PRDIV8 )))
#if ((FCLK_FREQ_KHZ < 150) || (FCLK_FREQ_KHZ > 200) || (FCLK_PRESCALER > 0x7F))
#error FLASH prescaler or clock out of range.
#endif /* Incorrect FCLK frequency. */
#else
/* This macro calculates the prescaler. */
#if ((OSCCLK_FREQ_KHZ * (BUSCLK_FREQ_KHZ + 200)) % (200 * BUSCLK_FREQ_KHZ) == 0)
#define FCLK_PRESCALER ((OSCCLK_FREQ_KHZ * (BUSCLK_FREQ_KHZ + 200) / (200 * BUSCLK_FREQ_KHZ)) - 1)
#else
#define FCLK_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 FCLK is within specified range. */
#define FCLK_FREQ_KHZ (OSCCLK_FREQ_KHZ / (1 + FCLK_PRESCALER))
#if ((FCLK_FREQ_KHZ < 150) || (FCLK_FREQ_KHZ > 200) || (FCLK_PRESCALER > 0x3F))
#error FLASH prescaler or clock out of range.
#endif /* Incorrect FCLK frequency. */
#endif /* OSCCLK_FREQ_KHZ > 12800 */
#endif
/************************* Prototypes ****************************************/
void ConfigFCLKDIV(void);
UINT8 ProgFlash(UINT16*, UINT16*, UINT16);
#endif /* End of Header file !defined */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -