source: rtems/c/src/lib/libbsp/lm32/shared/milkymist_timer/timer.c @ 9bf34835

4.115
Last change on this file since 9bf34835 was 9bf34835, checked in by Joel Sherrill <joel.sherrill@…>, on 08/20/10 at 21:23:27

2010-08-20 <yann.sionneau@…>

  • shared/milkymist_ac97/ac97.c, shared/milkymist_clock/ckinit.c, shared/milkymist_clock/clock.h, shared/milkymist_console/console.c, shared/milkymist_console/uart.c, shared/milkymist_console/uart.h, shared/milkymist_framebuffer/framebuffer.c, shared/milkymist_gpio/gpio.c, shared/milkymist_networking/mm_crc32.c, shared/milkymist_networking/network.c, shared/milkymist_networking/network.h, shared/milkymist_timer/timer.c: New files.
  • Property mode set to 100644
File size: 2.3 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 "../include/system_conf.h"
25#include "../../shared/clock/clock.h"
26
27static inline int timerread(unsigned int reg)
28{
29  return *((int*)(reg));
30}
31
32static inline void timerwrite(unsigned int reg, int value)
33{
34  *((int*)reg) = value;
35}
36
37bool benchmark_timer_find_average_overhead;
38
39void benchmark_timer_initialize( void )
40{
41  timerwrite(MM_TIMER1_COMPARE, 0xffffffff);
42  timerwrite(MM_TIMER1_COUNTER, 0);
43  timerwrite(MM_TIMER1_CONTROL, TIMER_ENABLE);
44}
45
46/*
47 *  The following controls the behavior of benchmark_timer_read().
48 *
49 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
50 *  is usually deducted from the number returned.
51 *
52 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
53 *  below this are "noise" and zero is returned.
54 */
55
56#define AVG_OVERHEAD      4  /* It typically takes X.X microseconds */
57                             /* (Y countdowns) to start/stop the timer. */
58                             /* This value is in microseconds. */
59#define LEAST_VALID       4  /* Don't trust a clicks value lower than this */
60
61int benchmark_timer_read( void )
62{
63  uint32_t ticks;
64  uint32_t total;
65  ticks = timerread(MM_TIMER1_COUNTER);
66  if (ticks == 0xffffffff)
67    printk("Timer overflow!\n");
68
69  total = ticks / (CPU_FREQUENCY / 1000000);
70
71  if ( benchmark_timer_find_average_overhead == true )
72    return total;
73  else
74  {
75    if ( total < LEAST_VALID )
76      return 0;
77
78    return (total - AVG_OVERHEAD);
79
80  }
81}
82
83void benchmark_timer_disable_subtracting_average_overhead(
84  bool find_flag
85)
86{
87  benchmark_timer_find_average_overhead = find_flag;
88}
Note: See TracBrowser for help on using the repository browser.