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

4.104.115
Last change on this file since be9f085 was b1783062, checked in by Joel Sherrill <joel.sherrill@…>, on 12/04/08 at 22:55:13

2008-12-04 Jukka Pietarinen <jukka.pietarinen@…>

  • ChangeLog?, Makefile.am, README, acinclude.m4, configure.ac, shared/clock/ckinit.c, shared/clock/clock.h, shared/console/console.c, shared/console/uart.c, shared/console/uart.h, shared/start/start.S, shared/startup/bspstart.c, shared/startup/setvec.c, shared/timer/timer.c, shared/tsmac/dp83848phy.h, shared/tsmac/tsmac.c, shared/tsmac/tsmac.h: New files.
  • Property mode set to 100644
File size: 2.9 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 *  COPYRIGHT (c) 1989-1999.
13 *  On-Line Applications Research Corporation (OAR).
14 *
15 *  The license and distribution terms for this file may be
16 *  found in the file LICENSE in this distribution or at
17 *  http://www.rtems.com/license/LICENSE.
18 *
19 *  $Id$
20 *
21 *  Jukka Pietarinen <jukka.pietarinen@mrf.fi>, 2008,
22 *  Micro-Research Finland Oy
23 */
24
25#include <rtems.h>
26#include <bsp.h>
27#include "../include/system_conf.h"
28#include "../../shared/clock/clock.h"
29
30static inline int timerread(unsigned int reg)
31{
32#ifdef TIMER1_BASE_ADDRESS
33  return *((int*)(TIMER1_BASE_ADDRESS + reg));
34#else
35#warning "Benchmarking timer TIMER1 not available!"
36  return 0;
37#endif
38}
39
40static inline void timerwrite(unsigned int reg, int value)
41{
42#ifdef TIMER1_BASE_ADDRESS
43  *((int*)(TIMER1_BASE_ADDRESS + reg)) = value;
44#endif
45}
46
47bool benchmark_timer_find_average_overhead;
48
49void benchmark_timer_initialize( void )
50{
51  /* Set timer period */
52  timerwrite(LM32_CLOCK_PERIOD, 0xffffffff);
53  /* Stop timer */
54  timerwrite(LM32_CLOCK_CR, LM32_CLOCK_CR_STOP);
55  /* Clear status register */
56  timerwrite(LM32_CLOCK_SR, 0);
57  /* Start timer */
58  timerwrite(LM32_CLOCK_CR, LM32_CLOCK_CR_START);
59}
60
61/*
62 *  The following controls the behavior of benchmark_timer_read().
63 *
64 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
65 *  is usually deducted from the number returned.
66 *
67 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
68 *  below this are "noise" and zero is returned.
69 */
70
71#define AVG_OVERHEAD      4  /* It typically takes X.X microseconds */
72                             /* (Y countdowns) to start/stop the timer. */
73                             /* This value is in microseconds. */
74#define LEAST_VALID       4  /* Don't trust a clicks value lower than this */
75
76int benchmark_timer_read( void )
77{
78  uint32_t ticks;
79  uint32_t total;
80  uint32_t status;
81
82  ticks = 0xffffffff - timerread(LM32_CLOCK_SNAPSHOT);
83  status = timerread(LM32_CLOCK_SR);
84  if (status & LM32_CLOCK_SR_TO)
85    printk("Timer overflow!\n");
86
87  total = ticks / (CPU_FREQUENCY / 1000000);
88
89  if ( benchmark_timer_find_average_overhead == true )
90    return total;          /* in XXX microsecond units */
91  else
92    {
93      if ( total < LEAST_VALID )
94        return 0;            /* below timer resolution */
95      /*
96       *  Somehow convert total into microseconds
97       */
98      return (total - AVG_OVERHEAD);
99    }
100}
101
102void benchmark_timer_disable_subtracting_average_overhead(
103  bool find_flag
104)
105{
106  benchmark_timer_find_average_overhead = find_flag;
107}
Note: See TracBrowser for help on using the repository browser.