|
1 // Copyright (c) 1996-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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // e32test\device\t_prom.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32test.h> |
|
19 #include <e32twin.h> |
|
20 #include <e32hal.h> |
|
21 #include <d32prom.h> |
|
22 |
|
23 GLDEF_D RDevE2Prom prom; |
|
24 GLDEF_D RTest test(_L("E2PROM tests")); |
|
25 |
|
26 #if !defined(__WINS__) |
|
27 LOCAL_C TInt CheckProm(TInt aVal) |
|
28 // |
|
29 // Write aVal to every location in prom and verify... |
|
30 // |
|
31 { |
|
32 |
|
33 TBuf16<16> buf; |
|
34 |
|
35 test(prom.WriteAll(aVal)==KErrNone); |
|
36 test(prom.ReadData(buf)==KErrNone); |
|
37 |
|
38 TInt len; |
|
39 |
|
40 for(len=0;len<16;len++) |
|
41 test(buf[len]==aVal); |
|
42 |
|
43 return(KErrNone); |
|
44 } |
|
45 #endif |
|
46 |
|
47 GLDEF_C TInt E32Main() |
|
48 // |
|
49 // Test E2 PROM handling. |
|
50 // |
|
51 { |
|
52 test.Title(); |
|
53 #if defined(__WINS__) |
|
54 test.Start(_L("This test is valid under EPOC platforms only")); |
|
55 test.End(); |
|
56 test.Close(); |
|
57 return(KErrNone); |
|
58 #else |
|
59 |
|
60 test.Start(_L("Loading E2PROM LDD")); |
|
61 TInt r=User::LoadLogicalDevice(_L("E2PROM")); |
|
62 test(r==KErrNone || r==KErrAlreadyExists); |
|
63 test.Next(_L("Opening device driver")); |
|
64 test(prom.Open()==KErrNone); |
|
65 test.Next(_L("Copying current contents of PROM")); |
|
66 TInt currentProtectValue=prom.ProtectRead(); |
|
67 TBuf16<16> currentContents; |
|
68 |
|
69 /* Random hacky code */ |
|
70 /* |
|
71 TBuf<0x100> buf; |
|
72 RProcess().CommandLine(buf); |
|
73 TLex lex(buf); |
|
74 TUint val; |
|
75 if (buf==KNullDesC) |
|
76 val=0; |
|
77 else |
|
78 { |
|
79 TInt r; |
|
80 r=lex.Val(val); |
|
81 test(r==KErrNone); |
|
82 test.Printf(_L("Setting to value %08x"), val); |
|
83 } |
|
84 currentContents.SetLength(16); |
|
85 Mem::FillZ((TUint8 *)currentContents.Ptr(), 32); |
|
86 test(prom.ReadData(currentContents)==KErrNone); |
|
87 currentContents[4]=val; |
|
88 TInt i; |
|
89 TUint8 s=0; |
|
90 for (i=1; i<32; i++) |
|
91 { |
|
92 s^=((TUint8*)currentContents.Ptr())[i]; |
|
93 } |
|
94 s^=0x42; |
|
95 ((TUint8*)currentContents.Ptr())[0]=s; |
|
96 test(prom.WriteData(currentContents)==KErrNone); |
|
97 test.Next(_L("Reading back")); |
|
98 test(prom.ReadData(currentContents)==KErrNone); |
|
99 test.Next(_L("Check checksum")); |
|
100 s=0; |
|
101 for (i=0; i<32; i++) |
|
102 { |
|
103 s^=((TUint8 *)currentContents.Ptr())[i]; |
|
104 } |
|
105 test.Printf(_L("checksum=%08x"), s); |
|
106 |
|
107 User::FreeLogicalDevice(_L("E2PROM")); |
|
108 test.End(); |
|
109 return KErrNone; |
|
110 } |
|
111 */ |
|
112 |
|
113 test(prom.ReadData(currentContents)==KErrNone); |
|
114 |
|
115 |
|
116 |
|
117 TBuf16<16> buf1; |
|
118 TBuf16<16> buf2; |
|
119 |
|
120 test.Next(_L("Clearing protect register")); |
|
121 |
|
122 test(prom.ProtectClear()==KErrNone); |
|
123 test(prom.ProtectRead()==63); |
|
124 |
|
125 test.Next(_L("Writing all")); |
|
126 |
|
127 test(CheckProm(0)==KErrNone); |
|
128 test(CheckProm(0x0008)==KErrNone); |
|
129 test(CheckProm(0x0080)==KErrNone); |
|
130 test(CheckProm(0x0800)==KErrNone); |
|
131 test(CheckProm(0x8000)==KErrNone); |
|
132 test(CheckProm(0xffff)==KErrNone); |
|
133 test(CheckProm(0xf0f0)==KErrNone); |
|
134 test(CheckProm(0xf00f)==KErrNone); |
|
135 |
|
136 test.Next(_L("Writing data")); |
|
137 |
|
138 TInt len; |
|
139 |
|
140 buf1.SetLength(16); |
|
141 |
|
142 for(len=0;len<16;len++) |
|
143 buf1[len]=(TInt16)len; |
|
144 |
|
145 test(prom.WriteData(buf1)==KErrNone); |
|
146 test.Next(_L("Reading and verifying")); |
|
147 test(prom.ReadData(buf2)==KErrNone); |
|
148 test(buf1==buf2); |
|
149 |
|
150 test.Next(_L("Testing protection")); |
|
151 test(prom.ProtectSet(6)==KErrNone); |
|
152 test(prom.ProtectRead()==6); |
|
153 test(prom.WriteAll(0)==KErrNone); |
|
154 test(prom.ReadData(buf2)==KErrNone); |
|
155 test(buf1==buf2); |
|
156 |
|
157 for(len=0;len<16;len++) |
|
158 buf1[len]=(TInt16)(len+0x8570); |
|
159 |
|
160 test(prom.WriteData(buf1)==KErrNone); |
|
161 test(prom.ReadData(buf2)==KErrNone); |
|
162 test(buf1!=buf2); |
|
163 |
|
164 for(len=6;len<16;len++) |
|
165 buf1[len]=(TInt16)len; |
|
166 |
|
167 test(buf1==buf2); |
|
168 test.Next(_L("Writing back original contents")); |
|
169 test(prom.ProtectClear()==KErrNone); |
|
170 test(prom.WriteData(currentContents)==KErrNone); |
|
171 test(prom.ProtectSet(currentProtectValue)==KErrNone); |
|
172 prom.Close(); |
|
173 |
|
174 test.End(); |
|
175 |
|
176 return(KErrNone); |
|
177 #endif |
|
178 } |
|
179 |