[d7a915da] | 1 | /* |
---|
[b360885] | 2 | * PXA255 timer by Yang Xi <hiyangxi@gmail.com> |
---|
[d7a915da] | 3 | * Copyright (c) 2004 by Jay Monkman <jtm@lopingdog.com> |
---|
| 4 | * |
---|
| 5 | * Notes: |
---|
| 6 | * This file manages the benchmark timer used by the RTEMS Timing Test |
---|
| 7 | * Suite. Each measured time period is demarcated by calls to |
---|
| 8 | * Timer_initialize() and Read_timer(). Read_timer() usually returns |
---|
| 9 | * the number of microseconds since Timer_initialize() exitted. |
---|
| 10 | * |
---|
[359e537] | 11 | * It is important that the timer start/stop overhead be determined |
---|
[d7a915da] | 12 | * when porting or modifying this code. |
---|
| 13 | * |
---|
| 14 | * The license and distribution terms for this file may be |
---|
| 15 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 16 | * http://www.rtems.org/license/LICENSE. |
---|
[d7a915da] | 17 | */ |
---|
| 18 | |
---|
| 19 | #include <rtems.h> |
---|
| 20 | #include <bsp.h> |
---|
| 21 | #include <pxa255.h> |
---|
| 22 | |
---|
| 23 | uint32_t tstart; |
---|
| 24 | static uint32_t tick_time; |
---|
[b360885] | 25 | bool benchmark_timer_find_average_overhead; |
---|
| 26 | |
---|
| 27 | bool benchmark_timer_is_initialized = false; |
---|
| 28 | |
---|
[d7a915da] | 29 | /* |
---|
[359e537] | 30 | * Use the timer count register to measure. |
---|
[d7a915da] | 31 | * The frequency of it is 3.4864MHZ |
---|
[b360885] | 32 | * The longest period we are able to capture is 4G/3.4864MHZ |
---|
[d7a915da] | 33 | */ |
---|
[b360885] | 34 | void benchmark_timer_initialize(void) |
---|
[d7a915da] | 35 | { |
---|
| 36 | tick_time = XSCALE_OS_TIMER_TCR; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | /* |
---|
| 40 | * The following controls the behavior of Read_timer(). |
---|
| 41 | * |
---|
| 42 | * AVG_OVEREHAD is the overhead for starting and stopping the timer. It |
---|
| 43 | * is usually deducted from the number returned. |
---|
| 44 | * |
---|
| 45 | * LEAST_VALID is the lowest number this routine should trust. Numbers |
---|
| 46 | * below this are "noise" and zero is returned. |
---|
| 47 | */ |
---|
| 48 | |
---|
| 49 | #define AVG_OVERHEAD 0 /* It typically takes X.X microseconds */ |
---|
| 50 | /* (Y countdowns) to start/stop the timer. */ |
---|
| 51 | /* This value is in microseconds. */ |
---|
| 52 | #define LEAST_VALID 1 /* Don't trust a clicks value lower than this */ |
---|
| 53 | |
---|
[b360885] | 54 | int benchmark_timer_read(void) |
---|
[d7a915da] | 55 | { |
---|
| 56 | |
---|
| 57 | uint32_t total; |
---|
| 58 | total = XSCALE_OS_TIMER_TCR; |
---|
| 59 | if(total>=tick_time) |
---|
| 60 | total -= tick_time; |
---|
| 61 | else |
---|
[b360885] | 62 | total += 0xffffffff - tick_time; /*Round up but not overflow*/ |
---|
[359e537] | 63 | |
---|
[b360885] | 64 | if ( benchmark_timer_find_average_overhead == true ) |
---|
[d7a915da] | 65 | return total; /*Counter cycles*/ |
---|
| 66 | |
---|
[b360885] | 67 | if ( total < LEAST_VALID ) |
---|
| 68 | return 0; /* below timer resolution */ |
---|
[d7a915da] | 69 | |
---|
[b360885] | 70 | return total; |
---|
[d7a915da] | 71 | } |
---|
| 72 | |
---|
[b360885] | 73 | void benchmark_timer_disable_subtracting_average_overhead( |
---|
[d7a915da] | 74 | bool find_flag |
---|
| 75 | ) |
---|
| 76 | { |
---|
[b360885] | 77 | benchmark_timer_find_average_overhead = find_flag; |
---|
[d7a915da] | 78 | } |
---|