ChibiOS 21.11.4
chtm.h
Go to the documentation of this file.
1/*
2 ChibiOS - Copyright (C) 2006,2007,2008,2009,2010,2011,2012,2013,2014,
3 2015,2016,2017,2018,2019,2020,2021 Giovanni Di Sirio.
4
5 This file is part of ChibiOS.
6
7 ChibiOS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation version 3 of the License.
10
11 ChibiOS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20/**
21 * @file rt/include/chtm.h
22 * @brief Time Measurement module macros and structures.
23 *
24 * @addtogroup time_measurement
25 * @{
26 */
27
28#ifndef CHTM_H
29#define CHTM_H
30
31#if (CH_CFG_USE_TM == TRUE) || defined(__DOXYGEN__)
32
33/*===========================================================================*/
34/* Module constants. */
35/*===========================================================================*/
36
37/**
38 * @brief Number of iterations in the calibration loop.
39 * @note This is required in order to assess the best result in
40 * architectures with instruction cache.
41 */
42#define TM_CALIBRATION_LOOP 4U
43
44/*===========================================================================*/
45/* Module pre-compile time settings. */
46/*===========================================================================*/
47
48/*===========================================================================*/
49/* Derived constants and error checks. */
50/*===========================================================================*/
51
52#if PORT_SUPPORTS_RT == FALSE
53#error "CH_CFG_USE_TM requires PORT_SUPPORTS_RT"
54#endif
55
56/*===========================================================================*/
57/* Module data structures and types. */
58/*===========================================================================*/
59
60/**
61 * @brief Type of a time measurement calibration data.
62 */
63typedef struct {
64 /**
65 * @brief Measurement calibration value.
66 */
69
70/**
71 * @brief Type of a Time Measurement object.
72 * @note The maximum measurable time period depends on the implementation
73 * of the realtime counter and its clock frequency.
74 * @note The measurement is not 100% cycle-accurate, it can be in excess
75 * of few cycles depending on the compiler and target architecture.
76 * @note Interrupts can affect measurement if the measurement is performed
77 * with interrupts enabled.
78 */
79typedef struct {
80 rtcnt_t best; /**< @brief Best measurement. */
81 rtcnt_t worst; /**< @brief Worst measurement. */
82 rtcnt_t last; /**< @brief Last measurement. */
83 ucnt_t n; /**< @brief Number of measurements. */
84 rttime_t cumulative; /**< @brief Cumulative measurement. */
86
87/*===========================================================================*/
88/* Module macros. */
89/*===========================================================================*/
90
91/*===========================================================================*/
92/* External declarations. */
93/*===========================================================================*/
94
95#ifdef __cplusplus
96extern "C" {
97#endif
102 time_measurement_t *tmp2);
103#ifdef __cplusplus
104}
105#endif
106
107/*===========================================================================*/
108/* Module inline functions. */
109/*===========================================================================*/
110
111/**
112 * @brief Time measurement initialization.
113 * @note Internal use only.
114 *
115 * @param[out] tcp pointer to the @p tm_calibration_t structure
116 *
117 * @notapi
118 */
120 unsigned i;
122
123 /* Time Measurement subsystem calibration, it does a null measurement
124 and calculates the call overhead which is subtracted to real
125 measurements.*/
126 tcp->offset = (rtcnt_t)0;
127 chTMObjectInit(&tm);
129 do {
132 i--;
133 } while (i > 0U);
134 tcp->offset = tm.best;
135}
136
137#endif /* CH_CFG_USE_TM == TRUE */
138
139#endif /* CHTM_H */
140
141/** @} */
port_rttime_t rttime_t
Definition chearly.h:78
port_rtcnt_t rtcnt_t
Definition chearly.h:77
uint32_t ucnt_t
Definition chearly.h:93
#define NOINLINE
Makes functions not inlineable.
Definition chtypes.h:91
NOINLINE void chTMChainMeasurementToX(time_measurement_t *tmp1, time_measurement_t *tmp2)
Stops a measurement and chains to the next one using the same time stamp.
Definition chtm.c:126
static void __tm_calibration_object_init(tm_calibration_t *tcp)
Time measurement initialization.
Definition chtm.h:119
void chTMObjectInit(time_measurement_t *tmp)
Initializes a TimeMeasurement object.
Definition chtm.c:79
NOINLINE void chTMStopMeasurementX(time_measurement_t *tmp)
Stops a measurement.
Definition chtm.c:109
#define TM_CALIBRATION_LOOP
Number of iterations in the calibration loop.
Definition chtm.h:42
NOINLINE void chTMStartMeasurementX(time_measurement_t *tmp)
Starts a measurement.
Definition chtm.c:96
Type of a Time Measurement object.
Definition chtm.h:79
rtcnt_t best
Best measurement.
Definition chtm.h:80
ucnt_t n
Number of measurements.
Definition chtm.h:83
rttime_t cumulative
Cumulative measurement.
Definition chtm.h:84
rtcnt_t last
Last measurement.
Definition chtm.h:82
rtcnt_t worst
Worst measurement.
Definition chtm.h:81
Type of a time measurement calibration data.
Definition chtm.h:63
rtcnt_t offset
Measurement calibration value.
Definition chtm.h:67