[30abd24] | 1 | /* Timer for Blackfin |
---|
| 2 | * |
---|
| 3 | * This file manages the benchmark timer used by the RTEMS Timing Test |
---|
| 4 | * Suite. Each measured time period is demarcated by calls to |
---|
[8c84731] | 5 | * benchmark_timer_initialize() and benchmark_timer_read(). benchmark_timer_read() usually returns |
---|
| 6 | * the number of microseconds since benchmark_timer_initialize() exitted. |
---|
[359e537] | 7 | * |
---|
[30abd24] | 8 | * Copyright (c) 2006 by Atos Automacao Industrial Ltda. |
---|
| 9 | * written by Alain Schaefer <alain.schaefer@easc.ch> |
---|
| 10 | * and Antonio Giovanini <antonio@atos.com.br> |
---|
| 11 | * |
---|
| 12 | * The license and distribution terms for this file may be |
---|
| 13 | * found in the file LICENSE in this distribution or at |
---|
| 14 | * http://www.rtems.com/license/LICENSE. |
---|
| 15 | */ |
---|
[359e537] | 16 | |
---|
[30abd24] | 17 | |
---|
| 18 | #include <rtems.h> |
---|
| 19 | #include <bsp.h> |
---|
| 20 | |
---|
| 21 | |
---|
| 22 | uint32_t Timer_interrupts; |
---|
[3551166d] | 23 | bool benchmark_timer_find_average_overhead; |
---|
[30abd24] | 24 | |
---|
| 25 | /* |
---|
[8c84731] | 26 | * benchmark_timer_initialize |
---|
[359e537] | 27 | * |
---|
[30abd24] | 28 | * Blackfin processor has a counter for clock cycles. |
---|
| 29 | */ |
---|
[8c84731] | 30 | void benchmark_timer_initialize( void ) |
---|
[30abd24] | 31 | { |
---|
| 32 | |
---|
| 33 | /*reset counters*/ |
---|
[682a05b3] | 34 | __asm__ ("R2 = 0;"); |
---|
| 35 | __asm__ ("CYCLES = R2;"); |
---|
| 36 | __asm__ ("CYCLES2 = R2;"); |
---|
[30abd24] | 37 | /*start counters*/ |
---|
[682a05b3] | 38 | __asm__ ("R2 = SYSCFG;"); |
---|
| 39 | __asm__ ("BITSET(R2,1);"); |
---|
| 40 | __asm__ ("SYSCFG = R2"); |
---|
[359e537] | 41 | |
---|
[30abd24] | 42 | } |
---|
| 43 | |
---|
| 44 | /* |
---|
[8c84731] | 45 | * The following controls the behavior of benchmark_timer_read(). |
---|
[30abd24] | 46 | * |
---|
| 47 | * AVG_OVEREHAD is the overhead for starting and stopping the timer. It |
---|
| 48 | * is usually deducted from the number returned. |
---|
| 49 | * |
---|
| 50 | * LEAST_VALID is the lowest number this routine should trust. Numbers |
---|
| 51 | * below this are "noise" and zero is returned. |
---|
| 52 | */ |
---|
| 53 | |
---|
| 54 | #define AVG_OVERHEAD 0 /* It typically takes X.X microseconds */ |
---|
| 55 | /* (Y countdowns) to start/stop the timer. */ |
---|
| 56 | /* This value is in microseconds. */ |
---|
| 57 | #define LEAST_VALID 1 /* Don't trust a clicks value lower than this */ |
---|
| 58 | |
---|
[8c84731] | 59 | int benchmark_timer_read( void ) |
---|
[30abd24] | 60 | { |
---|
| 61 | uint32_t clicks; |
---|
| 62 | uint32_t total; |
---|
[682a05b3] | 63 | register uint32_t cycles __asm__ ("R2"); |
---|
[30abd24] | 64 | |
---|
[359e537] | 65 | /* stop counter */ |
---|
[682a05b3] | 66 | __asm__ ("R2 = SYSCFG;"); |
---|
| 67 | __asm__ ("BITCLR(R2,1);"); |
---|
| 68 | __asm__ ("SYSCFG = R2;"); |
---|
| 69 | __asm__ ("R2 = CYCLES;"); |
---|
[30abd24] | 70 | |
---|
| 71 | |
---|
| 72 | clicks = cycles; /* Clock cycles */ |
---|
| 73 | |
---|
| 74 | /* converting to microseconds */ |
---|
[359e537] | 75 | total = clicks / (CCLK/1000000); |
---|
[30abd24] | 76 | |
---|
[8c84731] | 77 | if ( benchmark_timer_find_average_overhead == 1 ) |
---|
[30abd24] | 78 | return total; /* in XXX microsecond units */ |
---|
| 79 | else { |
---|
| 80 | if ( total < LEAST_VALID ) |
---|
| 81 | return 0; /* below timer resolution */ |
---|
| 82 | /* |
---|
| 83 | * Somehow convert total into microseconds |
---|
| 84 | */ |
---|
| 85 | return (total - AVG_OVERHEAD); |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | |
---|
[3551166d] | 89 | void benchmark_timer_disable_subtracting_average_overhead(bool find_flag) |
---|
[30abd24] | 90 | { |
---|
[8c84731] | 91 | benchmark_timer_find_average_overhead = find_flag; |
---|
[30abd24] | 92 | } |
---|