First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\pccd\t_pccd2.cpp
24 LOCAL_D RTest test(_L("T_PCCD2"));
25 const TSocket KSocket=0;
28 GLDEF_C TInt E32Main()
30 #if defined (__WINS__)
31 // Connect to all the local drives first as will be the case in ARM
32 TBusLocalDrive Drive[KMaxLocalDrives];
33 TBool ChangedFlag[KMaxLocalDrives];
35 for (i=0;i<KMaxLocalDrives;i++)
36 Drive[i].Connect(i,ChangedFlag[i]);
41 test.Start(_L("Load/open logical device"));
43 r=User::LoadLogicalDevice(_L("D_PCCDIF"));
44 test(r==KErrNone||r==KErrAlreadyExists);
45 RPcCardCntrlIf pccdDrv;
46 r=pccdDrv.Open(KSocket,pccdDrv.VersionRequired());
49 test.Next(_L("Power card and configure."));
50 UserSvr::ForceRemountMedia(ERemovableMedia0); // Media change - ensures test always starts from same state
51 User::After(300000); // Allow 0.3s after power down for controller to detect door closed.
54 test(pccdDrv.RegisterEvent(EPcCardEvMediaChange,&mrs)==KErrNone);
57 User::WaitForRequest(prs);
58 test(prs.Int()==KErrNone);
61 test(pccdDrv.SocketInfo(s,ind)==KErrNone);
62 test(s==EPcCardReady);
64 TPcCardTypePckg tyBuf;
65 TPcCardType &ty=tyBuf();
66 test(pccdDrv.CardInfo(&tyBuf)==KErrNone);
67 test(ty.iFuncType[0]==EFFixedDiskCard);
68 test(pccdDrv.ReqConfig(KFunc,1)==KErrNone);
70 // Test we can get the same chunk as the controllers attrib. chunk (its shareable).
71 test.Next(_L("Request 64K attribute chunk at 0H."));
73 ch.iMemType=EPcCardAttribMem;
77 test(pccdDrv.ReqMem(ch,EAccSpeed600nS,win0)==KErrNone);
80 test(pccdDrv.ReadMem(win0,0,8,rdBuf)==KErrNone);
81 // test(rdBuf.Compare(_L("\x01\xFF\x04\xFF\xDF\xFF\x72\xFF"))==0);
82 test(rdBuf[0]==0x01&&rdBuf[2]==0x04&&rdBuf[4]==0xDF&&rdBuf[6]==0x72);
84 // Test we can get small chunk within the controllers attrib. chunk (Win0 already allocated).
85 test.Next(_L("Request 16byte attribute chunk at 10H."));
86 ch.iMemType=EPcCardAttribMem;
89 test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win1)==KErrAccessDenied); // 1st chunk isn't shared
91 test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win1)==KErrNone);
93 test(pccdDrv.ReadMem(win1,0,8,rdBuf)==KErrNone);
94 // test(rdBuf.Compare(_L("\x03\xFF\xD9\xFF\x01\xFF\xFF\xFF"))==0);
95 test(rdBuf[0]==0x03&&rdBuf[2]==0xD9&&rdBuf[4]==0x01&&rdBuf[6]==0xFF);
97 // Test we can get a second small chunk, also within the controllers attrib. chunk but
98 // not clashing with previous chunk (Win1 already allocated).
99 test.Next(_L("Request 16byte attribute chunk at 20H."));
100 ch.iMemType=EPcCardAttribMem;
101 ch.iMemBaseAddr=0x20;
103 test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win0)==KErrNone);
105 test(pccdDrv.ReadMem(win0,0,8,rdBuf)==KErrNone);
106 // test(rdBuf.Compare(_L("\x20\xFF\x06\xFF\x45\xFF"))==2&&rdBuf[6]==0x00&&rdBuf[7]==0xFF); // 'Null causes problems with compare
107 test(rdBuf[0]==0x20&&rdBuf[2]==0x06&&rdBuf[4]==0x45&&rdBuf[6]==0x00);
109 // Test that requesting a chunk which lies partly but not entirely within the controllers
110 // chunk fails (Win0/Win1 already allocated).
111 test.Next(_L("Request 64K attribute chunk at 800H."));
112 test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win2)==KErrInUse);
113 pccdDrv.RelMem(win1);
114 ch.iMemType=EPcCardAttribMem;
115 ch.iMemBaseAddr=0x800;
117 test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win1)==KErrAccessDenied);
119 // Test we can get a small chunk beyond the controllers chunk (Win0 already allocated).
120 test.Next(_L("Request 16byte attribute chunk at 10800H."));
121 ch.iMemType=EPcCardAttribMem;
122 ch.iMemBaseAddr=0x10800;
124 test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win1)==KErrNone);
125 pccdDrv.RelMem(win1);
127 // Test we can get a large chunk beyond the controllers chunk (Win0 already allocated).
128 test.Next(_L("Request 4K attribute chunk at 10800H."));
129 ch.iMemType=EPcCardAttribMem;
130 ch.iMemBaseAddr=0x10800;
132 test(pccdDrv.ReqMem(ch,EAccSpeed300nS,win1)==KErrNone);
133 pccdDrv.RelMem(win1);
135 // Test we can get a chunk in a different memory type (Win0 already allocated).
136 test.Next(_L("Request 16byte IO chunk at 0H."));
137 ch.iMemType=EPcCardIo8Mem;
140 // test(pccdDrv.ReqMem(ch,EAccSpeed200nS,win1)==KErrNone); // ???
141 test(pccdDrv.ReqMem(ch,EAccSpeed250nS,win1)==KErrNone);
143 // Win0/Win1 allocated
146 test.Next(_L("Write/Read from ATA registers."));
147 test(pccdDrv.ReadConfigReg(KFunc,0,reg)==KErrNone); // Check its still configured
149 wrBuf.Copy(_L("\x04\x03\x02\x01"));
151 test(pccdDrv.WriteMem(win1,2,wrBuf)==KErrNone); // 4 bytes starting at Sector count
153 test(pccdDrv.ReadMem(win1,2,4,rdBuf)==KErrNone);
154 test(rdBuf.Compare(_L8("\x04\x03\x02\x01"))==0);
156 // Win0/Win1 allocated
157 test.Next(_L("Attempt to access window after power down."));
160 test(timer.CreateLocal()==KErrNone);
163 tim+=TTimeIntervalSeconds(8);
165 UserHal::SwitchOff();
166 User::WaitForRequest(trs);
167 test(trs.Int()==KErrNone);
169 User::WaitForRequest(prs);
170 test(prs.Int()==KErrNone);
171 // Check its been re-configured
173 test(pccdDrv.ReadConfigReg(KFunc,0,reg)==KErrNone);
175 // Check that window still OK after power down
176 test(pccdDrv.WriteMem(win1,2,wrBuf)==KErrNone); // 4 bytes starting at Sector count
178 test(pccdDrv.ReadMem(win1,2,4,rdBuf)==KErrNone);
179 test(rdBuf.Compare(_L8("\x04\x03\x02\x01"))==0);
181 // Win0/Win1 allocated
182 test.Next(_L("Attempt to access window after media change."));
183 UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change
184 User::WaitForRequest(mrs);
185 if (mrs.Int()!=KErrNone)
190 User::After(300000); // Allow 0.3s after power down for controller to detect door closed.
192 User::WaitForRequest(prs);
193 if (prs.Int()!=KErrNone)
198 // First access following media change must be supervisor call
199 if (pccdDrv.CardInfo(&tyBuf)!=KErrNone)
204 // Check its not been re-configured
205 if (pccdDrv.ReadConfigReg(KFunc,0,reg)!=KErrGeneral)
210 if (pccdDrv.ReadMem(win1,2,4,rdBuf)!=KErrNotReady)
217 r=User::FreeLogicalDevice(_L("PccdIf"));
222 #if defined (__WINS__)
223 for (i=0;i<KMaxLocalDrives;i++)
224 Drive[i].Disconnect();