source: rtems/c/src/lib/libcpu/m68k/mcf5272/timer/timer.c @ 6cd2074

4.11
Last change on this file since 6cd2074 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: 4.5 KB
Line 
1/**
2 *  @file
3 *
4 *  This module initializes TIMER 2 for on the MCF5272 for benchmarks.
5 */
6
7/*
8 *  Copyright (C) 2000 OKTET Ltd., St.-Petersburg, Russia
9 *  Author: Victor V. Vengerov <vvv@oktet.ru>
10 *
11 *  Based on work:
12 *  Author:
13 *    David Fiddes, D.J@fiddes.surfaid.org
14 *    http://www.calm.hw.ac.uk/davidf/coldfire/
15 *
16 *  COPYRIGHT (c) 1989-1998.
17 *  On-Line Applications Research Corporation (OAR).
18 *
19 *  The license and distribution terms for this file may be
20 *  found in the file LICENSE in this distribution or at
21 *  http://www.rtems.org/license/LICENSE.
22 */
23
24#include <rtems.h>
25#include <bsp.h>
26#include <mcf5272/mcf5272.h>
27#include <rtems/btimer.h>
28
29#define TRR2_VAL 65530
30
31uint32_t Timer_interrupts;
32
33bool benchmark_timer_find_average_overhead;
34
35/* External assembler interrupt handler routine */
36extern rtems_isr timerisr(rtems_vector_number vector);
37
38
39/* benchmark_timer_initialize --
40 *     Initialize timer 2 for accurate time measurement.
41 *
42 * PARAMETERS:
43 *     none
44 *
45 * RETURNS:
46 *     none
47 */
48void
49benchmark_timer_initialize(void)
50{
51    uint32_t icr;
52    /* Catch timer2 interrupts */
53    set_vector(timerisr, BSP_INTVEC_TMR2, 0);
54
55    /* Reset Timer */
56    g_timer_regs->tmr2 = MCF5272_TMR_RST;
57    g_timer_regs->tmr2 = MCF5272_TMR_CLK_STOP;
58    g_timer_regs->tmr2 = MCF5272_TMR_RST;
59    g_timer_regs->tcn2 = 0;  /* reset counter */
60    Timer_interrupts   = 0;  /* Clear timer ISR counter */
61    g_timer_regs->ter2 = MCF5272_TER_REF | MCF5272_TER_CAP;
62    g_timer_regs->trr2 = TRR2_VAL -1 ;
63
64
65    /* Set Timer 2 prescaler so that it counts in microseconds */
66    g_timer_regs->tmr2 = (
67        (((BSP_SYSTEM_FREQUENCY / 1000000) - 1) << MCF5272_TMR_PS_SHIFT) |
68        MCF5272_TMR_CE_DISABLE                                           |
69        MCF5272_TMR_ORI                                                  |
70        MCF5272_TMR_FRR                                                  |
71        MCF5272_TMR_CLK_MSTR                                             |
72        MCF5272_TMR_RST);
73
74    /* Initialize interrupts for timer2 */
75    icr = g_intctrl_regs->icr1;
76    icr = icr & ~(MCF5272_ICR1_TMR2_MASK | MCF5272_ICR1_TMR2_PI);
77    icr |= (MCF5272_ICR1_TMR2_IPL(BSP_INTLVL_TMR2) | MCF5272_ICR1_TMR2_PI);
78    g_intctrl_regs->icr1 = icr;
79
80}
81
82/*
83 *  The following controls the behavior of benchmark_timer_read().
84 *
85 *  FIND_AVG_OVERHEAD *  instructs the routine to return the "raw" count.
86 *
87 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
88 *  is usually deducted from the number returned.
89 *
90 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
91 *  below this are "noise" and zero is returned.
92 */
93
94#define AVG_OVERHEAD      0  /* It typically takes 2.0 microseconds */
95                             /* (Y countdowns) to start/stop the timer. */
96                             /* This value is in microseconds. */
97#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
98
99/* benchmark_timer_read --
100 *     Read timer value in microsecond units since timer start.
101 *
102 * PARAMETERS:
103 *     none
104 *
105 * RETURNS:
106 *     number of microseconds since timer has been started
107 */
108benchmark_timer_t
109benchmark_timer_read( void )
110{
111    uint16_t clicks;
112    uint32_t total;
113
114    /*
115     *  Read the timer and see how many clicks it has been since counter
116     *  rolled over.
117     */
118    clicks = g_timer_regs->tcn2;
119
120    /* Stop Timer... */
121    g_timer_regs->tmr2 = MCF5272_TMR_CLK_STOP | MCF5272_TMR_RST;
122
123    /*
124     *  Total is calculated by taking into account the number of timer
125     *  overflow interrupts since the timer was initialized and clicks
126     *  since the last interrupts.
127     */
128
129    total = (Timer_interrupts * TRR2_VAL) + clicks;
130
131    if ( benchmark_timer_find_average_overhead == 1 )
132        return total;          /* in XXX microsecond units */
133
134    if ( total < LEAST_VALID )
135        return 0;            /* below timer resolution */
136
137    /*
138     *  Return the count in microseconds
139     */
140    return (total - AVG_OVERHEAD);
141}
142
143/* benchmark_timer_disable_subtracting_average_overhead --
144 *     This routine is invoked by the "Check Timer" (tmck) test in the
145 *     RTEMS Timing Test Suite. It makes the benchmark_timer_read routine not
146 *     subtract the overhead required to initialize and read the benchmark
147 *     timer.
148 *
149 * PARAMETERS:
150 *     find_flag - bool flag, true if overhead must not be subtracted.
151 *
152 * RETURNS:
153 *     none
154 */
155void
156benchmark_timer_disable_subtracting_average_overhead(bool find_flag)
157{
158  benchmark_timer_find_average_overhead = find_flag;
159}
Note: See TracBrowser for help on using the repository browser.