author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 16 Apr 2010 16:24:37 +0300 | |
changeset 90 | 947f0dc9f7a8 |
parent 0 | a41df078684a |
child 293 | 0659d0e1a03c |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2002-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\dma\dmasim.cpp |
|
15 |
// DMA framework Platform Specific Layer (PSL) for software-emulated |
|
16 |
// DMA controller used for testing the DMA framework PIL. |
|
17 |
// |
|
18 |
// |
|
19 |
||
20 |
#include <drivers/dma.h> |
|
21 |
#include <kernel/kern_priv.h> |
|
22 |
||
23 |
||
24 |
const char KDmaPanicCat[] = "DMASIM"; |
|
25 |
||
26 |
const TInt KMaxTransferSize = 0x1FFF; |
|
27 |
const TInt KMemAlignMask = 3; // memory addresses passed to DMAC must be multiple of 4 |
|
28 |
const TInt KBurstSize = 0x800; |
|
29 |
||
30 |
typedef void (*TPseudoIsr)(); |
|
31 |
||
32 |
const TInt KChannelCount = 4; // # of channels per controller |
|
33 |
const TInt KDesCount = 256; // # of descriptors allocated per controller |
|
34 |
||
35 |
////////////////////////////////////////////////////////////////////////////// |
|
36 |
// SOFTWARE DMA CONTROLLER SIMULATION |
|
37 |
////////////////////////////////////////////////////////////////////////////// |
|
38 |
||
39 |
class DmacSb |
|
40 |
/** Single-buffer DMA controller software simulation */ |
|
41 |
{ |
|
42 |
public: |
|
43 |
enum { ECsRun = 0x80000000 }; |
|
44 |
public: |
|
45 |
static void DoTransfer(); |
|
46 |
private: |
|
47 |
static void BurstTransfer(); |
|
48 |
private: |
|
49 |
static TInt CurrentChannel; |
|
50 |
public: |
|
51 |
// pseudo registers |
|
52 |
static TUint8* SrcAddr[KChannelCount]; |
|
53 |
static TUint8* DestAddr[KChannelCount]; |
|
54 |
static TInt Count[KChannelCount]; |
|
55 |
static TUint32 ControlStatus[KChannelCount]; |
|
56 |
static TUint32 CompletionInt; |
|
57 |
static TUint32 ErrorInt; |
|
58 |
// hook for pseudo ISR |
|
59 |
static TPseudoIsr Isr; |
|
60 |
// transfer failure simulation |
|
61 |
static TInt FailCount[KChannelCount]; |
|
62 |
}; |
|
63 |
||
64 |
TUint8* DmacSb::SrcAddr[KChannelCount]; |
|
65 |
TUint8* DmacSb::DestAddr[KChannelCount]; |
|
66 |
TInt DmacSb::Count[KChannelCount]; |
|
67 |
TUint32 DmacSb::ControlStatus[KChannelCount]; |
|
68 |
TUint32 DmacSb::CompletionInt; |
|
69 |
TUint32 DmacSb::ErrorInt; |
|
70 |
TPseudoIsr DmacSb::Isr; |
|
71 |
TInt DmacSb::FailCount[KChannelCount]; |
|
72 |
TInt DmacSb::CurrentChannel; |
|
73 |
||
74 |
void DmacSb::DoTransfer() |
|
75 |
{ |
|
76 |
if (ControlStatus[CurrentChannel] & ECsRun) |
|
77 |
{ |
|
78 |
if (FailCount[CurrentChannel] > 0 && --FailCount[CurrentChannel] == 0) |
|
79 |
{ |
|
80 |
ControlStatus[CurrentChannel] &= ~ECsRun; |
|
81 |
ErrorInt |= 1 << CurrentChannel; |
|
82 |
Isr(); |
|
83 |
} |
|
84 |
else |
|
85 |
{ |
|
86 |
//__KTRACE_OPT(KDMA, Kern::Printf("DmacSb::DoTransfer channel %d", CurrentChannel)); |
|
87 |
if (Count[CurrentChannel] == 0) |
|
88 |
{ |
|
89 |
//__KTRACE_OPT(KDMA, Kern::Printf("DmacSb::DoTransfer transfer complete")); |
|
90 |
ControlStatus[CurrentChannel] &= ~ECsRun; |
|
91 |
CompletionInt |= 1 << CurrentChannel; |
|
92 |
Isr(); |
|
93 |
} |
|
94 |
else |
|
95 |
BurstTransfer(); |
|
96 |
} |
|
97 |
} |
|
98 |
||
99 |
CurrentChannel++; |
|
100 |
if (CurrentChannel >= KChannelCount) |
|
101 |
CurrentChannel = 0; |
|
102 |
} |
|
103 |
||
104 |
void DmacSb::BurstTransfer() |
|
105 |
{ |
|
106 |
//__KTRACE_OPT(KDMA, Kern::Printf("DmacSb::BurstTransfer")); |
|
107 |
TInt s = Min(Count[CurrentChannel], KBurstSize); |
|
108 |
memcpy(DestAddr[CurrentChannel], SrcAddr[CurrentChannel], s); |
|
109 |
Count[CurrentChannel] -= s; |
|
110 |
SrcAddr[CurrentChannel] += s; |
|
111 |
DestAddr[CurrentChannel] += s; |
|
112 |
} |
|
113 |
||
114 |
////////////////////////////////////////////////////////////////////////////// |
|
115 |
||
116 |
class DmacDb |
|
117 |
/** Double-buffer DMA controller software simulation */ |
|
118 |
{ |
|
119 |
public: |
|
120 |
enum { ECsRun = 0x80000000, ECsPrg = 0x40000000 }; |
|
121 |
public: |
|
122 |
static void Enable(TInt aIdx); |
|
123 |
static void DoTransfer(); |
|
124 |
private: |
|
125 |
static TInt CurrentChannel; |
|
126 |
private: |
|
127 |
// internal pseudo-registers |
|
128 |
static TUint8* ActSrcAddr[KChannelCount]; |
|
129 |
static TUint8* ActDestAddr[KChannelCount]; |
|
130 |
static TInt ActCount[KChannelCount]; |
|
131 |
public: |
|
132 |
// externally accessible pseudo-registers |
|
133 |
static TUint32 ControlStatus[KChannelCount]; |
|
134 |
static TUint8* PrgSrcAddr[KChannelCount]; |
|
135 |
static TUint8* PrgDestAddr[KChannelCount]; |
|
136 |
static TInt PrgCount[KChannelCount]; |
|
137 |
static TUint32 CompletionInt; |
|
138 |
static TUint32 ErrorInt; |
|
139 |
// hook for pseudo ISR |
|
140 |
static TPseudoIsr Isr; |
|
141 |
// transfer failure simulation |
|
142 |
static TInt FailCount[KChannelCount]; |
|
143 |
static TInt InterruptsToMiss[KChannelCount]; |
|
144 |
}; |
|
145 |
||
146 |
TUint8* DmacDb::PrgSrcAddr[KChannelCount]; |
|
147 |
TUint8* DmacDb::PrgDestAddr[KChannelCount]; |
|
148 |
TInt DmacDb::PrgCount[KChannelCount]; |
|
149 |
TUint8* DmacDb::ActSrcAddr[KChannelCount]; |
|
150 |
TUint8* DmacDb::ActDestAddr[KChannelCount]; |
|
151 |
TInt DmacDb::ActCount[KChannelCount]; |
|
152 |
TUint32 DmacDb::ControlStatus[KChannelCount]; |
|
153 |
TUint32 DmacDb::CompletionInt; |
|
154 |
TUint32 DmacDb::ErrorInt; |
|
155 |
TPseudoIsr DmacDb::Isr; |
|
156 |
TInt DmacDb::FailCount[KChannelCount]; |
|
157 |
TInt DmacDb::InterruptsToMiss[KChannelCount]; |
|
158 |
TInt DmacDb::CurrentChannel; |
|
159 |
||
160 |
void DmacDb::Enable(TInt aIdx) |
|
161 |
{ |
|
162 |
if (ControlStatus[aIdx] & ECsRun) |
|
163 |
ControlStatus[aIdx] |= ECsPrg; |
|
164 |
else |
|
165 |
{ |
|
166 |
ActSrcAddr[aIdx] = PrgSrcAddr[aIdx]; |
|
167 |
ActDestAddr[aIdx] = PrgDestAddr[aIdx]; |
|
168 |
ActCount[aIdx] = PrgCount[aIdx]; |
|
169 |
ControlStatus[aIdx] |= ECsRun; |
|
170 |
} |
|
171 |
} |
|
172 |
||
173 |
void DmacDb::DoTransfer() |
|
174 |
{ |
|
175 |
if (ControlStatus[CurrentChannel] & ECsRun) |
|
176 |
{ |
|
177 |
if (FailCount[CurrentChannel] > 0 && --FailCount[CurrentChannel] == 0) |
|
178 |
{ |
|
179 |
ControlStatus[CurrentChannel] &= ~ECsRun; |
|
180 |
ErrorInt |= 1 << CurrentChannel; |
|
181 |
Isr(); |
|
182 |
} |
|
183 |
else |
|
184 |
{ |
|
185 |
if (ActCount[CurrentChannel] == 0) |
|
186 |
{ |
|
187 |
if (ControlStatus[CurrentChannel] & ECsPrg) |
|
188 |
{ |
|
189 |
ActSrcAddr[CurrentChannel] = PrgSrcAddr[CurrentChannel]; |
|
190 |
ActDestAddr[CurrentChannel] = PrgDestAddr[CurrentChannel]; |
|
191 |
ActCount[CurrentChannel] = PrgCount[CurrentChannel]; |
|
192 |
ControlStatus[CurrentChannel] &= ~ECsPrg; |
|
193 |
} |
|
194 |
else |
|
195 |
ControlStatus[CurrentChannel] &= ~ECsRun; |
|
196 |
if (InterruptsToMiss[CurrentChannel] > 0) |
|
197 |
InterruptsToMiss[CurrentChannel]--; |
|
198 |
else |
|
199 |
{ |
|
200 |
CompletionInt |= 1 << CurrentChannel; |
|
201 |
Isr(); |
|
202 |
} |
|
203 |
} |
|
204 |
else |
|
205 |
{ |
|
206 |
TInt s = Min(ActCount[CurrentChannel], KBurstSize); |
|
207 |
memcpy(ActDestAddr[CurrentChannel], ActSrcAddr[CurrentChannel], s); |
|
208 |
ActCount[CurrentChannel] -= s; |
|
209 |
ActSrcAddr[CurrentChannel] += s; |
|
210 |
ActDestAddr[CurrentChannel] += s; |
|
211 |
} |
|
212 |
} |
|
213 |
} |
|
214 |
||
215 |
CurrentChannel++; |
|
216 |
if (CurrentChannel >= KChannelCount) |
|
217 |
CurrentChannel = 0; |
|
218 |
} |
|
219 |
||
220 |
||
221 |
////////////////////////////////////////////////////////////////////////////// |
|
222 |
||
223 |
class DmacSg |
|
224 |
/** Scatter/gather DMA controller software simulation */ |
|
225 |
{ |
|
226 |
public: |
|
227 |
enum { EChannelBitRun = 0x80000000 }; |
|
228 |
enum { EDesBitInt = 1 }; |
|
229 |
struct SDes |
|
230 |
{ |
|
231 |
TUint8* iSrcAddr; |
|
232 |
TUint8* iDestAddr; |
|
233 |
TInt iCount; |
|
234 |
TUint iControl; |
|
235 |
SDes* iNext; |
|
236 |
}; |
|
237 |
public: |
|
238 |
static void DoTransfer(); |
|
239 |
static void Enable(TInt aIdx); |
|
240 |
private: |
|
241 |
static TInt CurrentChannel; |
|
242 |
static TBool IsDescriptorLoaded[KChannelCount]; |
|
243 |
public: |
|
244 |
// externally accessible pseudo-registers |
|
245 |
static TUint32 ChannelControl[KChannelCount]; |
|
246 |
static TUint8* SrcAddr[KChannelCount]; |
|
247 |
static TUint8* DestAddr[KChannelCount]; |
|
248 |
static TInt Count[KChannelCount]; |
|
249 |
static TUint Control[KChannelCount]; |
|
250 |
static SDes* NextDes[KChannelCount]; |
|
251 |
static TUint32 CompletionInt; |
|
252 |
static TUint32 ErrorInt; |
|
253 |
// hook for pseudo ISR |
|
254 |
static TPseudoIsr Isr; |
|
255 |
// transfer failure simulation |
|
256 |
static TInt FailCount[KChannelCount]; |
|
257 |
static TInt InterruptsToMiss[KChannelCount]; |
|
258 |
}; |
|
259 |
||
260 |
TUint32 DmacSg::ChannelControl[KChannelCount]; |
|
261 |
TUint8* DmacSg::SrcAddr[KChannelCount]; |
|
262 |
TUint8* DmacSg::DestAddr[KChannelCount]; |
|
263 |
TInt DmacSg::Count[KChannelCount]; |
|
264 |
TUint DmacSg::Control[KChannelCount]; |
|
265 |
DmacSg::SDes* DmacSg::NextDes[KChannelCount]; |
|
266 |
TUint32 DmacSg::CompletionInt; |
|
267 |
TUint32 DmacSg::ErrorInt; |
|
268 |
TPseudoIsr DmacSg::Isr; |
|
269 |
TInt DmacSg::FailCount[KChannelCount]; |
|
270 |
TInt DmacSg::InterruptsToMiss[KChannelCount]; |
|
271 |
TInt DmacSg::CurrentChannel; |
|
272 |
TBool DmacSg::IsDescriptorLoaded[KChannelCount]; |
|
273 |
||
274 |
||
275 |
void DmacSg::DoTransfer() |
|
276 |
{ |
|
277 |
if (ChannelControl[CurrentChannel] & EChannelBitRun) |
|
278 |
{ |
|
279 |
if (FailCount[CurrentChannel] > 0 && --FailCount[CurrentChannel] == 0) |
|
280 |
{ |
|
281 |
ChannelControl[CurrentChannel] &= ~EChannelBitRun; |
|
282 |
ErrorInt |= 1 << CurrentChannel; |
|
283 |
Isr(); |
|
284 |
} |
|
285 |
else |
|
286 |
{ |
|
287 |
if (IsDescriptorLoaded[CurrentChannel]) |
|
288 |
{ |
|
289 |
if (Count[CurrentChannel] == 0) |
|
290 |
{ |
|
291 |
IsDescriptorLoaded[CurrentChannel] = EFalse; |
|
292 |
if (Control[CurrentChannel] & EDesBitInt) |
|
293 |
{ |
|
294 |
if (InterruptsToMiss[CurrentChannel] > 0) |
|
295 |
InterruptsToMiss[CurrentChannel]--; |
|
296 |
else |
|
297 |
{ |
|
298 |
CompletionInt |= 1 << CurrentChannel; |
|
299 |
Isr(); |
|
300 |
} |
|
301 |
} |
|
302 |
} |
|
303 |
else |
|
304 |
{ |
|
305 |
TInt s = Min(Count[CurrentChannel], KBurstSize); |
|
306 |
memcpy(DestAddr[CurrentChannel], SrcAddr[CurrentChannel], s); |
|
307 |
Count[CurrentChannel] -= s; |
|
308 |
SrcAddr[CurrentChannel] += s; |
|
309 |
DestAddr[CurrentChannel] += s; |
|
310 |
} |
|
311 |
} |
|
312 |
// Need to test again as new descriptor must be loaded if |
|
313 |
// completion has just occured. |
|
314 |
if (! IsDescriptorLoaded[CurrentChannel]) |
|
315 |
{ |
|
316 |
if (NextDes[CurrentChannel] != NULL) |
|
317 |
{ |
|
318 |
SrcAddr[CurrentChannel] = NextDes[CurrentChannel]->iSrcAddr; |
|
319 |
DestAddr[CurrentChannel] = NextDes[CurrentChannel]->iDestAddr; |
|
320 |
Count[CurrentChannel] = NextDes[CurrentChannel]->iCount; |
|
321 |
Control[CurrentChannel] = NextDes[CurrentChannel]->iControl; |
|
322 |
NextDes[CurrentChannel] = NextDes[CurrentChannel]->iNext; |
|
323 |
IsDescriptorLoaded[CurrentChannel] = ETrue; |
|
324 |
} |
|
325 |
else |
|
326 |
ChannelControl[CurrentChannel] &= ~EChannelBitRun; |
|
327 |
} |
|
328 |
} |
|
329 |
} |
|
330 |
||
331 |
CurrentChannel++; |
|
332 |
if (CurrentChannel >= KChannelCount) |
|
333 |
CurrentChannel = 0; |
|
334 |
} |
|
335 |
||
336 |
||
337 |
void DmacSg::Enable(TInt aIdx) |
|
338 |
{ |
|
339 |
SrcAddr[aIdx] = NextDes[aIdx]->iSrcAddr; |
|
340 |
DestAddr[aIdx] = NextDes[aIdx]->iDestAddr; |
|
341 |
Count[aIdx] = NextDes[aIdx]->iCount; |
|
342 |
Control[aIdx] = NextDes[aIdx]->iControl; |
|
343 |
NextDes[aIdx] = NextDes[aIdx]->iNext; |
|
344 |
IsDescriptorLoaded[aIdx] = ETrue; |
|
345 |
ChannelControl[aIdx] |= EChannelBitRun; |
|
346 |
} |
|
347 |
||
348 |
////////////////////////////////////////////////////////////////////////////// |
|
349 |
||
350 |
class DmacSim |
|
351 |
/** |
|
352 |
Harness calling the various DMA controller simulators periodically. |
|
353 |
*/ |
|
354 |
{ |
|
355 |
public: |
|
356 |
static void StartEmulation(); |
|
357 |
static void StopEmulation(); |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
358 |
static TBool InISR(); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
359 |
static void Synchronize(); |
0 | 360 |
private: |
361 |
enum { KPeriod = 1 }; // in ms |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
362 |
enum { EDmaSimIdle=0u, EDmaSimStarted=1u, EDmaSimInISR=2u, EDmaSimStopping=0x80000000u }; |
0 | 363 |
static void TickCB(TAny* aThis); |
364 |
static NTimer Timer; |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
365 |
static volatile TInt StartStop; |
0 | 366 |
}; |
367 |
||
368 |
NTimer DmacSim::Timer; |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
369 |
volatile TInt DmacSim::StartStop; |
0 | 370 |
|
371 |
void DmacSim::StartEmulation() |
|
372 |
{ |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
373 |
__DMA_ASSERTA(StartStop==EDmaSimIdle); |
0 | 374 |
new (&Timer) NTimer(&TickCB, 0); |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
375 |
__e32_atomic_store_ord32(&StartStop, EDmaSimStarted); |
0 | 376 |
__DMA_ASSERTA(Timer.OneShot(KPeriod, EFalse) == KErrNone); |
377 |
} |
|
378 |
||
379 |
void DmacSim::StopEmulation() |
|
380 |
{ |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
381 |
TInt orig = __e32_atomic_tas_ord32(&StartStop, (TInt)EDmaSimStarted, (TInt)EDmaSimStopping, 0); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
382 |
if (orig == EDmaSimIdle) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
383 |
return; // wasn't running |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
384 |
// loop until we succeed in cancelling the timer or the timer callback |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
385 |
// notices that we are shutting down |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
386 |
while (!Timer.Cancel() && __e32_atomic_load_acq32(&StartStop)!=EDmaSimIdle) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
387 |
{} |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
388 |
__e32_atomic_store_ord32(&StartStop, EDmaSimIdle); |
0 | 389 |
} |
390 |
||
391 |
void DmacSim::TickCB(TAny*) |
|
392 |
{ |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
393 |
TInt orig = (TInt)__e32_atomic_ior_acq32(&StartStop, EDmaSimInISR); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
394 |
if (orig >= 0) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
395 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
396 |
DmacSb::DoTransfer(); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
397 |
DmacDb::DoTransfer(); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
398 |
DmacSg::DoTransfer(); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
399 |
} |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
400 |
orig = (TInt)__e32_atomic_and_rel32(&StartStop, (TUint32)~EDmaSimInISR); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
401 |
if (orig < 0) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
402 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
403 |
__e32_atomic_store_rel32(&StartStop, EDmaSimIdle); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
404 |
return; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
405 |
} |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
406 |
TInt r = Timer.Again(KPeriod); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
407 |
if (r == KErrArgument) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
408 |
r = Timer.OneShot(KPeriod); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
409 |
__DMA_ASSERTA(r == KErrNone); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
410 |
} |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
411 |
|
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
412 |
TBool DmacSim::InISR() |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
413 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
414 |
return __e32_atomic_load_acq32(&StartStop) & EDmaSimInISR; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
415 |
} |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
416 |
|
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
417 |
void DmacSim::Synchronize() |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
418 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
419 |
while (InISR()) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
420 |
{} |
0 | 421 |
} |
422 |
||
423 |
////////////////////////////////////////////////////////////////////////////// |
|
424 |
// PSL FOR DMA SIMULATION |
|
425 |
////////////////////////////////////////////////////////////////////////////// |
|
426 |
||
427 |
class DSimSbController : public TDmac |
|
428 |
{ |
|
429 |
public: |
|
430 |
DSimSbController(); |
|
431 |
private: |
|
432 |
static void Isr(); |
|
433 |
// from TDmac |
|
434 |
virtual void Transfer(const TDmaChannel& aChannel, const SDmaDesHdr& aHdr); |
|
435 |
virtual void StopTransfer(const TDmaChannel& aChannel); |
|
436 |
virtual TInt FailNext(const TDmaChannel& aChannel); |
|
437 |
virtual TBool IsIdle(const TDmaChannel& aChannel); |
|
438 |
virtual TInt MaxTransferSize(TDmaChannel& aChannel, TUint aFlags, TUint32 aPslInfo); |
|
439 |
virtual TUint MemAlignMask(TDmaChannel& aChannel, TUint aFlags, TUint32 aPslInfo); |
|
440 |
public: |
|
441 |
static const SCreateInfo KInfo; |
|
442 |
TDmaSbChannel iChannels[KChannelCount]; |
|
443 |
}; |
|
444 |
||
445 |
DSimSbController SbController; |
|
446 |
||
447 |
const TDmac::SCreateInfo DSimSbController::KInfo = |
|
448 |
{ |
|
449 |
KChannelCount, |
|
450 |
KDesCount, |
|
451 |
0, |
|
452 |
sizeof(SDmaPseudoDes), |
|
453 |
0, |
|
454 |
}; |
|
455 |
||
456 |
DSimSbController::DSimSbController() |
|
457 |
: TDmac(KInfo) |
|
458 |
{ |
|
459 |
DmacSb::Isr = Isr; |
|
460 |
} |
|
461 |
||
462 |
||
463 |
void DSimSbController::Transfer(const TDmaChannel& aChannel, const SDmaDesHdr& aHdr) |
|
464 |
{ |
|
465 |
TUint32 i = aChannel.PslId(); |
|
466 |
const SDmaPseudoDes& des = HdrToDes(aHdr); |
|
467 |
DmacSb::SrcAddr[i] = (TUint8*) des.iSrc; |
|
468 |
DmacSb::DestAddr[i] = (TUint8*) des.iDest; |
|
469 |
DmacSb::Count[i] = des.iCount; |
|
470 |
DmacSb::ControlStatus[i] |= DmacSb::ECsRun; |
|
471 |
} |
|
472 |
||
473 |
||
474 |
void DSimSbController::StopTransfer(const TDmaChannel& aChannel) |
|
475 |
{ |
|
476 |
__e32_atomic_and_ord32(&DmacSb::ControlStatus[aChannel.PslId()], (TUint32)~DmacSb::ECsRun); |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
477 |
DmacSim::Synchronize(); |
0 | 478 |
} |
479 |
||
480 |
||
481 |
TInt DSimSbController::FailNext(const TDmaChannel& aChannel) |
|
482 |
{ |
|
483 |
DmacSb::FailCount[aChannel.PslId()] = 1; |
|
484 |
return KErrNone; |
|
485 |
} |
|
486 |
||
487 |
||
488 |
TBool DSimSbController::IsIdle(const TDmaChannel& aChannel) |
|
489 |
{ |
|
490 |
return (DmacSb::ControlStatus[aChannel.PslId()] & DmacSb::ECsRun) == 0; |
|
491 |
} |
|
492 |
||
493 |
||
494 |
TInt DSimSbController::MaxTransferSize(TDmaChannel& /*aChannel*/, TUint /*aFlags*/, TUint32 /*aPslInfo*/) |
|
495 |
{ |
|
496 |
return KMaxTransferSize; |
|
497 |
} |
|
498 |
||
499 |
||
500 |
TUint DSimSbController::MemAlignMask(TDmaChannel& /*aChannel*/, TUint /*aFlags*/, TUint32 /*aPslInfo*/) |
|
501 |
{ |
|
502 |
return KMemAlignMask; |
|
503 |
} |
|
504 |
||
505 |
||
506 |
void DSimSbController::Isr() |
|
507 |
{ |
|
508 |
for (TInt i = 0; i < KChannelCount; i++) |
|
509 |
{ |
|
510 |
TUint32 mask = (1 << i); |
|
511 |
if (DmacSb::CompletionInt & mask) |
|
512 |
{ |
|
513 |
DmacSb::CompletionInt &= ~mask; |
|
514 |
HandleIsr(SbController.iChannels[i], ETrue); |
|
515 |
} |
|
516 |
if (DmacSb::ErrorInt & mask) |
|
517 |
{ |
|
518 |
DmacSb::ErrorInt &= ~mask; |
|
519 |
HandleIsr(SbController.iChannels[i], EFalse); |
|
520 |
} |
|
521 |
} |
|
522 |
} |
|
523 |
||
524 |
////////////////////////////////////////////////////////////////////////////// |
|
525 |
||
526 |
class DSimDbController : public TDmac |
|
527 |
{ |
|
528 |
public: |
|
529 |
DSimDbController(); |
|
530 |
private: |
|
531 |
static void Isr(); |
|
532 |
// from TDmac |
|
533 |
virtual void Transfer(const TDmaChannel& aChannel, const SDmaDesHdr& aHdr); |
|
534 |
virtual void StopTransfer(const TDmaChannel& aChannel); |
|
535 |
virtual TInt FailNext(const TDmaChannel& aChannel); |
|
536 |
virtual TInt MissNextInterrupts(const TDmaChannel& aChannel, TInt aInterruptCount); |
|
537 |
virtual TBool IsIdle(const TDmaChannel& aChannel); |
|
538 |
virtual TInt MaxTransferSize(TDmaChannel& aChannel, TUint aFlags, TUint32 aPslInfo); |
|
539 |
virtual TUint MemAlignMask(TDmaChannel& aChannel, TUint aFlags, TUint32 aPslInfo); |
|
540 |
public: |
|
541 |
static const SCreateInfo KInfo; |
|
542 |
TDmaDbChannel iChannels[KChannelCount]; |
|
543 |
}; |
|
544 |
||
545 |
DSimDbController DbController; |
|
546 |
||
547 |
const TDmac::SCreateInfo DSimDbController::KInfo = |
|
548 |
{ |
|
549 |
KChannelCount, |
|
550 |
KDesCount, |
|
551 |
0, |
|
552 |
sizeof(SDmaPseudoDes), |
|
553 |
0, |
|
554 |
}; |
|
555 |
||
556 |
||
557 |
DSimDbController::DSimDbController() |
|
558 |
: TDmac(KInfo) |
|
559 |
{ |
|
560 |
DmacDb::Isr = Isr; |
|
561 |
} |
|
562 |
||
563 |
||
564 |
void DSimDbController::Transfer(const TDmaChannel& aChannel, const SDmaDesHdr& aHdr) |
|
565 |
{ |
|
566 |
TUint32 i = aChannel.PslId(); |
|
567 |
const SDmaPseudoDes& des = HdrToDes(aHdr); |
|
568 |
DmacDb::PrgSrcAddr[i] = (TUint8*) des.iSrc; |
|
569 |
DmacDb::PrgDestAddr[i] = (TUint8*) des.iDest; |
|
570 |
DmacDb::PrgCount[i] = des.iCount; |
|
571 |
DmacDb::Enable(i); |
|
572 |
} |
|
573 |
||
574 |
||
575 |
void DSimDbController::StopTransfer(const TDmaChannel& aChannel) |
|
576 |
{ |
|
577 |
__e32_atomic_and_ord32(&DmacDb::ControlStatus[aChannel.PslId()], (TUint32)~(DmacDb::ECsRun|DmacDb::ECsPrg)); |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
578 |
DmacSim::Synchronize(); |
0 | 579 |
} |
580 |
||
581 |
||
582 |
TInt DSimDbController::FailNext(const TDmaChannel& aChannel) |
|
583 |
{ |
|
584 |
DmacDb::FailCount[aChannel.PslId()] = 1; |
|
585 |
return KErrNone; |
|
586 |
} |
|
587 |
||
588 |
||
589 |
TInt DSimDbController::MissNextInterrupts(const TDmaChannel& aChannel, TInt aInterruptCount) |
|
590 |
{ |
|
591 |
__DMA_ASSERTD((DmacDb::ControlStatus[aChannel.PslId()] & DmacDb::ECsRun) == 0); |
|
592 |
__DMA_ASSERTD(aInterruptCount >= 0); |
|
593 |
// At most one interrupt can be missed with double-buffer controller |
|
594 |
if (aInterruptCount == 1) |
|
595 |
{ |
|
596 |
DmacDb::InterruptsToMiss[aChannel.PslId()] = aInterruptCount; |
|
597 |
return KErrNone; |
|
598 |
} |
|
599 |
else |
|
600 |
return KErrNotSupported; |
|
601 |
} |
|
602 |
||
603 |
||
604 |
TBool DSimDbController::IsIdle(const TDmaChannel& aChannel) |
|
605 |
{ |
|
606 |
return (DmacDb::ControlStatus[aChannel.PslId()] & DmacDb::ECsRun) == 0; |
|
607 |
} |
|
608 |
||
609 |
||
610 |
TInt DSimDbController::MaxTransferSize(TDmaChannel& /*aChannel*/, TUint /*aFlags*/, TUint32 /*aPslInfo*/) |
|
611 |
{ |
|
612 |
return KMaxTransferSize; |
|
613 |
} |
|
614 |
||
615 |
||
616 |
TUint DSimDbController::MemAlignMask(TDmaChannel& /*aChannel*/, TUint /*aFlags*/, TUint32 /*aPslInfo*/) |
|
617 |
{ |
|
618 |
return KMemAlignMask; |
|
619 |
} |
|
620 |
||
621 |
||
622 |
void DSimDbController::Isr() |
|
623 |
{ |
|
624 |
for (TInt i = 0; i < KChannelCount; i++) |
|
625 |
{ |
|
626 |
TUint32 mask = (1 << i); |
|
627 |
if (DmacDb::CompletionInt & mask) |
|
628 |
{ |
|
629 |
DmacDb::CompletionInt &= ~mask; |
|
630 |
HandleIsr(DbController.iChannels[i], ETrue); |
|
631 |
} |
|
632 |
if (DmacDb::ErrorInt & mask) |
|
633 |
{ |
|
634 |
DmacDb::ErrorInt &= ~mask; |
|
635 |
HandleIsr(DbController.iChannels[i], EFalse); |
|
636 |
} |
|
637 |
} |
|
638 |
} |
|
639 |
||
640 |
////////////////////////////////////////////////////////////////////////////// |
|
641 |
||
642 |
class DSimSgController : public TDmac |
|
643 |
{ |
|
644 |
public: |
|
645 |
DSimSgController(); |
|
646 |
private: |
|
647 |
static void Isr(); |
|
648 |
// from TDmac |
|
649 |
virtual void Transfer(const TDmaChannel& aChannel, const SDmaDesHdr& aHdr); |
|
650 |
virtual void StopTransfer(const TDmaChannel& aChannel); |
|
651 |
virtual TBool IsIdle(const TDmaChannel& aChannel); |
|
652 |
virtual TInt MaxTransferSize(TDmaChannel& aChannel, TUint aFlags, TUint32 aPslInfo); |
|
653 |
virtual TUint MemAlignMask(TDmaChannel& aChannel, TUint aFlags, TUint32 aPslInfo); |
|
654 |
virtual void InitHwDes(const SDmaDesHdr& aHdr, TUint32 aSrc, TUint32 aDest, TInt aCount, |
|
655 |
TUint aFlags, TUint32 aPslInfo, TUint32 aCookie); |
|
656 |
virtual void ChainHwDes(const SDmaDesHdr& aHdr, const SDmaDesHdr& aNextHdr); |
|
657 |
virtual void AppendHwDes(const TDmaChannel& aChannel, const SDmaDesHdr& aLastHdr, |
|
658 |
const SDmaDesHdr& aNewHdr); |
|
659 |
virtual void UnlinkHwDes(const TDmaChannel& aChannel, SDmaDesHdr& aHdr); |
|
660 |
virtual TInt FailNext(const TDmaChannel& aChannel); |
|
661 |
virtual TInt MissNextInterrupts(const TDmaChannel& aChannel, TInt aInterruptCount); |
|
662 |
private: |
|
663 |
inline DmacSg::SDes* HdrToHwDes(const SDmaDesHdr& aHdr); |
|
664 |
public: |
|
665 |
static const SCreateInfo KInfo; |
|
666 |
TDmaSgChannel iChannels[KChannelCount]; |
|
667 |
}; |
|
668 |
||
669 |
DSimSgController SgController; |
|
670 |
||
671 |
const TDmac::SCreateInfo DSimSgController::KInfo = |
|
672 |
{ |
|
673 |
KChannelCount, |
|
674 |
KDesCount, |
|
675 |
KCapsBitHwDes, |
|
676 |
sizeof(DmacSg::SDes), |
|
677 |
#ifdef __WINS__ |
|
678 |
0, |
|
679 |
#else |
|
680 |
EMapAttrSupRw|EMapAttrFullyBlocking, |
|
681 |
#endif |
|
682 |
}; |
|
683 |
||
684 |
||
685 |
inline DmacSg::SDes* DSimSgController::HdrToHwDes(const SDmaDesHdr& aHdr) |
|
686 |
{ |
|
687 |
return static_cast<DmacSg::SDes*>(TDmac::HdrToHwDes(aHdr)); |
|
688 |
} |
|
689 |
||
690 |
||
691 |
DSimSgController::DSimSgController() |
|
692 |
: TDmac(KInfo) |
|
693 |
{ |
|
694 |
DmacSg::Isr = Isr; |
|
695 |
} |
|
696 |
||
697 |
||
698 |
void DSimSgController::Transfer(const TDmaChannel& aChannel, const SDmaDesHdr& aHdr) |
|
699 |
{ |
|
700 |
TUint32 i = aChannel.PslId(); |
|
701 |
DmacSg::NextDes[i] = HdrToHwDes(aHdr); |
|
702 |
DmacSg::Enable(i); |
|
703 |
} |
|
704 |
||
705 |
||
706 |
void DSimSgController::StopTransfer(const TDmaChannel& aChannel) |
|
707 |
{ |
|
708 |
__e32_atomic_and_ord32(&DmacSg::ChannelControl[aChannel.PslId()], (TUint32)~DmacSg::EChannelBitRun); |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
709 |
DmacSim::Synchronize(); |
0 | 710 |
} |
711 |
||
712 |
||
713 |
void DSimSgController::InitHwDes(const SDmaDesHdr& aHdr, TUint32 aSrc, TUint32 aDest, TInt aCount, |
|
714 |
TUint /*aFlags*/, TUint32 /*aPslInfo*/, TUint32 /*aCookie*/) |
|
715 |
{ |
|
716 |
DmacSg::SDes& des = *HdrToHwDes(aHdr); |
|
717 |
des.iSrcAddr = reinterpret_cast<TUint8*>(aSrc); |
|
718 |
des.iDestAddr = reinterpret_cast<TUint8*>(aDest); |
|
719 |
des.iCount = static_cast<TInt16>(aCount); |
|
720 |
des.iControl |= DmacSg::EDesBitInt; |
|
721 |
des.iNext = NULL; |
|
722 |
} |
|
723 |
||
724 |
||
725 |
void DSimSgController::ChainHwDes(const SDmaDesHdr& aHdr, const SDmaDesHdr& aNextHdr) |
|
726 |
{ |
|
727 |
DmacSg::SDes& des = *HdrToHwDes(aHdr); |
|
728 |
des.iControl &= ~DmacSg::EDesBitInt; |
|
729 |
des.iNext = HdrToHwDes(aNextHdr); |
|
730 |
} |
|
731 |
||
732 |
||
733 |
void DSimSgController::AppendHwDes(const TDmaChannel& aChannel, const SDmaDesHdr& aLastHdr, |
|
734 |
const SDmaDesHdr& aNewHdr) |
|
735 |
{ |
|
736 |
TUint32 i = aChannel.PslId(); |
|
737 |
DmacSg::SDes* pNewDes = HdrToHwDes(aNewHdr); |
|
738 |
TInt prevLevel = NKern::DisableAllInterrupts(); |
|
739 |
||
740 |
if ((DmacSg::ChannelControl[i] & DmacSg::EChannelBitRun) == 0) |
|
741 |
{ |
|
742 |
DmacSg::NextDes[i] = pNewDes; |
|
743 |
DmacSg::Enable(i); |
|
744 |
} |
|
745 |
else if (DmacSg::NextDes[i] == NULL) |
|
746 |
DmacSg::NextDes[i] = pNewDes; |
|
747 |
else |
|
748 |
HdrToHwDes(aLastHdr)->iNext = pNewDes; |
|
749 |
||
750 |
NKern::RestoreInterrupts(prevLevel); |
|
751 |
} |
|
752 |
||
753 |
||
754 |
void DSimSgController::UnlinkHwDes(const TDmaChannel& /*aChannel*/, SDmaDesHdr& aHdr) |
|
755 |
{ |
|
756 |
DmacSg::SDes* pD = HdrToHwDes(aHdr); |
|
757 |
pD->iNext = NULL; |
|
758 |
pD->iControl |= DmacSg::EDesBitInt; |
|
759 |
} |
|
760 |
||
761 |
||
762 |
TInt DSimSgController::FailNext(const TDmaChannel& aChannel) |
|
763 |
{ |
|
764 |
__DMA_ASSERTD((DmacSg::ChannelControl[aChannel.PslId()] & DmacSg::EChannelBitRun) == 0); |
|
765 |
DmacSg::FailCount[aChannel.PslId()] = 1; |
|
766 |
return KErrNone; |
|
767 |
} |
|
768 |
||
769 |
||
770 |
TInt DSimSgController::MissNextInterrupts(const TDmaChannel& aChannel, TInt aInterruptCount) |
|
771 |
{ |
|
772 |
__DMA_ASSERTD((DmacSg::ChannelControl[aChannel.PslId()] & DmacSg::EChannelBitRun) == 0); |
|
773 |
__DMA_ASSERTD(aInterruptCount >= 0); |
|
774 |
DmacSg::InterruptsToMiss[aChannel.PslId()] = aInterruptCount; |
|
775 |
return KErrNone; |
|
776 |
} |
|
777 |
||
778 |
||
779 |
TBool DSimSgController::IsIdle(const TDmaChannel& aChannel) |
|
780 |
{ |
|
781 |
return (DmacSg::ChannelControl[aChannel.PslId()] & DmacSg::EChannelBitRun) == 0; |
|
782 |
} |
|
783 |
||
784 |
||
785 |
TInt DSimSgController::MaxTransferSize(TDmaChannel& /*aChannel*/, TUint /*aFlags*/, TUint32 /*aPslInfo*/) |
|
786 |
{ |
|
787 |
return KMaxTransferSize; |
|
788 |
} |
|
789 |
||
790 |
||
791 |
TUint DSimSgController::MemAlignMask(TDmaChannel& /*aChannel*/, TUint /*aFlags*/, TUint32 /*aPslInfo*/) |
|
792 |
{ |
|
793 |
return KMemAlignMask; |
|
794 |
} |
|
795 |
||
796 |
||
797 |
void DSimSgController::Isr() |
|
798 |
{ |
|
799 |
for (TInt i = 0; i < KChannelCount; i++) |
|
800 |
{ |
|
801 |
TUint32 mask = (1 << i); |
|
802 |
if (DmacSg::CompletionInt & mask) |
|
803 |
{ |
|
804 |
DmacSg::CompletionInt &= ~mask; |
|
805 |
HandleIsr(SgController.iChannels[i], ETrue); |
|
806 |
} |
|
807 |
if (DmacSg::ErrorInt & mask) |
|
808 |
{ |
|
809 |
DmacSg::ErrorInt &= ~mask; |
|
810 |
HandleIsr(SgController.iChannels[i], EFalse); |
|
811 |
} |
|
812 |
} |
|
813 |
} |
|
814 |
||
815 |
||
816 |
////////////////////////////////////////////////////////////////////////////// |
|
817 |
// Channel opening/closing |
|
818 |
||
819 |
enum TController { ESb=0, EDb=1, ESg=2 }; |
|
820 |
||
821 |
const TUint32 KControllerMask = 0x30; |
|
822 |
const TUint32 KControllerShift = 4; |
|
823 |
const TUint32 KChannelIdxMask = 3; |
|
824 |
||
825 |
#define MKCHN(type, idx) (((type)<<KControllerShift)|idx) |
|
826 |
||
827 |
static TUint32 TestSbChannels[] = { MKCHN(ESb,0), MKCHN(ESb,1), MKCHN(ESb,2), MKCHN(ESb,3) }; |
|
828 |
static TUint32 TestDbChannels[] = { MKCHN(EDb,0), MKCHN(EDb,1), MKCHN(EDb,2), MKCHN(EDb,3) }; |
|
829 |
static TUint32 TestSgChannels[] = { MKCHN(ESg,0), MKCHN(ESg,1), MKCHN(ESg,2), MKCHN(ESg,3) }; |
|
830 |
||
831 |
static TDmaTestInfo TestInfo = |
|
832 |
{ |
|
833 |
KMaxTransferSize, |
|
834 |
KMemAlignMask, |
|
835 |
0, |
|
836 |
KChannelCount, |
|
837 |
TestSbChannels, |
|
838 |
KChannelCount, |
|
839 |
TestDbChannels, |
|
840 |
KChannelCount, |
|
841 |
TestSgChannels, |
|
842 |
}; |
|
843 |
||
844 |
EXPORT_C const TDmaTestInfo& DmaTestInfo() |
|
845 |
{ |
|
846 |
return TestInfo; |
|
847 |
} |
|
848 |
||
849 |
// Keep track of opened channels so Tick callback used to fake DMA |
|
850 |
// transfers is enabled only when necessary. |
|
851 |
static TInt OpenChannelCount = 0; |
|
852 |
||
853 |
||
854 |
TDmaChannel* DmaChannelMgr::Open(TUint32 aOpenId) |
|
855 |
{ |
|
856 |
TInt dmac = (aOpenId & KControllerMask) >> KControllerShift; |
|
857 |
__DMA_ASSERTD(dmac < 3); |
|
858 |
TInt i = aOpenId & KChannelIdxMask; |
|
859 |
TDmaChannel* pC = NULL; |
|
860 |
TDmac* controller = NULL; |
|
861 |
switch (dmac) |
|
862 |
{ |
|
863 |
case ESb: |
|
864 |
pC = SbController.iChannels + i; |
|
865 |
controller = &SbController; |
|
866 |
break; |
|
867 |
case EDb: |
|
868 |
pC = DbController.iChannels + i; |
|
869 |
controller = &DbController; |
|
870 |
break; |
|
871 |
case ESg: |
|
872 |
pC = SgController.iChannels + i; |
|
873 |
controller = &SgController; |
|
874 |
break; |
|
875 |
default: |
|
876 |
__DMA_CANT_HAPPEN(); |
|
877 |
} |
|
878 |
||
879 |
if (++OpenChannelCount == 1) |
|
880 |
{ |
|
881 |
__KTRACE_OPT(KDMA, Kern::Printf("Enabling DMA simulation")); |
|
882 |
DmacSim::StartEmulation(); |
|
883 |
} |
|
884 |
if (pC->IsOpened()) |
|
885 |
return NULL; |
|
886 |
pC->iController = controller; |
|
887 |
pC->iPslId = i; |
|
888 |
return pC; |
|
889 |
} |
|
890 |
||
891 |
||
892 |
void DmaChannelMgr::Close(TDmaChannel* /*aChannel*/) |
|
893 |
{ |
|
894 |
if (--OpenChannelCount == 0) |
|
895 |
{ |
|
896 |
DmacSim::StopEmulation(); |
|
897 |
__KTRACE_OPT(KDMA, Kern::Printf("Stopping DMA simulation")); |
|
898 |
} |
|
899 |
} |
|
900 |
||
901 |
TInt DmaChannelMgr::StaticExtension(TInt /*aCmd*/, TAny* /*aArg*/) |
|
902 |
{ |
|
903 |
return KErrNotSupported; |
|
904 |
} |
|
905 |
||
906 |
////////////////////////////////////////////////////////////////////////////// |
|
907 |
||
908 |
// |
|
909 |
// On hardware, this code is inside a kernel extension. |
|
910 |
// |
|
911 |
||
912 |
DECLARE_STANDARD_EXTENSION() |
|
913 |
{ |
|
914 |
__KTRACE_OPT(KDMA, Kern::Printf("Starting DMA simulator...")); |
|
915 |
TInt r; |
|
916 |
r = SbController.Create(DSimSbController::KInfo); |
|
917 |
if (r != KErrNone) |
|
918 |
return r; |
|
919 |
r = DbController.Create(DSimDbController::KInfo); |
|
920 |
if (r != KErrNone) |
|
921 |
return r; |
|
922 |
r = SgController.Create(DSimSgController::KInfo); |
|
923 |
if (r != KErrNone) |
|
924 |
return r; |
|
925 |
||
926 |
return KErrNone; |
|
927 |
} |
|
928 |
||
929 |
// |
|
930 |
// On WINS, this code is inside a LDD (see mmp file) so we need some |
|
931 |
// bootstrapping code to call the kernel extension entry point. |
|
932 |
// |
|
933 |
||
934 |
class DDummyLdd : public DLogicalDevice |
|
935 |
{ |
|
936 |
public: |
|
937 |
// from DLogicalDevice |
|
938 |
TInt Install(); |
|
939 |
void GetCaps(TDes8& aDes) const; |
|
940 |
TInt Create(DLogicalChannelBase*& aChannel); |
|
941 |
}; |
|
942 |
||
943 |
TInt DDummyLdd::Create(DLogicalChannelBase*& aChannel) |
|
944 |
{ |
|
945 |
aChannel=NULL; |
|
946 |
return KErrNone; |
|
947 |
} |
|
948 |
||
949 |
TInt DDummyLdd::Install() |
|
950 |
{ |
|
951 |
_LIT(KLddName, "DmaSim"); |
|
952 |
TInt r = SetName(&KLddName); |
|
953 |
if (r == KErrNone) |
|
954 |
r = InitExtension(); |
|
955 |
return r; |
|
956 |
} |
|
957 |
||
958 |
void DDummyLdd::GetCaps(TDes8& /*aDes*/) const |
|
959 |
{ |
|
960 |
} |
|
961 |
||
962 |
EXPORT_C DLogicalDevice* CreateLogicalDevice() |
|
963 |
{ |
|
964 |
return new DDummyLdd; |
|
965 |
} |
|
966 |
||
967 |
||
968 |
//--- |