[8ef3818] | 1 | /* timer.c |
---|
| 2 | * |
---|
| 3 | * This file manages the interval timer on the PowerPC MPC8xx. |
---|
| 4 | * NOTE: This is not the PIT, but rather the RTEMS interval |
---|
| 5 | * timer |
---|
| 6 | * We shall use the bottom 32 bits of the timebase register, |
---|
| 7 | * |
---|
| 8 | * The following was in the 403 version of this file. I don't |
---|
| 9 | * know what it means. JTM 5/19/98 |
---|
| 10 | * NOTE: It is important that the timer start/stop overhead be |
---|
| 11 | * determined when porting or modifying this code. |
---|
| 12 | * |
---|
| 13 | * Author: Jay Monkman (jmonkman@frasca.com) |
---|
| 14 | * Copywright (C) 1998 by Frasca International, Inc. |
---|
| 15 | * |
---|
| 16 | * Derived from c/src/lib/libcpu/ppc/ppc403/timer/timer.c: |
---|
| 17 | * |
---|
| 18 | * Author: Andrew Bray <andy@i-cubed.co.uk> |
---|
| 19 | * |
---|
| 20 | * COPYRIGHT (c) 1995 by i-cubed ltd. |
---|
| 21 | * |
---|
| 22 | * To anyone who acknowledges that this file is provided "AS IS" |
---|
| 23 | * without any express or implied warranty: |
---|
| 24 | * permission to use, copy, modify, and distribute this file |
---|
| 25 | * for any purpose is hereby granted without fee, provided that |
---|
| 26 | * the above copyright notice and this notice appears in all |
---|
| 27 | * copies, and that the name of i-cubed limited not be used in |
---|
| 28 | * advertising or publicity pertaining to distribution of the |
---|
| 29 | * software without specific, written prior permission. |
---|
| 30 | * i-cubed limited makes no representations about the suitability |
---|
| 31 | * of this software for any purpose. |
---|
| 32 | * |
---|
| 33 | * Derived from c/src/lib/libcpu/hppa1_1/timer/timer.c: |
---|
| 34 | * |
---|
| 35 | * COPYRIGHT (c) 1989-1998. |
---|
| 36 | * On-Line Applications Research Corporation (OAR). |
---|
| 37 | * Copyright assigned to U.S. Government, 1994. |
---|
| 38 | * |
---|
| 39 | * The license and distribution terms for this file may be |
---|
| 40 | * found in the file LICENSE in this distribution or at |
---|
| 41 | * http://www.OARcorp.com/rtems/license.html. |
---|
| 42 | * |
---|
| 43 | * $Id$ |
---|
| 44 | */ |
---|
| 45 | |
---|
| 46 | #include <rtems.h> |
---|
| 47 | #include <mpc8xx.h> |
---|
| 48 | |
---|
| 49 | static volatile rtems_unsigned32 Timer_starting; |
---|
| 50 | static rtems_boolean Timer_driver_Find_average_overhead; |
---|
| 51 | |
---|
| 52 | /* |
---|
| 53 | * This is so small that this code will be reproduced where needed. |
---|
| 54 | */ |
---|
| 55 | static inline rtems_unsigned32 get_itimer(void) |
---|
| 56 | { |
---|
| 57 | rtems_unsigned32 ret; |
---|
| 58 | |
---|
| 59 | asm volatile ("mftb %0" : "=r" ((ret))); /* TBLO */ |
---|
| 60 | |
---|
| 61 | return ret; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | void Timer_initialize(void) |
---|
| 65 | { |
---|
| 66 | /* set interrupt level and enable timebase. This should never */ |
---|
| 67 | /* generate an interrupt however. */ |
---|
| 68 | m8xx.tbscr |= M8xx_TBSCR_TBIRQ(4) | M8xx_TBSCR_TBE; |
---|
| 69 | |
---|
| 70 | Timer_starting = get_itimer(); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | int Read_timer(void) |
---|
| 74 | { |
---|
| 75 | rtems_unsigned32 clicks; |
---|
| 76 | rtems_unsigned32 total; |
---|
| 77 | |
---|
| 78 | clicks = get_itimer(); |
---|
| 79 | |
---|
| 80 | total = clicks - Timer_starting; |
---|
| 81 | |
---|
| 82 | if ( Timer_driver_Find_average_overhead == 1 ) |
---|
| 83 | return total; /* in XXX microsecond units */ |
---|
| 84 | |
---|
| 85 | else { |
---|
[61bd0301] | 86 | if ( total < rtems_cpu_configuration_get_timer_least_valid() ) { |
---|
[8ef3818] | 87 | return 0; /* below timer resolution */ |
---|
| 88 | } |
---|
[61bd0301] | 89 | return (total - rtems_cpu_configuration_get_timer_average_overhead()); |
---|
[8ef3818] | 90 | } |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | rtems_status_code Empty_function(void) |
---|
| 94 | { |
---|
| 95 | return RTEMS_SUCCESSFUL; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | void Set_find_average_overhead(rtems_boolean find_flag) |
---|
| 99 | { |
---|
| 100 | Timer_driver_Find_average_overhead = find_flag; |
---|
| 101 | } |
---|