source: rtems/c/src/lib/libbsp/arm/edb7312/timer/timer.c @ f2f11abe

4.104.114.84.95
Last change on this file since f2f11abe was f2f11abe, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/03 at 18:50:57

2003-09-04 Joel Sherrill <joel@…>

  • clock/clockdrv.c, console/uart.c, include/bsp.h, include/ep7312.h, irq/bsp_irq_asm.S, irq/bsp_irq_init.c, irq/irq.c, irq/irq.h, start/start.S, startup/bspstart.c, startup/exit.c, startup/linkcmds, timer/timer.c: URL for license changed.
  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 * Cirrus EP7312 Timer driver
3 *
4 * Copyright (c) 2002 by Jay Monkman <jtm@smoothsmoothie.com>
5 *     
6 *  The license and distribution terms for this file may be
7 *  found in the file LICENSE in this distribution or at
8 *
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 * Notes:
12 *  This file manages the benchmark timer used by the RTEMS Timing Test
13 *  Suite.  Each measured time period is demarcated by calls to
14 *  Timer_initialize() and Read_timer().  Read_timer() usually returns
15 *  the number of microseconds since Timer_initialize() exitted.
16 *
17 *  It is important that the timer start/stop overhead be determined
18 *  when porting or modifying this code.
19 *
20 *  $Id$
21*/
22
23#include <rtems.h>
24#include <bsp.h>
25#include <ep7312.h>
26
27rtems_unsigned16 tstart;
28rtems_boolean Timer_driver_Find_average_overhead;
29
30void Timer_initialize( void )
31{
32    *EP7312_SYSCON1 |= EP7312_SYSCON1_TC2_512KHZ;
33    *EP7312_TC2D = 0xffff;
34}
35
36/*
37 *  The following controls the behavior of Read_timer().
38 *
39 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
40 *  is usually deducted from the number returned.
41 *
42 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
43 *  below this are "noise" and zero is returned.
44 */
45
46#define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
47                             /* (Y countdowns) to start/stop the timer. */
48                             /* This value is in microseconds. */
49#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
50
51int Read_timer( void )
52{
53  rtems_unsigned16 t;
54  rtems_unsigned32 total;
55  t = *EP7312_TC2D;
56
57  /*
58   *  Total is calculated by taking into account the number of timer overflow
59   *  interrupts since the timer was initialized and clicks since the last
60   *  interrupts.
61   */
62
63  total = (unsigned32)0x0000ffff - t;  /* result is 1/512000 = ~2 uS */
64  total = (total * 1953) / 1000;   /* convert to uS */
65  if ( Timer_driver_Find_average_overhead == 1 )
66    return total;          /* in XXX microsecond units */
67  else {
68    if ( total < LEAST_VALID )
69      return 0;            /* below timer resolution */
70  /*
71   *  Somehow convert total into microseconds
72   */
73      return (total - AVG_OVERHEAD);
74    }
75}
76
77/*
78 *  Empty function call used in loops to measure basic cost of looping
79 *  in Timing Test Suite.
80 */
81
82rtems_status_code Empty_function( void )
83{
84  return RTEMS_SUCCESSFUL;
85}
86
87void Set_find_average_overhead(
88  rtems_boolean find_flag
89)
90{
91  Timer_driver_Find_average_overhead = find_flag;
92}
93
Note: See TracBrowser for help on using the repository browser.