📄 flash_nor_ram.c
字号:
/*====*====*====*====*====*====*====*====*====*====*====*====*====*====*====* E M B E D D E D F I L E S Y S T E M GENERAL DESCRIPTION File System NOR Device Driver Simulation over P/SRAM Copyright (c) 1999 - 2006 by QUALCOMM Incorporated. All Rights Reserved. *====*====*====*====*====*====*====*====*====*====*====*====*====*====*====*/ /*=========================================================================== EDIT HISTORY FOR MODULE $Header: //depot/asic/msmshared/drivers/flash/MSM_FLASH.01.04/flash_nor_ram.c#3 $ $DateTime: 2006/05/26 10:49:40 $ $Author: dhamimp $ when who what, where, why -------- --- ---------------------------------------------------------- 10/11/05 dp RAM driver to simulate a NOR Flash ===========================================================================*/ /*=========================================================================== INCLUDE FILES FOR MODULE ===========================================================================*/#include "customer.h"#include "comdef.h"#include <memory.h>#include "flash_nor_device.h"#include "flash_nor_msm.h"#include "clk.h"#include "flash_msg.h" /* Forward function prototypes */LOCAL flash_status fsi_ram_configure (fsi_nor_device *nor_device, flash_ptr_type eraseaddr);LOCAL flash_status fsi_ram_write (byte *buffer, flash_ptr_type baseaddr, dword offset, dword count);LOCAL flash_status fsi_ram_erase (flash_ptr_type baseaddr, dword offset);LOCAL flash_status fsi_ram_erase_status (flash_ptr_type eraseaddr);LOCAL flash_status fsi_ram_suspend (flash_ptr_type eraseaddr);LOCAL flash_status fsi_ram_resume (flash_ptr_type eraseaddr);LOCAL struct fsi_dev_ops flash_ram_op_functions ={ fsi_ram_configure, /* Configuration of hardware */ fs_nor_device_worded_read, /* Read operation. */ fsi_ram_write, /* Write for Spansion. */ fsi_ram_erase, /* Erase for Spansion. */ fsi_ram_erase_status, /* Status for Spansion. */ fsi_ram_suspend, fsi_ram_resume,}; /* Device information for each operation. */LOCAL fsi_nor_device RAM_NOR = { "NOR_ON_RAM", 0, /* # of codes to match */ {0,0,0,0}, /* Manufacture codes. */ 0, { FLASH_NOR_EFS2_START_BYTE_OFFSET, /* Byte offset to EFS2 area. */ (FLASH_NOR_EFS2_END_BYTE_OFFSET - FLASH_NOR_EFS2_START_BYTE_OFFSET) + 1, FLASH_NOR_EFS2_SECTOR_BYTE_SIZE, FLASH_NOR_EFS2_NUM_SECTORS }, INIT_NOT_NEEDED, &flash_ram_op_functions};/*===========================================================================FUNCTION FSI_RAM_ERASEDESCRIPTION Initiate erase operation.DEPENDENCIES fsi_target is initializedRETURN VALUE FLASH_SUCCESS - If erase operation was successfully initiated FLASH_OP_NOT_COMPLETE - If an erase operation is already in progress FLASH_FAILURE - If erase operation could not otherwise be startedSIDE EFFECTS None===========================================================================*/LOCAL flash_statusfsi_ram_erase (flash_ptr_type baseaddr, dword offset){ volatile word *wptr; volatile byte *bptr; dword i; extern fsi_nor_device *nor_device; wptr = baseaddr + BYTE_TO_WORD_OFFSET(offset); bptr = (volatile byte *) wptr; for (i=0; i < nor_device->efs_info.efs_blk_bsize; i++) { bptr[i] = 0xFF; } return FLASH_SUCCESS;}/*===========================================================================FUNCTION FSI_RAM_ERASE_STATUSDESCRIPTION Erase status check.DEPENDENCIES The device must be in the erasing state.RETURN VALUE FLASH_SUCCESS - The erase is finished, component is not in read state FLASH_OP_NOT_COMPLETE - The erase is still happening. FLASH_FAILURE - Something went wrong with the erase.SIDE EFFECTS None===========================================================================*/LOCAL flash_statusfsi_ram_erase_status (flash_ptr_type eraseaddr ){ return FLASH_SUCCESS;}/*===========================================================================FUNCTION FSI_RAM_WRITEDESCRIPTION Write a block of bytes.DEPENDENCIES The device must not be in erasing state.RETURN VALUE FLASH_SUCCESS - If write completed normally FLASH_FAILURE - If write operation failedSIDE EFFECTS None===========================================================================*/LOCAL flash_statusfsi_ram_write (byte *buffer, flash_ptr_type baseaddr, dword offset, dword count){ volatile byte *part_base, *bptr; volatile word *wptr, *check_ptr; word value; word tmp; /* Base address of operation. */ part_base = ((volatile byte *) baseaddr + offset); check_ptr = (volatile word *) ((dword) part_base & ~1); /* Determine if the block is aligned or not. */ if (((dword) buffer & 1) == 0 && (offset & 1) == 0 && (count & 1) == 0) { /* Do word operations. */ wptr = (volatile word *) part_base; /* Since we're already aligned, we could compare with 0, but the 1 will be needed for future optimizations. */ while (count > 1) { value = *((word *) buffer); *wptr = value; buffer += 2; wptr += 1; count -= 2; } } else { /* Do byte operations. */ bptr = part_base; while (count > 0) { value = *buffer; /* The command accesses need to be word oriented or the data will be placed on the wrong data lines. Compute a word pointer from the byte pointer that is always at an even address. */ wptr = ((volatile word *) ((dword) bptr & ~1)); /* Get old value. */ tmp = *wptr; /* Assumes little endian. */ if (((dword) bptr & 1) == 0) value = tmp & (value | 0xFF00); else value = tmp & ((value << 8) | 0x00FF); *wptr = value; buffer += 1; bptr += 1; count -= 1; } } return FLASH_SUCCESS;}/*======================================================================FUNCTION FSI_RAM_SUSPENDDESCRIPTION Suspend an erase operation.DEPENDENCIESRETURN VALUE FLASH_SUCCESS - The erase has completed. FLASH_OP_NOT_COMPLETE - The erase was suspended, reads may be done. FLASH_FAILURE - The suspend failed, or an erase was not in progress.SIDE EFFECTS None========================================================================*/LOCAL flash_statusfsi_ram_suspend (flash_ptr_type eraseaddr){ return FLASH_SUCCESS;}/*===========================================================================FUNCTION FSI_RAM_RESUMEDESCRIPTION Resume a suspended erase.DEPENDENCIESRETURN VALUE FLASH_SUCCESS - The erase has been resumed. FLASH_FAILURE - An error occurred.SIDE EFFECTS None===========================================================================*/LOCAL flash_statusfsi_ram_resume (flash_ptr_type eraseaddr){ return FLASH_SUCCESS;}/*===========================================================================FUNCTION FSI_RAM_CONFIGUREDESCRIPTION Do any necessary initializtion.DEPENDENCIES RETURN VALUE FLASH_SUCCESS - Success FLASH_FAILURE - An error occurred.SIDE EFFECTS None===========================================================================*/LOCAL flash_statusfsi_ram_configure (fsi_nor_device * nor_device, flash_ptr_type baseaddr){ /* just a stub for devices that need no configuration */ return FLASH_SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -