ChibiOS/RT  6.1.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 /* Module pre-compile time settings. */
39 /*===========================================================================*/
40 
41 /*===========================================================================*/
42 /* Derived constants and error checks. */
43 /*===========================================================================*/
44 
45 #if PORT_SUPPORTS_RT == FALSE
46 #error "CH_CFG_USE_TM requires PORT_SUPPORTS_RT"
47 #endif
48 
49 /*===========================================================================*/
50 /* Module data structures and types. */
51 /*===========================================================================*/
52 
53 /**
54  * @brief Type of a time measurement calibration data.
55  */
56 typedef struct {
57  /**
58  * @brief Measurement calibration value.
59  */
60  rtcnt_t offset;
62 
63 /**
64  * @brief Type of a Time Measurement object.
65  * @note The maximum measurable time period depends on the implementation
66  * of the realtime counter and its clock frequency.
67  * @note The measurement is not 100% cycle-accurate, it can be in excess
68  * of few cycles depending on the compiler and target architecture.
69  * @note Interrupts can affect measurement if the measurement is performed
70  * with interrupts enabled.
71  */
72 typedef struct {
73  rtcnt_t best; /**< @brief Best measurement. */
74  rtcnt_t worst; /**< @brief Worst measurement. */
75  rtcnt_t last; /**< @brief Last measurement. */
76  ucnt_t n; /**< @brief Number of measurements. */
77  rttime_t cumulative; /**< @brief Cumulative measurement. */
79 
80 /*===========================================================================*/
81 /* Module macros. */
82 /*===========================================================================*/
83 
84 /*===========================================================================*/
85 /* External declarations. */
86 /*===========================================================================*/
87 
88 #ifdef __cplusplus
89 extern "C" {
90 #endif
91  void _tm_init(void);
93  NOINLINE void chTMStartMeasurementX(time_measurement_t *tmp);
94  NOINLINE void chTMStopMeasurementX(time_measurement_t *tmp);
95  NOINLINE void chTMChainMeasurementToX(time_measurement_t *tmp1,
96  time_measurement_t *tmp2);
97 #ifdef __cplusplus
98 }
99 #endif
100 
101 /*===========================================================================*/
102 /* Module inline functions. */
103 /*===========================================================================*/
104 
105 #endif /* CH_CFG_USE_TM == TRUE */
106 
107 #endif /* CHTM_H */
108 
109 /** @} */
tm_calibration_t
Type of a time measurement calibration data.
Definition: chtm.h:56
time_measurement_t::cumulative
rttime_t cumulative
Cumulative measurement.
Definition: chtm.h:77
time_measurement_t::last
rtcnt_t last
Last measurement.
Definition: chtm.h:75
tm_calibration_t::offset
rtcnt_t offset
Measurement calibration value.
Definition: chtm.h:60
time_measurement_t::worst
rtcnt_t worst
Worst measurement.
Definition: chtm.h:74
time_measurement_t::n
ucnt_t n
Number of measurements.
Definition: chtm.h:76
time_measurement_t
Type of a Time Measurement object.
Definition: chtm.h:72
_tm_init
void _tm_init(void)
Initializes the time measurement unit.
Definition: chtm.c:84
chTMObjectInit
void chTMObjectInit(time_measurement_t *tmp)
Initializes a TimeMeasurement object.
Definition: chtm.c:109
chTMStopMeasurementX
NOINLINE void chTMStopMeasurementX(time_measurement_t *tmp)
Stops a measurement.
Definition: chtm.c:139
time_measurement_t::best
rtcnt_t best
Best measurement.
Definition: chtm.h:73
chTMChainMeasurementToX
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:156
chTMStartMeasurementX
NOINLINE void chTMStartMeasurementX(time_measurement_t *tmp)
Starts a measurement.
Definition: chtm.c:126