Search
lxdream.org :: lxdream/test/timer.c
lxdream 0.9.1
released Jun 29
Download Now
filename test/timer.c
changeset 225:e5cea6125580
next262:bc96e0b79308
author nkeynes
date Wed Sep 20 09:52:32 2006 +0000 (14 years ago)
permissions -rw-r--r--
last change Commit start of SH4 test cases
file annotate diff log raw
nkeynes@225
     1
#include "../lib.h"
nkeynes@225
     2
#define TMU_CHANNEL 2
nkeynes@225
     3
nkeynes@225
     4
#define TOCR 0xFFD80000  /* Output control register */
nkeynes@225
     5
#define TSTR 0xFFD80004  /* Start register */
nkeynes@225
     6
#define TCOR(c) (0xFFD80008 + (c*12))  /* Constant register */
nkeynes@225
     7
#define TCNT(c) (0xFFD8000C + (c*12))  /* Count register */
nkeynes@225
     8
#define TCR(c)  (0xFFD80010 + (c*12))  /* Control register */
nkeynes@225
     9
nkeynes@225
    10
/**
nkeynes@225
    11
 * Initialize the on-chip timer controller. We snag TMU channel 2 in its
nkeynes@225
    12
 * highest resolution mode, and start it counting down from max_int. 
nkeynes@225
    13
 */
nkeynes@225
    14
void timer_start() {
nkeynes@225
    15
    unsigned int val = long_read(TSTR);
nkeynes@225
    16
    long_write( TSTR, val & (~(1<<TMU_CHANNEL)) ); /* Stop counter */
nkeynes@225
    17
    long_write( TCOR(TMU_CHANNEL), 0xFFFFFFFF );
nkeynes@225
    18
    long_write( TCNT(TMU_CHANNEL), 0xFFFFFFFF );
nkeynes@225
    19
    long_write( TCR(TMU_CHANNEL), 0x00000000 );
nkeynes@225
    20
    long_write( TSTR, val | (1<<TMU_CHANNEL) );
nkeynes@225
    21
}
nkeynes@225
    22
nkeynes@225
    23
/**
nkeynes@225
    24
 * Report the current value of TMU2.
nkeynes@225
    25
 */
nkeynes@225
    26
long timer_gettime() {
nkeynes@225
    27
    return long_read(TCNT(TMU_CHANNEL));
nkeynes@225
    28
}
nkeynes@225
    29
nkeynes@225
    30
/**
nkeynes@225
    31
 * Stop TMU2 and report the current value.
nkeynes@225
    32
 */
nkeynes@225
    33
long timer_stop() {
nkeynes@225
    34
    long_write( TSTR, long_read(TSTR) & (~(1<<TMU_CHANNEL)) );
nkeynes@225
    35
    return long_read( TCNT(TMU_CHANNEL) );
nkeynes@225
    36
}
nkeynes@225
    37
nkeynes@225
    38
nkeynes@225
    39
/**
nkeynes@225
    40
 * Convert the supplied timer value to a number of micro seconds since the timer
nkeynes@225
    41
 * was started.
nkeynes@225
    42
 */
nkeynes@225
    43
long timer_to_microsecs( long value ) {
nkeynes@225
    44
    return value;
nkeynes@225
    45
}
.