source: rtems/c/src/lib/libcpu/powerpc/mpc8260/timer/timer.c @ c499856

4.11
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on Mar 20, 2014 at 9:10:47 PM

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*  timer.c
2 *
3 *  This file manages the interval timer on the PowerPC MPC860.
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: Andy Dachs <a.dachs@sstl.co.uk>
14 *  Surrey Satellite Technlogy Limited
15 *   Modified for MPC8260
16 *   Derived from c/src/lib/libcpu/powerpc/mpc860/timer/timer.c:
17 *
18 *  Author: Jay Monkman (jmonkman@frasca.com)
19 *  Copywright (C) 1998 by Frasca International, Inc.
20 *
21 *  Derived from c/src/lib/libcpu/ppc/ppc403/timer/timer.c:
22 *
23 *  Author:     Andrew Bray <andy@i-cubed.co.uk>
24 *
25 *  COPYRIGHT (c) 1995 by i-cubed ltd.
26 *
27 *  To anyone who acknowledges that this file is provided "AS IS"
28 *  without any express or implied warranty:
29 *      permission to use, copy, modify, and distribute this file
30 *      for any purpose is hereby granted without fee, provided that
31 *      the above copyright notice and this notice appears in all
32 *      copies, and that the name of i-cubed limited not be used in
33 *      advertising or publicity pertaining to distribution of the
34 *      software without specific, written prior permission.
35 *      i-cubed limited makes no representations about the suitability
36 *      of this software for any purpose.
37 *
38 *  Derived from c/src/lib/libcpu/hppa1_1/timer/timer.c:
39 *
40 *  COPYRIGHT (c) 1989-2007.
41 *  On-Line Applications Research Corporation (OAR).
42 *
43 *  The license and distribution terms for this file may be
44 *  found in the file LICENSE in this distribution or at
45 *  http://www.rtems.org/license/LICENSE.
46 */
47
48#include <rtems.h>
49#include <mpc8260.h>
50
51static volatile uint32_t   Timer_starting;
52static bool benchmark_timer_find_average_overhead;
53
54/*
55 *  This is so small that this code will be reproduced where needed.
56 */
57static inline uint32_t   get_itimer(void)
58{
59   uint32_t   ret;
60
61   __asm__ volatile ("mftb %0" : "=r" ((ret))); /* TBLO */
62
63   return ret;
64}
65
66void benchmark_timer_initialize(void)
67{
68  /* set interrupt level and enable timebase. This should never */
69  /*  generate an interrupt however. */
70
71/*
72  m860.tbscr |= M860_TBSCR_TBIRQ(4) | M860_TBSCR_TBE;
73*/
74
75
76  Timer_starting = get_itimer();
77}
78
79extern uint32_t bsp_timer_least_valid;
80extern uint32_t bsp_timer_average_overhead;
81int benchmark_timer_read(void)
82{
83  uint32_t   clicks;
84  uint32_t   total;
85
86  clicks = get_itimer();
87
88  total = clicks - Timer_starting;
89
90  if ( benchmark_timer_find_average_overhead == 1 )
91    return total;          /* in XXX microsecond units */
92
93  else {
94    if ( total < bsp_timer_least_valid ) {
95      return 0;            /* below timer resolution */
96    }
97    return (total - bsp_timer_average_overhead);
98  }
99}
100
101void benchmark_timer_disable_subtracting_average_overhead(bool find_flag)
102{
103  benchmark_timer_find_average_overhead = find_flag;
104}
Note: See TracBrowser for help on using the repository browser.