First public contribution.
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\misc\strataflash.cpp
19 #include <e32def_private.h>
22 class StrataFlash : public Flash
25 virtual TInt Read(TUint32 anAddr, TUint32 aSize, TUint8* aDest);
26 virtual TInt BlankCheck(TUint32 anAddr, TUint32 aSize);
27 virtual TInt Erase(TUint32 anAddr, TUint32 aSize);
28 virtual TInt Write(TUint32 anAddr, TUint32 aSize, const TUint8* aSrc);
32 Flash* Flash::New(TUint32 /*anAddr*/)
34 return new StrataFlash;
37 TInt StrataFlash::Read(TUint32 anAddr, TUint32 aSize, TUint8* aDest)
39 Mem::Copy(aDest,(const TUint8*)anAddr,aSize);
43 TInt StrataFlash::BlankCheck(TUint32 anAddr, TUint32 aSize)
45 const TUint8* p=(const TUint8*)anAddr;
46 const TUint8* pE=p+aSize;
50 return (TUint32)p-anAddr;
55 TInt StrataFlash::Erase(TUint32 anAddr, TUint32 aSize)
57 TUint32 base=anAddr&~0x1ffff; // round base address down to block
58 TUint32 end=anAddr+aSize;
59 end=(end+0x1ffff)&~0x1ffff; // round end address up to block
60 TUint32 size=end-base;
61 for (; size; size-=0x20000, base+=0x20000)
63 volatile TUint8* p=(volatile TUint8*)base;
64 *p=0x20; // block erase
65 *p=0xd0; // block erase confirm
69 *p=0x50; // clear status reg
74 return (TUint32)p-anAddr+1;
80 TInt StrataFlash::Write(TUint32 anAddr, TUint32 aSize, const TUint8* aSrc)
82 volatile TUint8* p=(volatile TUint8*)anAddr;
83 const TUint8* pE=aSrc+aSize;
84 for (; aSrc<pE; aSrc++, p++)
86 *p=0x40; // byte write
87 *p=*aSrc; // write data
91 *p=0x50; // clear status reg
96 return (TUint32)p-anAddr+1;