1 | /** |
---|
2 | * @file |
---|
3 | * @brief Timer Driver for the PowerPC 405. |
---|
4 | * |
---|
5 | * This file manages the interval timer on the PowerPC 405. |
---|
6 | * We shall use the bottom 32 bits of the timebase register, |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Author: Andrew Bray <andy@i-cubed.co.uk> |
---|
11 | * |
---|
12 | * COPYRIGHT (c) 1995 by i-cubed ltd. |
---|
13 | * |
---|
14 | * To anyone who acknowledges that this file is provided "AS IS" |
---|
15 | * without any express or implied warranty: |
---|
16 | * permission to use, copy, modify, and distribute this file |
---|
17 | * for any purpose is hereby granted without fee, provided that |
---|
18 | * the above copyright notice and this notice appears in all |
---|
19 | * copies, and that the name of i-cubed limited not be used in |
---|
20 | * advertising or publicity pertaining to distribution of the |
---|
21 | * software without specific, written prior permission. |
---|
22 | * i-cubed limited makes no representations about the suitability |
---|
23 | * of this software for any purpose. |
---|
24 | * |
---|
25 | * Derived from c/src/lib/libcpu/hppa1.1/timer/timer.c: |
---|
26 | * |
---|
27 | * COPYRIGHT (c) 1989-2007. |
---|
28 | * On-Line Applications Research Corporation (OAR). |
---|
29 | * |
---|
30 | * The license and distribution terms for this file may be |
---|
31 | * found in the file LICENSE in this distribution or at |
---|
32 | * http://www.rtems.org/license/LICENSE. |
---|
33 | * |
---|
34 | * Modifications for PPC405GP by Dennis Ehlin |
---|
35 | * |
---|
36 | * Further mods for PPC405EX/EXr by Michael Hamel |
---|
37 | * |
---|
38 | */ |
---|
39 | |
---|
40 | #include <rtems.h> |
---|
41 | #include <rtems/btimer.h> |
---|
42 | #include <libcpu/powerpc-utility.h> |
---|
43 | |
---|
44 | extern uint32_t bsp_timer_least_valid; |
---|
45 | extern uint32_t bsp_timer_average_overhead; |
---|
46 | |
---|
47 | static volatile uint32_t startedAt; |
---|
48 | static bool subtractOverhead; |
---|
49 | |
---|
50 | void benchmark_timer_initialize(void) |
---|
51 | { |
---|
52 | /* We are going to rely on clock.c to sort out where the clock comes from */ |
---|
53 | startedAt = ppc_time_base(); |
---|
54 | } |
---|
55 | |
---|
56 | benchmark_timer_t benchmark_timer_read(void) |
---|
57 | { |
---|
58 | uint32_t clicks, total; |
---|
59 | |
---|
60 | clicks = ppc_time_base(); |
---|
61 | total = clicks - startedAt; |
---|
62 | if ( ! subtractOverhead ) |
---|
63 | return total; /* in XXX microsecond units */ |
---|
64 | else if ( total < bsp_timer_least_valid ) |
---|
65 | return 0; /* below timer resolution */ |
---|
66 | else |
---|
67 | return (total - bsp_timer_average_overhead); |
---|
68 | } |
---|
69 | |
---|
70 | void benchmark_timer_disable_subtracting_average_overhead(bool find_flag) |
---|
71 | { |
---|
72 | subtractOverhead = find_flag; |
---|
73 | } |
---|