OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [powerpc/] [psim/] [timer/] [timer.c] - Blame information for rev 318

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 on
4
 *  the MEC.
5
 *
6
 *  COPYRIGHT (c) 1989-1999.
7
 *  On-Line Applications Research Corporation (OAR).
8
 *
9
 *  The license and distribution terms for this file may be
10
 *  found in found in the file LICENSE in this distribution or at
11
 *  http://www.OARcorp.com/rtems/license.html.
12
 *
13
 *  Ported to ERC32 implementation of the SPARC by On-Line Applications
14
 *  Research Corporation (OAR) under contract to the European Space
15
 *  Agency (ESA).
16
 *
17
 *  ERC32 modifications of respective RTEMS file: COPYRIGHT (c) 1995.
18
 *  European Space Agency.
19
 *
20
 *  $Id: timer.c,v 1.2 2001-09-27 12:01:02 chris Exp $
21
 */
22
 
23
#include <assert.h>
24
 
25
#include <bsp.h>
26
 
27
rtems_unsigned64 Timer_driver_Start_time;
28
 
29
rtems_boolean Timer_driver_Find_average_overhead;
30
 
31
void Timer_initialize()
32
{
33
  /*
34
   *  Timer runs long and accurate enough not to require an interrupt.
35
   */
36
 
37
 
38
  Timer_driver_Start_time = PPC_Get_timebase_register();
39
 
40
 
41
}
42
 
43
#define AVG_OVERHEAD     24  /* It typically takes 24 instructions */
44
                             /*     to start/stop the timer. */
45
#define LEAST_VALID       1  /* Don't trust a value lower than this */
46
                             /* psim can count instructions. :) */
47
 
48
int Read_timer()
49
{
50
  rtems_unsigned64  clicks;
51
  rtems_unsigned64  total64;
52
  rtems_unsigned32  total;
53
 
54
  /* approximately CLOCK_SPEED clicks per microsecond */
55
 
56
  clicks = PPC_Get_timebase_register();
57
 
58
  assert( clicks > Timer_driver_Start_time );
59
 
60
  total64 = clicks - Timer_driver_Start_time;
61
 
62
  assert( total64 <= 0xffffffff );  /* fits into a unsigned32 */
63
 
64
  total = (rtems_unsigned32) total64;
65
 
66
  if ( Timer_driver_Find_average_overhead == 1 )
67
    return total;          /* in one microsecond units */
68
 
69
  if ( total < LEAST_VALID )
70
    return 0;            /* below timer resolution */
71
 
72
  return total - AVG_OVERHEAD;
73
}
74
 
75
rtems_status_code Empty_function( void )
76
{
77
  return RTEMS_SUCCESSFUL;
78
}
79
 
80
void Set_find_average_overhead(
81
  rtems_boolean find_flag
82
)
83
{
84
  Timer_driver_Find_average_overhead = find_flag;
85
}

powered by: WebSVN 2.1.0

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