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

📄 intel_c3_1x16.c

📁 Ep93XX TionProV2 BSP
💻 C
📖 第 1 页 / 共 2 页
字号:
        *gpusCurAddr = FLASH_READ_STATUS;

        gbUnlocked  = TRUE;
    }

}

//****************************************************************************
// FinishEraseFlashJ3_1x16
//****************************************************************************
// Finishes the flash eraseing processes for J3 Flash.  See 
// OEMFinishEraseFlash for paramter description.
//
BOOL  FinishEraseFlashC3_1x16 (void)
{
    BOOL    bSuccess;
    //
    // Check to see if the flash has been completely erased. If so just
    // return.
    //
    if(gbFlashEraseComplete)
    {
        return TRUE;
    }

    //
    // Wait for the Flash block command to succeed.
    //
    bSuccess = WaitForReady(gpusCurAddr, 10000, EXT_STATUS_WBUFFER_READY);
    if(bSuccess == FALSE)
    {
        return FALSE;
    }

    *gpusCurAddr  = FLASH_CLEAR_STATUS;

    //
    // Erase the block before unlocking the next block.
    //
    if(gbUnlocked)
    {
        //
        // Erase the flash block
        //
        *gpusCurAddr = FLASH_BLOCK_ERASE;
        *gpusCurAddr = FLASH_BLOCK_ERASE_RESUME;

        //
        // Read erase status.
        //
        *gpusCurAddr = FLASH_READ_STATUS;

        //
        // Wait for the Flash block command to succeed.
        //
        bSuccess = WaitForReady(gpusCurAddr, 10000, EXT_STATUS_WBUFFER_READY);
        if(bSuccess == FALSE)
        {
            return FALSE;
        }

        *gpusCurAddr    = FLASH_CLEAR_STATUS;
        gbUnlocked      = FALSE;

        //
        // Increment to the next block.
        //
        gpusCurAddr+= sBlockInfo[gdwCurEraseRegion].block_size>>1;

		//
		//go to the next bloxk
		//
		gdwCurEraseBlock = gdwCurEraseBlock+1;
		if(gdwCurEraseBlock>=sBlockInfo[gdwCurEraseRegion].blocks)
		{
			gdwCurEraseBlock=0;
			gdwCurEraseRegion=gdwCurEraseRegion+1;
			//
			//return error the current postiotn > the Flash MAX length
			//
			if(gdwCurEraseRegion>=gdwNumEraseRegion)
				return FALSE;
		}
    }
    // Erase the Flash
    //
    while((DWORD)gpusCurAddr < (gdwStartAddr + gdwLength))
    {
        // Clear the lock bits if the flash block was locked.
        //
        *gpusCurAddr = FLASH_LOCK_BIT;
        *gpusCurAddr = FLASH_LOCK_CLEAR;
        *gpusCurAddr = FLASH_READ_STATUS;

        //
        // Wait for the Flash block command to succeed.
        //
        bSuccess = WaitForReady(gpusCurAddr, 10000, EXT_STATUS_WBUFFER_READY);
        *gpusCurAddr  = FLASH_CLEAR_STATUS;
        
        if(!bSuccess)
        {
            break;
        }
        //
        // Erase the flash block
        //
        *gpusCurAddr = FLASH_BLOCK_ERASE;
        *gpusCurAddr = FLASH_BLOCK_ERASE_RESUME;
        *gpusCurAddr = FLASH_READ_STATUS;
        
        //
        // Wait for the Flash block command to succeed.
        //
        bSuccess = WaitForReady(gpusCurAddr, 10000, EXT_STATUS_WBUFFER_READY);
        *gpusCurAddr  = FLASH_CLEAR_STATUS;
        
        if(!bSuccess)
        {
            break;
        }
        //
        // Occasionally write out a dot so they don't think
        // the system is dead.
        //
        EdbgOutputDebugString(".");
        
        //
        // Increment to the next block.
        //
        gpusCurAddr+= sBlockInfo[gdwCurEraseRegion].block_size>>1;

		//
		//go to the next bloxk
		//
		gdwCurEraseBlock = gdwCurEraseBlock+1;
		if(gdwCurEraseBlock>=sBlockInfo[gdwCurEraseRegion].blocks)
		{
			gdwCurEraseBlock=0;
			gdwCurEraseRegion=gdwCurEraseRegion+1;
			//
			//return error the current postiotn > the Flash MAX length
			//
			if(gdwCurEraseRegion>gdwNumEraseRegion)
				return FALSE;
		}
	}        
	return bSuccess;
}
//****************************************************************************
// WriteFlashJ3_1x16
//****************************************************************************
//  Writes to J3 Flash.  Different from parameters than  OEMWriteFlash.
//
//  dwDest       -  Address in flash where the start of the downloaded image 
//                  is to be written. Note that if this is not a flash 
//                  block-aligned address, the platform code will need 
//                  to take this into account and handle it as a special
//                  case. 
//
//  dwSource     -  Location of the Flash Cache.
//
//  dwLength     -  Length of the image, in bytes, to be written to flash. 
// 
//
BOOL  WriteFlashC3_1x16(DWORD dwDest, DWORD dwSource, DWORD dwLength)
{
    ULONG               ulCount;
    volatile PUSHORT    pusBlockAddress;
    volatile PUSHORT    pusDest, pusSource;
    BOOL                bSuccess;

    ulCount     = 0;
    pusDest     = (PUSHORT)dwDest;
    pusSource   = (PUSHORT)dwSource;

	//
	//get the current region and block index
	//
   GotEraseFlashSectorIndex(dwDest);
	
    while( ulCount < dwLength)
    {   
		ULONG i;
		ULONG ulCountCmp;
		ulCountCmp = ulCount;

		for(i=0;( i<(sBlockInfo[gdwCurEraseRegion].block_size/2)) && (ulCount < dwLength); i++)
		{
			pusDest[ulCount>>1] = 0x0040;	//#define     FLASH_WRITE_WORD    0x0040

			pusDest[ulCount>>1] = pusSource[ulCount>>1];
			bSuccess = WaitForReady(&pusDest[ulCount>>1], 50000, EXT_STATUS_WBUFFER_READY);
			if( !bSuccess )
			{
				EdbgOutputDebugString("\r\nfail at 0x%x 0x%x\r\n.",
					(ULONG) (&pusDest[ulCount>>1]),
					(ULONG) (&pusSource[ulCount>>1]));
				while (1);
				return bSuccess;
			}
			//if( ulCount % 1023 == 0)
			//	EdbgOutputDebugString("+");
			ulCount += sizeof(USHORT);
		}

		if( bSuccess )
		{
			pusDest[ulCountCmp>>1] = FLASH_READ_MODE;

			for(i=0; (i<(sBlockInfo[gdwCurEraseRegion].block_size/2)) && (ulCountCmp < (int)dwLength); i++)
			//for(i=0; i<4096 && ulCountCmp < dwLength; i++)
			{
				// verify pargramed word
				unsigned short t;
				//pusDest[ulCountCmp>>1] = FLASH_READ_MODE;
				t = pusDest[ulCountCmp>>1];
				if( t != pusSource[ulCountCmp>>1] )
				{
					bSuccess = FALSE;
					EdbgOutputDebugString("\r\nmismatch at 0x%x 0x%x 0x%x != 0x%x  failed\r\n.",
						(ULONG) (&pusDest[ulCountCmp>>1]),
						(ULONG) (&pusSource[ulCountCmp>>1]),
						t,
						pusSource[ulCountCmp>>1] );
					while(1);
					return bSuccess;			
				}		
				//if( ulCountCmp % 1023 == 0)
				//	EdbgOutputDebugString("-");
				ulCountCmp += sizeof(USHORT);
			}
		}
		EdbgOutputDebugString(".");

		//
		//go to the next bloxk
		//
		 gdwCurEraseBlock = gdwCurEraseBlock+1;
		 if(gdwCurEraseBlock>=sBlockInfo[gdwCurEraseRegion].blocks)
		 {
			gdwCurEraseBlock=0;
			gdwCurEraseRegion=gdwCurEraseRegion+1;
			//
			//return error the current postiotn > the Flash MAX length
			//
			if(gdwCurEraseRegion>=gdwNumEraseRegion)
				return FALSE;
		 }
	}   
    pusBlockAddress = (unsigned short*)PHYSICAL_ADDR_FLASH;
     
    *pusBlockAddress =  FLASH_READ_MODE;

    return TRUE;
}


//****************************************************************************
// WaitForReady
//****************************************************************************
// Wait until the flash is ready.
// 
//
static BOOL  WaitForReady
(
    volatile USHORT *pusFlash, 
    ULONG           ulTimeoutInMsec, 
    USHORT          usBitField
)
{
    ULONG       ulStart;
    ULONG       ulCurrent;
    BOOL        bSuccess = FALSE;
   
    ulStart = GetSystemTimeInMsec();
    do
    {
        //
        // See if there are errors.
        //
        if((*pusFlash & usBitField)== usBitField)
        {
            bSuccess = TRUE;
            break;
        }
        
        //
        // Get the current time.
        //
        ulCurrent = GetSystemTimeInMsec();
    } while(ulCurrent<ulStart + ulTimeoutInMsec);

    if(!bSuccess)
    {
        EdbgOutputDebugString("*pusFlash        = %x .\n",(ULONG)*pusFlash);
    }        
    
    return bSuccess;
}

⌨️ 快捷键说明

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