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

4.115
Last change on this file since b8ee42c was b8ee42c, checked in by Gedare Bloom <gedare@…>, on 11/27/11 at 17:30:18

2011-11-27 Sebastien Bourdeauducq <seb@…>

PR 1970/bsps

  • milkymist_clock/ckinit.c, milkymist_console/console.c, milkymist_console/uart.c, milkymist_timer/timer.c: Support for the new Milkymist sysctl and clock frequency detection.
  • Property mode set to 100644
File size: 2.2 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
28bool benchmark_timer_find_average_overhead;
29
30void benchmark_timer_initialize(void)
31{
32  MM_WRITE(MM_TIMER1_COMPARE, 0xffffffff);
33  MM_WRITE(MM_TIMER1_COUNTER, 0);
34  MM_WRITE(MM_TIMER1_CONTROL, TIMER_ENABLE);
35}
36
37/*
38 *  The following controls the behavior of benchmark_timer_read().
39 *
40 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
41 *  is usually deducted from the number returned.
42 *
43 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
44 *  below this are "noise" and zero is returned.
45 */
46
47#define AVG_OVERHEAD      4  /* It typically takes X.X microseconds */
48                             /* (Y countdowns) to start/stop the timer. */
49                             /* This value is in microseconds. */
50#define LEAST_VALID       4  /* Don't trust a clicks value lower than this */
51
52uint32_t benchmark_timer_read(void)
53{
54  uint32_t ticks;
55  uint32_t total;
56
57  ticks = MM_READ(MM_TIMER1_COUNTER);
58  if (ticks == 0xffffffff)
59    printk("Timer overflow!\n");
60
61  total = ticks / (MM_READ(MM_FREQUENCY) / 1000000);
62
63  if (benchmark_timer_find_average_overhead)
64    return total;
65  else
66  {
67    if (total < LEAST_VALID)
68      return 0;
69
70    return (total - AVG_OVERHEAD);
71  }
72}
73
74void benchmark_timer_disable_subtracting_average_overhead(
75  bool find_flag
76)
77{
78  benchmark_timer_find_average_overhead = find_flag;
79}
Note: See TracBrowser for help on using the repository browser.