📄 flash_data.c
字号:
/***************************************************************************
* File: flash_data.c - Implement the read and write functions
*
* The content of this file or document is CONFIDENTIAL and PROPRIETARY
* to Jade Technologies Co., Ltd. It is subject to the terms of a
* License Agreement between Licensee and Jade Technologies Co., Ltd.
* restricting among other things, the use, reproduction, distribution
* and transfer. Each of the embodiments, including this information
* and any derivative work shall retain this copyright notice.
*
* Copyright (c) 2005 Jade Technologies Co., Ltd.
* All rights reserved.
****************************************************************************/
#include "flash.h"
//------------------------------------------------------------------------------
// Macros
//------------------------------------------------------------------------------
#define MIN(__x,__y) ((__x)<(__y)?(__x):(__y))
#define MAX(__x,__y) ((__x)>(__y)?(__x):(__y))
unsigned char * CacheBuf;
unsigned long dwBlockAddr = 0;
unsigned long dwBlockStartAddr = 0;
//------------------------------------------------------------------------------
// Functions
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//
// Checks the status of the flash device by checking toggle in bit 6.
//
// address - Address to check
//
// return 0 - Success -1 - Failure
//
//------------------------------------------------------------------------------
int FLA_cfi_check_status (unsigned long address)
{
unsigned long dwTimeOut = 0;
unsigned char status,Pre_status;
Pre_status = FLASH(address) & 0x40;
// Get the current status
while(dwTimeOut < 0x7ffff) {
status = FLASH(address) & 0x40;
if(status == Pre_status)
break;
Pre_status = status;
dwTimeOut ++;
}
// Return status
if (dwTimeOut >= 0x7ffff)
return -1;
else
return 0;
}
//------------------------------------------------------------------------------
//
// Writes a byte the flash device.
//
// address - Address to write
// byte - Data to write
//
// return 0 - Success -1 - Failure
//
//------------------------------------------------------------------------------
int FLA_cfi_write_byte (unsigned long address, unsigned char byte)
{
FLASH_COMMAND(0x5555, 0xaa);
FLASH_COMMAND(0x2aaa, 0x55);
FLASH_COMMAND(0x5555, 0xa0);
FLASH(address) = byte;
return FLA_cfi_check_status (address);
}
//------------------------------------------------------------------------------
//
// Reads a byte from the flash device.
//
// address - Address to read
// byte - Pointer to data to read
//
// return 0 - Success -1 - Failure
//
//------------------------------------------------------------------------------
int FLA_cfi_read_byte (unsigned long address, unsigned char * pbyte)
{
*pbyte = FLASH(address);
return FLA_cfi_check_status (address);
}
//------------------------------------------------------------------------------
//
// Erases a block.
//
// address - Address to erase
//
// return 0 - Success -1 - Failure
//
//------------------------------------------------------------------------------
int FLA_cfi_erase_block (unsigned long address)
{
//RETAILMSG(MSG_DATA, (_T("FLASH: FLA_cfi_erase_block: 0x%x\r\n"), address));
FLASH_COMMAND(0x5555, 0xaa);
FLASH_COMMAND(0x2aaa, 0x55);
FLASH_COMMAND(0x5555, 0x80);
FLASH_COMMAND(0x5555, 0xaa);
FLASH_COMMAND(0x2aaa, 0x55);
FLASH_DATA(address, 0x30);
return FLA_cfi_check_status (address);
}
//------------------------------------------------------------------------------
//
// Erases the entire chip.
//
// address - Address to erase
//
// return 0 - Success -1 - Failure
//
//------------------------------------------------------------------------------
void FLA_cfi_erase_chip ( )
{
RETAILMSG(MSG_DATA, (_T("FLASH: FLA_cfi_erase_chip\r\n")));
FLASH_COMMAND(0x5555, 0xaa);
FLASH_COMMAND(0x2aaa, 0x55);
FLASH_COMMAND(0x5555, 0x80);
FLASH_COMMAND(0x5555, 0xaa);
FLASH_COMMAND(0x2aaa, 0x55);
FLASH_COMMAND(0x5555, 0x10);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -