⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 am29lv160_driver.c

📁 flash AM29LV160 的驱动程序
💻 C
字号:
/*
 * File       : AM29LV160_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 "AM29LV160_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 AM29LV160_Init(  void *paddr, UINT32 num_bytes   )
#ifdef _IAR_CODE
@ "DATA_PER_RAM"
#endif
{
	volatile UINT8 *addr = ( UINT8 * ) ( ( UINT32 ) paddr & AM29LV160_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 + 0x555 ) = FLASH_CODE_55 ;
	*( addr + 0xAAA ) = ID_IN_CODE ;

	// get the manufacturer code and device code
	man_code = *addr ;
	dev_code = *(addr + 2 ) ;

	// get the device in read mode.
	*addr = CMD_READ_ARRAY ;

	// print the manufacturer code and device code
	printf("\n Manufacturer code : 0x%X", man_code ) ;
	if( dev_code == AMD_ID_29LV160BB )
	{
		printf("\nDevice Id: AM29LV160BB") ;
	}
	else if(  dev_code  == AMD_ID_29LV160TB )
	{
		printf("\nDevice Id: AM29LV160TB") ;
	}
	else
	{
		printf("\nUnknown device" ) ;
	}

	return SUCCESS ;
}

INT32 AM29LV160_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 AM29LV160_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 & AM29LV160_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 + 0x555 ) = 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 AM29LV160_Erase( void *paddr, UINT32 num_bytes )
#ifdef _IAR_CODE
@ "DATA_PER_RAM"
#endif
{
	volatile UINT8 *addr = ( UINT8 * )( ( UINT32 ) paddr & AM29LV160_MASK_BITS ) ;
	UINT8 result ;

	// setup the Sector Erase command
	*( addr + 0xAAA ) = FLASH_CODE_AA ;
	*( addr + 0x555 ) = 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 ;
		}
	}

	// the device is put in the READ ARRAY mode after the ERASE is complete
//	*( addr + 0x555 ) = CMD_READ_ARRAY ;

	return SUCCESS;
}

INT AM29LV160_Close( void )
#ifdef _IAR_CODE
@ "DATA_PER_RAM"
#endif
{
	return SUCCESS ;
}

/*
extern void InitUART ( void ) ;


void MyAppEntry( void )
{
	void *paddr = ( void * ) 0x300000 ;
	INT8 *buf = "Hello" ;
	INT8 recvbuf[5] ;
	INT8 bb ;

	InitUART() ;
	printf("\nAM29LV160_Init:" ) ;
	AM29LV160_Init( paddr, 0x2000 ) ;
	bb = 'A' ;
	printf("\nAM29LV160_Erase:" ) ;
	AM29LV160_Erase( paddr, 0x2000 ) ;
	bb = 'B' ;
	printf("\nAM29LV160_Write:" ) ;
	AM29LV160_Write( paddr, buf, 5 ) ;
	bb = 'C' ;
	printf("\nAM29LV160_Read:" ) ;
	AM29LV160_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 + -