source: rtems-docs/bsp_howto/timer.rst @ 489740f

4.115
Last change on this file since 489740f was 489740f, checked in by Chris Johns <chrisj@…>, on 05/20/16 at 02:47:09

Set SPDX License Identifier in each source file.

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