1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/nkernsa/arm/armutils.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,232 @@
1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\nkernsa\arm\armutils.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <arm.h>
1.22 +#include <nktest/nkutils.h>
1.23 +
1.24 +const TUint32 KPageSize = 0x1000u;
1.25 +
1.26 +extern "C" {
1.27 +
1.28 +void thread_request_signal(NThread* aThread);
1.29 +
1.30 +TUint64 fcf;
1.31 +TUint32 nfcf;
1.32 +TUint32 nfcfs;
1.33 +
1.34 +
1.35 +TUint32 round_to_page(TUint32 x)
1.36 + {
1.37 + return (x + KPageSize - 1) &~ (KPageSize - 1);
1.38 + }
1.39 +
1.40 +
1.41 +TLinAddr __initial_stack_base()
1.42 + {
1.43 + return __stack_pointer() & ~0xfff;
1.44 + }
1.45 +
1.46 +TInt __initial_stack_size()
1.47 + {
1.48 + return 0x1000;
1.49 + }
1.50 +
1.51 +TUint64 fast_counter_freq()
1.52 + {
1.53 + return fcf;
1.54 + }
1.55 +
1.56 +TUint32 norm_fast_counter_freq()
1.57 + {
1.58 + return nfcf;
1.59 + }
1.60 +
1.61 +void init_fast_counter()
1.62 + {
1.63 + NKern::Sleep(30);
1.64 + TUint64 initial = fast_counter();
1.65 + NKern::Sleep(1000);
1.66 + TUint64 final = fast_counter();
1.67 + fcf = final - initial;
1.68 + TUint64 f = fcf;
1.69 + nfcfs = 0;
1.70 + while (f > 2000000)
1.71 + f>>=1, ++nfcfs;
1.72 + nfcf = (TUint32)(fcf >> nfcfs);
1.73 +
1.74 + DEBUGPRINT("fcf=%lx",fcf);
1.75 + DEBUGPRINT("nfcf=%d",nfcf);
1.76 + }
1.77 +
1.78 +TInt __microseconds_to_fast_counter(TInt us)
1.79 + {
1.80 + TUint64 x = TUint64(TUint32(us));
1.81 + x *= fcf;
1.82 + x += TUint64(500000);
1.83 + x /= TUint64(1000000);
1.84 +
1.85 + return (TInt)x;
1.86 + }
1.87 +
1.88 +TInt __microseconds_to_norm_fast_counter(TInt us)
1.89 + {
1.90 + TUint64 x = TUint64(TUint32(us));
1.91 + x *= nfcf;
1.92 + x += TUint64(500000);
1.93 + x /= TUint64(1000000);
1.94 +
1.95 + return (TInt)x;
1.96 + }
1.97 +
1.98 +void nfcfspin(TUint32 aTicks)
1.99 + {
1.100 + TUint64 ticks = aTicks;
1.101 + ticks <<= nfcfs;
1.102 + fcfspin(ticks);
1.103 + }
1.104 +
1.105 +void fcfspin(TUint64 aTicks)
1.106 + {
1.107 + TUint64 t0 = fast_counter();
1.108 + TUint64 t1;
1.109 + do {
1.110 + t1 = fast_counter();
1.111 + t1 -= t0;
1.112 + } while (t1<aTicks);
1.113 + }
1.114 +
1.115 +extern TUint32 __cpsr();
1.116 +void CheckPoint()
1.117 + {
1.118 + KPrintf("CPSR=%08x", __cpsr());
1.119 + }
1.120 +
1.121 +void thread_request_signal(NThread* aThread)
1.122 + {
1.123 + NKern::ThreadRequestSignal(aThread);
1.124 + }
1.125 +}
1.126 +
1.127 +TAny* operator new(TUint aSize) __NO_THROW
1.128 +//
1.129 +// The global new operator.
1.130 +//
1.131 + {
1.132 +
1.133 + return malloc(aSize);
1.134 + }
1.135 +
1.136 +TAny* operator new[](TUint aSize) __NO_THROW
1.137 + {
1.138 +
1.139 + return malloc(aSize);
1.140 + }
1.141 +
1.142 +void operator delete(TAny* aPtr) __NO_THROW
1.143 +//
1.144 +// The replacement delete operator.
1.145 +//
1.146 + {
1.147 +
1.148 + free(aPtr);
1.149 + }
1.150 +
1.151 +void operator delete[](TAny* aPtr) __NO_THROW
1.152 + {
1.153 +
1.154 + free(aPtr);
1.155 + }
1.156 +
1.157 +#ifdef __ARMCC__
1.158 +TAny* operator new(TUint aSize, const std::nothrow_t& aNoThrow) __NO_THROW
1.159 +//
1.160 +// The global new operator.
1.161 +//
1.162 + {
1.163 + (void)aNoThrow;
1.164 + return malloc(aSize);
1.165 + }
1.166 +
1.167 +TAny* operator new[](TUint aSize, const std::nothrow_t& aNoThrow) __NO_THROW
1.168 + {
1.169 + (void)aNoThrow;
1.170 + return malloc(aSize);
1.171 + }
1.172 +#endif
1.173 +
1.174 +#ifdef __SMP__
1.175 +#include <arm_tmr.h>
1.176 +
1.177 +void TickTimerFn(TAny*);
1.178 +NFastSemaphore TTSem;
1.179 +
1.180 +void TTIDfcFn(TAny*)
1.181 + {
1.182 + TTSem.Signal();
1.183 + }
1.184 +
1.185 +TDfc TTIDfc(&TTIDfcFn,0);
1.186 +NTimer TickTimer(&TickTimerFn,0);
1.187 +volatile TInt State=0;
1.188 +volatile TInt Cycle=0;
1.189 +volatile TInt WC[1024];
1.190 +volatile TInt WCI=0;
1.191 +
1.192 +void TickTimerFn(TAny* aPtr)
1.193 + {
1.194 + ArmLocalTimer& T = LOCAL_TIMER;
1.195 + TInt c = (TInt)T.iWatchdogCount;
1.196 + WC[WCI++]=c;
1.197 + if (c<0)
1.198 + {
1.199 + if (++State==3)
1.200 + {
1.201 + if (++Cycle==3)
1.202 + {
1.203 + TTIDfc.Add();
1.204 + return;
1.205 + }
1.206 + T.iWatchdogCount = 1900000u;
1.207 + State = 0;
1.208 + }
1.209 + }
1.210 + TickTimer.Again(1);
1.211 + }
1.212 +
1.213 +void DoWatchdogTimerTest()
1.214 + {
1.215 + NKern::FSSetOwner(&TTSem, NKern::CurrentThread());
1.216 + ArmLocalTimer& T = LOCAL_TIMER;
1.217 + T.iWatchdogLoad = KMaxTUint32;
1.218 + T.iWatchdogCount = 2097152;
1.219 + T.iWatchdogIntStatus = 1;
1.220 + __e32_io_completion_barrier();
1.221 + T.iWatchdogCtrl = 3;
1.222 + __e32_io_completion_barrier();
1.223 + TickTimer.OneShot(1);
1.224 + NKern::FSWait(&TTSem);
1.225 + TInt i;
1.226 + for (i=0; i<WCI; ++i)
1.227 + {
1.228 + DEBUGPRINT("%03d: %d", i, WC[i]);
1.229 + }
1.230 + }
1.231 +
1.232 +
1.233 +#endif
1.234 +
1.235 +