source: rtems/c/src/lib/libcpu/arm/mc9328mxl/timer/timer.c @ 6edbd66

4.104.114.84.95
Last change on this file since 6edbd66 was 93f4a906, checked in by Joel Sherrill <joel.sherrill@…>, on 03/12/07 at 11:17:07

2007-03-12 Joel Sherrill <joel@…>

  • at91rm9200/clock/clock.c, at91rm9200/dbgu/dbgu.c, at91rm9200/include/at91rm9200.h, at91rm9200/include/at91rm9200_dbgu.h, at91rm9200/include/at91rm9200_emac.h, at91rm9200/include/at91rm9200_gpio.h, at91rm9200/include/at91rm9200_mem.h, at91rm9200/include/at91rm9200_pmc.h, at91rm9200/include/bits.h, at91rm9200/irq/bsp_irq_asm.S, at91rm9200/irq/bsp_irq_init.c, at91rm9200/irq/irq.c, at91rm9200/irq/irq.h, at91rm9200/pmc/pmc.c, at91rm9200/timer/timer.c, mc9328mxl/clock/clockdrv.c, mc9328mxl/include/mc9328mxl.h, mc9328mxl/irq/bsp_irq_asm.S, mc9328mxl/irq/bsp_irq_init.c, mc9328mxl/irq/irq.c, mc9328mxl/irq/irq.h, mc9328mxl/timer/timer.c, s3c2400/clock/clockdrv.c, s3c2400/timer/timer.c: Correct license URL and/or fix mistake in copyright notice. Both of these mistakes appear to be from code submitted after these changes were made previously.
  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 * Cogent CSB336 Timer driver
3 *
4 * This uses timer 2 for timing measurments.
5 *
6 * Copyright (c) 2004 Cogent Computer Systems
7 *        Written by Jay Monkman <jtm@lopingdog.com>
8 *     
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *
12 *  http://www.rtems.com/license/LICENSE.
13 *
14 * Notes:
15 *  This file manages the benchmark timer used by the RTEMS Timing Test
16 *  Suite.  Each measured time period is demarcated by calls to
17 *  Timer_initialize() and Read_timer().  Read_timer() usually returns
18 *  the number of microseconds since Timer_initialize() exitted.
19 *
20 *  It is important that the timer start/stop overhead be determined
21 *  when porting or modifying this code.
22 *
23 *  timer.c,v 1.1 2002/11/13 17:55:09 joel Exp
24*/
25
26#include <rtems.h>
27#include <bsp.h>
28#include <mc9328mxl.h>
29
30uint32_t g_start;
31uint32_t g_freq;
32
33rtems_boolean Timer_driver_Find_average_overhead;
34
35   
36/*
37 * Set up Timer 1
38 */
39void Timer_initialize( void )
40{
41    MC9328MXL_TMR2_TCTL = (MC9328MXL_TMR_TCTL_CLKSRC_PCLK1 |
42                            MC9328MXL_TMR_TCTL_FRR |
43                            MC9328MXL_TMR_TCTL_TEN);
44    /* set prescaler to 1 (register value + 1) */ \
45    MC9328MXL_TMR2_TPRER = 0;
46
47    /* get freq of counter in KHz */
48    g_freq = get_perclk1_freq() / 1000;
49
50    g_start =  MC9328MXL_TMR2_TCN;
51}
52
53/*
54 *  The following controls the behavior of Read_timer().
55 *
56 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
57 *  is usually deducted from the number returned.
58 *
59 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
60 *  below this are "noise" and zero is returned.
61 */
62
63#define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
64                             /* (Y countdowns) to start/stop the timer. */
65                             /* This value is in microseconds. */
66#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
67
68int Read_timer( void )
69{
70  uint32_t t;
71  unsigned long long total;
72
73  t =  MC9328MXL_TMR2_TCN;
74  /*
75   *  Total is calculated by taking into account the number of timer overflow
76   *  interrupts since the timer was initialized and clicks since the last
77   *  interrupts.
78   */
79
80  total = (t - g_start);
81
82  /* convert to nanoseconds */
83  total = (total * 1000)/ g_freq;
84
85  if ( Timer_driver_Find_average_overhead == 1 ) {
86    return (int) total;
87  } else if ( total < LEAST_VALID ) {
88      return 0;       
89  }
90  /*
91   *  Somehow convert total into microseconds
92   */
93
94  return (total - AVG_OVERHEAD);
95}
96
97/*
98 *  Empty function call used in loops to measure basic cost of looping
99 *  in Timing Test Suite.
100 */
101
102rtems_status_code Empty_function( void )
103{
104  return RTEMS_SUCCESSFUL;
105}
106
107void Set_find_average_overhead(
108  rtems_boolean find_flag
109)
110{
111  Timer_driver_Find_average_overhead = find_flag;
112}
113
Note: See TracBrowser for help on using the repository browser.