source: rtems/c/src/lib/libbsp/arm/gumstix/timer/timer.c @ e9d6114

5
Last change on this file since e9d6114 was e9d6114, checked in by Sebastian Huber <sebastian.huber@…>, on 12/08/17 at 06:32:10

bsp/gumstix: Move libcpu files to BSP

Update #3254.

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/**
2 * @file
3 * @brief PXA255 timer
4 */
5
6/*
7 * PXA255 timer by Yang Xi <hiyangxi@gmail.com>
8 * Copyright (c) 2004 by Jay Monkman <jtm@lopingdog.com>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#include <bsp.h>
16#include <rtems.h>
17#include <rtems/btimer.h>
18#include <pxa255.h>
19
20uint32_t tstart;
21static uint32_t tick_time;
22bool benchmark_timer_find_average_overhead;
23
24bool benchmark_timer_is_initialized = false;
25
26/*
27 * Use the timer count register to measure.
28 * The frequency of it is 3.4864MHZ
29 * The longest period we are able to capture is 4G/3.4864MHZ
30 */
31void benchmark_timer_initialize(void)
32{
33  tick_time = XSCALE_OS_TIMER_TCR;
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
51benchmark_timer_t benchmark_timer_read(void)
52{
53
54  uint32_t total;
55  total = XSCALE_OS_TIMER_TCR;
56  if(total>=tick_time)
57    total -= tick_time;
58  else
59    total += 0xffffffff - tick_time; /*Round up but not overflow*/
60
61  if ( benchmark_timer_find_average_overhead == true )
62    return total;          /*Counter cycles*/
63
64  if ( total < LEAST_VALID )
65    return 0;            /* below timer resolution */
66
67  return total;
68}
69
70void benchmark_timer_disable_subtracting_average_overhead(
71  bool find_flag
72)
73{
74  benchmark_timer_find_average_overhead = find_flag;
75}
Note: See TracBrowser for help on using the repository browser.