source: rtems/c/src/lib/libbsp/lm32/shared/milkymist_timer/timer.c @ 44d7753

4.11
Last change on this file since 44d7753 was 44d7753, checked in by Ralf Corsepius <ralf.corsepius@…>, on Feb 9, 2011 at 8:19:30 AM

2011-02-09 Ralf Corsépius <ralf.corsepius@…>

  • shared/milkymist_timer/timer.c, shared/timer/timer.c: Include <rtems/btimer.h>. Fix benchmark_timer_read() definition.
  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*  timer.c
2 *
3 *  This file manages the benchmark timer used by the RTEMS Timing
4 *  Test Suite.  Each measured time period is demarcated by calls to
5 *  benchmark_timer_initialize() and benchmark_timer_read().
6 *  benchmark_timer_read() usually returns the number of microseconds
7 *  since benchmark_timer_initialize() exitted.
8 *
9 *  NOTE: It is important that the timer start/stop overhead be
10 *        determined when porting or modifying this code.
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 *
16 *  $Id$
17 *
18 *  COPYRIGHT (c) Yann Sionneau <yann.sionneau@telecom-sudparis.eu> (GSoC 2010)
19 *  Telecom SudParis
20 */
21
22#include <rtems.h>
23#include <bsp.h>
24#include <rtems/btimer.h>
25#include "../include/system_conf.h"
26#include "../../shared/clock/clock.h"
27
28static inline int timerread(unsigned int reg)
29{
30  return *((int*)(reg));
31}
32
33static inline void timerwrite(unsigned int reg, int value)
34{
35  *((int*)reg) = value;
36}
37
38bool benchmark_timer_find_average_overhead;
39
40void benchmark_timer_initialize( void )
41{
42  timerwrite(MM_TIMER1_COMPARE, 0xffffffff);
43  timerwrite(MM_TIMER1_COUNTER, 0);
44  timerwrite(MM_TIMER1_CONTROL, TIMER_ENABLE);
45}
46
47/*
48 *  The following controls the behavior of benchmark_timer_read().
49 *
50 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
51 *  is usually deducted from the number returned.
52 *
53 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
54 *  below this are "noise" and zero is returned.
55 */
56
57#define AVG_OVERHEAD      4  /* It typically takes X.X microseconds */
58                             /* (Y countdowns) to start/stop the timer. */
59                             /* This value is in microseconds. */
60#define LEAST_VALID       4  /* Don't trust a clicks value lower than this */
61
62uint32_t benchmark_timer_read( void )
63{
64  uint32_t ticks;
65  uint32_t total;
66  ticks = timerread(MM_TIMER1_COUNTER);
67  if (ticks == 0xffffffff)
68    printk("Timer overflow!\n");
69
70  total = ticks / (CPU_FREQUENCY / 1000000);
71
72  if ( benchmark_timer_find_average_overhead == true )
73    return total;
74  else
75  {
76    if ( total < LEAST_VALID )
77      return 0;
78
79    return (total - AVG_OVERHEAD);
80
81  }
82}
83
84void benchmark_timer_disable_subtracting_average_overhead(
85  bool find_flag
86)
87{
88  benchmark_timer_find_average_overhead = find_flag;
89}
Note: See TracBrowser for help on using the repository browser.