source: rtems/bsps/arm/csb336/btimer/btimer.c @ e0dd8a5a

5
Last change on this file since e0dd8a5a was e0dd8a5a, checked in by Sebastian Huber <sebastian.huber@…>, on 04/20/18 at 10:08:42

bsps: Move benchmark timer to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[8fbe2e6]1/**
2 *  @file
3 *  @brief Cogent CSB336 Timer driver
[1cfcfd3]4 *
5 * This uses timer 2 for timing measurments.
[8fbe2e6]6 */
7
8/*
[1cfcfd3]9 * Copyright (c) 2004 Cogent Computer Systems
10 *        Written by Jay Monkman <jtm@lopingdog.com>
[359e537]11 *
[1cfcfd3]12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
[c499856]14 *  http://www.rtems.org/license/LICENSE.
[8fbe2e6]15 */
[1cfcfd3]16
17#include <rtems.h>
18#include <bsp.h>
[8fbe2e6]19#include <rtems/btimer.h>
[1cfcfd3]20#include <mc9328mxl.h>
21
22uint32_t g_start;
23uint32_t g_freq;
24
[3551166d]25bool benchmark_timer_find_average_overhead;
[1cfcfd3]26
[359e537]27
[1cfcfd3]28/*
29 * Set up Timer 1
30 */
[18bfc42]31void benchmark_timer_initialize( void )
[1cfcfd3]32{
[359e537]33    MC9328MXL_TMR2_TCTL = (MC9328MXL_TMR_TCTL_CLKSRC_PCLK1 |
[1cfcfd3]34                            MC9328MXL_TMR_TCTL_FRR |
35                            MC9328MXL_TMR_TCTL_TEN);
36    /* set prescaler to 1 (register value + 1) */ \
37    MC9328MXL_TMR2_TPRER = 0;
38
39    /* get freq of counter in KHz */
40    g_freq = get_perclk1_freq() / 1000;
41
42    g_start =  MC9328MXL_TMR2_TCN;
43}
44
45/*
[18bfc42]46 *  The following controls the behavior of benchmark_timer_read().
[1cfcfd3]47 *
48 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
49 *  is usually deducted from the number returned.
50 *
51 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
52 *  below this are "noise" and zero is returned.
53 */
54
55#define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
56                             /* (Y countdowns) to start/stop the timer. */
57                             /* This value is in microseconds. */
58#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
59
[8fbe2e6]60benchmark_timer_t benchmark_timer_read( void )
[1cfcfd3]61{
[15ebe58b]62  uint32_t t;
[1cfcfd3]63  unsigned long long total;
64
65  t =  MC9328MXL_TMR2_TCN;
66  /*
67   *  Total is calculated by taking into account the number of timer overflow
68   *  interrupts since the timer was initialized and clicks since the last
69   *  interrupts.
70   */
71
72  total = (t - g_start);
73
74  /* convert to nanoseconds */
[359e537]75  total = (total * 1000)/ g_freq;
[1cfcfd3]76
[18bfc42]77  if ( benchmark_timer_find_average_overhead == 1 ) {
[359e537]78    return (int) total;
[1cfcfd3]79  } else if ( total < LEAST_VALID ) {
[359e537]80      return 0;
[1cfcfd3]81  }
82  /*
83   *  Somehow convert total into microseconds
84   */
85
86  return (total - AVG_OVERHEAD);
87}
88
[3551166d]89void benchmark_timer_disable_subtracting_average_overhead(bool find_flag)
[1cfcfd3]90{
[18bfc42]91  benchmark_timer_find_average_overhead = find_flag;
[1cfcfd3]92}
93
Note: See TracBrowser for help on using the repository browser.