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