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

📄 mvflash.c

📁 Mavell AP32 无线模块驱动。VxWorks BSP BootRom源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
                    (FLASH_WIDTH == 8) ) /* 32 or 64 bit */                {                    MV_READ_SHORT(FLASH_BASE_ADDR + 0x1*FLASH_WIDTH,&devId);                }            }            break;    }    /* Try to locate the device in the supported flashes list (FLASE_TYPE).        according to the keys:        1) mfrId - manufactor ID.       2) devId - device ID.     */    while(true)    {        if (mvFlashTypes[pArray] == 0)        {            mvFlashReset();            printf ("Flash not supported: manu=0x%x, dev=0x%x\n", mfrId, devId);            return 0;  /* Device not in the list */        }        if( (mvFlashTypes[pArray] == mfrId) &&              (mvFlashTypes[pArray+1] == devId))        {            FLASH_POINTER_TO_FLASH = pArray;            for(counter = 0 ; counter < mvFlashTypes[FLASH_NUMBER_OF_SECTORS] ;                 counter++)            {                flashSize = flashSize +                     mvFlashTypes[FLASH_FIRST_SECTOR_SIZE + counter];            }            if( FLASH_MODE != PURE8 )            {                mvFlashReset();                printf ("Flash found: manu=0x%x, dev=0x%x, siz=%u\n", mfrId, devId, flashSize);                return (flashSize * _1K * (FLASH_WIDTH / (FLASH_MODE / 8)) );            }            else            {                mvFlashReset();                printf ("Flash found: manu=0x%x, dev=0x%x, siz=%u\n", mfrId, devId, flashSize);                return (flashSize * _1K * FLASH_WIDTH);            }        }        pArray += (3 + mvFlashTypes[pArray+2]); /* Move to next entry */    }}/******************************************************************************** mvFlashEraseSector - Erases a specific sector in the flash memory.** DESCRIPTION:*       None.** INPUT:*       sectorNumber - the sector number to be erased.** OUTPUT:*       None.** RETURN:*       true on success,false on failure.********************************************************************************/bool mvFlashEraseSector(unsigned int sectorNumber){     unsigned int    regValue;    unsigned int    sectorBaseAddress = 0;    unsigned int    i;    unsigned int    data20,dataD0,data70;    unsigned int    dataPoll;    unsigned int    FirstAddr,SecondAddr,ThirdAddr,FourthAddr,FifthAddr;    unsigned int    FirstData,SecondData,ThirdData;    unsigned int    FourthData,FifthData,SixthData;    /* calculate the sector base Address according to the following parametrs:       1: FLASH_WIDTH       2: the size of each sector which it detailed in the table */        /* checking the if the sectorNumber is legal.*/    if ( sectorNumber > mvFlashTypes[FLASH_NUMBER_OF_SECTORS] - 1)         return false;    /* now the calculation begining of the sector Address */    for (i=0 ; i < sectorNumber ; i++)    {        sectorBaseAddress=sectorBaseAddress +             mvFlashTypes[FLASH_FIRST_SECTOR_SIZE+i];        }    /* In case of X8 wide the address should be */    if( FLASH_MODE == PURE8 )        sectorBaseAddress = _1K * sectorBaseAddress;    if( FLASH_MODE == X8 )        sectorBaseAddress = _1K * sectorBaseAddress;    /* In case of X16 wide the address should be */    if( FLASH_MODE == X16 )        sectorBaseAddress = _1K * sectorBaseAddress / 2;      mvFlashReset();  	if ( (mvFlashTypes[FLASH_POINTER_TO_FLASH] == AMD_FLASH) ||   \         (mvFlashTypes[FLASH_POINTER_TO_FLASH] == ST_FLASH) || \         (mvFlashTypes[FLASH_POINTER_TO_FLASH] == SST_FLASH) ||          (mvFlashTypes[FLASH_POINTER_TO_FLASH] == MXIC_FLASH) )    {        switch(FLASH_WIDTH)        {            case 1:                if( FLASH_MODE == PURE8) /* Boot Flash PURE8*/                {                    FirstAddr  = 0x5555;                    SecondAddr = 0x2aaa;                    ThirdAddr  = 0x5555;                    FourthAddr = 0x5555;                     FifthAddr  = 0x2aaa;                }                else                {                    FirstAddr  = 0xaaaa;                    SecondAddr = 0x5555;                    ThirdAddr  = 0xaaaa;                    FourthAddr = 0xaaaa;                     FifthAddr  = 0x5555;                }                MV_WRITE_CHAR(FLASH_BASE_ADDR + FirstAddr,0xAA);                MV_WRITE_CHAR(FLASH_BASE_ADDR + SecondAddr,0x55);                MV_WRITE_CHAR(FLASH_BASE_ADDR + ThirdAddr,0x80);                MV_WRITE_CHAR(FLASH_BASE_ADDR + FourthAddr,0xAA);                MV_WRITE_CHAR(FLASH_BASE_ADDR + FifthAddr,0x55);                MV_WRITE_CHAR((FLASH_BASE_ADDR + (sectorBaseAddress &                                                   0xffffff00)),0x30);                /* Poll on the flash */                do{                    MV_READ_CHAR(FLASH_BASE_ADDR + sectorBaseAddress,                                 &regValue);                 } while((regValue & 0x80) != 0x80);                break;            case 2:                if (FLASH_MODE == X16)                {                    FirstData  = 0xaa;      /* Data for the First  Cycle    */                    SecondData = 0x55;      /* Data for the Second Cycle    */                    ThirdData  = 0x80;      /* Data for the Third  Cycle    */                    FourthData = 0xaa;      /* Data for the Fourth Cycle    */                    FifthData  = 0x55;      /* Data for the Fifth  Cycle    */                    if (mvFlashTypes[FLASH_POINTER_TO_FLASH] == SST_FLASH)                        SixthData  = 0x50;      /* Data for the Sixth  Cycle    */                    else                        SixthData  = 0x30;      /* Data for the Sixth  Cycle    */                    FirstAddr  = 0x5555;    /* Address for the First  Cycle */                    SecondAddr = 0x2aaa;    /* Address for the Second Cycle */                    ThirdAddr  = 0x5555;    /* Address for the Third  Cycle */                    FourthAddr = 0x5555;    /* Address for the Fourth Cycle */                    FifthAddr  = 0x2aaa;    /* Address for the Fifth  Cycle */                }                else /* (FLASH_MODE = 8) */                {                    FirstData  = 0xaaaa;     /* Data for the First  Cycle    */                    SecondData = 0x5555;     /* Data for the Second Cycle    */                    ThirdData  = 0x8080;     /* Data for the Third  Cycle    */                    FourthData = 0xaaaa;     /* Data for the Fourth Cycle    */                    FifthData  = 0x5555;     /* Data for the Fifth  Cycle    */                    SixthData  = 0x3030;     /* Data for the Sixth  Cycle    */                    FirstAddr  = 0xaaaa;     /* Address for the First  Cycle */                    SecondAddr = 0x5555;     /* Address for the Second Cycle */                    ThirdAddr  = 0xaaaa;     /* Address for the Third  Cycle */                    FourthAddr = 0xaaaa;     /* Address for the Fourth Cycle */                    FifthAddr  = 0x5555;     /* Address for the Fifth  Cycle */                }                MV_WRITE_SHORT(FLASH_BASE_ADDR + FirstAddr * FLASH_WIDTH,                            FirstData);                MV_WRITE_SHORT(FLASH_BASE_ADDR + SecondAddr * FLASH_WIDTH,                            SecondData);                MV_WRITE_SHORT(FLASH_BASE_ADDR + ThirdAddr * FLASH_WIDTH,                            ThirdData);                MV_WRITE_SHORT(FLASH_BASE_ADDR + FourthAddr * FLASH_WIDTH,                            FourthData);                MV_WRITE_SHORT(FLASH_BASE_ADDR + FifthAddr * FLASH_WIDTH,                            FifthData);                MV_WRITE_SHORT(FLASH_BASE_ADDR +                       (sectorBaseAddress & 0xffffff00)* FLASH_WIDTH,SixthData);                /* Poll on the flash */                if (FLASH_MODE == X16) /* 1 device of 16 bit */                {                    dataPoll = 0x0080;                }                else /* (FLASH_MODE = 8) ==> 2 devices , 8 bit each => 16bit*/                {                    dataPoll = 0x8080;                }                do{                    MV_READ_SHORT(FLASH_BASE_ADDR+sectorBaseAddress *                                   FLASH_WIDTH,&regValue);                 } while((regValue & dataPoll) != dataPoll);                break;            case 4:                if (FLASH_MODE == X16)                {                    FirstData  = 0x00aa00aa; /* Data for the First  Cycle    */                    SecondData = 0x00550055; /* Data for the Second Cycle    */                    ThirdData  = 0x00800080; /* Data for the Third  Cycle    */                    FourthData = 0x00aa00aa; /* Data for the Fourth Cycle    */                    FifthData  = 0x00550055; /* Data for the Fifth  Cycle    */                    SixthData  = 0x00300030; /* Data for the Sixth  Cycle    */                    FirstAddr  = 0x5555;     /* Address for the First  Cycle */                    SecondAddr = 0x2aaa;     /* Address for the Second Cycle */                    ThirdAddr  = 0x5555;     /* Address for the Third  Cycle */                    FourthAddr = 0x5555;     /* Address for the Fourth Cycle */                    FifthAddr  = 0x2aaa;     /* Address for the Fifth  Cycle */                }                else /* if (FLASH_MODE == 8) */                {                    FirstData  = 0xaaaaaaaa; /* Data for the First  Cycle    */                    SecondData = 0x55555555; /* Data for the Second Cycle    */                    ThirdData  = 0x80808080; /* Data for the Third  Cycle    */                    FourthData = 0xAAAAAAAA; /* Data for the Fourth Cycle    */                    FifthData  = 0x55555555; /* Data for the Fifth  Cycle    */                    SixthData  = 0x30303030; /* Data for the Sixth  Cycle    */                    FirstAddr  = 0xaaaa;     /* Address for the First  Cycle */                    SecondAddr = 0x5555;     /* Address for the Second Cycle */                    ThirdAddr  = 0xaaaa;     /* Address for the Third  Cycle */                    FourthAddr = 0xaaaa;     /* Address for the Fourth Cycle */                    FifthAddr  = 0x5555;     /* Address for the Fifth  Cycle */                }                MV_WRITE_WORD(FLASH_BASE_ADDR + FirstAddr * FLASH_WIDTH,                           FirstData);                MV_WRITE_WORD(FLASH_BASE_ADDR + SecondAddr * FLASH_WIDTH,                           SecondData);                MV_WRITE_WORD(FLASH_BASE_ADDR + ThirdAddr * FLASH_WIDTH,                           ThirdData);                MV_WRITE_WORD(FLASH_BASE_ADDR + FourthAddr * FLASH_WIDTH,                           FourthData);                MV_WRITE_WORD(FLASH_BASE_ADDR + FifthAddr * FLASH_WIDTH,                           FifthData);                MV_WRITE_WORD(FLASH_BASE_ADDR +                            (sectorBaseAddress & 0xffffff00) * FLASH_WIDTH,                           SixthData);                /* Poll on the flash */                if (FLASH_MODE == X16) /* 4 devices , 16 bit each => 64bit */                {                    dataPoll = 0x00800080;                }                else /* (FLASH_MODE = 8) ==> 8 devices , 8 bit each => 64bit*/                {                    dataPoll = 0x80808080;                }                do{                    MV_READ_WORD(FLASH_BASE_ADDR+sectorBaseAddress *                               FLASH_WIDTH,&regValue);                } while((regValue & dataPoll) != dataPoll);                break;            case 8: /* In case of 64bit width the transformation is 1->8 */                if (FLASH_MODE == X16)                {                    FirstData  = 0x00aa00aa; /* Data for the First  Cycle    */                    SecondData = 0x00550055; /* Data for the Second Cycle    */                    ThirdData  = 0x00800080; /* Data for the Third  Cycle    */                    FourthData = 0x00aa00aa; /* Data for the Fourth Cycle    */                    FifthData  = 0x00550055; /* Data for the Fifth  Cycle    */                    SixthData  = 0x00300030; /* Data for the Sixth  Cycle    */                    FirstAddr  = 0x5555;     /* Address for the First  Cycle */                    SecondAddr = 0x2aaa;     /* Address for the Second Cycle */                    ThirdAddr  = 0x5555;     /* Address for the Third  Cycle */                    FourthAddr = 0x5555;     /* Address for the Fourth Cycle */                    FifthAddr  = 0x2aaa;     /* Address for the Fifth  Cycle */                }                else /* (FLASH_MODE = 8 */                {                    FirstData  = 0xaaaaaaaa; /* Data for the First  Cycle    */                    SecondData = 0x55555555; /* Data for the Second Cycle    */                    ThirdData  = 0x80808080; /* Data for the Third  Cycle    */                    FourthData = 0xAAAAAAAA; /* Data for the Fourth Cycle    */                    FifthData  = 0x55555555; /* Data for the Fifth  Cycle    */                    SixthData  = 0x30303030; /* Data for the Sixth  Cycle    */                    FirstAddr  = 0xaaaa;     /* Address for the First  Cycle */                    SecondAddr = 0x5555;     /* Address for the Second Cycle */                    ThirdAddr  = 0xaaaa;     /* Address for the Third  Cycle */

⌨️ 快捷键说明

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