OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libcpu/] [powerpc/] [mpc6xx/] [timer/] [timer.c] - Blame information for rev 607

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*  timer.c
2
 *
3
 *  This file implements a benchmark timer using the General Purpose Timer.
4
 *
5
 *  Notes:
6
 *
7
 *  BSP_TIMER_AVG_OVERHEAD and BSP_TIMER_LEAST_VALID are required to be
8
 *  provided in bsp.h
9
 *
10
 *  COPYRIGHT (c) 1989-1997.
11
 *  On-Line Applications Research Corporation (OAR).
12
 *  Copyright assigned to U.S. Government, 1994.
13
 *
14
 *  The license and distribution terms for this file may in
15
 *  the file LICENSE in this distribution or at
16
 *  http://www.OARcorp.com/rtems/license.html.
17
 *
18
 *  $Id: timer.c,v 1.2 2001-09-27 12:01:25 chris Exp $
19
 */
20
 
21
#include <assert.h>
22
#include <libcpu/cpu.h>
23
#include <bsp.h>
24
 
25
rtems_unsigned64 Timer_driver_Start_time;
26
 
27
rtems_boolean Timer_driver_Find_average_overhead = 0;
28
unsigned clicks_overhead = 0;
29
 
30
/*
31
 * Timer Get overhead
32
 */
33
 
34
int Timer_get_clicks_overhead()
35
{
36
  rtems_unsigned64  clicks;
37
 
38
  PPC_Set_timebase_register((unsigned64) 0);
39
  clicks = PPC_Get_timebase_register();
40
  assert(clicks <= 0xffffffff);
41
  clicks_overhead = (unsigned) clicks;
42
  return clicks_overhead;
43
}
44
 
45
/*
46
 * Timer_initialize
47
 */
48
void Timer_initialize()
49
{
50
 
51
  /*
52
   *  Timer runs long and accurate enough not to require an interrupt.
53
   */
54
 
55
  if (clicks_overhead == 0) clicks_overhead = Timer_get_clicks_overhead();
56
  PPC_Set_timebase_register((unsigned64) 0);
57
}
58
 
59
 
60
/*
61
 *  Read_timer
62
 */
63
int Read_timer()
64
{
65
  rtems_unsigned64  total64;
66
  rtems_unsigned32  total;
67
 
68
  /* approximately CLOCK_SPEED clicks per microsecond */
69
 
70
  total64 = PPC_Get_timebase_register();
71
 
72
  assert( total64 <= 0xffffffff );  /* fits into a unsigned32 */
73
 
74
  total = (rtems_unsigned32) total64;
75
 
76
  if ( Timer_driver_Find_average_overhead == 1 )
77
    return total;          /* in "clicks" of the decrementer units */
78
 
79
  return (int) BSP_Convert_decrementer(total - clicks_overhead);
80
}
81
 
82
unsigned long long Read_long_timer()
83
{
84
  rtems_unsigned64  total64;
85
 
86
  total64 = PPC_Get_timebase_register();
87
  return BSP_Convert_decrementer(total64 - clicks_overhead);
88
}
89
 
90
rtems_status_code Empty_function( void )
91
{
92
  return RTEMS_SUCCESSFUL;
93
}
94
 
95
void Set_find_average_overhead(
96
  rtems_boolean find_flag
97
)
98
{
99
  Timer_driver_Find_average_overhead = find_flag;
100
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.