source:
rtems/c/src/lib/libcpu/bfin/timer/timer.c
@
30abd24
Last change on this file since 30abd24 was 30abd24, checked in by Joel Sherrill <joel.sherrill@…>, on 08/15/08 at 20:18:41 | |
---|---|
|
|
File size: 2.6 KB |
Line | |
---|---|
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 |
5 | * Timer_initialize() and Read_timer(). Read_timer() usually returns |
6 | * the number of microseconds since Timer_initialize() exitted. |
7 | * |
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 | * |
16 | * $Id$ |
17 | */ |
18 | |
19 | |
20 | #include <rtems.h> |
21 | #include <bsp.h> |
22 | |
23 | |
24 | uint32_t Timer_interrupts; |
25 | rtems_boolean Timer_driver_Find_average_overhead; |
26 | |
27 | /* |
28 | * Timer_initialize |
29 | * |
30 | * Blackfin processor has a counter for clock cycles. |
31 | */ |
32 | void Timer_initialize( void ) |
33 | { |
34 | |
35 | /*reset counters*/ |
36 | asm ("R2 = 0;"); |
37 | asm ("CYCLES = R2;"); |
38 | asm ("CYCLES2 = R2;"); |
39 | /*start counters*/ |
40 | asm ("R2 = SYSCFG;"); |
41 | asm ("BITSET(R2,1);"); |
42 | asm ("SYSCFG = R2"); |
43 | |
44 | } |
45 | |
46 | /* |
47 | * The following controls the behavior of Read_timer(). |
48 | * |
49 | * AVG_OVEREHAD is the overhead for starting and stopping the timer. It |
50 | * is usually deducted from the number returned. |
51 | * |
52 | * LEAST_VALID is the lowest number this routine should trust. Numbers |
53 | * below this are "noise" and zero is returned. |
54 | */ |
55 | |
56 | #define AVG_OVERHEAD 0 /* It typically takes X.X microseconds */ |
57 | /* (Y countdowns) to start/stop the timer. */ |
58 | /* This value is in microseconds. */ |
59 | #define LEAST_VALID 1 /* Don't trust a clicks value lower than this */ |
60 | |
61 | int Read_timer( void ) |
62 | { |
63 | uint32_t clicks; |
64 | uint32_t total; |
65 | register uint32_t cycles asm ("R2"); |
66 | |
67 | /* stop counter */ |
68 | asm("R2 = SYSCFG;"); |
69 | asm("BITCLR(R2,1);"); |
70 | asm("SYSCFG = R2;"); |
71 | asm("R2 = CYCLES;"); |
72 | |
73 | |
74 | clicks = cycles; /* Clock cycles */ |
75 | |
76 | /* converting to microseconds */ |
77 | total = clicks / (CCLK/1000000); |
78 | |
79 | if ( Timer_driver_Find_average_overhead == 1 ) |
80 | return total; /* in XXX microsecond units */ |
81 | else { |
82 | if ( total < LEAST_VALID ) |
83 | return 0; /* below timer resolution */ |
84 | /* |
85 | * Somehow convert total into microseconds |
86 | */ |
87 | return (total - AVG_OVERHEAD); |
88 | } |
89 | } |
90 | |
91 | /* |
92 | * Empty function call used in loops to measure basic cost of looping |
93 | * in Timing Test Suite. |
94 | */ |
95 | |
96 | rtems_status_code Empty_function( void ) |
97 | { |
98 | return RTEMS_SUCCESSFUL; |
99 | } |
100 | |
101 | void Set_find_average_overhead( |
102 | rtems_boolean find_flag |
103 | ) |
104 | { |
105 | Timer_driver_Find_average_overhead = find_flag; |
106 | } |
Note: See TracBrowser
for help on using the repository browser.