|
ChibiOS/RT
2.6.0 |
00001 /* 00002 ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, 00003 2011,2012,2013 Giovanni Di Sirio. 00004 00005 This file is part of ChibiOS/RT. 00006 00007 ChibiOS/RT is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 ChibiOS/RT is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 00020 --- 00021 00022 A special exception to the GPL can be applied should you wish to distribute 00023 a combined work that includes ChibiOS/RT, without being obliged to provide 00024 the source code for any proprietary components. See the file exception.txt 00025 for full details of how and when the exception can be applied. 00026 */ 00027 00028 /** 00029 * @file tm.h 00030 * @brief Time Measurement driver header. 00031 * 00032 * @addtogroup TM 00033 * @{ 00034 */ 00035 00036 #ifndef _TM_H_ 00037 #define _TM_H_ 00038 00039 #if HAL_USE_TM || defined(__DOXYGEN__) 00040 00041 /*===========================================================================*/ 00042 /* Driver constants. */ 00043 /*===========================================================================*/ 00044 00045 /*===========================================================================*/ 00046 /* Driver pre-compile time settings. */ 00047 /*===========================================================================*/ 00048 00049 /*===========================================================================*/ 00050 /* Derived constants and error checks. */ 00051 /*===========================================================================*/ 00052 00053 /*===========================================================================*/ 00054 /* Driver data structures and types. */ 00055 /*===========================================================================*/ 00056 00057 /** 00058 * @brief Type of a Time Measurement object. 00059 * @note Start/stop of measurements is performed through the function 00060 * pointers in order to avoid inlining of those functions which 00061 * could compromise measurement accuracy. 00062 * @note The maximum measurable time period depends on the implementation 00063 * of the realtime counter in the HAL driver. 00064 * @note The measurement is not 100% cycle-accurate, it can be in excess 00065 * of few cycles depending on the compiler and target architecture. 00066 * @note Interrupts can affect measurement if the measurement is performed 00067 * with interrupts enabled. 00068 */ 00069 typedef struct TimeMeasurement TimeMeasurement; 00070 00071 /** 00072 * @brief Time Measurement structure. 00073 */ 00074 struct TimeMeasurement { 00075 void (*start)(TimeMeasurement *tmp); /**< @brief Starts a measurement. */ 00076 void (*stop)(TimeMeasurement *tmp); /**< @brief Stops a measurement. */ 00077 halrtcnt_t last; /**< @brief Last measurement. */ 00078 halrtcnt_t worst; /**< @brief Worst measurement. */ 00079 halrtcnt_t best; /**< @brief Best measurement. */ 00080 }; 00081 00082 /*===========================================================================*/ 00083 /* Driver macros. */ 00084 /*===========================================================================*/ 00085 00086 /** 00087 * @brief Starts a measurement. 00088 * @pre The @p TimeMeasurement must be initialized. 00089 * @note This function can be invoked in any context. 00090 * 00091 * @param[in,out] tmp pointer to a @p TimeMeasurement structure 00092 * 00093 * @special 00094 */ 00095 #define tmStartMeasurement(tmp) (tmp)->start(tmp) 00096 00097 /** 00098 * @brief Stops a measurement. 00099 * @pre The @p TimeMeasurement must be initialized. 00100 * @note This function can be invoked in any context. 00101 * 00102 * @param[in,out] tmp pointer to a @p TimeMeasurement structure 00103 * 00104 * @special 00105 */ 00106 #define tmStopMeasurement(tmp) (tmp)->stop(tmp) 00107 00108 /*===========================================================================*/ 00109 /* External declarations. */ 00110 /*===========================================================================*/ 00111 00112 #ifdef __cplusplus 00113 extern "C" { 00114 #endif 00115 void tmInit(void); 00116 void tmObjectInit(TimeMeasurement *tmp); 00117 #ifdef __cplusplus 00118 } 00119 #endif 00120 00121 #endif /* HAL_USE_TM */ 00122 00123 #endif /* _TM_H_ */ 00124 00125 /** @} */