source: rtems/c/src/lib/libcpu/m68k/mcf5272/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: 4.5 KB
RevLine 
[8fbe2e6]1/**
2 *  @file
[3cfd520]3 *
4 *  This module initializes TIMER 2 for on the MCF5272 for benchmarks.
[8fbe2e6]5 */
6
7/*
[3cfd520]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
[c499856]21 *  http://www.rtems.org/license/LICENSE.
[3cfd520]22 */
23
24#include <rtems.h>
25#include <bsp.h>
26#include <mcf5272/mcf5272.h>
[8fbe2e6]27#include <rtems/btimer.h>
[3cfd520]28
[023f1dd9]29#define TRR2_VAL 65530
[3cfd520]30
[ee5769ad]31uint32_t Timer_interrupts;
[3cfd520]32
[3551166d]33bool benchmark_timer_find_average_overhead;
[3cfd520]34
35/* External assembler interrupt handler routine */
36extern rtems_isr timerisr(rtems_vector_number vector);
37
38
[a5cd2271]39/* benchmark_timer_initialize --
[3cfd520]40 *     Initialize timer 2 for accurate time measurement.
41 *
42 * PARAMETERS:
43 *     none
44 *
45 * RETURNS:
46 *     none
47 */
48void
[a5cd2271]49benchmark_timer_initialize(void)
[3cfd520]50{
[ee5769ad]51    uint32_t icr;
[3cfd520]52    /* Catch timer2 interrupts */
53    set_vector(timerisr, BSP_INTVEC_TMR2, 0);
[023f1dd9]54
[3cfd520]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/*
[a5cd2271]83 *  The following controls the behavior of benchmark_timer_read().
[3cfd520]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
[a5cd2271]99/* benchmark_timer_read --
[3cfd520]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 */
[8fbe2e6]108benchmark_timer_t
[a5cd2271]109benchmark_timer_read( void )
[3cfd520]110{
[ee5769ad]111    uint16_t clicks;
112    uint32_t total;
[3cfd520]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;
[023f1dd9]119
[3cfd520]120    /* Stop Timer... */
121    g_timer_regs->tmr2 = MCF5272_TMR_CLK_STOP | MCF5272_TMR_RST;
122
123    /*
[023f1dd9]124     *  Total is calculated by taking into account the number of timer
[3cfd520]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
[a5cd2271]131    if ( benchmark_timer_find_average_overhead == 1 )
[3cfd520]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
[a5cd2271]143/* benchmark_timer_disable_subtracting_average_overhead --
[3cfd520]144 *     This routine is invoked by the "Check Timer" (tmck) test in the
[a5cd2271]145 *     RTEMS Timing Test Suite. It makes the benchmark_timer_read routine not
[3cfd520]146 *     subtract the overhead required to initialize and read the benchmark
147 *     timer.
148 *
149 * PARAMETERS:
[3551166d]150 *     find_flag - bool flag, true if overhead must not be subtracted.
[3cfd520]151 *
152 * RETURNS:
153 *     none
154 */
155void
[3551166d]156benchmark_timer_disable_subtracting_average_overhead(bool find_flag)
[3cfd520]157{
[a5cd2271]158  benchmark_timer_find_average_overhead = find_flag;
[3cfd520]159}
Note: See TracBrowser for help on using the repository browser.