source: rtems-docs/bsp_howto/timer.rst @ d389819

4.115
Last change on this file since d389819 was d389819, checked in by Amar Takhar <amar@…>, on 01/18/16 at 05:37:40

Convert all Unicode to ASCII(128)

  • Property mode set to 100644
File size: 3.5 KB
Line 
1Timer Driver
2############
3
4The timer driver is primarily used by the RTEMS Timing Tests.
5This driver provides as accurate a benchmark timer as possible.
6It typically reports its time in microseconds, CPU cycles, or
7bus cycles.  This information can be very useful for determining
8precisely what pieces of code require optimization and to measure the
9impact of specific minor changes.
10
11The gen68340 BSP also uses the Timer Driver to support a high performance
12mode of the on-CPU UART.
13
14Benchmark Timer
15===============
16
17The RTEMS Timing Test Suite requires a benchmark timer.  The
18RTEMS Timing Test Suite is very helpful for determining
19the performance of target hardware and comparing its performance
20to that of other RTEMS targets.
21
22This section describes the routines which are assumed to exist by
23the RTEMS Timing Test Suite.  The names used are *EXACTLY* what
24is used in the RTEMS Timing Test Suite so follow the naming convention.
25
26benchmark_timer_initialize
27--------------------------
28
29Initialize the timer source.
30.. code:: c
31
32    void benchmark_timer_initialize(void)
33    {
34    initialize the benchmark timer
35    }
36
37Read_timer
38----------
39
40The ``benchmark_timer_read`` routine returns the number of benchmark
41time units (typically microseconds) that have elapsed since the last
42call to ``benchmark_timer_initialize``.
43.. code:: c
44
45    benchmark_timer_t benchmark_timer_read(void)
46    {
47    stop time = read the hardware timer
48    if the subtract overhead feature is enabled
49    subtract overhead from stop time
50    return the stop time
51    }
52
53Many implementations of this routine subtract the overhead required
54to initialize and read the benchmark timer.  This makes the times reported
55more accurate.
56
57Some implementations report 0 if the harware timer value change is
58sufficiently small.  This is intended to indicate that the execution time
59is below the resolution of the timer.
60
61benchmark_timer_disable_subtracting_average_overhead
62----------------------------------------------------
63
64This routine is invoked by the "Check Timer" (``tmck``) test in the
65RTEMS Timing Test Suite.  It makes the ``benchmark_timer_read``
66routine NOT subtract the overhead required
67to initialize and read the benchmark timer.  This is used
68by the ``tmoverhd`` test to determine the overhead
69required to initialize and read the timer.
70.. code:: c
71
72    void benchmark_timer_disable_subtracting_average_overhead(bool find_flag)
73    {
74    disable the subtract overhead feature
75    }
76
77The ``benchmark_timer_find_average_overhead`` variable is used to
78indicate the state of the "subtract overhead feature".
79
80gen68340 UART FIFO Full Mode
81============================
82
83The gen68340 BSP is an example of the use of the timer to support the UART
84input FIFO full mode (FIFO means First In First Out and roughly means
85buffer). This mode consists in the UART raising an interrupt when n
86characters have been received (*n* is the UART's FIFO length). It results
87in a lower interrupt processing time, but the problem is that a scanf
88primitive will block on a receipt of less than *n* characters. The solution
89is to set a timer that will check whether there are some characters
90waiting in the UART's input FIFO. The delay time has to be set carefully
91otherwise high rates will be broken:
92
93- if no character was received last time the interrupt subroutine was
94  entered, set a long delay,
95
96- otherwise set the delay to the delay needed for *n* characters
97  receipt.
98
99.. COMMENT: COPYRIGHT (c) 1988-2002.
100
101.. COMMENT: On-Line Applications Research Corporation (OAR).
102
103.. COMMENT: All rights reserved.
104
Note: See TracBrowser for help on using the repository browser.