source: rtems/c/src/lib/libcpu/powerpc/mpc6xx/timer/timer.c @ c499856

4.115
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: 1.9 KB
Line 
1/*  timer.c
2 *
3 *  This file implements a benchmark timer using the PPC Timebase
4 *
5 *  Notes: NONE
6 *
7 *  COPYRIGHT (c) 1989-2000.
8 *  On-Line Applications Research Corporation (OAR).
9 *
10 *  The license and distribution terms for this file may in
11 *  the file LICENSE in this distribution or at
12 *  http://www.rtems.org/license/LICENSE.
13 */
14
15#include <rtems/system.h>
16#include <assert.h>
17#include <rtems.h>
18#include <bsp.h>
19#include <libcpu/powerpc-utility.h>
20
21
22uint64_t   Timer_driver_Start_time;
23
24bool benchmark_timer_find_average_overhead = false;
25unsigned clicks_overhead = 0;
26
27/*
28 * Timer Get overhead
29 */
30
31int Timer_get_clicks_overhead(void)
32{
33  uint64_t    clicks;
34
35  PPC_Set_timebase_register((uint64_t) 0);
36  clicks = PPC_Get_timebase_register();
37  assert(clicks <= 0xffffffff);
38  clicks_overhead = (unsigned) clicks;
39  return clicks_overhead;
40}
41
42/*
43 * benchmark_timer_initialize
44 */
45void benchmark_timer_initialize(void)
46{
47
48  /*
49   *  Timer runs long and accurate enough not to require an interrupt.
50   */
51
52  if (clicks_overhead == 0) clicks_overhead = Timer_get_clicks_overhead();
53  PPC_Set_timebase_register((uint64_t) 0);
54}
55
56
57/*
58 *  benchmark_timer_read
59 */
60
61int benchmark_timer_read(void)
62{
63  uint64_t    total64;
64  uint32_t    total;
65
66  /* approximately CLOCK_SPEED clicks per microsecond */
67
68  total64 = PPC_Get_timebase_register();
69
70  assert( total64 <= 0xffffffff );  /* fits into a uint32_t   */
71
72  total = (uint32_t) total64;
73
74  if ( benchmark_timer_find_average_overhead == true )
75    return total;          /* in "clicks" of the decrementer units */
76
77  return (int) BSP_Convert_decrementer(total - clicks_overhead);
78}
79
80unsigned long long Read_long_timer(void)
81{
82  uint64_t    total64;
83
84  total64 = PPC_Get_timebase_register();
85  return BSP_Convert_decrementer(total64 - clicks_overhead);
86}
87
88void benchmark_timer_disable_subtracting_average_overhead(bool find_flag)
89{
90  benchmark_timer_find_average_overhead = find_flag;
91}
Note: See TracBrowser for help on using the repository browser.