source: rtems/c/src/lib/libcpu/powerpc/mpc5xx/timer/timer.c @ f9acc33

4.115
Last change on this file since f9acc33 was f9acc33, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/11/11 at 09:46:53

2011-02-11 Ralf Corsépius <ralf.corsepius@…>

  • e500/mmu/mmu.c, mpc505/ictrl/ictrl.c, mpc505/timer/timer.c, mpc5xx/ictrl/ictrl.c, mpc5xx/timer/timer.c, mpc6xx/altivec/vec_sup.c, mpc6xx/clock/c_clock.c, mpc6xx/mmu/bat.c, mpc6xx/mmu/bat.h, mpc6xx/mmu/pte121.c, mpc8260/timer/timer.c, mpc8xx/timer/timer.c, new-exceptions/cpu.c, new-exceptions/bspsupport/ppc_exc_initialize.c, ppc403/clock/clock.c, ppc403/console/console.c, ppc403/console/console.c.polled, ppc403/console/console405.c, ppc403/irq/ictrl.c, ppc403/tty_drv/tty_drv.c, rtems/powerpc/cache.h, shared/include/powerpc-utility.h, shared/src/cache.c: Use "asm" instead of "asm" for improved c99-compliance.
  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*  timer.c
2 *
3 *  This file manages the interval timer on the PowerPC MPC5xx.
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 *
14 *  MPC5xx port sponsored by Defence Research and Development Canada - Suffield
15 *  Copyright (C) 2004, Real-Time Systems Inc. (querbach@realtime.bc.ca)
16 *
17 *  Derived from c/src/lib/libcpu/powerpc/mpc8xx/timer/timer.c:
18 *
19 *  Author: Jay Monkman (jmonkman@frasca.com)
20 *  Copywright (C) 1998 by Frasca International, Inc.
21 *
22 *  Derived from c/src/lib/libcpu/ppc/ppc403/timer/timer.c:
23 *
24 *  Author:     Andrew Bray <andy@i-cubed.co.uk>
25 *
26 *  COPYRIGHT (c) 1995 by i-cubed ltd.
27 *
28 *  To anyone who acknowledges that this file is provided "AS IS"
29 *  without any express or implied warranty:
30 *      permission to use, copy, modify, and distribute this file
31 *      for any purpose is hereby granted without fee, provided that
32 *      the above copyright notice and this notice appears in all
33 *      copies, and that the name of i-cubed limited not be used in
34 *      advertising or publicity pertaining to distribution of the
35 *      software without specific, written prior permission.
36 *      i-cubed limited makes no representations about the suitability
37 *      of this software for any purpose.
38 *
39 *  Derived from c/src/lib/libcpu/hppa1_1/timer/timer.c:
40 *
41 *  COPYRIGHT (c) 1989-2007.
42 *  On-Line Applications Research Corporation (OAR).
43 *
44 *  The license and distribution terms for this file may be
45 *  found in the file LICENSE in this distribution or at
46 *  http://www.rtems.com/license/LICENSE.
47 *
48 *  $Id$
49 */
50
51#include <rtems.h>
52#include <mpc5xx.h>
53
54static volatile uint32_t Timer_starting;
55static bool benchmark_timer_find_average_overhead;
56
57extern uint32_t bsp_timer_least_valid;
58extern uint32_t bsp_timer_average_overhead;
59
60/*
61 *  This is so small that this code will be reproduced where needed.
62 */
63static inline uint32_t get_itimer(void)
64{
65   uint32_t ret;
66
67   __asm__ volatile ("mftb %0" : "=r" ((ret))); /* TBLO */
68
69   return ret;
70}
71
72void benchmark_timer_initialize(void)
73{
74  /* set interrupt level and enable timebase. This should never */
75  /*  generate an interrupt however. */
76  usiu.tbscrk = USIU_UNLOCK_KEY;
77  usiu.tbscr |= USIU_TBSCR_TBIRQ(4)     /* interrupt priority level */
78              | USIU_TBSCR_TBF          /* freeze timebase during debug */
79              | USIU_TBSCR_TBE;         /* enable timebase */
80  usiu.tbscrk = 0;
81
82  Timer_starting = get_itimer();
83}
84
85int benchmark_timer_read(void)
86{
87  uint32_t clicks;
88  uint32_t total;
89
90  clicks = get_itimer();
91
92  total = clicks - Timer_starting;
93
94  if ( benchmark_timer_find_average_overhead == 1 )
95    return total;          /* in XXX microsecond units */
96
97  else {
98    if ( total < bsp_timer_least_valid ) {
99      return 0;            /* below timer resolution */
100    }
101    return (total - bsp_timer_average_overhead);
102  }
103}
104
105void benchmark_timer_disable_subtracting_average_overhead(bool find_flag)
106{
107  benchmark_timer_find_average_overhead = find_flag;
108}
Note: See TracBrowser for help on using the repository browser.