📄 at49bv162_driver.c
字号:
/*
* File : AT49BV162_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 "AT49BV162_Driver.h"
// The driver uses hte configuration of 0x00 which specifies
// NO PRODUCT IDENTIFICATION EXIT is necessary. The device itself will issue
// the PRODUCT IDENTIFICATION EXIT command after the PROGRAM OR ERASE
// operation is carried out and the device is put in the READ ARRAY mode.
INT AT49BV162_Init( void *paddr, UINT32 num_bytes )
#ifdef _IAR_CODE
@ "DATA_PER_RAM"
#endif
{
volatile UINT8 *addr = ( UINT8 * ) ( ( UINT32 ) paddr & AT49BV162_MASK_BITS ) ;
volatile UINT8 dev_code=0, man_code =0;
// the address passed is the base address of the flash.
// Setup PRODUCT_IDENTIFICATION_ENTRY MODE
*( addr + 0xAAA ) = FLASH_CODE_AA ;
*( addr + 0x554 ) = FLASH_CODE_55 ;
*( addr + 0xAAA ) = ID_IN_CODE ;
// get the manufacturer code and device code
man_code = *addr ;
dev_code = *(addr + 2 ) ;
// the address passed is the base address of the flash.
// Setup PRODUCT_IDENTIFICATION_EXIT MODE
*( addr + 0xAAA ) = FLASH_CODE_AA ;
*( addr + 0x554 ) = FLASH_CODE_55 ;
*( addr + 0xAAA ) = ID_OUT_CODE ;
// print the manufacturer code and device code
printf("\n Manufacturer code : 0x%X", man_code ) ;
if( dev_code == ATM_ID_BV162A_163A )
{
printf("\nDevice Id: AT49BV162/163A") ;
}
else if( dev_code == ATM_ID_BV162AT_163AT )
{
printf("\nDevice Id: AT49BV162T/163AT") ;
}
else
{
printf("\nUnknown device" ) ;
}
return SUCCESS ;
}
INT32 AT49BV162_Read( void *paddr, void *pbuf, UINT num_bytes )
#ifdef _IAR_CODE
@ "DATA_PER_RAM"
#endif
{
UINT nbytes ;
UINT8 *pcbuf = ( UINT8 * ) pbuf ;
UINT8 *pcaddr = ( UINT8 * ) paddr ;
// By default the device is in READ ARRAY mode, just copy the
// contents from the device to the appropraite memory location.
for( nbytes = 0 ; nbytes < num_bytes ; nbytes++ )
{
*pcbuf = *pcaddr ;
pcbuf++ ;
pcaddr++ ;
}
return num_bytes ;
}
INT32 AT49BV162_Write( void *paddr, void *pbuf, UINT num_bytes )
#ifdef _IAR_CODE
@ "DATA_PER_RAM"
#endif
{
volatile UINT8 *addr = ( UINT8 * ) paddr ;
volatile UINT8 *base_addr = ( UINT8 * ) ( ( UINT32 ) paddr & AT49BV162_MASK_BITS ) ;
UINT8 *buf = ( UINT8 * ) pbuf ;
UINT8 result ;
UINT nbytes = 0 ;
for( nbytes = 0 ; nbytes < num_bytes ; nbytes++ )
{
// setup the Program command for the device.
*( base_addr + 0xAAA ) = FLASH_CODE_AA ;
*( base_addr + 0x554 ) = FLASH_CODE_55 ;
*( base_addr + 0xAAA ) = CMD_PROGRAM ;
*addr = *buf ;
while(1)
{
// loop till when the same data read back that means the byte is written
// onto the device.
result = *addr ;
if( result == *buf )
break ;
}
buf ++ ;
addr ++ ;
}
return num_bytes;
}
INT AT49BV162_Erase( void *paddr, UINT32 num_bytes )
#ifdef _IAR_CODE
@ "DATA_PER_RAM"
#endif
{
volatile UINT8 *addr = ( UINT8 * )( ( UINT32 ) paddr & AT49BV162_MASK_BITS ) ;
UINT8 result ;
// setup the Sector Erase command
*( addr + 0xAAA ) = FLASH_CODE_AA ;
*( addr + 0x554 ) = FLASH_CODE_55 ;
*( addr + 0xAAA ) = CMD_ERASE_SETUP ;
*( addr + 0xAAA ) = FLASH_CODE_AA ;
*( addr + 0x554 ) = FLASH_CODE_55 ;
*( addr ) = CMD_ERASE_CONFIRM ; // Erasing the sector
while(1)
{
result = *addr ;
if ( (result) & BIT_ERASE_DONE)
{
// the erase is completed.
break ;
}
}
return SUCCESS;
}
INT AT49BV162_Close( void )
#ifdef _IAR_CODE
@ "DATA_PER_RAM"
#endif
{
return SUCCESS ;
}
/*
void MyAppEntry( void )
{
void *paddr = ( void * ) 0x31FF20 ;
INT8 *buf = "Hello" ;
INT8 recvbuf[5] ;
// printf("\nAT49BV162_Entry" ) ;
AT49BV162_Init( paddr, 0x2000 ) ;
AT49BV162_Erase( paddr, 0x2000 ) ;
AT49BV162_Write( paddr, buf, 5 ) ;
AT49BV162_Read( paddr, &recvbuf[0], 5 ) ;
if( memcmp( &recvbuf[0], buf, 5 ) == 0 )
printf("\nStrings Equal" ) ;
else
printf("\nStrings Not Equal" ) ;
return ;
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -