source: rtems/c/src/lib/libcpu/arm/lpc22xx/timer/timer.c @ 61e293b6

4.104.114.84.95
Last change on this file since 61e293b6 was 61e293b6, checked in by Ralf Corsepius <ralf.corsepius@…>, on Apr 25, 2007 at 11:57:13 AM

Use current OAR license file URL.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 * RTL22xx board Timer driver
3 *
4 * This uses Timer1 for timing measurments.
5 * 
6 *  By Ray xu, modify form Mc9328mxl    RTEMS DSP
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *
11 *  http://www.rtems.com/license/LICENSE.
12 *
13 * Notes:
14 *  This file manages the benchmark timer used by the RTEMS Timing Test
15 *  Suite.  Each measured time period is demarcated by calls to
16 *  Timer_initialize() and Read_timer().  Read_timer() usually returns
17 *  the number of microseconds since Timer_initialize() exitted.
18 *
19 *  It is important that the timer start/stop overhead be determined
20 *  when porting or modifying this code.
21 *
22 *  timer.c,v 1.1 2002/11/13 17:55:09 joel Exp
23*/
24
25#include <rtems.h>
26#include <bsp.h>
27#include <lpc22xx.h>
28#include "lpc_timer.h"
29uint32_t g_start;
30uint32_t g_freq;
31
32#ifndef __cplusplus
33#define bool    int
34#define true    1
35#define false   0
36
37#endif/* __cplusplus */
38
39rtems_boolean Timer_driver_Find_average_overhead;
40
41   
42/*
43 * Set up Timer 1
44 */
45void Timer_initialize( void )
46{
47        T1TCR &= 0;      /* disable and clear timer 0  */ 
48       g_start = (T1TC/(LPC22xx_Fpclk/1000000));
49       T1PC  = 0;            /* TC is incrementet on every pclk.*/ 
50        T1MR0 = ((LPC22xx_Fpclk/1000* BSP_Configuration.microseconds_per_tick) / 1000); /* initialize the timer period and prescaler */ 
51       T1EMR = 0;  /*No external match*/ 
52        T1TCR = 1; /*enable timer1*/ 
53       g_freq = LPC22xx_Fpclk / 1000;
54}
55
56/*
57 *  The following controls the behavior of Read_timer().
58 *
59 *  AVG_OVEREHAD is the overhead for starting and stopping the timer.  It
60 *  is usually deducted from the number returned.
61 *
62 *  LEAST_VALID is the lowest number this routine should trust.  Numbers
63 *  below this are "noise" and zero is returned.
64 */
65
66#define AVG_OVERHEAD      0  /* It typically takes X.X microseconds */
67                             /* (Y countdowns) to start/stop the timer. */
68                             /* This value is in microseconds. */
69#define LEAST_VALID       1  /* Don't trust a clicks value lower than this */
70
71int Read_timer( void )
72{
73  uint32_t t;
74  unsigned long long total;
75 
76  t = (T1TC/(LPC22xx_Fpclk/1000000));
77  /*
78   *  Total is calculated by taking into account the number of timer overflow
79   *  interrupts since the timer was initialized and clicks since the last
80   *  interrupts. currently it is not supported
81   */
82
83  total = (t - g_start);
84
85  /* convert to nanoseconds */
86
87  if ( Timer_driver_Find_average_overhead == 1 ) {
88    return (int) total; 
89  } else if ( total < LEAST_VALID ) {
90      return 0;       
91  }
92  /*
93   *  Somehow convert total into microseconds
94   */
95
96  return (total - AVG_OVERHEAD);
97}
98
99/*
100 *  Empty function call used in loops to measure basic cost of looping
101 *  in Timing Test Suite.
102 */
103
104rtems_status_code Empty_function( void )
105{
106  return RTEMS_SUCCESSFUL;
107}
108
109void Set_find_average_overhead(
110  rtems_boolean find_flag
111)
112{
113  Timer_driver_Find_average_overhead = find_flag;
114}
115
Note: See TracBrowser for help on using the repository browser.