📄 mt28f008_driver.c
字号:
/*
* File : MT28F008_Driver.c
* Description: This file contains the Flash driver for use in ZiLOG File System
* Author : (Reused from Prototype fs driver code)
* Created on : 30-APR-2003
*
* 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 "MT28F008_Driver.h"
/*Readback Fail Flag: Every line flashed is read back to verify whether
* flashing happened properly. This flag is set when there is a readback
* fail.
*/
UINT8 gucReadbackFailed = 0 ; //default to no readback fails
INT32 FlashError(UINT8 ucStatus)
#ifdef _IAR_CODE
@ "DATA_PER_RAM"
#endif
{
// printf("\n FLASHERROR" ) ;
// while(1) ;
if(ucStatus & MT28F008_ERASE_SUSPENDED)
return -MT28F008_ERASE_SUSPENDED;
if(ucStatus & MT28F008_ERASE_ERROR)
return -MT28F008_ERASE_ERROR;
if(ucStatus & MT28F008_WRITE_ERROR)
return -MT28F008_WRITE_ERROR;
if(ucStatus & MT28F008_NO_VOLTAGE)
return -MT28F008_NO_VOLTAGE;
return SUCCESS;
}
INT MT28F008_Init( void *paddr, UINT32 num_bytes )
#ifdef _IAR_CODE
@ "DATA_PER_RAM"
#endif
{
volatile UINT8 *ucPtr = ( UINT8 * ) paddr ;
*ucPtr=MT28F008_RESET;
*ucPtr=MT28F008_CLEAR_STATUS_REG;
*ucPtr=MT28F008_READ_ARRAY;
return SUCCESS ;
}
INT32 MT28F008_Read( void *paddr, void *pbuf, UINT num_bytes )
#ifdef _IAR_CODE
@ "DATA_PER_RAM"
#endif
{
volatile UINT8 *ptr ;
UINT8 *pcaddr = ( UINT8 * ) paddr ;
UINT8 *pcbuf = ( UINT8 * ) pbuf ;
UINT nbytes ;
ptr = pcaddr ;
// Read set up
*ptr=MT28F008_RESET;
*ptr=MT28F008_CLEAR_STATUS_REG;
*ptr=MT28F008_READ_ARRAY;
for( nbytes = 0 ; nbytes < num_bytes ; nbytes++ )
{
*pcbuf = *pcaddr ;
pcbuf++ ;
pcaddr++ ;
}
return num_bytes ;
}
INT32 MT28F008_Write( void *paddr, void *pbuf, UINT num_bytes )
#ifdef _IAR_CODE
@ "DATA_PER_RAM"
#endif
{
UINT i;
volatile UINT8 *ucPtr;
UINT8 *ucSrcAddr;
UINT8 ucStatus;
ucSrcAddr=(UINT8*)pbuf;
ucPtr = ( UINT8 * ) paddr;
for(i=0; i < num_bytes; i++, ucPtr++)
{
// Write set up
*ucPtr=MT28F008_RESET;
*ucPtr=MT28F008_CLEAR_STATUS_REG;
*ucPtr=MT28F008_WRITE_SETUP;
*ucPtr=*ucSrcAddr;
do
{
ucStatus = (UINT8)(MT28F008_STATUS_BITS & *ucPtr);
} while( ucStatus == MT28F008_BUSY);
if(ucStatus != MT28F008_READY)
{ //if failed ..
//wait(ONE_SECOND);
*ucPtr=MT28F008_RESET; // try one more time
*ucPtr=MT28F008_CLEAR_STATUS_REG;
*ucPtr=MT28F008_WRITE_SETUP;
*ucPtr=*ucSrcAddr;
do
{
ucStatus = (UINT8)(MT28F008_STATUS_BITS & *ucPtr);
} while( ucStatus == MT28F008_BUSY);
if( ucStatus != MT28F008_READY)
{
*ucPtr=MT28F008_RESET;
*ucPtr=MT28F008_CLEAR_STATUS_REG;
*ucPtr=MT28F008_READ_ARRAY;
return FlashError(ucStatus);
}
}//end 'if:failed'
ucSrcAddr++;
}
*ucPtr=MT28F008_RESET;
*ucPtr=MT28F008_CLEAR_STATUS_REG;
*ucPtr=MT28F008_READ_ARRAY;
//Readback the data from the flash and verify with the
// data buffer whether they match
// if( memcmp( (void*)(ucPtr-num_bytes), (void*)pbuf, num_bytes ) ) //doesn't match?
// gucReadbackFailed = 1 ; //set the flag saying that read back failed
return num_bytes;
}
INT MT28F008_Erase( void *paddr, UINT32 num_bytes )
#ifdef _IAR_CODE
@ "DATA_PER_RAM"
#endif
{
UINT8 ucStatus;
UINT8 *ucPtr= (UINT8*)paddr;
*ucPtr=MT28F008_RESET;
*ucPtr=MT28F008_CLEAR_STATUS_REG;
*ucPtr=MT28F008_ERASE_SETUP;
*ucPtr=MT28F008_ERASE_CONFIRM;
do
{
ucStatus = (UINT8)(MT28F008_STATUS_BITS & *ucPtr);
} while(ucStatus == MT28F008_BUSY);
if(ucStatus != MT28F008_READY)// if failed ...
{
//wait(ONE_SECOND);
*ucPtr=MT28F008_RESET; // try one more time
*ucPtr=MT28F008_CLEAR_STATUS_REG;
*ucPtr=MT28F008_ERASE_SETUP;
*ucPtr=MT28F008_ERASE_CONFIRM;
do
{
ucStatus = (UINT8)(MT28F008_STATUS_BITS & *ucPtr);
} while(ucStatus == MT28F008_BUSY);
if(ucStatus != MT28F008_READY)
{
*ucPtr=MT28F008_RESET;
*ucPtr=MT28F008_CLEAR_STATUS_REG;
*ucPtr=MT28F008_READ_ARRAY;
return FlashError(ucStatus);
}
}
*ucPtr=MT28F008_RESET;
*ucPtr=MT28F008_CLEAR_STATUS_REG;
*ucPtr=MT28F008_READ_ARRAY;
return SUCCESS;
}
INT MT28F008_Close( void )
#ifdef _IAR_CODE
@ "DATA_PER_RAM"
#endif
{
return SUCCESS ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -