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