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

📄 intel.c

📁 EP9315的wince下载程序。download.exe
💻 C
📖 第 1 页 / 共 3 页
字号:
                {
                    IntelFlashEraseSector(pInfo,iEraseBase);
                    
                    //
                    //for(iIdx = 0; iIdx < (pInfo->pQuery->sBlockInfo[i].block_size>>1); iIdx++)
            	    //{
            	    //	if(*(ptr16 + (iEraseBase >> 1) + iIdx) != 0xffff)
            	    //	{
               	    //		return 1;;
              	    //}
 
   	    	    //}
                    return 0;
                }

            }
        }
    } 
    else if (usByteWidth == 2)
    {
        for(i = 0; i < pInfo->pQuery->NumEraseBlocks; i++) {
            for(j = 0; j< pInfo->pQuery->sBlockInfo[i].blocks; j++) {

                if(iEraseLen > pInfo->pQuery->sBlockInfo[i].block_size*2) {
                    iEraseLen = iEraseLen - (pInfo->pQuery->sBlockInfo[i].block_size *2);
                    IntelFlashEraseSector(pInfo,iEraseBase);
                    iEraseBase=iEraseBase + (pInfo->pQuery->sBlockInfo[i].block_size *2);
                } else {
                    IntelFlashEraseSector(pInfo,iEraseBase);
                    return 0;
                }

            }
        }
    } else{
        // No such parameter.
        return 1;
    }

    return 1;
}
*/
//****************************************************************************
// Name       : IntelFlashEraseChip
// Description: This routine erase the flash chip.
// Arguments  : 
// Return     : 0 - succuss.
//              1 - failure.
// Note(s)    :
//****************************************************************************
int IntelFlashEraseChip(struct FlashInfo *pInfo)
{
    if(!(IntelFlashErase(pInfo, 0, pInfo->pQuery->DeviceSize))) return 1;
    else return 0;
}

//****************************************************************************
// Name       : IntelFlashProgramSector
// Description: This routine program the specified sector of amd.
// Arguments  : iOffset - the offset address.
//              len  - the length.
// Return     : 0 - succuss.
//              1 - failure.
// Note(s)    :
//****************************************************************************
int IntelFlashProgramSector(struct FlashInfo *pInfo, int iOffset, void *data, int len)
{
    volatile unsigned short *ptr16 = (volatile unsigned short *)pInfo->FlashBase;
    volatile unsigned long *ptr32 = (volatile unsigned long *)pInfo->FlashBase;
    unsigned short *pusData16 =(unsigned short *)data;
    unsigned long *pulData32 =(unsigned long *)data;
	
	unsigned short usByteWidth = pInfo->ByteWidth;
	int iIdx;
	int iResult = 0;

	if (usByteWidth == 1){
	    for(iIdx = 0; iIdx < (len>>1); iIdx++){
            // Write the program word command.
            *(ptr16+(iOffset >> 1))= CMD_PROGRAM_SETUP;
            // Write one 16bit width word.
            *(ptr16 + (iOffset >> 1) + iIdx) = *(pusData16 + iIdx);

            // Wait until the data word has been programmed.
            IntelFlashWaitUntilForProgram(pInfo, 0); 
            }
            // Put the FLASH into read array mode.
            *ptr16= CMD_READ_ARRAY; 
        
            //Read-back verification after writing data to flash
            for(iIdx = 0; iIdx < (len>>1); iIdx++)
            {
            	if(*(ptr16 + (iOffset >> 1) + iIdx) != *(pusData16 + iIdx))
            	{
               	    iResult = 1;
               	    break;
            	}
            	else
            	{
	           iResult = 0;
	        }
	    }
        
            
	} else if (usByteWidth == 2){
	    for(iIdx = 0; iIdx < (len>>2); iIdx++){
             // Write the program word command.
            *(ptr32+(iOffset >> 2))= (CMD_PROGRAM_SETUP << 16) | CMD_PROGRAM_SETUP;
            // Write one 32bit width word.
            *(ptr32 + (iOffset >> 2) + iIdx) = *(pulData32 + iIdx);

            // Wait until the data word has been programmed.
            IntelFlashWaitUntilForProgram(pInfo, 0); 
            }
            // Put the FLASH into read array mode.
            *ptr32= (CMD_READ_ARRAY << 16) | CMD_READ_ARRAY; 
        
            //Read-back verification after writing data to flash
            for(iIdx = 0; iIdx < (len>>2); iIdx++)
            {
            	if(*(pulData32+iIdx)!=*(ptr32+(iOffset >> 2)+iIdx))
            	{
               	    iResult = 1;
               	    break;
            	}
            	else
            	{
	           iResult = 0;
	        }
	    }
                 
	} else{
	    // No such parameter.
            return 1;
        }
    		
	return iResult;
}

//****************************************************************************
// Name       : IntelFlashProgramSector
// Description: This routine program the specified sector of amd.
// Arguments  : iOffset - the offset address.
//              len  - the length.
// Return     : 0 - succuss.
//              1 - failure.
// Note(s)    :
//****************************************************************************
int IntelFlashProgram(struct FlashInfo *pInfo, int iOffset, void *data, int len)
{
    volatile unsigned short *ptr16 = (volatile unsigned short *)pInfo->FlashBase;
    volatile unsigned long *ptr32 = (volatile unsigned long *)pInfo->FlashBase;
    unsigned short *pusData16 =(unsigned short *)data;
    unsigned long *pulData32 =(unsigned long *)data;
	
	unsigned short usByteWidth = pInfo->ByteWidth;
	int iIdx=0;
	int iResult = 0;
    	
	if (usByteWidth == 1){
	    for(iIdx = 0; iIdx < (len>>1); iIdx++){
            // Write the program word command.
            *(ptr16+(iOffset >> 1))= CMD_PROGRAM_SETUP;
            // Write one 16bit width word.
            *(ptr16 + (iOffset >> 1) + iIdx) = *(pusData16 + iIdx);

            // Wait until the data word has been programmed.
            IntelFlashWaitUntilForProgram(pInfo, 0); 
            }
            // Put the FLASH into read array mode.
            *ptr16= CMD_READ_ARRAY; 
            
            
            //Read-back verification after writing data to flash
            for(iIdx = 0; iIdx < (len>>1); iIdx++)
            {
            	if(*(ptr16 + (iOffset >> 1) + iIdx) != *(pusData16 + iIdx))
            	{
               	    iResult = 1;
               	    break;
            	}
            	else
            	{
	           iResult = 0;
	        }
	    }
        
            
	} else if (usByteWidth == 2){
	    for(iIdx = 0; iIdx < (len>>2); iIdx++){
             // Write the program word command.
            *(ptr32+(iOffset >> 2))= (CMD_PROGRAM_SETUP << 16) | CMD_PROGRAM_SETUP;
            // Write one 32bit width word.
            *(ptr32 + (iOffset >> 2) + iIdx) = *(pulData32 + iIdx);

            // Wait until the data word has been programmed.
            IntelFlashWaitUntilForProgram(pInfo, 0); 
            }
            // Put the FLASH into read array mode.
            *ptr32= (CMD_READ_ARRAY << 16) | CMD_READ_ARRAY; 
        
            //Read-back verification after writing data to flash
            for(iIdx = 0; iIdx < (len>>2); iIdx++)
            {
            	if(*(pulData32+iIdx)!=*(ptr32+(iOffset >> 2)+iIdx))
            	{
               	    iResult = 1;
               	    break;
            	}
            	else
            	{
	           iResult = 0;
	        }
	    }
                 
	} else{
	    // No such parameter.
            return 1;
        }
    		
	return iResult;
}


//****************************************************************************
// Name       : IntelFlashProgram
// Description: This routine program the intel flash.
// Arguments  : iOffset - the offset address.
//              data - the data pointer.
//              len  - the length.
// Return     : 0 - succuss.
//              1 - failure.
// Note(s)    :
//****************************************************************************
int IntelFlashProgram_old(struct FlashInfo *pInfo, int iOffset, void *data, int len)
{
    unsigned short usByteWidth = pInfo->ByteWidth;
	int i, j;
    int iProgramLen = len;
	int iProgramBase = 0;

	if (usByteWidth == 1){
            for(i = 0; i < pInfo->pQuery->NumEraseBlocks; i++) {
                for(j = 0; j< pInfo->pQuery->sBlockInfo[i].blocks; j++) {
                
                    if(iProgramLen > pInfo->pQuery->sBlockInfo[i].block_size) {
                	
                        iProgramLen = iProgramLen - pInfo->pQuery->sBlockInfo[i].block_size;
                    
                        if(1==IntelFlashProgramSector(pInfo, iOffset,
                        			(void *)((unsigned char *)data + iProgramBase),
                        			pInfo->pQuery->sBlockInfo[i].block_size)){
                    	    //program fail
                    	    return 1;
                        }
                        // program success
                        iProgramBase=iProgramBase + pInfo->pQuery->sBlockInfo[i].block_size;
                    
                    } 
                    else {
                	
                        if(1==IntelFlashProgramSector(pInfo, iOffset,
                        			(void *)((unsigned char *)data + iProgramBase),
                        			iProgramLen)){
                            //program fail
                    	    return 1;    	
                        }
			//program sucess
			return 0;
		    }
		
		}
	    }
	} 
	else if (usByteWidth == 2)
	{
            for(i = 0; i < pInfo->pQuery->NumEraseBlocks; i++) 
            {
                for(j = 0; j< pInfo->pQuery->sBlockInfo[i].blocks; j++) 
                {
                
                    if(iProgramLen > pInfo->pQuery->sBlockInfo[i].block_size*2) 
                    {
                        iProgramLen = iProgramLen - (pInfo->pQuery->sBlockInfo[i].block_size *2);
                        
                        if(1==IntelFlashProgramSector(pInfo, iOffset,
                        		(void *)((unsigned char *)data + iProgramBase),
                        		pInfo->pQuery->sBlockInfo[i].block_size))
                        {
                            //program fail	
                            return 1;                        
                        }                     
                        //program sucess
                        iProgramBase=iProgramBase + (pInfo->pQuery->sBlockInfo[i].block_size *2);
                    } 
                    else 
                    {
                        if(1==IntelFlashProgramSector(pInfo, iOffset,
                        		(void *)((unsigned char *)data + iProgramBase),
                        		iProgramLen))
                        {
                            //program fail
                            return 1;
                        }
                        //program sucess
			return 0;
		    }
		
 	        }
	    }  
	} 
	else{
	    // No such parameter.
            return 1;
        }
    
        return 1;
}

//****************************************************************************
// End
//****************************************************************************

⌨️ 快捷键说明

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