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

📄 flashutil.c

📁 vxworks的BSP开发配置文件
💻 C
📖 第 1 页 / 共 2 页
字号:
            for (i = 0; (i < size) && (retVal == OK); i+=4)                {                if (pFB != NULL)                    valtmp = *pFB++;                else                    valtmp = value;                for (pass = 0; pass < 2-flash32BitMode; pass++) {                    *pFW = FLASH28CMD_PROG_SETUP;           /* write setup */                    *pFW = valtmp;                    pFW++;                    valtmp >>= 16;                    /* wait for completion */                    for (ix = (FLASH_WIDTH/2)-1; ix >= 0; ix--)                         {                            for (;;)                                {                                    status = (*pFR) >> (ix * 16);                                    if (status & BIT(7))                                        break;                                }                            if (status & (BIT(5) | BIT(4) | BIT(3) | BIT(1)))                                {                                    retVal = ERROR;                                    break;                                }                        } /* end for ix */                    } /* end for pass */                } /* end for i */                        *--pFW = FLASH28CMD_RESET;                  /* read array */                        SYS_FLASH_WRITE_DISABLE_RTN ();             /* disable enable */            break;            }        default:            retVal = ERROR;        }     return (retVal);    }/******************************************************************************** flashNextBlock - Advance a pointer to the next flash block** This routine advances a pointer to the start of the next flash block* for a multi-block device.* * RETURNS: OK, or ERROR if the device type is unknown*/STATUS flashNextBlock    (    UINT32 *flash_offset      /* Offset into flash memory */    )    {    STATUS retVal = OK;    UINT32 blockSize;    UINT32 flashSize;    if (flashType == FTYPE_NONE)        flashType = flashTypeGet(*flash_offset);    switch (flashType)        {        case (FTYPE_28F800B):#ifdef INCLUDE_EXTRA        case (FTYPE_28F800T):#endif            flashSize = 1024*1024;            break;#ifdef INCLUDE_EXTRA        case (FTYPE_28F160B):        case (FTYPE_28F160T):            flashSize = 2 * 1024*1024;            break;        case (FTYPE_28F320T):        case (FTYPE_28F320C3T):#endif        case (FTYPE_28F320B):        case (FTYPE_28F320C3B):            flashSize = 4 * 1024*1024;            break;        default:            return ERROR;        }    if (flash32BitMode)        flashSize *= 2;    switch (flashType)        {        case (FTYPE_28F800B):#ifdef INCLUDE_EXTRA        case (FTYPE_28F160B):#endif        case (FTYPE_28F320B):        case (FTYPE_28F320C3B):            if (flash32BitMode) {                blockSize = 0x8000 * FLASH_WIDTH; /* Large block size */                if ((((*flash_offset) & (flashSize-1)) / (0x8000 * FLASH_WIDTH))                    == 0)                    blockSize /= 8;            } else {                blockSize = 0x4000 * FLASH_WIDTH; /* Large block size */                if ((((*flash_offset) & (flashSize-1)) / (0x4000 * FLASH_WIDTH))                    == 0)                    blockSize /= 8;            }            *flash_offset = (*flash_offset + blockSize) & ~(blockSize-1);            break;#ifdef INCLUDE_EXTRA        case (FTYPE_28F800T):            if (flash32BitMode) {                blockSize = 0x8000 * FLASH_WIDTH; /* Large block size */                if ((((*flash_offset) & (flashSize-1)) / (0x8000 * FLASH_WIDTH))                    == 15)                    blockSize /= 8;            } else {                blockSize = 0x4000 * FLASH_WIDTH; /* Large block size */                if ((((*flash_offset) & (flashSize-1)) / (0x4000 * FLASH_WIDTH))                    == 15)                    blockSize /= 8;            }            *flash_offset = (*flash_offset + blockSize) & ~(blockSize-1);            break;        case (FTYPE_28F160T):            if (flash32BitMode) {                blockSize = 0x8000 * FLASH_WIDTH; /* Large block size */                if ((((*flash_offset) & (flashSize-1)) / (0x8000 * FLASH_WIDTH))                    == 31)                    blockSize /= 8;            } else {                blockSize = 0x4000 * FLASH_WIDTH; /* Large block size */                if ((((*flash_offset) & (flashSize-1)) / (0x4000 * FLASH_WIDTH))                    == 31)                    blockSize /= 8;            }            *flash_offset = (*flash_offset + blockSize) & ~(blockSize-1);            break;        case (FTYPE_28F320T):        case (FTYPE_28F320C3T):            if (flash32BitMode) {                blockSize = 0x8000 * FLASH_WIDTH; /* Large block size */                if ((((*flash_offset) & (flashSize-1)) / (0x8000 * FLASH_WIDTH))                    == 63)                    blockSize /= 8;            } else {                blockSize = 0x4000 * FLASH_WIDTH; /* Large block size */                if ((((*flash_offset) & (flashSize-1)) / (0x4000 * FLASH_WIDTH))                    == 63)                    blockSize /= 8;            }            *flash_offset = (*flash_offset + blockSize) & ~(blockSize-1);            break;#endif        default:            retVal = ERROR;        }    return (retVal);    }#ifdef FLASH_SIZE/******************************************************************************** sysFlashGet - get the contents of flash memory** This routine copies the contents of flash memory into a specified* string.  The string is terminated with an EOS.** RETURNS: OK, or ERROR if access is outside the flash memory range.** SEE ALSO: sysFlashSet()** INTERNAL* If multiple tasks are calling sysFlashSet() and sysFlashGet(),* they should use a semaphore to ensure mutually exclusive access.*/STATUS sysFlashGet    (    char *string,    /* where to copy flash memory      */    int strLen,      /* maximum number of bytes to copy */    int offset       /* byte offset into flash memory   */    )    {    if ((offset < 0) || (strLen < 0) || ((offset + strLen) > FLASH_SIZE))        return (ERROR);    bcopyBytes ((char *) (FLASH_ADRS + offset), string, strLen);    string [strLen] = EOS;    return (OK);    }/******************************************************************************** sysFlashSet - write to flash memory** This routine copies a specified string into flash memory after calling * sysFlashErase() and clearing flash memory.** If the specified string must be overlaid on the contents of flash memory, * undefine FLASH_NO_OVERLAY.** RETURNS: OK, or ERROR if the write fails or the input parameters are * out of range.** SEE ALSO: sysFlashErase(), sysFlashGet(), sysFlashTypeGet(), sysFlashWrite()** INTERNAL* If multiple tasks are calling sysFlashSet() and sysFlashGet(),* they should use a semaphore to ensure mutually exclusive access to flash* memory.*/STATUS sysFlashSet    (    char *string,     /* string to be copied into flash memory */    int strLen,       /* maximum number of bytes to copy       */    int offset        /* byte offset into flash memory         */    )    {    int flashSize = FLASH_SIZE;    static char tempBuffer [FLASH_SIZE];    if ((offset < 0) || (strLen < 0) || ((offset + strLen) > flashSize))        return (ERROR);    /* see if contents are actually changing */    if (bcmp ((char *) (FLASH_ADRS + offset), string, strLen) == 0)        return (OK);    /* first read existing data */#ifndef FLASH_NO_OVERLAY    bcopyBytes ((char *) FLASH_ADRS, tempBuffer, flashSize);    bcopyBytes (string, (tempBuffer + offset), strLen);#else    bcopyBytes (string, tempBuffer, strLen);#endif  /* FLASH_NO_OVERLAY */    if (flashErase (FLASH_ADRS - FLASH_BASE) == ERROR) /* erase device */        return (ERROR);#ifndef FLASH_NO_OVERLAY                                /* program device */    if (flashWrite ((FLASH_TYPE*)tempBuffer, flashSize,                    (FLASH_ADRS - FLASH_BASE), 0) == ERROR)#else   /* FLASH_NO_OVERLAY */    if (flashWrite ((FLASH_TYPE*)tempBuffer, strLen,                    (FLASH_ADRS - FLASH_BASE) + offset, 0) == ERROR)#endif  /* FLASH_NO_OVERLAY */        return (ERROR);    return (OK);    }#endif /* ifdef FLASH_SIZE */

⌨️ 快捷键说明

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