[8fbe2e6] | 1 | /** |
---|
| 2 | * @file |
---|
| 3 | * @brief RTL22xx board Timer driver |
---|
[7d33199] | 4 | * |
---|
| 5 | * This uses Timer1 for timing measurments. |
---|
[8fbe2e6] | 6 | */ |
---|
| 7 | |
---|
| 8 | /* |
---|
| 9 | * By Ray Xu <rayx.cn@gmail.com>, modify form Mc9328mxl RTEMS DSP |
---|
[359e537] | 10 | * |
---|
[8fbe2e6] | 11 | * The license and distribution terms for this file may be |
---|
| 12 | * found in the file LICENSE in this distribution or at |
---|
| 13 | * http://www.rtems.org/license/LICENSE. |
---|
| 14 | */ |
---|
[7d33199] | 15 | |
---|
| 16 | #include <bsp.h> |
---|
[8fbe2e6] | 17 | #include <rtems.h> |
---|
| 18 | #include <rtems/btimer.h> |
---|
[7d33199] | 19 | #include <lpc22xx.h> |
---|
| 20 | #include "lpc_timer.h" |
---|
[8fbe2e6] | 21 | |
---|
[7d33199] | 22 | uint32_t g_start; |
---|
| 23 | uint32_t g_freq; |
---|
| 24 | |
---|
[3551166d] | 25 | bool benchmark_timer_find_average_overhead; |
---|
[7d33199] | 26 | |
---|
[359e537] | 27 | |
---|
[7d33199] | 28 | /* |
---|
| 29 | * Set up Timer 1 |
---|
| 30 | */ |
---|
[18bfc42] | 31 | void benchmark_timer_initialize( void ) |
---|
[7d33199] | 32 | { |
---|
| 33 | g_freq = LPC22xx_Fpclk / 1000; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | /* |
---|
[18bfc42] | 37 | * The following controls the behavior of benchmark_timer_read(). |
---|
[7d33199] | 38 | * |
---|
| 39 | * AVG_OVEREHAD is the overhead for starting and stopping the timer. It |
---|
| 40 | * is usually deducted from the number returned. |
---|
| 41 | * |
---|
| 42 | * LEAST_VALID is the lowest number this routine should trust. Numbers |
---|
| 43 | * below this are "noise" and zero is returned. |
---|
| 44 | */ |
---|
| 45 | |
---|
| 46 | #define AVG_OVERHEAD 0 /* It typically takes X.X microseconds */ |
---|
| 47 | /* (Y countdowns) to start/stop the timer. */ |
---|
| 48 | /* This value is in microseconds. */ |
---|
| 49 | #define LEAST_VALID 1 /* Don't trust a clicks value lower than this */ |
---|
| 50 | |
---|
[8fbe2e6] | 51 | benchmark_timer_t benchmark_timer_read( void ) |
---|
[7d33199] | 52 | { |
---|
[716f6be] | 53 | return (T0TC/(LPC22xx_Fpclk/1000000)); |
---|
[7d33199] | 54 | /* |
---|
| 55 | * Total is calculated by taking into account the number of timer overflow |
---|
| 56 | * interrupts since the timer was initialized and clicks since the last |
---|
[716f6be] | 57 | * interrupts. |
---|
[7d33199] | 58 | */ |
---|
| 59 | } |
---|
| 60 | |
---|
[3551166d] | 61 | void benchmark_timer_disable_subtracting_average_overhead(bool find_flag) |
---|
[7d33199] | 62 | { |
---|
[18bfc42] | 63 | benchmark_timer_find_average_overhead = find_flag; |
---|
[7d33199] | 64 | } |
---|
| 65 | |
---|