source: rtems-docs/bsp_howto/timer.rst @ 6d7a4d2

4.115
Last change on this file since 6d7a4d2 was 6d7a4d2, checked in by Chris Johns <chrisj@…>, on 06/17/16 at 05:05:41

Update the BSP howto.

Closes #2590.

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