source: rtems/c/src/lib/libbsp/mips/genmongoosev/timer/timer.c @ 8fbe2e6

4.11
Last change on this file since 8fbe2e6 was 8fbe2e6, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 4, 2014 at 1:59:49 PM

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: 2.6 KB
Line 
1/*
2 *  This file implements a benchmark timer using a MONGOOSE-V timer.
3 *
4 *  COPYRIGHT (c) 1989-2001.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.org/license/LICENSE.
10 */
11
12#include <assert.h>
13
14#include <bsp.h>
15#include <rtems/btimer.h>
16
17bool benchmark_timer_find_average_overhead;
18
19#if defined(USE_TIMER2_FOR_CLOCK)
20#define TIMER_BASE   MONGOOSEV_TIMER1_BASE
21#define TIMER_VECTOR MONGOOSEV_IRQ_TIMER1
22#else
23#define TIMER_BASE   MONGOOSEV_TIMER2_BASE
24#define TIMER_VECTOR MONGOOSEV_IRQ_TIMER2
25#endif
26
27void benchmark_timer_initialize(void)
28{
29  /*
30   *  Programming the compare register as the maximum value should let
31   *  it run long enough and accurate enough not to require an interrupt.
32   *  but if it ever does generate an interrupt, we will simply fault.
33   *
34   *  NOTE:  This is similar to the clock driver initialization
35   *         with the exception that the divider is disabled and
36   *         the compare register is set to the maximum value.
37   */
38
39   MONGOOSEV_WRITE_REGISTER( TIMER_BASE, MONGOOSEV_TIMER_CONTROL_REGISTER, 0);
40
41   MONGOOSEV_WRITE_REGISTER( TIMER_BASE,
42                             MONGOOSEV_TIMER_INITIAL_COUNTER_REGISTER,
43                             0xffffffff );
44
45   MONGOOSEV_WRITE_REGISTER( TIMER_BASE,
46                             MONGOOSEV_TIMER_CONTROL_REGISTER,
47                             MONGOOSEV_TIMER_CONTROL_COUNTER_ENABLE );
48
49}
50
51#define AVG_OVERHEAD      0  /* It typically takes N instructions */
52                             /*     to start/stop the timer. */
53
54#define LEAST_VALID       1  /* Don't trust a value lower than this */
55                             /* mongoose-v can count cycles. :) */
56#include <rtems/bspIo.h>
57
58benchmark_timer_t benchmark_timer_read(void)
59{
60  uint32_t          clicks;
61  uint32_t          total;
62  uint32_t          tcr;
63
64  clicks = MONGOOSEV_READ_REGISTER( TIMER_BASE,
65                                    MONGOOSEV_TIMER_INITIAL_COUNTER_REGISTER );
66  total = 0xffffffff - clicks;
67
68  tcr = MONGOOSEV_READ_REGISTER( TIMER_BASE, MONGOOSEV_TIMER_CONTROL_REGISTER );
69
70  MONGOOSEV_WRITE_REGISTER( TIMER_BASE,
71                            MONGOOSEV_TIMER_CONTROL_REGISTER,
72                            0 );
73
74  if ( tcr & MONGOOSEV_TIMER_CONTROL_TIMEOUT )
75    printk( "MG5 timer overran\n" );
76
77  if ( benchmark_timer_find_average_overhead == true )
78    return total;          /* in cycle units */
79
80  if ( total < LEAST_VALID )
81    return 0;            /* below timer resolution */
82
83  return (total - AVG_OVERHEAD) / CPU_CLOCK_RATE_MHZ;
84}
85
86void benchmark_timer_disable_subtracting_average_overhead(
87  bool find_flag
88)
89{
90  benchmark_timer_find_average_overhead = find_flag;
91}
92
93/* eof */
Note: See TracBrowser for help on using the repository browser.