chtm.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio.
  3. This file is part of ChibiOS.
  4. ChibiOS is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. ChibiOS is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. /**
  16. * @file chtm.h
  17. * @brief Time Measurement module macros and structures.
  18. *
  19. * @addtogroup time_measurement
  20. * @{
  21. */
  22. #ifndef CHTM_H
  23. #define CHTM_H
  24. #if (CH_CFG_USE_TM == TRUE) || defined(__DOXYGEN__)
  25. /*===========================================================================*/
  26. /* Module constants. */
  27. /*===========================================================================*/
  28. /*===========================================================================*/
  29. /* Module pre-compile time settings. */
  30. /*===========================================================================*/
  31. /*===========================================================================*/
  32. /* Derived constants and error checks. */
  33. /*===========================================================================*/
  34. #if PORT_SUPPORTS_RT == FALSE
  35. #error "CH_CFG_USE_TM requires PORT_SUPPORTS_RT"
  36. #endif
  37. /*===========================================================================*/
  38. /* Module data structures and types. */
  39. /*===========================================================================*/
  40. /**
  41. * @brief Type of a time measurement calibration data.
  42. */
  43. typedef struct {
  44. /**
  45. * @brief Measurement calibration value.
  46. */
  47. rtcnt_t offset;
  48. } tm_calibration_t;
  49. /**
  50. * @brief Type of a Time Measurement object.
  51. * @note The maximum measurable time period depends on the implementation
  52. * of the realtime counter and its clock frequency.
  53. * @note The measurement is not 100% cycle-accurate, it can be in excess
  54. * of few cycles depending on the compiler and target architecture.
  55. * @note Interrupts can affect measurement if the measurement is performed
  56. * with interrupts enabled.
  57. */
  58. typedef struct {
  59. rtcnt_t best; /**< @brief Best measurement. */
  60. rtcnt_t worst; /**< @brief Worst measurement. */
  61. rtcnt_t last; /**< @brief Last measurement. */
  62. ucnt_t n; /**< @brief Number of measurements. */
  63. rttime_t cumulative; /**< @brief Cumulative measurement. */
  64. } time_measurement_t;
  65. /*===========================================================================*/
  66. /* Module macros. */
  67. /*===========================================================================*/
  68. /*===========================================================================*/
  69. /* External declarations. */
  70. /*===========================================================================*/
  71. #ifdef __cplusplus
  72. extern "C" {
  73. #endif
  74. void _tm_init(void);
  75. void chTMObjectInit(time_measurement_t *tmp);
  76. NOINLINE void chTMStartMeasurementX(time_measurement_t *tmp);
  77. NOINLINE void chTMStopMeasurementX(time_measurement_t *tmp);
  78. NOINLINE void chTMChainMeasurementToX(time_measurement_t *tmp1,
  79. time_measurement_t *tmp2);
  80. #ifdef __cplusplus
  81. }
  82. #endif
  83. /*===========================================================================*/
  84. /* Module inline functions. */
  85. /*===========================================================================*/
  86. #endif /* CH_CFG_USE_TM == TRUE */
  87. #endif /* CHTM_H */
  88. /** @} */