1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 // All rights reserved. |
2 // All rights reserved. |
3 // This component and the accompanying materials are made available |
3 // This component and the accompanying materials are made available |
4 // under the terms of the License "Eclipse Public License v1.0" |
4 // under the terms of the License "Eclipse Public License v1.0" |
5 // which accompanies this distribution, and is available |
5 // which accompanies this distribution, and is available |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
353 */ |
353 */ |
354 { |
354 { |
355 public: |
355 public: |
356 static void StartEmulation(); |
356 static void StartEmulation(); |
357 static void StopEmulation(); |
357 static void StopEmulation(); |
358 static TBool InISR(); |
|
359 static void Synchronize(); |
|
360 private: |
358 private: |
361 enum { KPeriod = 1 }; // in ms |
359 enum { KPeriod = 1 }; // in ms |
362 enum { EDmaSimIdle=0u, EDmaSimStarted=1u, EDmaSimInISR=2u, EDmaSimStopping=0x80000000u }; |
|
363 static void TickCB(TAny* aThis); |
360 static void TickCB(TAny* aThis); |
364 static NTimer Timer; |
361 static NTimer Timer; |
365 static volatile TInt StartStop; |
|
366 }; |
362 }; |
367 |
363 |
368 NTimer DmacSim::Timer; |
364 NTimer DmacSim::Timer; |
369 volatile TInt DmacSim::StartStop; |
|
370 |
365 |
371 void DmacSim::StartEmulation() |
366 void DmacSim::StartEmulation() |
372 { |
367 { |
373 __DMA_ASSERTA(StartStop==EDmaSimIdle); |
|
374 new (&Timer) NTimer(&TickCB, 0); |
368 new (&Timer) NTimer(&TickCB, 0); |
375 __e32_atomic_store_ord32(&StartStop, EDmaSimStarted); |
|
376 __DMA_ASSERTA(Timer.OneShot(KPeriod, EFalse) == KErrNone); |
369 __DMA_ASSERTA(Timer.OneShot(KPeriod, EFalse) == KErrNone); |
377 } |
370 } |
378 |
371 |
379 void DmacSim::StopEmulation() |
372 void DmacSim::StopEmulation() |
380 { |
373 { |
381 TInt orig = __e32_atomic_tas_ord32(&StartStop, (TInt)EDmaSimStarted, (TInt)EDmaSimStopping, 0); |
374 // Ensure that timer really is cancelled. |
382 if (orig == EDmaSimIdle) |
375 TBool cancelled = EFalse; |
383 return; // wasn't running |
376 do |
384 // loop until we succeed in cancelling the timer or the timer callback |
377 { |
385 // notices that we are shutting down |
378 cancelled = Timer.Cancel(); |
386 while (!Timer.Cancel() && __e32_atomic_load_acq32(&StartStop)!=EDmaSimIdle) |
379 } |
387 {} |
380 while(!cancelled); |
388 __e32_atomic_store_ord32(&StartStop, EDmaSimIdle); |
|
389 } |
381 } |
390 |
382 |
391 void DmacSim::TickCB(TAny*) |
383 void DmacSim::TickCB(TAny*) |
392 { |
384 { |
393 TInt orig = (TInt)__e32_atomic_ior_acq32(&StartStop, EDmaSimInISR); |
385 DmacSb::DoTransfer(); |
394 if (orig >= 0) |
386 DmacDb::DoTransfer(); |
395 { |
387 DmacSg::DoTransfer(); |
396 DmacSb::DoTransfer(); |
388 __DMA_ASSERTA(Timer.Again(KPeriod) == KErrNone); |
397 DmacDb::DoTransfer(); |
|
398 DmacSg::DoTransfer(); |
|
399 } |
|
400 orig = (TInt)__e32_atomic_and_rel32(&StartStop, (TUint32)~EDmaSimInISR); |
|
401 if (orig < 0) |
|
402 { |
|
403 __e32_atomic_store_rel32(&StartStop, EDmaSimIdle); |
|
404 return; |
|
405 } |
|
406 TInt r = Timer.Again(KPeriod); |
|
407 if (r == KErrArgument) |
|
408 r = Timer.OneShot(KPeriod); |
|
409 __DMA_ASSERTA(r == KErrNone); |
|
410 } |
|
411 |
|
412 TBool DmacSim::InISR() |
|
413 { |
|
414 return __e32_atomic_load_acq32(&StartStop) & EDmaSimInISR; |
|
415 } |
|
416 |
|
417 void DmacSim::Synchronize() |
|
418 { |
|
419 while (InISR()) |
|
420 {} |
|
421 } |
389 } |
422 |
390 |
423 ////////////////////////////////////////////////////////////////////////////// |
391 ////////////////////////////////////////////////////////////////////////////// |
424 // PSL FOR DMA SIMULATION |
392 // PSL FOR DMA SIMULATION |
425 ////////////////////////////////////////////////////////////////////////////// |
393 ////////////////////////////////////////////////////////////////////////////// |
704 |
670 |
705 |
671 |
706 void DSimSgController::StopTransfer(const TDmaChannel& aChannel) |
672 void DSimSgController::StopTransfer(const TDmaChannel& aChannel) |
707 { |
673 { |
708 __e32_atomic_and_ord32(&DmacSg::ChannelControl[aChannel.PslId()], (TUint32)~DmacSg::EChannelBitRun); |
674 __e32_atomic_and_ord32(&DmacSg::ChannelControl[aChannel.PslId()], (TUint32)~DmacSg::EChannelBitRun); |
709 DmacSim::Synchronize(); |
|
710 } |
675 } |
711 |
676 |
712 |
677 |
713 void DSimSgController::InitHwDes(const SDmaDesHdr& aHdr, TUint32 aSrc, TUint32 aDest, TInt aCount, |
678 void DSimSgController::InitHwDes(const SDmaDesHdr& aHdr, TUint32 aSrc, TUint32 aDest, TInt aCount, |
714 TUint /*aFlags*/, TUint32 /*aPslInfo*/, TUint32 /*aCookie*/) |
679 TUint /*aFlags*/, TUint32 /*aPslInfo*/, TUint32 /*aCookie*/) |