source: rtems/bsps/powerpc/shared/dev/timer-ppc-dec.c @ 5f59e2a

5
Last change on this file since 5f59e2a was 5f59e2a, checked in by Sebastian Huber <sebastian.huber@…>, on 03/26/18 at 05:52:57

bsps/powerpc: Move dec timer driver

This patch is a part of the BSP source reorganization.

Update #3285.

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