|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32test.h> |
|
20 #include <e32ver.h> |
|
21 #include <e32cmn.h> |
|
22 #include <e32def.h> |
|
23 #include <e32def_private.h> |
|
24 #include "d_csi.h" |
|
25 |
|
26 _LIT(testName,"t_csi"); |
|
27 _LIT(KLddFileName, "d_csi.ldd"); // Kernel-side proxy LDD acting as a client of the IIC |
|
28 _LIT(KLddFileNameRoot, "d_csi"); |
|
29 |
|
30 // global data.. |
|
31 GLDEF_D RTest csiTest(testName); |
|
32 GLDEF_D RBusCsiTestClient gCsiLdd; // Channel to kernel-side proxy |
|
33 GLDEF_D TConfigSpiBufV01 SpiHeader; |
|
34 GLDEF_D TUint32 SpiConfig; |
|
35 |
|
36 LOCAL_C void SetDefaultHeader() |
|
37 { |
|
38 const TConfigSpiV01 DefaultHeader = |
|
39 { |
|
40 ESpiWordWidth_8, //iWordWidth |
|
41 260000, //iClkSpeed |
|
42 ESpiPolarityLowRisingEdge, //iClkMode |
|
43 500, // iTimeoutPeriod |
|
44 EBigEndian, // iEndianness |
|
45 EMsbFirst, //iBitOrder |
|
46 0, //iTransactionWaitCycles |
|
47 ESpiCSPinActiveLow //iCsPinActiveMode |
|
48 }; |
|
49 |
|
50 SpiHeader = DefaultHeader; |
|
51 } |
|
52 |
|
53 LOCAL_C void SetDefaultConfig() |
|
54 { |
|
55 //Set the default settings |
|
56 SpiConfig = 0; |
|
57 SET_CHAN_NUM(SpiConfig,KSpiChannel0); //0 or |
|
58 SET_BUS_TYPE(SpiConfig,ESpi); |
|
59 SET_SLAVE_ADDR(SpiConfig,1); // Any Number between 1 to 32 */ |
|
60 SetDefaultHeader(); |
|
61 } |
|
62 |
|
63 // ================== |
|
64 // MASTER tests |
|
65 // clock values supported by the navi-engine CSI interface |
|
66 const TUint32 TSpiClkSpeedValues[] = |
|
67 {130000, 260000, 521000, 1040000, 2080000, 4170000, 16670000}; |
|
68 |
|
69 LOCAL_C void TestClockSpeed() |
|
70 { |
|
71 TInt r = KErrNone; |
|
72 |
|
73 // try to set each of the supported clk speeds. (queuing a transaction using |
|
74 // header with one of them set).. |
|
75 for(TUint i = 0; i < sizeof(TSpiClkSpeedValues) / sizeof(TUint32); ++i) |
|
76 { |
|
77 SpiHeader().iClkSpeedHz = TSpiClkSpeedValues[i]; |
|
78 r = gCsiLdd.TestConfigParams(&SpiHeader, SpiConfig); |
|
79 csiTest(r == KErrNone); |
|
80 } |
|
81 |
|
82 // now try some of known - as not supported: |
|
83 SpiHeader().iClkSpeedHz = 300000; |
|
84 r = gCsiLdd.TestConfigParams(&SpiHeader, SpiConfig); |
|
85 if(r != KErrNotSupported) |
|
86 { |
|
87 csiTest.Printf(_L("Error setting clk %d, r = %d \n"), SpiHeader().iClkSpeedHz, r); |
|
88 csiTest(EFalse); |
|
89 } |
|
90 // Set it to the default header after testing |
|
91 SetDefaultHeader(); |
|
92 } |
|
93 |
|
94 |
|
95 LOCAL_C void TestWordWidth() |
|
96 { |
|
97 TInt r = KErrNone; |
|
98 for (TInt i = 0; i <= ESpiWordWidth_16; i++) |
|
99 { |
|
100 SpiHeader().iWordWidth = static_cast<TSpiWordWidth> (i); |
|
101 r = gCsiLdd.TestConfigParams(&SpiHeader, SpiConfig); |
|
102 switch (i) |
|
103 { |
|
104 case ESpiWordWidth_8: |
|
105 case ESpiWordWidth_16: |
|
106 |
|
107 csiTest(r == KErrNone); |
|
108 break; |
|
109 default: |
|
110 csiTest(r == KErrNotSupported); |
|
111 break; |
|
112 }//Switch |
|
113 } //For loop |
|
114 //Set it to the default header after testing |
|
115 SetDefaultHeader(); |
|
116 } |
|
117 |
|
118 LOCAL_C void TestAsynchTransactions() |
|
119 { |
|
120 // Queue 3 asynchronous Transaction and expect them to nogified in FIFO order. |
|
121 const TInt KNumberOfTransactions = 3; |
|
122 TRequestStatus status[KNumberOfTransactions]; |
|
123 |
|
124 TInt r = KErrNone; |
|
125 |
|
126 for(TInt i = 0; i < KNumberOfTransactions; ++i) |
|
127 { |
|
128 status[i] = KErrNotReady; |
|
129 gCsiLdd.TestAsynTransaction(status[i], &SpiHeader, SpiConfig); |
|
130 } |
|
131 |
|
132 // And Expect them to be notified in the same order. |
|
133 for(TInt i = 0; i < KNumberOfTransactions; ++i) |
|
134 { |
|
135 User::WaitForAnyRequest(); |
|
136 |
|
137 // next should be finished.. |
|
138 if(status[i] != KErrNone) |
|
139 { |
|
140 r = KErrGeneral; |
|
141 continue; |
|
142 } |
|
143 |
|
144 if(i == 0) // only first should be ready.. |
|
145 { |
|
146 if((status[1] == KErrNone) || |
|
147 (status[2] == KErrNone)) |
|
148 { |
|
149 r = KErrGeneral; |
|
150 continue; |
|
151 } |
|
152 } |
|
153 |
|
154 if(i == 1) // only first two should be ready.. |
|
155 { |
|
156 if(status[2] == KErrNone) |
|
157 { |
|
158 r = KErrGeneral; |
|
159 } |
|
160 } |
|
161 } |
|
162 |
|
163 csiTest(r == KErrNone); |
|
164 } |
|
165 |
|
166 LOCAL_C void TestMaster() |
|
167 { |
|
168 TInt r = KErrNone; |
|
169 |
|
170 // Instigate AudioCodecBeep |
|
171 csiTest.Printf(_L("Testing Audio Codec Beep\n")); |
|
172 r = gCsiLdd.TestAudioCodecBeep(); |
|
173 if(r == KErrNotSupported) |
|
174 { |
|
175 csiTest.Printf(_L("Master mode is not supported by the client, skipping master test.. \n")); |
|
176 return; |
|
177 } |
|
178 csiTest(r == KErrNone); |
|
179 |
|
180 // Instigate TransferTimeout |
|
181 csiTest.Printf(_L("Testing Transfer Timeout\n")); |
|
182 r = gCsiLdd.TestTransferTimeout(); |
|
183 csiTest(r == KErrNone); |
|
184 |
|
185 // Test TestBulkTransfer |
|
186 csiTest.Printf(_L("Testing TestBulkTransfer\n")); |
|
187 r = gCsiLdd.TestBulkTransfer(); |
|
188 csiTest(r == KErrNone); |
|
189 |
|
190 // Test Half Duplex |
|
191 csiTest.Printf(_L("Testing Half Duplex operations \n")); |
|
192 r = gCsiLdd.TestHalfDuplex(); |
|
193 csiTest(r == KErrNone); |
|
194 |
|
195 // TestDuplexTransaction |
|
196 csiTest.Printf(_L("Testing DuplexTransaction\n")); |
|
197 r = gCsiLdd.TestDuplexTransaction(); |
|
198 csiTest(r == KErrNone); |
|
199 |
|
200 // Test all available ClockSpeeds |
|
201 csiTest.Printf(_L("Testing Different ClockSpeeds\n")); |
|
202 TestClockSpeed(); |
|
203 |
|
204 // Test WordWidth |
|
205 csiTest.Printf(_L("Testing WordWidths\n")); |
|
206 TestWordWidth(); |
|
207 |
|
208 csiTest.Printf(_L("Testing Asynchronous Transactions\n")); |
|
209 TestAsynchTransactions(); |
|
210 } |
|
211 |
|
212 // ================== |
|
213 // SLAVE tests |
|
214 LOCAL_C TInt SlaveCaptureChannel(TInt aBufferSize) |
|
215 { |
|
216 csiTest.Printf(_L("SlaveCaptureChannel(), buff %d\n"), aBufferSize); |
|
217 // Open Slave channel (use buffers declared in the d_csi) |
|
218 TInt r = gCsiLdd.CaptureSlaveChannel(aBufferSize); |
|
219 if(r != KErrNone) |
|
220 { |
|
221 csiTest.Printf(_L("couln't Capture Slave Channel, r= %d\n"), r); |
|
222 } |
|
223 return r; |
|
224 } |
|
225 |
|
226 LOCAL_C TInt SlaveAsyncCaptureChannel(TInt aBufferSize) |
|
227 { |
|
228 // Open Slave channel (use buffers declared in the d_csi) |
|
229 TRequestStatus status; |
|
230 TInt r = KErrNone; |
|
231 |
|
232 gCsiLdd.CaptureSlaveChannel(aBufferSize, status); |
|
233 |
|
234 User::WaitForRequest(status); |
|
235 r = status.Int(); |
|
236 if (r != KErrCompletion) |
|
237 { |
|
238 csiTest.Printf(_L("SlaveAsyncCaptureChannel request returned, r= %d\n"), r); |
|
239 } |
|
240 return r; |
|
241 } |
|
242 |
|
243 LOCAL_C TInt SlaveReleaseChannel() |
|
244 { |
|
245 TInt r = gCsiLdd.ReleaseSlaveChannel(); |
|
246 if (r != KErrNone) |
|
247 { |
|
248 csiTest.Printf(_L("couln't Release Slave Channel, r= %d\n"), r); |
|
249 } |
|
250 return r; |
|
251 } |
|
252 |
|
253 #ifdef EXTERNAL_HW_LOOPBACK_USED |
|
254 LOCAL_C void StartSlaveRequest(TRequestStatus &aStatus) |
|
255 { |
|
256 csiTest.Printf(_L("StartSlaveRequest\n")); |
|
257 |
|
258 enum TTriggers |
|
259 { |
|
260 ERxAllBytes = 0x01, |
|
261 ERxUnderrun = 0x02, |
|
262 ERxOverrun = 0x04, |
|
263 ETxAllBytes = 0x08, |
|
264 ETxUnderrun = 0x10, |
|
265 ETxOverrun = 0x20, |
|
266 EGeneralBusError = 0x40 |
|
267 }; |
|
268 |
|
269 // register for all possible notifications.. |
|
270 TInt trigger = ERxAllBytes | ERxOverrun | ERxUnderrun | ETxAllBytes | ETxOverrun | ETxUnderrun; |
|
271 |
|
272 // Set notification trigger - this starts asynchronous Slave operation.. |
|
273 csiTest.Printf(_L("Set Notification trigger\n")); |
|
274 gCsiLdd.SetSlaveNotificationTrigger(aStatus, trigger); |
|
275 } |
|
276 |
|
277 LOCAL_C TInt WaitForSlaveReqest(TRequestStatus &aStatus) |
|
278 { |
|
279 csiTest.Printf(_L("Waiting for the slave to complete..\n")); |
|
280 User::WaitForRequest(aStatus); |
|
281 TInt r = aStatus.Int(); |
|
282 if(r != KErrNone) |
|
283 { |
|
284 csiTest.Printf(_L("request returned, r= %d\n"), r); |
|
285 } |
|
286 return r; |
|
287 } |
|
288 |
|
289 // Requirements: local-HW loopback between CSI channel 0 (master) and 1 (Slave) |
|
290 // in this test scenario we will: |
|
291 // 1. Initiate Asynchronous, full duplex Slave operation with buffers set 64 Bytes |
|
292 // 2. Queue one full duplex Master transfer with 64 bytes |
|
293 // 3. Wait and check the SlaveRequest competition |
|
294 LOCAL_C TInt TestSlaveNormalTransfer() |
|
295 { |
|
296 csiTest.Printf(_L("TestSlaveNormalTransfer()\n")); |
|
297 // capture the channel |
|
298 TInt r = SlaveCaptureChannel(64); |
|
299 csiTest(r == KErrNone); |
|
300 |
|
301 // instigate the request.. |
|
302 TRequestStatus status; |
|
303 StartSlaveRequest(status); |
|
304 |
|
305 // queue One FullDuplex transaction.. |
|
306 // (it can be either synchronous or asynchronous) |
|
307 // specify both MASTER_MODE and SLAVE_MODE to run the test |
|
308 csiTest.Printf(_L("QueueOneDuplexTransaction\n")); |
|
309 r = gCsiLdd.QueueOneDuplexTransaction(64); |
|
310 |
|
311 if (r == KErrNone) |
|
312 { |
|
313 csiTest.Printf(_L("WaitForSlaveRequest\n")); |
|
314 r = WaitForSlaveReqest(status); |
|
315 } |
|
316 else if (r == KErrNotSupported) |
|
317 { |
|
318 return r; |
|
319 } |
|
320 else |
|
321 { |
|
322 csiTest.Printf(_L("Error queuing duplex trans?\n")); |
|
323 } |
|
324 |
|
325 // release the channel.. |
|
326 SlaveReleaseChannel(); |
|
327 |
|
328 return r; |
|
329 } |
|
330 #endif |
|
331 |
|
332 LOCAL_C void TestSlave() |
|
333 { |
|
334 csiTest.Printf(_L("TestSlave operations\n")); |
|
335 TInt r = KErrNone; |
|
336 |
|
337 csiTest.Printf(_L("Capture channel\n")); |
|
338 r = SlaveCaptureChannel(64); |
|
339 if(r == KErrNotSupported) |
|
340 { |
|
341 csiTest.Printf(_L("Slave mode is not supported by the client, skipping slave tests.. \n")); |
|
342 return; |
|
343 } |
|
344 csiTest(r == KErrNone); |
|
345 |
|
346 csiTest.Printf(_L("Capture already captured channel\n")); |
|
347 r = SlaveCaptureChannel(64); |
|
348 csiTest(r == KErrInUse); |
|
349 |
|
350 csiTest.Printf(_L("Release channel\n")); |
|
351 r = SlaveReleaseChannel(); |
|
352 |
|
353 csiTest.Printf(_L("Asynchronously capture channel\n")); |
|
354 r = SlaveAsyncCaptureChannel(64); |
|
355 csiTest(r == KErrCompletion); |
|
356 |
|
357 csiTest.Printf(_L("Release channel\n")); |
|
358 r = SlaveReleaseChannel(); |
|
359 |
|
360 #ifdef EXTERNAL_HW_LOOPBACK_USED |
|
361 // this test needs additional HW loopback (channel 0 and 1) attached to the board |
|
362 r = TestSlaveNormalTransfer(); |
|
363 if(r == KErrNotSupported) |
|
364 { |
|
365 csiTest.Printf(_L("TestSlaveNormalTransfer() is not supported for slave only mode \n")); |
|
366 return; |
|
367 } |
|
368 csiTest(r == KErrNone); |
|
369 #endif |
|
370 } |
|
371 |
|
372 |
|
373 LOCAL_C void LoadTestDriver() |
|
374 { |
|
375 // csiTest.Printf(_L("Loading the proxy-device driver\n")); |
|
376 TInt r = User::LoadLogicalDevice(KLddFileName); |
|
377 if(r != KErrNone && r != KErrAlreadyExists) |
|
378 { |
|
379 csiTest.Printf(_L("Failed to load the proxy-device driver, r= %d\n"), r); |
|
380 csiTest.End(); |
|
381 } |
|
382 } |
|
383 |
|
384 LOCAL_C void OpenTestDriver() |
|
385 { |
|
386 // Open a Master SPI channel to the kernel side proxy |
|
387 TBufC<6> proxyName(KLddFileNameRoot); |
|
388 // csiTest.Printf(_L("opening the proxy-device driver\n")); |
|
389 TInt r = gCsiLdd.Open(proxyName); |
|
390 if(r != KErrNone) |
|
391 { |
|
392 csiTest.Printf(_L("Failed to open the proxy-device the driver, r= %d\n"), r); |
|
393 csiTest(r == KErrNone); |
|
394 } |
|
395 //Have the default config |
|
396 SetDefaultConfig(); |
|
397 } |
|
398 |
|
399 LOCAL_C void UnloadTestDriver() |
|
400 { |
|
401 TInt r = User::FreeLogicalDevice(KLddFileName); |
|
402 if(r != KErrNone) |
|
403 { |
|
404 csiTest.Printf(_L("Failed to unload the proxy-device driver, r= %d\n"), r); |
|
405 } |
|
406 } |
|
407 |
|
408 /************************************************* |
|
409 *********Main************************************ |
|
410 ************************************************/ |
|
411 EXPORT_C TInt E32Main() |
|
412 { |
|
413 csiTest.Title(); |
|
414 csiTest.Start(_L("Test CSI Master \n")); |
|
415 |
|
416 //Load the Test Driver |
|
417 LoadTestDriver(); |
|
418 __KHEAP_MARK; |
|
419 |
|
420 OpenTestDriver(); |
|
421 |
|
422 // Run tests for the Slave |
|
423 TestMaster(); |
|
424 |
|
425 // Run tests for the Slave |
|
426 TestSlave(); |
|
427 |
|
428 //Close the driver |
|
429 csiTest.Printf(_L("Tests completed OK, about to close channel\n")); |
|
430 |
|
431 gCsiLdd.Close(); |
|
432 |
|
433 __KHEAP_MARKEND; |
|
434 |
|
435 UnloadTestDriver(); |
|
436 csiTest.End(); |
|
437 |
|
438 return KErrNone; |
|
439 } |
|
440 |