os/kernelhwsrv/kerneltest/e32test/misc/strataflash.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/misc/strataflash.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,102 @@
     1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32test\misc\strataflash.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32def.h>
    1.22 +#include <e32def_private.h>
    1.23 +#include "flash.h"
    1.24 +
    1.25 +class StrataFlash : public Flash
    1.26 +	{
    1.27 +public:
    1.28 +	virtual TInt Read(TUint32 anAddr, TUint32 aSize, TUint8* aDest);
    1.29 +	virtual TInt BlankCheck(TUint32 anAddr, TUint32 aSize);
    1.30 +	virtual TInt Erase(TUint32 anAddr, TUint32 aSize);
    1.31 +	virtual TInt Write(TUint32 anAddr, TUint32 aSize, const TUint8* aSrc);
    1.32 +	};
    1.33 +
    1.34 +
    1.35 +Flash* Flash::New(TUint32 /*anAddr*/)
    1.36 +	{
    1.37 +	return new StrataFlash;
    1.38 +	}
    1.39 +
    1.40 +TInt StrataFlash::Read(TUint32 anAddr, TUint32 aSize, TUint8* aDest)
    1.41 +	{
    1.42 +	Mem::Copy(aDest,(const TUint8*)anAddr,aSize);
    1.43 +	return KErrNone;
    1.44 +	}
    1.45 +
    1.46 +TInt StrataFlash::BlankCheck(TUint32 anAddr, TUint32 aSize)
    1.47 +	{
    1.48 +	const TUint8* p=(const TUint8*)anAddr;
    1.49 +	const TUint8* pE=p+aSize;
    1.50 +	while(p<pE)
    1.51 +		{
    1.52 +		if (*p++!=0xff)
    1.53 +			return (TUint32)p-anAddr;
    1.54 +		}
    1.55 +	return 0;
    1.56 +	}
    1.57 +
    1.58 +TInt StrataFlash::Erase(TUint32 anAddr, TUint32 aSize)
    1.59 +	{
    1.60 +	TUint32 base=anAddr&~0x1ffff;	// round base address down to block
    1.61 +	TUint32 end=anAddr+aSize;
    1.62 +	end=(end+0x1ffff)&~0x1ffff;	// round end address up to block
    1.63 +	TUint32 size=end-base;
    1.64 +	for (; size; size-=0x20000, base+=0x20000)
    1.65 +		{
    1.66 +		volatile TUint8* p=(volatile TUint8*)base;
    1.67 +		*p=0x20;		// block erase
    1.68 +		*p=0xd0;		// block erase confirm
    1.69 +		TUint s=0;
    1.70 +		while ((s&0x80)==0)
    1.71 +			s=*p;
    1.72 +		*p=0x50;		// clear status reg
    1.73 +		*p=0xff;		// read mode
    1.74 +		if (s&0x20)
    1.75 +			{
    1.76 +			// error
    1.77 +			return (TUint32)p-anAddr+1;
    1.78 +			}
    1.79 +		}
    1.80 +	return 0;
    1.81 +	}
    1.82 +
    1.83 +TInt StrataFlash::Write(TUint32 anAddr, TUint32 aSize, const TUint8* aSrc)
    1.84 +	{
    1.85 +	volatile TUint8* p=(volatile TUint8*)anAddr;
    1.86 +	const TUint8* pE=aSrc+aSize;
    1.87 +	for (; aSrc<pE; aSrc++, p++)
    1.88 +		{
    1.89 +		*p=0x40;		// byte write
    1.90 +		*p=*aSrc;		// write data
    1.91 +		TUint s=0;
    1.92 +		while ((s&0x80)==0)
    1.93 +			s=*p;
    1.94 +		*p=0x50;		// clear status reg
    1.95 +		*p=0xff;		// read mode
    1.96 +		if (s&0x10)
    1.97 +			{
    1.98 +			// error
    1.99 +			return (TUint32)p-anAddr+1;
   1.100 +			}
   1.101 +		}
   1.102 +	return 0;
   1.103 +	}
   1.104 +
   1.105 +