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
RevLine 
[8fbe2e6]1/**
2 *  @file
3 *  @brief
[5d807b5]4 *
[714336d]5 *  This file implements a benchmark timer using the PPC Timebase Register.
[8fbe2e6]6 */
7
8/*
[714336d]9 *  COPYRIGHT (c) 1989-2014.
[5d807b5]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
[c499856]14 *  http://www.rtems.org/license/LICENSE.
[5d807b5]15 */
16
[8fbe2e6]17#include <bsp.h>
18#include <rtems.h>
[a73a977]19#include <rtems/system.h>
[8fbe2e6]20#include <rtems/btimer.h>
[5d807b5]21#include <assert.h>
[3fcc78ae]22#include <libcpu/powerpc-utility.h>
23
[bb22a3f3]24#ifndef BSP_Convert_decrementer
25#define BSP_Convert_decrementer(value) (value)
26#endif
27
[66c373bf]28uint64_t   Timer_driver_Start_time;
[5d807b5]29
[3942cce]30bool benchmark_timer_find_average_overhead = false;
[5d807b5]31unsigned clicks_overhead = 0;
32
33/*
34 * Timer Get overhead
35 */
[714336d]36static int Timer_get_clicks_overhead(void)
[5d807b5]37{
[66c373bf]38  uint64_t    clicks;
[5d807b5]39
[e208738]40  PPC_Set_timebase_register((uint64_t) 0);
[5d807b5]41  clicks = PPC_Get_timebase_register();
42  assert(clicks <= 0xffffffff);
43  clicks_overhead = (unsigned) clicks;
44  return clicks_overhead;
45}
46
47/*
[359e537]48 * benchmark_timer_initialize
[5d807b5]49 */
[6427f1a]50void benchmark_timer_initialize(void)
[5d807b5]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();
[e208738]58  PPC_Set_timebase_register((uint64_t) 0);
[5d807b5]59}
60
61
62/*
[6427f1a]63 *  benchmark_timer_read
[5d807b5]64 */
[8e13ca61]65
[8fbe2e6]66benchmark_timer_t benchmark_timer_read(void)
[5d807b5]67{
[66c373bf]68  uint64_t    total64;
69  uint32_t    total;
[5d807b5]70
71  /* approximately CLOCK_SPEED clicks per microsecond */
72
73  total64 = PPC_Get_timebase_register();
74
[66c373bf]75  assert( total64 <= 0xffffffff );  /* fits into a uint32_t   */
[5d807b5]76
[e208738]77  total = (uint32_t) total64;
[5d807b5]78
[3942cce]79  if ( benchmark_timer_find_average_overhead == true )
[5d807b5]80    return total;          /* in "clicks" of the decrementer units */
81
82  return (int) BSP_Convert_decrementer(total - clicks_overhead);
83}
84
[3942cce]85void benchmark_timer_disable_subtracting_average_overhead(bool find_flag)
[5d807b5]86{
[6427f1a]87  benchmark_timer_find_average_overhead = find_flag;
[5d807b5]88}
Note: See TracBrowser for help on using the repository browser.