source: rtems/c/src/lib/libcpu/arm/pxa255/timer/timer.c @ c499856

4.11
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on Mar 20, 2014 at 9:10:47 PM

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*
2 * PXA255 timer by Yang Xi <hiyangxi@gmail.com>
3 * Copyright (c) 2004 by Jay Monkman <jtm@lopingdog.com>
4 *
5 * Notes:
6 *  This file manages the benchmark timer used by the RTEMS Timing Test
7 *  Suite.  Each measured time period is demarcated by calls to
8 *  Timer_initialize() and Read_timer().  Read_timer() usually returns
9 *  the number of microseconds since Timer_initialize() exitted.
10 *
11 *  It is important that the timer start/stop overhead be determined
12 *  when porting or modifying this code.
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.org/license/LICENSE.
17 */
18
19#include <rtems.h>
20#include <bsp.h>
21#include <pxa255.h>
22
23uint32_t tstart;
24static uint32_t tick_time;
25bool benchmark_timer_find_average_overhead;
26
27bool benchmark_timer_is_initialized = false;
28
29/*
30 * Use the timer count register to measure.
31 * The frequency of it is 3.4864MHZ
32 * The longest period we are able to capture is 4G/3.4864MHZ
33 */
34void benchmark_timer_initialize(void)
35{
36  tick_time = XSCALE_OS_TIMER_TCR;
37}
38
39/*
40 *  The following controls the behavior of Read_timer().
41 *
42 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
43 *  is usually deducted from the number returned.
44 *
45 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
46 *  below this are "noise" and zero is returned.
47 */
48
49#define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
50                             /* (Y countdowns) to start/stop the timer. */
51                             /* This value is in microseconds. */
52#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
53
54int benchmark_timer_read(void)
55{
56
57  uint32_t total;
58  total = XSCALE_OS_TIMER_TCR;
59  if(total>=tick_time)
60    total -= tick_time;
61  else
62    total += 0xffffffff - tick_time; /*Round up but not overflow*/
63
64  if ( benchmark_timer_find_average_overhead == true )
65    return total;          /*Counter cycles*/
66
67  if ( total < LEAST_VALID )
68    return 0;            /* below timer resolution */
69
70  return total;
71}
72
73void benchmark_timer_disable_subtracting_average_overhead(
74  bool find_flag
75)
76{
77  benchmark_timer_find_average_overhead = find_flag;
78}
Note: See TracBrowser for help on using the repository browser.