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