baseport/syborg/specific/highrestimer.h
author Gareth Stockwell <gareth.stockwell@accenture.com>
Wed, 22 Sep 2010 17:06:27 +0100
branchgraphics-phase-3
changeset 112 b6c206049d8a
parent 55 2c1e559d48bf
permissions -rw-r--r--
Copied NVM model library code from default branch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
     1
/*
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
     3
* All rights reserved.
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
     4
* This component and the accompanying materials are made available
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
     6
* which accompanies this distribution, and is available
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
     8
*
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
     9
* Initial Contributors:
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    11
*
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    12
* Contributors:
55
2c1e559d48bf BUG 1296: E32test t_cputime.exe failed while testing Fast Counter
bugtracker-ml@nttdocomo.com
parents: 2
diff changeset
    13
* NTT Docomo, Inc : BUG 1296
0
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    14
*
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    15
* Description:
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    16
*
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    17
*/
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    18
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    19
/**
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    20
 * @file
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    21
 * @internalTechnology
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    22
 *
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    23
 * The highrestimer.h header file defines how to access the high resoltion
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    24
 * timer, if one is supported.  This file is used by default if the variant does
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    25
 * not export one to \epoc32\include\nkern. 
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    26
 */
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    27
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    28
#ifndef __HIGHRESTIMER_H__
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    29
#define __HIGHRESTIMER_H__
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    30
//
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    31
// Copyright (c) 2008 Symbian Ltd. All rights reserved.
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    32
//
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    33
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    34
#include <syborg.h>
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    35
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    36
/**
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    37
 * Macro indicating that a high resolution timer is supported.
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    38
 */
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    39
#define HAS_HIGH_RES_TIMER
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    40
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    41
/**
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    42
 * Assembler macro to get the the current value of the high res timer and place
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    43
 * it in the specified register.
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    44
 * Reads the 32-bit value from a free-running counter that represents the current time. 
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    45
 * Syborg timers have 'microsecond resolution'. NB. This value comes from the host clock
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    46
 * and so there is a good chance that the kernels tick based notion of time (elapsed) and that
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    47
 * measured by the free running timer will get out of kilter. This affects t_cputime from e32test
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    48
 * amongst other things.
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    49
 */
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    50
//#define GET_HIGH_RES_TICK_COUNT(Rd) asm("nop");
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    51
// Hi-jacking r10 for tmp, not good if Rd is R10 -- grepping the the kernel shows it's not (for now)
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    52
#define GET_HIGH_RES_TICK_COUNT(Rd)						         \
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    53
  asm("push {r10}");										     \
55
2c1e559d48bf BUG 1296: E32test t_cputime.exe failed while testing Fast Counter
bugtracker-ml@nttdocomo.com
parents: 2
diff changeset
    54
  asm("mov r10, #1");										     \
0
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    55
  asm("ldr "#Rd", =%a0"               : : "i" (KHwBaseRtc + 4)); \
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    56
  asm("str r10, ["#Rd", #%a0]"        : : "i" (0));			     \
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    57
  asm("pop {r10}");                                              \
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    58
  asm("ldr "#Rd", =%a0"               : : "i" (KHwBaseRtc + 8)); \
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    59
  asm("ldr "#Rd", ["#Rd", #%a0]"      : : "i" (0));              
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    60
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    61
/**
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    62
 * The frequency of the timer in Hz.
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    63
 */
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    64
const TInt KHighResTimerFrequency = 1000000;
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    65
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    66
/**
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    67
 * Macro indicating that the timer counts up if defined.
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    68
 */
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    69
#define HIGH_RES_TIMER_COUNTS_UP
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    70
ffa851df0825 Initial syborg (baseport) and documentation import
martin.trojer@nokia.com
parents:
diff changeset
    71
#endif  // __HIGHRESTIMER_H__