sl@0
|
1 |
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32test\misc\strataflash32.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <e32def.h>
|
sl@0
|
19 |
#include <e32def_private.h>
|
sl@0
|
20 |
#include "flash.h"
|
sl@0
|
21 |
|
sl@0
|
22 |
#include <e32test.h>
|
sl@0
|
23 |
GLREF_C RTest test;
|
sl@0
|
24 |
|
sl@0
|
25 |
class StrataFlash32 : public Flash
|
sl@0
|
26 |
{
|
sl@0
|
27 |
public:
|
sl@0
|
28 |
virtual TInt Read(TUint32 anAddr, TUint32 aSize, TUint8* aDest);
|
sl@0
|
29 |
virtual TInt BlankCheck(TUint32 anAddr, TUint32 aSize);
|
sl@0
|
30 |
virtual TInt Erase(TUint32 anAddr, TUint32 aSize);
|
sl@0
|
31 |
virtual TInt Write(TUint32 anAddr, TUint32 aSize, const TUint8* aSrc);
|
sl@0
|
32 |
};
|
sl@0
|
33 |
|
sl@0
|
34 |
|
sl@0
|
35 |
Flash* Flash::New(TUint32 /*anAddr*/)
|
sl@0
|
36 |
{
|
sl@0
|
37 |
return new StrataFlash32;
|
sl@0
|
38 |
}
|
sl@0
|
39 |
|
sl@0
|
40 |
TInt StrataFlash32::Read(TUint32 anAddr, TUint32 aSize, TUint8* aDest)
|
sl@0
|
41 |
{
|
sl@0
|
42 |
Mem::Move(aDest,(const TUint32*)anAddr,aSize);
|
sl@0
|
43 |
return KErrNone;
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
TInt StrataFlash32::BlankCheck(TUint32 anAddr, TUint32 aSize)
|
sl@0
|
47 |
{
|
sl@0
|
48 |
const TUint32* p=(const TUint32*)anAddr;
|
sl@0
|
49 |
const TUint32* pE=p+(aSize+3)/4;
|
sl@0
|
50 |
while(p<pE)
|
sl@0
|
51 |
{
|
sl@0
|
52 |
if (*p++!=0xffffffff)
|
sl@0
|
53 |
return (TUint32)p-anAddr;
|
sl@0
|
54 |
}
|
sl@0
|
55 |
return 0;
|
sl@0
|
56 |
}
|
sl@0
|
57 |
|
sl@0
|
58 |
TInt StrataFlash32::Erase(TUint32 anAddr, TUint32 aSize)
|
sl@0
|
59 |
{
|
sl@0
|
60 |
TUint32 base=anAddr&~0x3ffff; // round base address down to block
|
sl@0
|
61 |
TUint32 end=anAddr+aSize;
|
sl@0
|
62 |
end=(end+0x3ffff)&~0x3ffff; // round end address up to block
|
sl@0
|
63 |
TUint32 size=end-base;
|
sl@0
|
64 |
volatile TUint32* p=(volatile TUint32*)base;
|
sl@0
|
65 |
*p=0x00500050; // clear status reg
|
sl@0
|
66 |
for (; size; size-=0x40000, p+=0x40000/4)
|
sl@0
|
67 |
{
|
sl@0
|
68 |
*p=0x00200020; // block erase
|
sl@0
|
69 |
*p=0x00d000d0; // block erase confirm
|
sl@0
|
70 |
while ((*p & 0x00800080)!=0x00800080) {}
|
sl@0
|
71 |
TUint32 s=*p;
|
sl@0
|
72 |
*p=0x00500050; // clear status reg
|
sl@0
|
73 |
*p=0x00ff00ff; // read mode
|
sl@0
|
74 |
if (s&0x00200020)
|
sl@0
|
75 |
{
|
sl@0
|
76 |
// error
|
sl@0
|
77 |
return (TUint32)p-anAddr+1;
|
sl@0
|
78 |
}
|
sl@0
|
79 |
}
|
sl@0
|
80 |
return 0;
|
sl@0
|
81 |
}
|
sl@0
|
82 |
|
sl@0
|
83 |
TInt StrataFlash32::Write(TUint32 anAddr, TUint32 aSize, const TUint8* aSrc)
|
sl@0
|
84 |
{
|
sl@0
|
85 |
volatile TUint32* p=(volatile TUint32*)anAddr;
|
sl@0
|
86 |
const TUint32* pS=(const TUint32*)aSrc;
|
sl@0
|
87 |
aSize=(aSize+63)&~63;
|
sl@0
|
88 |
/*
|
sl@0
|
89 |
const TUint32* pE=pS+aSize/4;
|
sl@0
|
90 |
for (; pS<pE; pS++, p++)
|
sl@0
|
91 |
{
|
sl@0
|
92 |
*p=0x00400040; // word write
|
sl@0
|
93 |
*p=*pS; // write data
|
sl@0
|
94 |
while ((*p & 0x00800080)!=0x00800080);
|
sl@0
|
95 |
TUint32 s=*p;
|
sl@0
|
96 |
*p=0x00500050; // clear status reg
|
sl@0
|
97 |
*p=0x00ff00ff; // read mode
|
sl@0
|
98 |
if (s&0x00100010)
|
sl@0
|
99 |
{
|
sl@0
|
100 |
// error
|
sl@0
|
101 |
return (TUint32)p-anAddr+1;
|
sl@0
|
102 |
}
|
sl@0
|
103 |
}
|
sl@0
|
104 |
*/
|
sl@0
|
105 |
|
sl@0
|
106 |
TUint32 s=0;
|
sl@0
|
107 |
*p=0x00500050; // clear status reg
|
sl@0
|
108 |
while(aSize)
|
sl@0
|
109 |
{
|
sl@0
|
110 |
TUint32 wb_offset=((TUint32)p)&0x3f;
|
sl@0
|
111 |
TUint32 max_count=(64-wb_offset)/4;
|
sl@0
|
112 |
TUint32 count=Min(aSize/4,max_count);
|
sl@0
|
113 |
TUint32 cwd=count-1;
|
sl@0
|
114 |
cwd|=(cwd<<16);
|
sl@0
|
115 |
|
sl@0
|
116 |
s=0;
|
sl@0
|
117 |
do {
|
sl@0
|
118 |
*p=0x00e800e8; // Write to Buffer
|
sl@0
|
119 |
*p=0x00700070; // Read status register
|
sl@0
|
120 |
s=*p;
|
sl@0
|
121 |
} while ((s&0x00800080)!=0x00800080);
|
sl@0
|
122 |
s=*p;
|
sl@0
|
123 |
*p=cwd;
|
sl@0
|
124 |
TUint32 i;
|
sl@0
|
125 |
for (i=0; i<count; ++i)
|
sl@0
|
126 |
*p++=*pS++;
|
sl@0
|
127 |
*p=0x00d000d0; // Write confirm
|
sl@0
|
128 |
aSize-=4*count;
|
sl@0
|
129 |
while ((*p & 0x00800080)!=0x00800080) {} // Wait for write to complete
|
sl@0
|
130 |
s=*p;
|
sl@0
|
131 |
if (s&0x00300030)
|
sl@0
|
132 |
break;
|
sl@0
|
133 |
}
|
sl@0
|
134 |
*p=0x00500050; // clear status reg
|
sl@0
|
135 |
*p=0x00ff00ff; // read mode
|
sl@0
|
136 |
if (s&0x00300030)
|
sl@0
|
137 |
{
|
sl@0
|
138 |
// error
|
sl@0
|
139 |
return (TUint32)p-anAddr+1;
|
sl@0
|
140 |
}
|
sl@0
|
141 |
|
sl@0
|
142 |
return 0;
|
sl@0
|
143 |
}
|
sl@0
|
144 |
|
sl@0
|
145 |
|