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

📄 flash.c

📁 Ep93XX TionProV2 BSP
💻 C
📖 第 1 页 / 共 2 页
字号:
//**********************************************************************
//                                                                      
// Filename: flash.c 
//                                                                      
// Description: Contains the CE flash routines.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//                                                               
// Use of this source code is subject to the terms of the Cirrus end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to 
// use this source code. For a copy of the EULA, please see the 
// EULA.RTF on your install media.
//
// Copyright(c) Cirrus Logic Corporation 2005, All Rights Reserved                       
//                                                                      
//**********************************************************************

#include <windows.h>
#include <memorymap.h>
#include <hwdefs.h>
#include <halether.h>
#include <clocks.h>
#include "flash.h"

DWORD				gdwFlashSize=FLASH_SIZE;
//
// Function pointer to Flash routines.
//
static PFN_START_ERASE_FLASH     pfnStartErase     = 0;
static PFN_CONTINUE_ERASE_FLASH  pfnContinueErase  = 0;
static PFN_FINISH_ERASE_FLASH    pfnFinishErase    = 0;
static PFN_WRITE_FLASH           pfnWriteFlash     = 0;


#if EP93XX_FLASH_WIDTH == 16
    
    #if EP93XX_FLASH_TYPE ==FLASH_TYPE_C3

	    #include "flash\intel_c3_1x16.c"
    
    #elif EP93XX_FLASH_TYPE ==FLASH_TYPE_P3

		#include "flash\intel_p30_1x16.c"
    
    #elif EP93XX_FLASH_TYPE ==FLASH_TYPE_AMD

		#include "flash\spansion29lv320d_1x16.c"
	//#elif add new files to support new flash here.
    #elif  (EP93XX_FLASH_TYPE == FLASH_TYPE_J3)
		#include "flash\intel_j3_1x16.c"
	#else
	#error "Error, Please specify Flash Type\r\n"
    #endif
    
#elif EP93XX_FLASH_WIDTH ==32
   
    #if EP93XX_FLASH_TYPE ==FLASH_TYPE_C3
		
		#include "flash\intel_c3_2x16.c"
    
    #elif EP93XX_FLASH_TYPE == FLASH_TYPE_P3

	    #include "flash\intel_p30_2x16.c"
    
    #elif EP93XX_FLASH_TYPE == FLASH_TYPE_AMD
    
		#include "flash\spansion29lv320d_2x16.c"

	//#elif add new files to support new flash here.
    #elif  (EP93XX_FLASH_TYPE == FLASH_TYPE_J3)
		#include "flash\intel_j3_2x16.c"
    #endif
#else 
#error "Error, Flash width is not specified\n"
#endif



BOOL InitializeFlash( void )
{
    ULONG   ulSMC=0;
	int wait1;
	int wait2;

	//for WAIT_STATES(A), the largest value of 'A' should be 500, when A is 500,
	//WAIT_STATES(A) is 31, which has reached the largest value of WAIT_STATES(A).
	#if (EP93XX_FLASH_TYPE==FLASH_TYPE_C3)

		wait2=0x1F;
		wait1=0x1F;

	#elif (EP93XX_FLASH_TYPE == FLASH_TYPE_AMD)

		wait2=0x1F;
		wait1=0x1F;

	#elif (EP93XX_FLASH_TYPE == FLASH_TYPE_P3)

		wait2=0x1F;
		wait1=0x1F;

	#elif  (EP93XX_FLASH_TYPE == FLASH_TYPE_J3)

		wait2=WAIT_STATES(35);
		wait1=WAIT_STATES(150);

	#else  //The lowest value
		wait2=0x1F;
		wait1=0x1F;
	#endif
	//
	ulSMC   = (( wait2 <<SMCBCR_WST2_SHIFT) & SMCBCR_WST2_MASK) | 
			  (( wait1 <<SMCBCR_WST1_SHIFT) & SMCBCR_WST1_MASK);

	//Add other values:
	*FLASH_SMC = ulSMC |  ( 1 & SMCBCR_IDCY_MASK )  |SMCBCR_WP | SMCBCR_PME | SMCBCR_RBLE

			#if EP93XX_FLASH_WIDTH==16
			|  SMCBCR_MW_16BIT
			#else
			|  SMCBCR_MW_32BIT
			#endif
			;


    ulSMC        = *FLASH_SMC;
    ulSMC       |= SMCBCR_WPERR;
    ulSMC       &= ~SMCBCR_WP;
    *FLASH_SMC = ulSMC ;

    //
    // Fill in the pointers for the following.
    //

#if (EP93XX_FLASH_WIDTH==16)

    EdbgOutputDebugString("16 bit flash\r\n");
    
	#if (EP93XX_FLASH_TYPE==FLASH_TYPE_C3)

		EdbgOutputDebugString("1X16 C3 Flash Defined\r\n" );
		if( !QueryIntelFlashC3_1x16() ){
			EdbgOutputDebugString("Defined C3 Flash, but not found. stop.\r\n" );
			EdbgOutputDebugString("Defined C3 Flash, but not found. stop.\r\n" );
			return FALSE;
		}
		pfnStartErase       = StartEraseFlashC3_1x16;
		pfnContinueErase    = ContinueEraseFlashC3_1x16;
		pfnFinishErase      = FinishEraseFlashC3_1x16;
		pfnWriteFlash       = WriteFlashC3_1x16;
    
	#elif (EP93XX_FLASH_TYPE == FLASH_TYPE_P3)

		EdbgOutputDebugString("1X16 P3 Flash Defined\r\n" );
		if( !QueryIntelFlashP30_1x16() ){
			EdbgOutputDebugString("Defined P3 Flash, but not found. stop.\r\n" );
			return FALSE;
		}
		pfnStartErase       = StartEraseFlashP30_1x16;
		pfnContinueErase    = ContinueEraseFlashP30_1x16;
		pfnFinishErase      = FinishEraseFlashP30_1x16;
		pfnWriteFlash       = WriteFlashP30_1x16;
    
	#elif (EP93XX_FLASH_TYPE == FLASH_TYPE_AMD)
		EdbgOutputDebugString("1X16 AMD Flash Defined\r\n" );
		if(!AmdFlashSpansion29LV320D_1x16() ){
			EdbgOutputDebugString("Defined C3 Flash, but not found. stop.\r\n" );
			return FALSE;
		}
		pfnStartErase       = StartEraseSpansion29LV320D_1x16;
		pfnContinueErase    = ContinueEraseSpansion29LV320D_1x16;
		pfnFinishErase      = FinishEraseSpansion29LV320D_1x16;
		pfnWriteFlash       = WriteSpansion29LV320D_1x16;

    #elif  (EP93XX_FLASH_TYPE == FLASH_TYPE_J3)

		EdbgOutputDebugString("1X16 J3 Flash Defined\r\n" );

		pfnStartErase       = StartEraseFlashJ3_1x16;
		pfnContinueErase    = ContinueEraseFlashJ3_1x16;
		pfnFinishErase      = FinishEraseFlashJ3_1x16;
		pfnWriteFlash       = WriteFlashJ3_1x16;
	#else
	#error "Error, Please specify Flash Type\r\n"
    #endif

#elif EP93XX_FLASH_WIDTH == 32
   
   #if EP93XX_FLASH_TYPE == FLASH_TYPE_C3 
		EdbgOutputDebugString("2X16 C3 Flash Defined\r\n" );
		if(!QueryIntelFlashC3_2x16() ){
			EdbgOutputDebugString("Defined C3 Flash, but not found. stop.\r\n" );
			return FALSE;
		}
		pfnStartErase       = StartEraseFlashC3_2x16;
		pfnContinueErase    = ContinueEraseFlashC3_2x16;
		pfnFinishErase      = FinishEraseFlashC3_2x16;
		pfnWriteFlash       = WriteFlashC3_2x16;

    #elif EP93XX_FLASH_TYPE == FLASH_TYPE_P3
		EdbgOutputDebugString("2X16 P3 Flash Defined\r\n" );
		if(!QueryIntelFlashP30_2x16() ){
			EdbgOutputDebugString("Defined P3 Flash, but not found. stop.\r\n" );
			return FALSE;
		}
		pfnStartErase       = StartEraseFlashP30_2x16;
		pfnContinueErase    = ContinueEraseFlashP30_2x16;
		pfnFinishErase      = FinishEraseFlashP30_2x16;
		pfnWriteFlash       = WriteFlashP30_2x16;
   
    #elif EP93XX_FLASH_TYPE == FLASH_TYPE_AMD
		EdbgOutputDebugString("2X16 AMD Flash Defined\r\n" );
		if(!AmdFlashSpansion29LV320D_2x16() ){
			EdbgOutputDebugString("Defined C3 Flash, but not found. stop.\r\n" );
			return FALSE;
		}
		pfnStartErase       = StartEraseSpansion29LV320D_2x16;
		pfnContinueErase    = ContinueEraseSpansion29LV320D_2x16;
		pfnFinishErase      = FinishEraseSpansion29LV320D_2x16;
		pfnWriteFlash       = WriteSpansion29LV320D_2x16;

    #elif  (EP93XX_FLASH_TYPE == FLASH_TYPE_J3)

		EdbgOutputDebugString("2X16 J3 Flash Defined\r\n" );
		pfnStartErase       = StartEraseFlashJ3_2x16;
		pfnContinueErase    = ContinueEraseFlashJ3_2x16;
		pfnFinishErase      = FinishEraseFlashJ3_2x16;
		pfnWriteFlash       = WriteFlashJ3_2x16;
	#else
	#error "Error, Please specify Flash Type\r\n"
    #endif

#else 
#error "Error, Flash width is not specified\n"

#endif

	EdbgOutputDebugString("Initialize Flash, succeed\r\n" );
	return TRUE;
}

//****************************************************************************
// OEMIsFlashAddr
//****************************************************************************
// dwAddr  - Address of a BIN file record. This is the address checked to see 
//           whether it lies in flash or RAM.  
//
// return    TRUE  - SUCESS
//           FALSE - ERROR
//
BOOL OEMIsFlashAddr (DWORD dwAddr)
{
    BOOL    bReturnValue = FALSE;

    if(PHYSICAL_ADDR_FLASH <= dwAddr  &&
        dwAddr < (PHYSICAL_ADDR_FLASH + FLASH_SIZE ))
    {
        bReturnValue = TRUE;
    }
    
    return bReturnValue;
}



//****************************************************************************
//  OEMMapMemAddr
//****************************************************************************
// dwImageStart  -  Start address of image. 
//
// dwAddr        -  Address of a BIN record. If this address lies in a 
//                  platforms flash address space, typically the offset 
//                  from dwImageStart is computed and added to a RAM-based file 
//                  cache area. 
//
// Return Values    Address at which the BIN record should be copied to 
//                  provide file caching before and during the flash update 
//                  process.
//
LPBYTE OEMMapMemAddr
(
    DWORD dwImageStart,
    DWORD dwAddr
)
{
    LPBYTE  pReturnValue;

    if(OEMIsFlashAddr(dwImageStart))
    {
#if (defined EDB9302A )
        pReturnValue = (LPBYTE)( (dwAddr - FLASH_VIRTUAL_MEMORY) + (0x00000000| FLASH_CACHE_MEMORY_OFFSET) ); 
#else
        pReturnValue = (LPBYTE)( (dwAddr - FLASH_VIRTUAL_MEMORY) + FLASH_CACHE_PHYSICAL_MEMORY ); 
#endif

    }
    //  
    // Hack hack hack.  Looks like eboot thinks that this is the wrong address.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -