1 | /* |
---|
2 | * RTL22xx board Timer driver |
---|
3 | * |
---|
4 | * This uses Timer1 for timing measurments. |
---|
5 | * |
---|
6 | * By Ray xu<rayx.cn@gmail.com>, 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 | * $Id$ |
---|
23 | */ |
---|
24 | |
---|
25 | #include <rtems.h> |
---|
26 | #include <bsp.h> |
---|
27 | #include <lpc22xx.h> |
---|
28 | #include "lpc_timer.h" |
---|
29 | uint32_t g_start; |
---|
30 | uint32_t g_freq; |
---|
31 | |
---|
32 | rtems_boolean Timer_driver_Find_average_overhead; |
---|
33 | |
---|
34 | |
---|
35 | /* |
---|
36 | * Set up Timer 1 |
---|
37 | */ |
---|
38 | void Timer_initialize( void ) |
---|
39 | { |
---|
40 | g_freq = LPC22xx_Fpclk / 1000; |
---|
41 | } |
---|
42 | |
---|
43 | /* |
---|
44 | * The following controls the behavior of Read_timer(). |
---|
45 | * |
---|
46 | * AVG_OVEREHAD is the overhead for starting and stopping the timer. It |
---|
47 | * is usually deducted from the number returned. |
---|
48 | * |
---|
49 | * LEAST_VALID is the lowest number this routine should trust. Numbers |
---|
50 | * below this are "noise" and zero is returned. |
---|
51 | */ |
---|
52 | |
---|
53 | #define AVG_OVERHEAD 0 /* It typically takes X.X microseconds */ |
---|
54 | /* (Y countdowns) to start/stop the timer. */ |
---|
55 | /* This value is in microseconds. */ |
---|
56 | #define LEAST_VALID 1 /* Don't trust a clicks value lower than this */ |
---|
57 | |
---|
58 | int Read_timer( void ) |
---|
59 | { |
---|
60 | return (T0TC/(LPC22xx_Fpclk/1000000)); |
---|
61 | /* |
---|
62 | * Total is calculated by taking into account the number of timer overflow |
---|
63 | * interrupts since the timer was initialized and clicks since the last |
---|
64 | * interrupts. |
---|
65 | */ |
---|
66 | } |
---|
67 | |
---|
68 | /* |
---|
69 | * Empty function call used in loops to measure basic cost of looping |
---|
70 | * in Timing Test Suite. |
---|
71 | */ |
---|
72 | |
---|
73 | rtems_status_code Empty_function( void ) |
---|
74 | { |
---|
75 | return RTEMS_SUCCESSFUL; |
---|
76 | } |
---|
77 | |
---|
78 | void Set_find_average_overhead( |
---|
79 | rtems_boolean find_flag |
---|
80 | ) |
---|
81 | { |
---|
82 | Timer_driver_Find_average_overhead = find_flag; |
---|
83 | } |
---|
84 | |
---|