[3235ad9] | 1 | /* timer.c |
---|
| 2 | * |
---|
| 3 | * This file manages the interval timer on the PowerPC 403*. |
---|
| 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 | * |
---|
[08311cc3] | 26 | * COPYRIGHT (c) 1989-1999. |
---|
[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 |
---|
[03f2154e] | 31 | * http://www.OARcorp.com/rtems/license.html. |
---|
[3235ad9] | 32 | * |
---|
[879a047] | 33 | * $Id$ |
---|
[3235ad9] | 34 | */ |
---|
| 35 | |
---|
| 36 | #include <rtems.h> |
---|
| 37 | |
---|
| 38 | static volatile rtems_unsigned32 Timer_starting; |
---|
| 39 | static rtems_boolean Timer_driver_Find_average_overhead; |
---|
| 40 | |
---|
| 41 | /* |
---|
| 42 | * This is so small that this code will be reproduced where needed. |
---|
| 43 | */ |
---|
[93bea77] | 44 | static inline rtems_unsigned32 get_itimer(void) |
---|
[3235ad9] | 45 | { |
---|
| 46 | rtems_unsigned32 ret; |
---|
| 47 | |
---|
[e57b0e2] | 48 | asm volatile ("mfspr %0, 0x3dd" : "=r" ((ret))); /* TBLO */ |
---|
[3235ad9] | 49 | |
---|
| 50 | return ret; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | void Timer_initialize() |
---|
| 54 | { |
---|
| 55 | rtems_unsigned32 iocr; |
---|
| 56 | |
---|
[e57b0e2] | 57 | asm volatile ("mfdcr %0, 0xa0" : "=r" (iocr)); /* IOCR */ |
---|
[3235ad9] | 58 | iocr &= ~4; |
---|
| 59 | iocr |= 4; /* Select external timer clock */ |
---|
[e57b0e2] | 60 | asm volatile ("mtdcr 0xa0, %0" : "=r" (iocr) : "0" (iocr)); /* IOCR */ |
---|
[3235ad9] | 61 | |
---|
| 62 | Timer_starting = get_itimer(); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | int Read_timer() |
---|
| 66 | { |
---|
| 67 | rtems_unsigned32 clicks; |
---|
| 68 | rtems_unsigned32 total; |
---|
| 69 | |
---|
| 70 | clicks = get_itimer(); |
---|
| 71 | |
---|
| 72 | total = clicks - Timer_starting; |
---|
| 73 | |
---|
| 74 | if ( Timer_driver_Find_average_overhead == 1 ) |
---|
| 75 | return total; /* in XXX microsecond units */ |
---|
| 76 | |
---|
| 77 | else { |
---|
[458bd34] | 78 | if ( total < rtems_cpu_configuration_get_timer_least_valid() ) |
---|
[3235ad9] | 79 | return 0; /* below timer resolution */ |
---|
[458bd34] | 80 | return (total - rtems_cpu_configuration_get_timer_average_overhead()); |
---|
[3235ad9] | 81 | } |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | rtems_status_code Empty_function( void ) |
---|
| 85 | { |
---|
| 86 | return RTEMS_SUCCESSFUL; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | void Set_find_average_overhead( |
---|
| 90 | rtems_boolean find_flag |
---|
| 91 | ) |
---|
| 92 | { |
---|
| 93 | Timer_driver_Find_average_overhead = find_flag; |
---|
| 94 | } |
---|