📄 intflash_driver.c
字号:
/*
* File : IntFlash_Driver.c
* Description: This file contains the Flash driver for use in ZiLOG File System
* Author :
* Created on : 04-OCT-2004
*
* Copyright 2004 ZiLOG Inc. ALL RIGHTS RESERVED.
*
* This file contains unpublished confidential and proprietary information
* of ZiLOG, Inc.
* NO PART OF THIS WORK MAY BE DUPLICATED, STORED, PUBLISHED OR DISCLOSED
* IN ANY FORM WITHOUT THE PRIOR WRITTEN CONSENT OF ZiLOG, INC.
* This is not a license and no use of any kind of this work is authorized
* in the absence of a written license granted by ZiLOG, Inc. in ZiLOG's
* sole discretion
*/
#include <stdio.h>
#include <string.h>
#include "IntFlash_Driver.h"
#ifdef _EZ80F91
#include <eZ80F91.h>
#endif
#ifdef _EZ80F92
#include <eZ80F92.h>
#endif
#ifdef _EZ80F93
#include <eZ80F93.h>
#endif
#ifdef _IAR_CODE
#define LOC_ADDR UINT32
#else
#define LOC_ADDR UINT
#endif
// global variables
//UINT32 g_nSysClock = 50000000UL ;
#ifdef _EZ80F91
UINT8 g_nPagesPerBlock = 16 ;
#endif
#ifdef _EZ80F92
UINT8 g_nPagesPerBlock = 16 ;
#endif
/* Renuka : Defined g_nPagesPerBlock for F92 */
#ifdef _EZ80F93
UINT8 g_nPagesPerBlock = 16 ;
#endif
INT IntFlash_Init( VOID *paddr, UINT32 num_bytes )
#ifdef _IAR_CODE
@ "DATA_PER_RAM"
#endif
{
// Unprotect the flash blocks
// write FLASH_KEY register to unprotect teh FLASH_FDIV and FLASH_PROT registers
FLASH_KEY = 0xB6 ;
FLASH_KEY = 0x49 ;
// set the FLASH_FDIV register
#ifdef _EZ80F91
FLASH_FDIV = 0xFF ; //( UINT8) ( ulFdiv & 0xFF ) ;
#endif
#ifdef _EZ80F92
FLASH_FDIV = 0x66 ;
#endif
#ifdef _EZ80F93
FLASH_FDIV = 0x66 ;
#endif
// write FLASH_KEY register to unprotect teh FLASH_FDIV and FLASH_PROT registers
FLASH_KEY = 0xB6 ;
FLASH_KEY = 0x49 ;
// enable write/erase protect for boot block (32KB)
// disable write/erase protect for other blocks.
FLASH_PROT = 0x00 ;
return SUCCESS ;
}
INT32 IntFlash_Read( VOID *paddr, VOID *pbuf, UINT num_bytes )
#ifdef _IAR_CODE
@ "DATA_PER_RAM"
#endif
{
// the number of bytes passed to this function is always less than
// 512 bytes
UINT16 nBytes ;
volatile UINT8 *pcBuf = ( UINT8 * ) pbuf ;
volatile UINT8 *pcaddr = ( UINT8 * ) paddr ;
#ifdef _EZ80F91
// set the PAGE, ROW and COL registers
FLASH_PAGE = GETPAGE( (LOC_ADDR) pcaddr ) ;
FLASH_ROW = GETROW( (LOC_ADDR) pcaddr ) ;
FLASH_COL = GETCOL( (LOC_ADDR) pcaddr ) ;
#endif
// now in a loop read the num_bytes values from FLASH_DATA register
for( nBytes = 0 ; nBytes < num_bytes ; nBytes++ )
{
#ifdef _EZ80F91
*pcBuf = FLASH_DATA ;
#endif
#if defined(_EZ80F92) || defined(_EZ80F93)
*pcBuf = *pcaddr ;
#endif
pcBuf++ ;
#if defined(_EZ80F92) || defined(_EZ80F93)
pcaddr++ ;
#endif
}
return num_bytes ;
}
INT32 IntFlash_Write( VOID *paddr, VOID *pbuf, UINT num_bytes )
#ifdef _IAR_CODE
@ "DATA_PER_RAM"
#endif
{
// the number of bytes passed to this function is always less than
// 512 bytes
UINT16 nBytes ;
volatile UINT8 *pcBuf = ( UINT8 * ) pbuf ;
volatile UINT8 *pcaddr = ( UINT8 * ) paddr ;
#ifdef _EZ80F91
// set the PAGE, ROW and COL registers
FLASH_PAGE = GETPAGE( (LOC_ADDR) pcaddr ) ;
FLASH_ROW = GETROW( (LOC_ADDR) pcaddr ) ;
FLASH_COL = GETCOL( (LOC_ADDR) pcaddr ) ;
#endif
// now in a loop read the num_bytes values from FLASH_DATA register
for( nBytes = 0 ; nBytes < num_bytes ; nBytes++ )
{
#if defined(_EZ80F92) || defined(_EZ80F93)
// set the PAGE, ROW and COL registers
FLASH_PAGE = GETPAGE( (LOC_ADDR) pcaddr ) ;
FLASH_ROW = GETROW( (LOC_ADDR) pcaddr ) ;
FLASH_COL = GETCOL( (LOC_ADDR) pcaddr ) ;
#endif
FLASH_DATA = *pcBuf ;
pcBuf++ ;
#if defined(_EZ80F92) || defined(_EZ80F93)
pcaddr++ ;
#endif
}
return num_bytes ;
}
INT IntFlash_Erase( VOID *paddr, UINT32 num_bytes )
#ifdef _IAR_CODE
@ "DATA_PER_RAM"
#endif
{
// the provided address is the start address of the 32 KB block.
// and each 32 KB contains 16 2 KB pages. So need to erase the 16 pages.
// given start address is relative from ZERO address. So, from this, we
// calculate the page numbers to erase.
UINT8 nPageNum = GETPAGE( (UINT32) paddr ) ;
UINT nCnt ;
for( nCnt = 0 ; nCnt < g_nPagesPerBlock ; nCnt++ )
{
// store the PAGE NUM in the register
FLASH_PAGE = nPageNum ;
// setup the flash erase
FLASH_PGCTL = FLASH_PGCTL_PG_ERASE_ENABLE ;
// now poll for the
while(1)
{
// If erase is complete, break from the loop
if( !(FLASH_PGCTL & FLASH_PGCTL_PG_ERASE_ENABLE ) )
break ;
}
// go to next page
nPageNum++ ;
}
return SUCCESS;
}
INT IntFlash_Close( VOID )
#ifdef _IAR_CODE
@ "DATA_PER_RAM"
#endif
{
// disable INTERNAL FLASH
FLASH_CTRL = 0x00 ;
return SUCCESS ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -