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

📄 i28f640j3mem.c

📁 WINDRIVER SBC405 BSP
💻 C
字号:
/* i28F640J3Mem.c - Intel 28F640J3 Flash Memory library *//* Copyright 1984-2001 Wind River Systems, Inc. *//*modification history--------------------01b,03jul01,g_h  move sysNvRamGet & sysNvRamSet to sysNvRam.c and make                 i28F640J3Write() , i28F640J3EraseSector() global.01a,16apr01,g_h  written*//*DESCRIPTIONThis library contains routines to manipulate Intel 28F640J3 Flash memory.Read and write routines are included.The macros NV_RAM_ADRS and NV_RAM_SIZE must be defined to indicate theaddress and size of the Flash memory.This module use the visionWare flash algorithm.The Intel 28F640J3 access is BITS:16 BUS:32 BOOT:NONE ACCESS:INTEGER.*//* includes */#include "i28F640J3Mem.h"#include "memLib.h"#include "stdlib.h"/* LOCALs */LOCAL void   iOSync(void){ }static const tFLASH erase1 = 		{ 0x200020 };static const tFLASH erase2 = 		{ 0xD000D0 };static const tFLASH program =		{ 0x400040 };static const tFLASH readArray =		{ 0xFF00FF };static const tFLASH clearStatus =	{ 0x500050 };static const tFLASH erased =            { (UINT32)-1 };static const tFLASH readyBits =		{ 0x800080 };static const tFLASH eraseBits =		{ 0x200020 };static const tFLASH programBits =	{ 0x100010 };static const tFLASH bufferWrite =	{ 0xE800E8 };static const tFLASH confirmWrite =	{ 0xD000D0 };static const tFLASH bufferCount =	{ 0xF000F  };/************************************************************************* i28F640J3Write - write data to the Intel 29F640J3** This routine write given data to the Intel 29F640J3 FLASH device.** RETURNS: Number of byte writen** SEE ALSO: i28F640J3EraseSector()*/UINT32 i28F640J3Write    (    volatile UINT8 * pDest,     UINT8          * pSource,    UINT32           length    )    {    UINT32 mask;    UINT32 tempBuffer[0x10];    UINT   n;    UINT   originalLength = length;    tFLASH data;    volatile UINT32 *pBlock = (UINT32 *)((UINT32)pDest & ~0x3FFFF);    while (length)        {        *(volatile UINT32 *)pDest = readArray.Float;        if ((((UINT32)pDest & 0x3F) == 0) && (length >= 0x40))	    {            memcpy((char *)&tempBuffer, pSource, 0x40);            *pBlock = bufferWrite.Float;            iOSync();            if (*pBlock == readyBits.Integer)	        {		*pBlock = bufferCount.Float;		for (n = 0; n < 0x10; ++n)                    ((volatile UINT32 *)pDest)[n] = tempBuffer[n];                iOSync();		*pBlock = confirmWrite.Float;                iOSync();                while (*(volatile UINT32 *)pDest != readyBits.Integer);		pDest   += 0x40;		pSource += 0x40;		length  -= 0x40;		continue;		}            iOSync();            *(volatile UINT32 *)pDest = readArray.Float;            }            n = ((unsigned int)pDest & 5);            if (n)		{		pDest -= n;		pSource -= n;		mask = (UINT32)-1 MASKSHIFTOP1 (8 * n);		}	    else		mask = (UINT32)-1;            if ((n + length) < 4)		mask &= (UINT32)-1 MASKSHIFTOP2 (8 * (4 - (n + length)));	    data.Integer  = readUnaligned(pSource) & mask;	    data.Integer |= *(UINT32 *)pDest & (~mask);	    pSource      += 4;	    *(volatile UINT32 *)pDest = clearStatus.Float;	    iOSync();	    *(volatile UINT32 *)pDest = program.Float;	    iOSync();	    *(volatile UINT32 *)pDest = data.Float;	    iOSync();            while (*(volatile UINT32 *)pDest != readyBits.Integer);	    pDest  += 4;	    length -= min(4 - n, length);	}        iOSync();	*(volatile UINT32 *)(pDest - 4) = readArray.Float;	return (originalLength - length);}/************************************************************************* i28F640J3EraseSector - erase sector in the Intel 29F640J3** This routine erase given sector in the Intel 29F640J3 FLASH device.** RETURNS: OK** SEE ALSO: i28F640J3Write()*/UINT32 i28F640J3EraseSector    (    volatile UINT8 * pSector    )    {    *(volatile UINT32 *)pSector = clearStatus.Float;    iOSync();    *(volatile UINT32 *)pSector = erase1.Float;    iOSync();    *(volatile UINT32 *)pSector = erase2.Float;    iOSync();    while (*(volatile UINT32 *)pSector != readyBits.Integer);    *(volatile UINT32 *)pSector = readArray.Float;        return (OK);}

⌨️ 快捷键说明

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