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 | * |
---|
9 | * Author: Andrew Bray <andy@i-cubed.demon.co.uk> |
---|
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 | * |
---|
24 | * Derived from c/src/lib/libcpu/hppa1_1/timer/timer.c: |
---|
25 | * |
---|
26 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
27 | * On-Line Applications Research Corporation (OAR). |
---|
28 | * All rights assigned to U.S. Government, 1994. |
---|
29 | * |
---|
30 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
31 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
32 | * notice must appear in all copies of this file and its derivatives. |
---|
33 | * |
---|
34 | * $Id$ |
---|
35 | */ |
---|
36 | |
---|
37 | #include <bsp.h> |
---|
38 | #include <rtems.h> |
---|
39 | |
---|
40 | extern rtems_cpu_table Cpu_table; /* owned by BSP */ |
---|
41 | |
---|
42 | static volatile rtems_unsigned32 Timer_starting; |
---|
43 | static rtems_boolean Timer_driver_Find_average_overhead; |
---|
44 | |
---|
45 | /* |
---|
46 | * This is so small that this code will be reproduced where needed. |
---|
47 | */ |
---|
48 | static INLINE rtems_unsigned32 get_itimer(void) |
---|
49 | { |
---|
50 | rtems_unsigned32 ret; |
---|
51 | |
---|
52 | asm volatile ("mftblo %0" : "=r" ((ret))); |
---|
53 | |
---|
54 | return ret; |
---|
55 | } |
---|
56 | |
---|
57 | void Timer_initialize() |
---|
58 | { |
---|
59 | rtems_unsigned32 iocr; |
---|
60 | |
---|
61 | asm volatile ("mfiocr %0" : "=r" (iocr)); |
---|
62 | iocr &= ~4; |
---|
63 | iocr |= 4; /* Select external timer clock */ |
---|
64 | asm volatile ("mtiocr %0" : "=r" (iocr) : "0" (iocr)); |
---|
65 | |
---|
66 | Timer_starting = get_itimer(); |
---|
67 | } |
---|
68 | |
---|
69 | int Read_timer() |
---|
70 | { |
---|
71 | rtems_unsigned32 clicks; |
---|
72 | rtems_unsigned32 total; |
---|
73 | |
---|
74 | clicks = get_itimer(); |
---|
75 | |
---|
76 | total = clicks - Timer_starting; |
---|
77 | |
---|
78 | if ( Timer_driver_Find_average_overhead == 1 ) |
---|
79 | return total; /* in XXX microsecond units */ |
---|
80 | |
---|
81 | else { |
---|
82 | if ( total < Cpu_table.timer_least_valid ) |
---|
83 | return 0; /* below timer resolution */ |
---|
84 | return (total - Cpu_table.timer_average_overhead); |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | rtems_status_code Empty_function( void ) |
---|
89 | { |
---|
90 | return RTEMS_SUCCESSFUL; |
---|
91 | } |
---|
92 | |
---|
93 | void Set_find_average_overhead( |
---|
94 | rtems_boolean find_flag |
---|
95 | ) |
---|
96 | { |
---|
97 | Timer_driver_Find_average_overhead = find_flag; |
---|
98 | } |
---|