OpenCores
URL https://opencores.org/ocsvn/cryptosorter/cryptosorter/trunk

Subversion Repositories cryptosorter

[/] [cryptosorter/] [trunk/] [memocodeDesignContest2008/] [ctrl/] [ref_pc/] [timer.h] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 kfleming
/*
2
 * This source file contains C code for PPC405 cycle counter timer utilities
3
 *
4
 * Redistributions of any form whatsoever must retain and/or include the
5
 * following acknowledgment, notices and disclaimer:
6
 *
7
 * This product includes software developed by Carnegie Mellon University.
8
 *
9
 * Copyright (c) 2006 by J. C. Hoe, Carnegie Mellon University
10
 *
11
 * You may not use the name "Carnegie Mellon University" or derivations
12
 * thereof to endorse or promote products derived from this software.
13
 *
14
 * If you modify the software you must place a notice on or within any
15
 * modified version provided or made available to any third party stating
16
 * that you have modified the software.  The notice shall include at least
17
 * your name, address, phone number, email address and the date and purpose
18
 * of the modification.
19
 *
20
 * THE SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY WARRANTY OF ANY KIND, EITHER
21
 * EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO ANY WARRANTY
22
 * THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS OR BE ERROR-FREE AND ANY
23
 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
24
 * TITLE, OR NON-INFRINGEMENT.  IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
25
 * BE LIABLE FOR ANY DAMAGES, INCLUDING BUT NOT LIMITED TO DIRECT, INDIRECT,
26
 * SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM, OR IN
27
 * ANY WAY CONNECTED WITH THIS SOFTWARE (WHETHER OR NOT BASED UPON WARRANTY,
28
 * CONTRACT, TORT OR OTHERWISE).
29
 */
30
 
31
#define MHZ 300
32
 
33
typedef struct
34
{
35
    unsigned int upper;
36
    unsigned int lower;
37
} TIME_STAMP;
38
 
39
static long long ts_get_ll() {
40
        unsigned int upper, upper2;
41
        unsigned int lower;
42
 
43
        unsigned long long ans;
44
        unsigned int x;
45
 
46
        // see PPC405 programmer's manual for explanation
47
        do {
48
                asm volatile ("mftbu %[arg]" : [arg] "=r" (upper) : );
49
                asm volatile ("mftb %[arg]" : [arg] "=r" (lower) : );
50
                asm volatile ("mftbu %[arg]" : [arg] "=r" (upper2) : );
51
        } while (upper!=upper2);
52
 
53
        ans=upper;
54
        ans=ans<<32;
55
        ans|=lower;
56
 
57
        return ans;
58
}
59
 
60
 
61
static unsigned int ts_elapse_us(long long start, long long finish) {
62
        unsigned long long elapse=(finish-start);
63
 
64
        unsigned int xf=finish;
65
        unsigned int xs=start;
66
 
67
        elapse=elapse/MHZ;
68
 
69
        return elapse;
70
}
71
 
72
static unsigned int ts_elapse_ns(long long start, long long finish) {
73
        unsigned long long elapse=(finish-start);
74
 
75
        unsigned int xf=finish;
76
        unsigned int xs=start;
77
 
78
        elapse=(elapse*1000)/MHZ;
79
        return elapse;
80
 
81
}

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.