sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\nkernsa\arm\armutils.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: sl@0: const TUint32 KPageSize = 0x1000u; sl@0: sl@0: extern "C" { sl@0: sl@0: void thread_request_signal(NThread* aThread); sl@0: sl@0: TUint64 fcf; sl@0: TUint32 nfcf; sl@0: TUint32 nfcfs; sl@0: sl@0: sl@0: TUint32 round_to_page(TUint32 x) sl@0: { sl@0: return (x + KPageSize - 1) &~ (KPageSize - 1); sl@0: } sl@0: sl@0: sl@0: TLinAddr __initial_stack_base() sl@0: { sl@0: return __stack_pointer() & ~0xfff; sl@0: } sl@0: sl@0: TInt __initial_stack_size() sl@0: { sl@0: return 0x1000; sl@0: } sl@0: sl@0: TUint64 fast_counter_freq() sl@0: { sl@0: return fcf; sl@0: } sl@0: sl@0: TUint32 norm_fast_counter_freq() sl@0: { sl@0: return nfcf; sl@0: } sl@0: sl@0: void init_fast_counter() sl@0: { sl@0: NKern::Sleep(30); sl@0: TUint64 initial = fast_counter(); sl@0: NKern::Sleep(1000); sl@0: TUint64 final = fast_counter(); sl@0: fcf = final - initial; sl@0: TUint64 f = fcf; sl@0: nfcfs = 0; sl@0: while (f > 2000000) sl@0: f>>=1, ++nfcfs; sl@0: nfcf = (TUint32)(fcf >> nfcfs); sl@0: sl@0: DEBUGPRINT("fcf=%lx",fcf); sl@0: DEBUGPRINT("nfcf=%d",nfcf); sl@0: } sl@0: sl@0: TInt __microseconds_to_fast_counter(TInt us) sl@0: { sl@0: TUint64 x = TUint64(TUint32(us)); sl@0: x *= fcf; sl@0: x += TUint64(500000); sl@0: x /= TUint64(1000000); sl@0: sl@0: return (TInt)x; sl@0: } sl@0: sl@0: TInt __microseconds_to_norm_fast_counter(TInt us) sl@0: { sl@0: TUint64 x = TUint64(TUint32(us)); sl@0: x *= nfcf; sl@0: x += TUint64(500000); sl@0: x /= TUint64(1000000); sl@0: sl@0: return (TInt)x; sl@0: } sl@0: sl@0: void nfcfspin(TUint32 aTicks) sl@0: { sl@0: TUint64 ticks = aTicks; sl@0: ticks <<= nfcfs; sl@0: fcfspin(ticks); sl@0: } sl@0: sl@0: void fcfspin(TUint64 aTicks) sl@0: { sl@0: TUint64 t0 = fast_counter(); sl@0: TUint64 t1; sl@0: do { sl@0: t1 = fast_counter(); sl@0: t1 -= t0; sl@0: } while (t1 sl@0: sl@0: void TickTimerFn(TAny*); sl@0: NFastSemaphore TTSem; sl@0: sl@0: void TTIDfcFn(TAny*) sl@0: { sl@0: TTSem.Signal(); sl@0: } sl@0: sl@0: TDfc TTIDfc(&TTIDfcFn,0); sl@0: NTimer TickTimer(&TickTimerFn,0); sl@0: volatile TInt State=0; sl@0: volatile TInt Cycle=0; sl@0: volatile TInt WC[1024]; sl@0: volatile TInt WCI=0; sl@0: sl@0: void TickTimerFn(TAny* aPtr) sl@0: { sl@0: ArmLocalTimer& T = LOCAL_TIMER; sl@0: TInt c = (TInt)T.iWatchdogCount; sl@0: WC[WCI++]=c; sl@0: if (c<0) sl@0: { sl@0: if (++State==3) sl@0: { sl@0: if (++Cycle==3) sl@0: { sl@0: TTIDfc.Add(); sl@0: return; sl@0: } sl@0: T.iWatchdogCount = 1900000u; sl@0: State = 0; sl@0: } sl@0: } sl@0: TickTimer.Again(1); sl@0: } sl@0: sl@0: void DoWatchdogTimerTest() sl@0: { sl@0: NKern::FSSetOwner(&TTSem, NKern::CurrentThread()); sl@0: ArmLocalTimer& T = LOCAL_TIMER; sl@0: T.iWatchdogLoad = KMaxTUint32; sl@0: T.iWatchdogCount = 2097152; sl@0: T.iWatchdogIntStatus = 1; sl@0: __e32_io_completion_barrier(); sl@0: T.iWatchdogCtrl = 3; sl@0: __e32_io_completion_barrier(); sl@0: TickTimer.OneShot(1); sl@0: NKern::FSWait(&TTSem); sl@0: TInt i; sl@0: for (i=0; i