Update contrib.
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\strataflash32.cpp
19 #include <e32def_private.h>
25 class StrataFlash32 : public Flash
28 virtual TInt Read(TUint32 anAddr, TUint32 aSize, TUint8* aDest);
29 virtual TInt BlankCheck(TUint32 anAddr, TUint32 aSize);
30 virtual TInt Erase(TUint32 anAddr, TUint32 aSize);
31 virtual TInt Write(TUint32 anAddr, TUint32 aSize, const TUint8* aSrc);
35 Flash* Flash::New(TUint32 /*anAddr*/)
37 return new StrataFlash32;
40 TInt StrataFlash32::Read(TUint32 anAddr, TUint32 aSize, TUint8* aDest)
42 Mem::Move(aDest,(const TUint32*)anAddr,aSize);
46 TInt StrataFlash32::BlankCheck(TUint32 anAddr, TUint32 aSize)
48 const TUint32* p=(const TUint32*)anAddr;
49 const TUint32* pE=p+(aSize+3)/4;
53 return (TUint32)p-anAddr;
58 TInt StrataFlash32::Erase(TUint32 anAddr, TUint32 aSize)
60 TUint32 base=anAddr&~0x3ffff; // round base address down to block
61 TUint32 end=anAddr+aSize;
62 end=(end+0x3ffff)&~0x3ffff; // round end address up to block
63 TUint32 size=end-base;
64 volatile TUint32* p=(volatile TUint32*)base;
65 *p=0x00500050; // clear status reg
66 for (; size; size-=0x40000, p+=0x40000/4)
68 *p=0x00200020; // block erase
69 *p=0x00d000d0; // block erase confirm
70 while ((*p & 0x00800080)!=0x00800080) {}
72 *p=0x00500050; // clear status reg
73 *p=0x00ff00ff; // read mode
77 return (TUint32)p-anAddr+1;
83 TInt StrataFlash32::Write(TUint32 anAddr, TUint32 aSize, const TUint8* aSrc)
85 volatile TUint32* p=(volatile TUint32*)anAddr;
86 const TUint32* pS=(const TUint32*)aSrc;
89 const TUint32* pE=pS+aSize/4;
90 for (; pS<pE; pS++, p++)
92 *p=0x00400040; // word write
94 while ((*p & 0x00800080)!=0x00800080);
96 *p=0x00500050; // clear status reg
97 *p=0x00ff00ff; // read mode
101 return (TUint32)p-anAddr+1;
107 *p=0x00500050; // clear status reg
110 TUint32 wb_offset=((TUint32)p)&0x3f;
111 TUint32 max_count=(64-wb_offset)/4;
112 TUint32 count=Min(aSize/4,max_count);
118 *p=0x00e800e8; // Write to Buffer
119 *p=0x00700070; // Read status register
121 } while ((s&0x00800080)!=0x00800080);
125 for (i=0; i<count; ++i)
127 *p=0x00d000d0; // Write confirm
129 while ((*p & 0x00800080)!=0x00800080) {} // Wait for write to complete
134 *p=0x00500050; // clear status reg
135 *p=0x00ff00ff; // read mode
139 return (TUint32)p-anAddr+1;