kerneltest/e32test/nkernsa/arm/armutils.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2008-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\nkernsa\arm\armutils.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <arm.h>
       
    19 #include <nktest/nkutils.h>
       
    20 
       
    21 const TUint32 KPageSize = 0x1000u;
       
    22 
       
    23 extern "C" {
       
    24 
       
    25 void thread_request_signal(NThread* aThread);
       
    26 
       
    27 TUint64 fcf;
       
    28 TUint32 nfcf;
       
    29 TUint32 nfcfs;
       
    30 
       
    31 
       
    32 TUint32 round_to_page(TUint32 x)
       
    33 	{
       
    34 	return (x + KPageSize - 1) &~ (KPageSize - 1);
       
    35 	}
       
    36 
       
    37 
       
    38 TLinAddr __initial_stack_base()
       
    39 	{
       
    40 	return __stack_pointer() & ~0xfff;
       
    41 	}
       
    42 
       
    43 TInt __initial_stack_size()
       
    44 	{
       
    45 	return 0x1000;
       
    46 	}
       
    47 
       
    48 TUint64 fast_counter_freq()
       
    49 	{
       
    50 	return fcf;
       
    51 	}
       
    52 
       
    53 TUint32 norm_fast_counter_freq()
       
    54 	{
       
    55 	return nfcf;
       
    56 	}
       
    57 
       
    58 void init_fast_counter()
       
    59 	{
       
    60 	NKern::Sleep(30);
       
    61 	TUint64 initial = fast_counter();
       
    62 	NKern::Sleep(1000);
       
    63 	TUint64 final = fast_counter();
       
    64 	fcf = final - initial;
       
    65 	TUint64 f = fcf;
       
    66 	nfcfs = 0;
       
    67 	while (f > 2000000)
       
    68 		f>>=1, ++nfcfs;
       
    69 	nfcf = (TUint32)(fcf >> nfcfs);
       
    70 
       
    71 	DEBUGPRINT("fcf=%lx",fcf);
       
    72 	DEBUGPRINT("nfcf=%d",nfcf);
       
    73 	}
       
    74 
       
    75 TInt __microseconds_to_fast_counter(TInt us)
       
    76 	{
       
    77 	TUint64 x = TUint64(TUint32(us));
       
    78 	x *= fcf;
       
    79 	x += TUint64(500000);
       
    80 	x /= TUint64(1000000);
       
    81 
       
    82 	return (TInt)x;
       
    83 	}
       
    84 
       
    85 TInt __microseconds_to_norm_fast_counter(TInt us)
       
    86 	{
       
    87 	TUint64 x = TUint64(TUint32(us));
       
    88 	x *= nfcf;
       
    89 	x += TUint64(500000);
       
    90 	x /= TUint64(1000000);
       
    91 
       
    92 	return (TInt)x;
       
    93 	}
       
    94 
       
    95 void nfcfspin(TUint32 aTicks)
       
    96 	{
       
    97 	TUint64 ticks = aTicks;
       
    98 	ticks <<= nfcfs;
       
    99 	fcfspin(ticks);
       
   100 	}
       
   101 
       
   102 void fcfspin(TUint64 aTicks)
       
   103 	{
       
   104 	TUint64 t0 = fast_counter();
       
   105 	TUint64 t1;
       
   106 	do	{
       
   107 		t1 = fast_counter();
       
   108 		t1 -= t0;
       
   109 		} while (t1<aTicks);
       
   110 	}
       
   111 
       
   112 extern TUint32 __cpsr();
       
   113 void CheckPoint()
       
   114 	{
       
   115 	KPrintf("CPSR=%08x", __cpsr());
       
   116 	}
       
   117 
       
   118 void thread_request_signal(NThread* aThread)
       
   119 	{
       
   120 	NKern::ThreadRequestSignal(aThread);
       
   121 	}
       
   122 }
       
   123 
       
   124 TAny* operator new(TUint aSize) __NO_THROW
       
   125 //
       
   126 // The global new operator.
       
   127 //
       
   128 	{
       
   129 
       
   130 	return malloc(aSize);
       
   131 	}
       
   132 
       
   133 TAny* operator new[](TUint aSize) __NO_THROW
       
   134     {
       
   135 
       
   136     return malloc(aSize);
       
   137     }
       
   138 
       
   139 void operator delete(TAny* aPtr) __NO_THROW
       
   140 //
       
   141 // The replacement delete operator.
       
   142 //
       
   143 	{
       
   144 
       
   145 	free(aPtr);
       
   146 	}
       
   147 
       
   148 void operator delete[](TAny* aPtr) __NO_THROW
       
   149     {
       
   150 
       
   151 	free(aPtr);
       
   152     }
       
   153 
       
   154 #ifdef __ARMCC__
       
   155 TAny* operator new(TUint aSize, const std::nothrow_t& aNoThrow) __NO_THROW
       
   156 //
       
   157 // The global new operator.
       
   158 //
       
   159 	{
       
   160 	(void)aNoThrow;
       
   161 	return malloc(aSize);
       
   162 	}
       
   163 
       
   164 TAny* operator new[](TUint aSize, const std::nothrow_t& aNoThrow) __NO_THROW
       
   165     {
       
   166     (void)aNoThrow;
       
   167     return malloc(aSize);
       
   168     }
       
   169 #endif
       
   170 
       
   171 #ifdef __SMP__
       
   172 #include <arm_tmr.h>
       
   173 
       
   174 void TickTimerFn(TAny*);
       
   175 NFastSemaphore TTSem;
       
   176 
       
   177 void TTIDfcFn(TAny*)
       
   178 	{
       
   179 	TTSem.Signal();
       
   180 	}
       
   181 
       
   182 TDfc TTIDfc(&TTIDfcFn,0);
       
   183 NTimer TickTimer(&TickTimerFn,0);
       
   184 volatile TInt State=0;
       
   185 volatile TInt Cycle=0;
       
   186 volatile TInt WC[1024];
       
   187 volatile TInt WCI=0;
       
   188 
       
   189 void TickTimerFn(TAny* aPtr)
       
   190 	{
       
   191 	ArmLocalTimer& T = LOCAL_TIMER;
       
   192 	TInt c = (TInt)T.iWatchdogCount;
       
   193 	WC[WCI++]=c;
       
   194 	if (c<0)
       
   195 		{
       
   196 		if (++State==3)
       
   197 			{
       
   198 			if (++Cycle==3)
       
   199 				{
       
   200 				TTIDfc.Add();
       
   201 				return;
       
   202 				}
       
   203 			T.iWatchdogCount = 1900000u;
       
   204 			State = 0;
       
   205 			}
       
   206 		}
       
   207 	TickTimer.Again(1);
       
   208 	}
       
   209 
       
   210 void DoWatchdogTimerTest()
       
   211 	{
       
   212 	NKern::FSSetOwner(&TTSem, NKern::CurrentThread());
       
   213 	ArmLocalTimer& T = LOCAL_TIMER;
       
   214 	T.iWatchdogLoad = KMaxTUint32;
       
   215 	T.iWatchdogCount = 2097152;
       
   216 	T.iWatchdogIntStatus = 1;
       
   217 	__e32_io_completion_barrier();
       
   218 	T.iWatchdogCtrl = 3;
       
   219 	__e32_io_completion_barrier();
       
   220 	TickTimer.OneShot(1);
       
   221 	NKern::FSWait(&TTSem);
       
   222 	TInt i;
       
   223 	for (i=0; i<WCI; ++i)
       
   224 		{
       
   225 		DEBUGPRINT("%03d: %d", i, WC[i]);
       
   226 		}
       
   227 	}
       
   228 
       
   229 
       
   230 #endif
       
   231 
       
   232