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

4.115
Last change on this file since 8fbe2e6 was 8fbe2e6, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/14 at 13:59:49

Use correct prototype of benchmark_timer_read()

This change starts with removing the effectively empty file
timerdrv.h. The prototypes for benchmark_timer_XXX() were in
btimer.h which was not universally used. Thus every use of
timerdrv.h had to be changed to btimer.h. Then the prototypes
for benchmark_timer_read() had to be adjusted to return
benchmark_timer_t rather than int or uint32_t.

I took this opportunity to also correct the file headers to
separate the copyright from the file description comments which
is needed to ensure the copyright isn't propagated into Doxygen
output.

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/**
2 *  @file
3 *  @brief Timer Driver for the PowerPC MPC5xx.
4 *
5 *  This file manages the interval timer on the PowerPC MPC5xx.
6 *  @noe This is not the PIT, but rather the RTEMS interval timer.
7 *  We shall use the bottom 32 bits of the timebase register,
8 */
9
10/*
11 *  MPC5xx port sponsored by Defence Research and Development Canada - Suffield
12 *  Copyright (C) 2004, Real-Time Systems Inc. (querbach@realtime.bc.ca)
13 *
14 *  Derived from c/src/lib/libcpu/powerpc/mpc8xx/timer/timer.c:
15 *
16 *  Author: Jay Monkman (jmonkman@frasca.com)
17 *  Copywright (C) 1998 by Frasca International, Inc.
18 *
19 *  Derived from c/src/lib/libcpu/ppc/ppc403/timer/timer.c:
20 *
21 *  Author:     Andrew Bray <andy@i-cubed.co.uk>
22 *
23 *  COPYRIGHT (c) 1995 by i-cubed ltd.
24 *
25 *  To anyone who acknowledges that this file is provided "AS IS"
26 *  without any express or implied warranty:
27 *      permission to use, copy, modify, and distribute this file
28 *      for any purpose is hereby granted without fee, provided that
29 *      the above copyright notice and this notice appears in all
30 *      copies, and that the name of i-cubed limited not be used in
31 *      advertising or publicity pertaining to distribution of the
32 *      software without specific, written prior permission.
33 *      i-cubed limited makes no representations about the suitability
34 *      of this software for any purpose.
35 *
36 *  Derived from c/src/lib/libcpu/hppa1_1/timer/timer.c:
37 *
38 *  COPYRIGHT (c) 1989-2007.
39 *  On-Line Applications Research Corporation (OAR).
40 *
41 *  The license and distribution terms for this file may be
42 *  found in the file LICENSE in this distribution or at
43 *  http://www.rtems.org/license/LICENSE.
44 */
45
46#include <rtems.h>
47#include <rtems/btimer.h>
48#include <mpc5xx.h>
49
50static volatile uint32_t Timer_starting;
51static bool benchmark_timer_find_average_overhead;
52
53extern uint32_t bsp_timer_least_valid;
54extern uint32_t bsp_timer_average_overhead;
55
56/*
57 *  This is so small that this code will be reproduced where needed.
58 */
59static inline uint32_t get_itimer(void)
60{
61   uint32_t ret;
62
63   __asm__ volatile ("mftb %0" : "=r" ((ret))); /* TBLO */
64
65   return ret;
66}
67
68void benchmark_timer_initialize(void)
69{
70  /* set interrupt level and enable timebase. This should never */
71  /*  generate an interrupt however. */
72  usiu.tbscrk = USIU_UNLOCK_KEY;
73  usiu.tbscr |= USIU_TBSCR_TBIRQ(4)     /* interrupt priority level */
74              | USIU_TBSCR_TBF          /* freeze timebase during debug */
75              | USIU_TBSCR_TBE;         /* enable timebase */
76  usiu.tbscrk = 0;
77
78  Timer_starting = get_itimer();
79}
80
81benchmark_timer_t 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.