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

📄 intel.c

📁 嵌入式系统 EP93xx处理器
💻 C
📖 第 1 页 / 共 3 页
字号:
//****************************************************************************//// INTEL.c - The intel flash function definition.//// Copyright (c) 2006 Cirrus Logic, Inc.////****************************************************************************#include "ep93xx.h"#include "flash.h"#include "intel.h"#include <string.h>#define Intel_compatible_MAX 3static struct sFlashManufactureId sIntel_ManufactureId[Intel_compatible_MAX]={	{0x0089,"'Intel"},	{0x002c,"Micron"},	{0x00b0,"Sharp"}};//****************************************************************************// Name       : IntelFlashQuery// Description: This routine read the flash manufactureid and deviceid.// Return     : 0 - succuss.//              1 - failure.// Note(s)    ://****************************************************************************int IntelFlashQuery(struct FlashInfo *pInfo){    volatile unsigned short *ptr16 = (volatile unsigned short *)pInfo->FlashBase;    volatile unsigned long *ptr32 = (volatile unsigned long *)pInfo->FlashBase;    unsigned short usByteWidth = pInfo->ByteWidth;    int iIdx, iResult;    if (usByteWidth == 1){        // Query 16 bitwidth id.        *ptr16 = CMD_READ_ID_CODES;        pInfo->ManufactureId = *ptr16;        pInfo->DeviceId[0]   = *(ptr16+1);                // Query 16 bitwidth flash.        *ptr16 = CMD_READ_QUERY;        pInfo->pQuery->DeviceSize = 1 << (*(ptr16 + 0x27) & 0xFF);        pInfo->pQuery->NumEraseBlocks = *(ptr16 + 0x2c) & 0xFFFF;        for(iIdx = 0; iIdx < pInfo->pQuery->NumEraseBlocks; iIdx++){            pInfo->pQuery->sBlockInfo[iIdx].blocks =                (*(ptr16 + 0x2d + (iIdx<<2)) & 0xFFFF) + 1;            pInfo->pQuery->sBlockInfo[iIdx].block_size =                (((*(ptr16 + 0x30 + (iIdx<<2)) & 0xFFFF) << 8) +                (*(ptr16 + 0x2f + (iIdx<<2)) & 0xFFFF)) << 8;        }        // Put the FLASH into read array mode.        *ptr16 = CMD_READ_ARRAY;        iResult = 0;    } else if (usByteWidth == 2){        // Query 32 bitwidth id.        *ptr32 = (CMD_READ_ID_CODES << 16) | CMD_READ_ID_CODES;        pInfo->ManufactureId = (unsigned short)(((*ptr32 >> 16) & (*ptr32)) & 0xFFFF);        pInfo->DeviceId[0]   = (unsigned short)(*(ptr32+1));                // Query 32 bitwidth flash.        *ptr32 = (CMD_READ_QUERY << 16) | CMD_READ_QUERY;        pInfo->pQuery->DeviceSize = 1 << (*(ptr32 + 0x27) & 0xFF);        pInfo->pQuery->DeviceSize = pInfo->pQuery->DeviceSize *2;                pInfo->pQuery->NumEraseBlocks = *(ptr32 + 0x2c) & 0xFFFF;        for(iIdx = 0; iIdx < pInfo->pQuery->NumEraseBlocks; iIdx++){            pInfo->pQuery->sBlockInfo[iIdx].blocks =                (*(ptr32 + 0x2d + (iIdx<<2)) & 0xFFFF) + 1;            pInfo->pQuery->sBlockInfo[iIdx].block_size =                (((*(ptr32 + 0x30 + (iIdx<<2)) & 0xFFFF) << 8) +                (*(ptr32 + 0x2f + (iIdx<<2)) & 0xFFFF)) << 8;        }        // Put the FLASH into read array mode.        *ptr32 = (CMD_READ_ARRAY << 16) | CMD_READ_ARRAY;        iResult = 0;    } else{        // No such parameter.        iResult = 1;    }    //if(pInfo->ManufactureId == 0x0089) return 0;    //else return 1;    for(iIdx=0;iIdx<Intel_compatible_MAX;iIdx++)    {    	if(pInfo->ManufactureId == sIntel_ManufactureId[iIdx].manufacture_id)     	{    	    return 0;    	}    }    return 1;}//****************************************************************************// Name       : IntelFlashWaitUntilForProgram// Description: IntelFlashWaitForProgram waits until bit 7 & 23 becomes one,//              indicating that the embedded program (be it a chip erase,//              sector erase, or data store program) has completed executing.// Arguments  : iOffset - the offset address.// Return     : 0 - succuss.//              1 - failure.// Note(s)    ://****************************************************************************int IntelFlashWaitUntilForProgram(struct FlashInfo *pInfo, int timeout){    volatile unsigned short *ptr16 = (volatile unsigned short *)pInfo->FlashBase;    volatile unsigned long *ptr32 = (volatile unsigned long *)pInfo->FlashBase;    unsigned short usByteWidth = pInfo->ByteWidth;    int iResult = 0;    if (usByteWidth == 1){        unsigned short usTemp;        // Send the Read status register command        *ptr16 = CMD_READ_STATUS_REGISTER;        // Read from the FLASH memory until bit 7 & 23 are one.        while(1)        {            // Read the status register from the FLASH memory.            usTemp = *ptr16;            // Mask off all bits except for bit 7 & 23.            usTemp &= CMD_STATUS_READY;            // If bit 7 & 23 are one, then quit waiting.            if(usTemp == CMD_STATUS_READY) break;        }        // Clear the status register.        *ptr16 = CMD_CLEAR_STATUS_REGISTER;        iResult=0;    } else if (usByteWidth == 2){        unsigned long ulTemp;        // Send the Read status register command        *ptr32 = (CMD_READ_STATUS_REGISTER << 16) | CMD_READ_STATUS_REGISTER;        // Read from the FLASH memory until bit 7 & 23 are one.        while(1)        {            // Read the status register from the FLASH memory.            ulTemp = *ptr32;            // Mask off all bits except for bit 7 & 23.            ulTemp &= (CMD_STATUS_READY << 16) | CMD_STATUS_READY;            // If bit 7 & 23 are one, then quit waiting.            if(ulTemp == ((CMD_STATUS_READY << 16) | CMD_STATUS_READY)) break;        }        // Clear the status register.        *ptr32 = (CMD_CLEAR_STATUS_REGISTER << 16) | CMD_CLEAR_STATUS_REGISTER;        iResult=0;    } else{        // No such parameter.        return 1;    }    return iResult;}//****************************************************************************// Name       : IntelFlashClearLockBits// Description: This routine erase the specified sector of intel.// Arguments  : iOffset - the offset address.// Return     : 0 - succuss.//              1 - failure.// Note(s)    ://****************************************************************************int IntelFlashClearLockBits(struct FlashInfo *pInfo, int iSector){    volatile unsigned short *ptr16 = (volatile unsigned short *)pInfo->FlashBase;    volatile unsigned long *ptr32 = (volatile unsigned long *)pInfo->FlashBase;    unsigned short usByteWidth = pInfo->ByteWidth;    int iResult = 0;            if (usByteWidth == 1){        // Put the FLASH into read array mode.        *(ptr16 + (iSector >> 1)) = CMD_READ_ARRAY;        // Clear the Block lock bit before attempting to erase        // Or program C3 or J3 FLASH devices.        *(ptr16 + (iSector >> 1)) = CMD_CONFIG_SETUP;        *(ptr16 + (iSector >> 1)) = CMD_CONFIRM;        // Wait until the Clear Block lock bit command has completed.        IntelFlashWaitUntilForProgram(pInfo, 0);        // Put the FLASH into read array mode.        *(ptr16 + (iSector >> 1)) = CMD_READ_ARRAY;        iResult = 0;    } else if (usByteWidth == 2){        // Put the FLASH into read array mode.        *(ptr32 + (iSector >> 2)) = (CMD_READ_ARRAY << 16) | CMD_READ_ARRAY;        // Clear the Block lock bit before attempting to erase        // Or program C3 or J3 FLASH devices.        *(ptr32 + (iSector >> 2)) = (CMD_CONFIG_SETUP << 16) | CMD_CONFIG_SETUP;        *(ptr32 + (iSector >> 2)) = (CMD_CONFIRM << 16) | CMD_CONFIRM;        // Wait until the Clear Block lock bit command has completed.        IntelFlashWaitUntilForProgram(pInfo, 0);        // Put the FLASH into read array mode.        *(ptr32 + (iSector >> 2)) = (CMD_READ_ARRAY << 16) | CMD_READ_ARRAY;        iResult = 0;            } else{        // No such parameter.        return 1;    }    return iResult;}//****************************************************************************// Name       : IntelFlashEraseSector// Description: This routine erase the specified sector of intel.// Arguments  : iOffset - the offset address.//              len  - the length.// Return     : 0 - succuss.//              1 - failure.// Note(s)    ://****************************************************************************int IntelFlashEraseSector(struct FlashInfo *pInfo, int iSector){    volatile unsigned short *ptr16 = (volatile unsigned short *)pInfo->FlashBase;    volatile unsigned long *ptr32 = (volatile unsigned long *)pInfo->FlashBase;    unsigned short usByteWidth = pInfo->ByteWidth;    int iResult = 0;    IntelFlashClearLockBits(pInfo, iSector);    if (usByteWidth == 1){        // Write the erase command to the FLASH memory.        *(ptr16 + (iSector >> 1)) = CMD_BLOCK_ERASE;        *(ptr16 + (iSector >> 1)) = CMD_CONFIRM;        // Wait until the sector erase has completed.        IntelFlashWaitUntilForProgram(pInfo, 0);        // Put the FLASH into read array mode.        *ptr16 = CMD_READ_ARRAY;        iResult = 0;            } else if (usByteWidth == 2){        // Write the erase command to the FLASH memory.        *(ptr32 + (iSector >> 2)) = (CMD_BLOCK_ERASE << 16) | CMD_BLOCK_ERASE;        *(ptr32 + (iSector >> 2)) = (CMD_CONFIRM << 16) | CMD_CONFIRM;        // Wait until the sector erase has completed.        IntelFlashWaitUntilForProgram(pInfo, 0);        // Put the FLASH into read array mode.        *ptr32 = (CMD_READ_ARRAY << 16) | CMD_READ_ARRAY;        iResult = 0;    } else{        // No such parameter.        return 1;    }    return iResult;}//****************************************************************************// Name       : GetSectorIndex// Description: This routine erase the sectors of intel.// Arguments  : iOffset - the offset address.//              len  - the length.// Return     : 0 - succuss.//              1 - failure.// Note(s)    ://****************************************************************************int GetSectorIndex(struct FlashInfo *pInfo,int lStartAddress,			unsigned long * pulSectorBase,int * piCurEraseRegion,			int * piCurEraseBlock ){    unsigned short usByteWidth = pInfo->ByteWidth;    int i, j;    int iEraseBase = lStartAddress;        *pulSectorBase = 0;    if(lStartAddress==0)    {        *piCurEraseRegion = 0;        *piCurEraseBlock  = 0;      	return 0;    }        if (usByteWidth == 1)    {        for(i = 0; i < pInfo->pQuery->NumEraseBlocks; i++)         {                 for(j = 0; j< pInfo->pQuery->sBlockInfo[i].blocks; j++)             {				                                if(iEraseBase >= pInfo->pQuery->sBlockInfo[i].block_size)                 {                    *pulSectorBase = *pulSectorBase + pInfo->pQuery->sBlockInfo[i].block_size;                    iEraseBase = iEraseBase - pInfo->pQuery->sBlockInfo[i].block_size;                }                 else                 {                    *piCurEraseRegion = i;                    *piCurEraseBlock  = j;                      return 0;                }            }

⌨️ 快捷键说明

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