![]() |
|
|||
File indexing completed on 2025-05-11 08:24:14
0001 /* SPDX-License-Identifier: BSD-2-Clause */ 0002 0003 /** 0004 * @file 0005 * 0006 * @brief Timespec API 0007 * 0008 * This include file contains API for manipulating timespecs. 0009 */ 0010 0011 /* 0012 * Copyright (c) 2012. 0013 * Krzysztof Miesowicz <krzysztof.miesowicz@gmail.com> 0014 * 0015 * Redistribution and use in source and binary forms, with or without 0016 * modification, are permitted provided that the following conditions 0017 * are met: 0018 * 1. Redistributions of source code must retain the above copyright 0019 * notice, this list of conditions and the following disclaimer. 0020 * 2. Redistributions in binary form must reproduce the above copyright 0021 * notice, this list of conditions and the following disclaimer in the 0022 * documentation and/or other materials provided with the distribution. 0023 * 0024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 0025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0027 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 0028 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 0029 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 0030 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 0031 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 0032 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 0033 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 0034 * POSSIBILITY OF SUCH DAMAGE. 0035 */ 0036 0037 #ifndef _RTEMS_TIMESPEC_H 0038 #define _RTEMS_TIMESPEC_H 0039 0040 #include <rtems/score/timespec.h> 0041 0042 #ifdef __cplusplus 0043 extern "C" { 0044 #endif 0045 0046 /** 0047 * @defgroup TimespecAPI Timespec 0048 * 0049 * @ingroup RTEMSAPIClassic 0050 * 0051 * @brief Timespec API 0052 * 0053 * @{ 0054 * 0055 */ 0056 0057 /** 0058 * @brief Is timespec valid 0059 * 0060 * This method determines the validity of a timespec. 0061 * 0062 * @param[in] time is the timespec instance to validate. 0063 * 0064 * @retval true The timespec is valid. 0065 * @retval false The timespec is not valid. 0066 */ 0067 static inline bool rtems_timespec_is_valid( 0068 const struct timespec *time 0069 ) 0070 { 0071 return _Timespec_Is_valid(time); 0072 } 0073 0074 /** 0075 * @brief Timespec less than operator. 0076 * 0077 * This method is the less than operator for timespecs. 0078 * 0079 * @param[in] lhs is the left hand side timespec 0080 * @param[in] rhs is the right hand side timespec 0081 * 0082 * @retval true @a lhs is less than @a rhs. 0083 * @retval false @a lhs is not less than @a rhs. 0084 * 0085 */ 0086 static inline bool rtems_timespec_less_than( 0087 const struct timespec *lhs, 0088 const struct timespec *rhs 0089 ) 0090 { 0091 return _Timespec_Less_than(lhs,rhs); 0092 } 0093 0094 /** 0095 * @brief Add to a timespec. 0096 * 0097 * This routine adds two timespecs. The second argument is added 0098 * to the first. 0099 * 0100 * @param[in] time is the base time to be added to 0101 * @param[in] add is the timespec to add to the first argument 0102 * 0103 * @return This method returns the number of seconds @a time increased by. 0104 */ 0105 static inline time_t rtems_timespec_add_to( 0106 struct timespec *time, 0107 const struct timespec *add 0108 ) 0109 { 0110 return _Timespec_Add_to(time,add); 0111 } 0112 0113 /** 0114 * @brief Convert timespec to number of ticks. 0115 * 0116 * This routine convert the @a time timespec to the corresponding number 0117 * of clock ticks. 0118 * 0119 * @param[in] time is the time to be converted 0120 * 0121 * @return This method returns the number of ticks computed. 0122 */ 0123 static inline uint32_t rtems_timespec_to_ticks( 0124 const struct timespec *time 0125 ) 0126 { 0127 return _Timespec_To_ticks(time); 0128 } 0129 0130 /** 0131 * @brief Convert ticks to timespec. 0132 * 0133 * This routine converts the @a ticks value to the corresponding 0134 * timespec format @a time. 0135 * 0136 * @param[in] time is the timespec format time result 0137 * @param[in] ticks is the number of ticks to convert 0138 */ 0139 0140 static inline void rtems_timespec_from_ticks( 0141 uint32_t ticks, 0142 struct timespec *time 0143 ) 0144 { 0145 _Timespec_From_ticks(ticks,time); 0146 } 0147 0148 /** 0149 * @brief Subtract two timespec. 0150 * 0151 * This routine subtracts two timespecs. @a result is set to 0152 * @a end - @a start. 0153 * 0154 * @param[in] start is the starting time 0155 * @param[in] end is the ending time 0156 * @param[in] result is the difference between starting and ending time. 0157 * 0158 * @return This method fills in @a result. 0159 */ 0160 static inline void rtems_timespec_subtract( 0161 const struct timespec *start, 0162 const struct timespec *end, 0163 struct timespec *result 0164 ) 0165 { 0166 _Timespec_Subtract(start,end,result); 0167 } 0168 0169 /** 0170 * @brief Divide timespec by integer. 0171 * 0172 * This routine divides a timespec by an integer value. The expected 0173 * use is to assist in benchmark calculations where you typically 0174 * divide a duration by a number of iterations. 0175 * 0176 * @param[in] time is the total 0177 * @param[in] iterations is the number of iterations 0178 * @param[in] result is the average time. 0179 * 0180 * @return This method fills in @a result. 0181 */ 0182 static inline void rtems_timespec_divide_by_integer( 0183 const struct timespec *time, 0184 uint32_t iterations, 0185 struct timespec *result 0186 ) 0187 { 0188 _Timespec_Divide_by_integer(time,iterations,result); 0189 } 0190 0191 /** 0192 * @brief Divide timespec. 0193 * 0194 * This routine divides a timespec by another timespec. The 0195 * intended use is for calculating percentages to three decimal points. 0196 * 0197 * @param[in] lhs is the left hand number 0198 * @param[in] rhs is the right hand number 0199 * @param[in] ival_percentage is the integer portion of the average 0200 * @param[in] fval_percentage is the thousandths of percentage 0201 * 0202 * @return This method fills in @a result. 0203 */ 0204 static inline void rtems_timespec_divide( 0205 const struct timespec *lhs, 0206 const struct timespec *rhs, 0207 uint32_t *ival_percentage, 0208 uint32_t *fval_percentage 0209 ) 0210 { 0211 _Timespec_Divide(lhs,rhs,ival_percentage,fval_percentage); 0212 } 0213 0214 /** 0215 * @brief Set timespec to seconds nanosecond. 0216 * 0217 * This method sets the timespec to the specified seconds and nanoseconds 0218 * value. 0219 * 0220 * @param[in] _time points to the timespec instance to validate. 0221 * @param[in] _seconds is the seconds portion of the timespec 0222 * @param[in] _nanoseconds is the nanoseconds portion of the timespec 0223 */ 0224 static inline void rtems_timespec_set( 0225 struct timespec *_time, 0226 time_t _seconds, 0227 uint32_t _nanoseconds 0228 ) 0229 { 0230 _Timespec_Set( _time, _seconds, _nanoseconds ); 0231 } 0232 0233 /** 0234 * @brief Zero timespec. 0235 * 0236 * This method sets the timespec to zero. 0237 * value. 0238 * 0239 * @param[in] _time points to the timespec instance to zero. 0240 */ 0241 static inline void rtems_timespec_zero( 0242 struct timespec *_time 0243 ) 0244 { 0245 _Timespec_Set_to_zero( _time ); 0246 } 0247 0248 /** 0249 * @brief Get seconds portion of timespec. 0250 * 0251 * This method returns the seconds portion of the specified timespec 0252 * 0253 * @param[in] _time points to the timespec 0254 * 0255 * @return The seconds portion of @a _time. 0256 */ 0257 static inline time_t rtems_timespec_get_seconds( 0258 struct timespec *_time 0259 ) 0260 { 0261 return _Timespec_Get_seconds( _time ); 0262 } 0263 0264 /** 0265 * @brief Get nanoseconds portion of timespec. 0266 * 0267 * This method returns the nanoseconds portion of the specified timespec 0268 * 0269 * @param[in] _time points to the timespec 0270 * 0271 * @return The nanoseconds portion of @a _time. 0272 */ 0273 static inline uint32_t rtems_timespec_get_nanoseconds( 0274 struct timespec *_time 0275 ) 0276 { 0277 return _Timespec_Get_nanoseconds( _time ); 0278 } 0279 0280 /** 0281 * @brief Timespec greater than operator. 0282 * 0283 * This method is the greater than operator for timespecs. 0284 * 0285 * @param[in] _lhs is the left hand side timespec 0286 * @param[in] _rhs is the right hand side timespec 0287 * 0288 * @retval true @a _lhs is greater than @a _rhs. 0289 * @retval false @a _lhs is not greater than @a _rhs. 0290 */ 0291 static inline bool rtems_timespec_greater_than( 0292 const struct timespec *_lhs, 0293 const struct timespec *_rhs 0294 ) 0295 { 0296 return _Timespec_Greater_than( _lhs, _rhs ); 0297 } 0298 /** 0299 * @brief Timespec equal to Operator 0300 * 0301 * This method is the is equal to than operator for timespecs. 0302 * 0303 * @param[in] lhs is the left hand side timespec 0304 * @param[in] rhs is the right hand side timespec 0305 * 0306 * @retval true @a lhs is equal to @a rhs. 0307 * @retval false @a lhs is not equal to @a rhs. 0308 */ 0309 static inline bool rtems_timespec_equal_to( 0310 const struct timespec *lhs, 0311 const struct timespec *rhs 0312 ) 0313 { 0314 return _Timespec_Equal_to( lhs, rhs); 0315 } 0316 0317 /** @} */ 0318 0319 #ifdef __cplusplus 0320 } 0321 #endif 0322 0323 #endif 0324 /* end of include file */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |