source: rtems/c/src/lib/libcpu/powerpc/mpc8xx/timer/timer.c @ 21e1c44

4.104.114.84.95
Last change on this file since 21e1c44 was 21e1c44, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/03 at 18:53:10

2003-09-04 Joel Sherrill <joel@…>

  • mpc6xx/clock/c_clock.c, mpc6xx/clock/c_clock.h, mpc6xx/exceptions/raw_exception.c, mpc6xx/exceptions/raw_exception.h, mpc6xx/mmu/bat.c, mpc6xx/mmu/bat.h, mpc6xx/mmu/mmuAsm.S, mpc6xx/timer/timer.c, mpc8260/clock/clock.c, mpc8260/console-generic/console-generic.c, mpc8260/cpm/brg.c, mpc8260/exceptions/raw_exception.c, mpc8260/exceptions/raw_exception.h, mpc8260/include/cpm.h, mpc8260/include/mmu.h, mpc8260/mmu/mmu.c, mpc8260/timer/timer.c, mpc8xx/clock/clock.c, mpc8xx/console-generic/console-generic.c, mpc8xx/exceptions/raw_exception.c, mpc8xx/exceptions/raw_exception.h, mpc8xx/include/cpm.h, mpc8xx/include/mmu.h, mpc8xx/mmu/mmu.c, mpc8xx/timer/timer.c, ppc403/clock/clock.c, ppc403/console/console.c.polled, ppc403/timer/timer.c, rtems/powerpc/debugmod.h, shared/include/byteorder.h, shared/include/cpuIdent.c, shared/include/cpuIdent.h, shared/include/io.h, shared/include/mmu.h, shared/include/page.h, shared/include/pgtable.h, shared/include/spr.h: URL for license changed.
  • Property mode set to 100644
File size: 3.1 KB
Line 
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 *
38 *  The license and distribution terms for this file may be
39 *  found in the file LICENSE in this distribution or at
40 *  http://www.rtems.com/license/LICENSE.
41 *
42 *  $Id$
43 */
44
45#include <rtems.h>
46#include <mpc8xx.h>
47
48static volatile rtems_unsigned32 Timer_starting;
49static rtems_boolean Timer_driver_Find_average_overhead;
50
51/*
52 *  This is so small that this code will be reproduced where needed.
53 */
54static inline rtems_unsigned32 get_itimer(void)
55{
56   rtems_unsigned32 ret;
57
58   asm volatile ("mftb %0" : "=r" ((ret))); /* TBLO */
59
60   return ret;
61}
62
63void Timer_initialize(void)
64{
65  /* set interrupt level and enable timebase. This should never */
66  /*  generate an interrupt however. */
67  m8xx.tbscr |= M8xx_TBSCR_TBIRQ(4) | M8xx_TBSCR_TBE;
68 
69  Timer_starting = get_itimer();
70}
71
72#ifndef  rtems_cpu_configuration_get_timer_least_valid
73#define  rtems_cpu_configuration_get_timer_least_valid() 0
74#endif
75
76#ifndef  rtems_cpu_configuration_get_timer_average_overhead
77#define  rtems_cpu_configuration_get_timer_average_overhead() 0
78#endif
79
80int Read_timer(void)
81{
82  rtems_unsigned32 clicks;
83  rtems_unsigned32 total;
84
85  clicks = get_itimer();
86
87  total = clicks - Timer_starting;
88
89  if ( Timer_driver_Find_average_overhead == 1 )
90    return total;          /* in XXX microsecond units */
91
92  else {
93    if ( total < rtems_cpu_configuration_get_timer_least_valid() ) {
94      return 0;            /* below timer resolution */
95    }
96    return (total - rtems_cpu_configuration_get_timer_average_overhead());
97  }
98}
99
100rtems_status_code Empty_function(void)
101{
102  return RTEMS_SUCCESSFUL;
103}
104
105void Set_find_average_overhead(rtems_boolean find_flag)
106{
107  Timer_driver_Find_average_overhead = find_flag;
108}
Note: See TracBrowser for help on using the repository browser.