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

📄 intel_p30_1x16.c

📁 Ep93XX TionProV2 BSP
💻 C
📖 第 1 页 / 共 2 页
字号:
			if(gdwCurEraseRegion>=gdwNumEraseRegion)
				return ;
		}
        //
        // Clear the lock bits if the flash block was locked.
        //
        *gpusCurAddr = FLASH_LOCK_BIT;
        *gpusCurAddr = FLASH_LOCK_CLEAR;
        *gpusCurAddr = FLASH_READ_STATUS;

        gbUnlocked  = TRUE;
    }
}

//****************************************************************************
// FinishEraseFlashJ3_1x16
//****************************************************************************
// Finishes the flash eraseing processes for J3 Flash.  See 
// OEMFinishEraseFlash for paramter description.
//
BOOL  FinishEraseFlashP30_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))
    {
//		EdbgOutputDebugString("Erasing %d, size %x-- %x\r\n.",gdwCurEraseBlock
//			,sBlockInfo[gdwCurEraseRegion].block_size, gpusCurAddr);

        //
        // 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. 
//
#define CLEAR_STATUS_CMD        0x0050
#define READ_STATUS_CMD			0x0070 
//
BOOL  WriteFlashP30_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_P30_1X16(dwDest);
	
    while( ulCount < dwLength)
    {   
		ULONG i;
		ULONG ulCountCmp;

		ulCountCmp = ulCount;

//	    pusDest[ulCountCmp>>1] = CLEAR_STATUS_CMD;

//		EdbgOutputDebugString("block size is =%x\r\n",sBlockInfo[gdwCurEraseRegion].block_size);
		for(i=0;( i<(sBlockInfo[gdwCurEraseRegion].block_size/2)) && (ulCount < dwLength); i++)
		{
			pusDest[ulCount>>1] = 0x0040;

			pusDest[ulCount>>1] = pusSource[ulCount>>1];

//			pusDest[ulCountCmp>>1] = READ_STATUS_CMD;

			bSuccess = WaitForReady(&pusDest[ulCount>>1], 50000, EXT_STATUS_WBUFFER_READY);
//			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;
			}
//			pusDest[ulCountCmp>>1] = CLEAR_STATUS_CMD;

			ulCount += sizeof(USHORT);
		}
		pusDest[ulCountCmp>>1] = FLASH_READ_MODE;

		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("WaitForReady error = %x .\n",(ULONG)*pusFlash);
    }        
    
    return bSuccess;
}

⌨️ 快捷键说明

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