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 | * http://www.rtems.org/license/LICENSE. |
---|
11 | * |
---|
12 | * Notes: |
---|
13 | * This file manages the benchmark timer used by the RTEMS Timing Test |
---|
14 | * Suite. Each measured time period is demarcated by calls to |
---|
15 | * benchmark_timer_initialize() and benchmark_timer_read(). benchmark_timer_read() usually returns |
---|
16 | * the number of microseconds since benchmark_timer_initialize() exitted. |
---|
17 | * |
---|
18 | * It is important that the timer start/stop overhead be determined |
---|
19 | * when porting or modifying this code. |
---|
20 | */ |
---|
21 | |
---|
22 | #include <rtems.h> |
---|
23 | #include <bsp.h> |
---|
24 | #include <lpc22xx.h> |
---|
25 | #include "lpc_timer.h" |
---|
26 | uint32_t g_start; |
---|
27 | uint32_t g_freq; |
---|
28 | |
---|
29 | bool benchmark_timer_find_average_overhead; |
---|
30 | |
---|
31 | |
---|
32 | /* |
---|
33 | * Set up Timer 1 |
---|
34 | */ |
---|
35 | void benchmark_timer_initialize( void ) |
---|
36 | { |
---|
37 | g_freq = LPC22xx_Fpclk / 1000; |
---|
38 | } |
---|
39 | |
---|
40 | /* |
---|
41 | * The following controls the behavior of benchmark_timer_read(). |
---|
42 | * |
---|
43 | * AVG_OVEREHAD is the overhead for starting and stopping the timer. It |
---|
44 | * is usually deducted from the number returned. |
---|
45 | * |
---|
46 | * LEAST_VALID is the lowest number this routine should trust. Numbers |
---|
47 | * below this are "noise" and zero is returned. |
---|
48 | */ |
---|
49 | |
---|
50 | #define AVG_OVERHEAD 0 /* It typically takes X.X microseconds */ |
---|
51 | /* (Y countdowns) to start/stop the timer. */ |
---|
52 | /* This value is in microseconds. */ |
---|
53 | #define LEAST_VALID 1 /* Don't trust a clicks value lower than this */ |
---|
54 | |
---|
55 | int benchmark_timer_read( void ) |
---|
56 | { |
---|
57 | return (T0TC/(LPC22xx_Fpclk/1000000)); |
---|
58 | /* |
---|
59 | * Total is calculated by taking into account the number of timer overflow |
---|
60 | * interrupts since the timer was initialized and clicks since the last |
---|
61 | * interrupts. |
---|
62 | */ |
---|
63 | } |
---|
64 | |
---|
65 | void benchmark_timer_disable_subtracting_average_overhead(bool find_flag) |
---|
66 | { |
---|
67 | benchmark_timer_find_average_overhead = find_flag; |
---|
68 | } |
---|
69 | |
---|