source: rtems/c/src/lib/libcpu/powerpc/ppc403/timer/timer.c @ 20f54e9

4.104.114.84.95
Last change on this file since 20f54e9 was 458bd34, checked in by Joel Sherrill <joel.sherrill@…>, on 11/05/99 at 16:44:02

This is another pass at making sure that nothing outside the BSP
unnecessarily uses any variables defined by the BSP. On this
sweep, use of BSP_Configuration and Cpu_table was eliminated.

A significant part of this modification was the addition of
macros to access fields in the RTEMS configuration structures.

This is necessary to strengthen the division between the BSP independent
parts of RTEMS and the BSPs themselves. This started after
comments and analysis by Ralf Corsepius <corsepiu@…>.

  • Property mode set to 100644
File size: 2.6 KB
Line 
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.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-1998.
27 *  On-Line Applications Research Corporation (OAR).
28 *  Copyright assigned to U.S. Government, 1994.
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.OARcorp.com/rtems/license.html.
33 *
34 *  $Id$
35 */
36
37#include <rtems.h>
38
39static volatile rtems_unsigned32 Timer_starting;
40static rtems_boolean Timer_driver_Find_average_overhead;
41
42/*
43 *  This is so small that this code will be reproduced where needed.
44 */
45static inline rtems_unsigned32 get_itimer(void)
46{
47   rtems_unsigned32 ret;
48
49   asm volatile ("mfspr %0, 0x3dd" : "=r" ((ret))); /* TBLO */
50
51   return ret;
52}
53
54void Timer_initialize()
55{
56  rtems_unsigned32 iocr;
57
58  asm volatile ("mfdcr %0, 0xa0" : "=r" (iocr)); /* IOCR */
59  iocr &= ~4;
60  iocr |= 4;  /* Select external timer clock */
61  asm volatile ("mtdcr 0xa0, %0" : "=r" (iocr) : "0" (iocr)); /* IOCR */
62
63  Timer_starting = get_itimer();
64}
65
66int Read_timer()
67{
68  rtems_unsigned32 clicks;
69  rtems_unsigned32 total;
70
71  clicks = get_itimer();
72
73  total = clicks - Timer_starting;
74
75  if ( Timer_driver_Find_average_overhead == 1 )
76    return total;          /* in XXX microsecond units */
77
78  else {
79    if ( total < rtems_cpu_configuration_get_timer_least_valid() )
80      return 0;            /* below timer resolution */
81    return (total - rtems_cpu_configuration_get_timer_average_overhead());
82  }
83}
84
85rtems_status_code Empty_function( void )
86{
87  return RTEMS_SUCCESSFUL;
88}
89
90void Set_find_average_overhead(
91  rtems_boolean find_flag
92)
93{
94  Timer_driver_Find_average_overhead = find_flag;
95}
Note: See TracBrowser for help on using the repository browser.