![]() |
|
|||
File indexing completed on 2025-05-11 08:24:13
0001 /* SPDX-License-Identifier: BSD-2-Clause */ 0002 0003 /** 0004 * @file 0005 * 0006 * @ingroup RTEMSScoreTimestamp 0007 * 0008 * @brief This header file provides interfaces of the 0009 * @ref RTEMSScoreTimestamp which are only used by the implementation. 0010 */ 0011 0012 /* 0013 * COPYRIGHT (c) 1989-2009. 0014 * On-Line Applications Research Corporation (OAR). 0015 * 0016 * Redistribution and use in source and binary forms, with or without 0017 * modification, are permitted provided that the following conditions 0018 * are met: 0019 * 1. Redistributions of source code must retain the above copyright 0020 * notice, this list of conditions and the following disclaimer. 0021 * 2. Redistributions in binary form must reproduce the above copyright 0022 * notice, this list of conditions and the following disclaimer in the 0023 * documentation and/or other materials provided with the distribution. 0024 * 0025 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 0026 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0027 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0028 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 0029 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 0030 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 0031 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 0032 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 0033 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 0034 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 0035 * POSSIBILITY OF SUCH DAMAGE. 0036 */ 0037 0038 #ifndef _RTEMS_SCORE_TIMESTAMPIMPL_H 0039 #define _RTEMS_SCORE_TIMESTAMPIMPL_H 0040 0041 /** 0042 * @addtogroup RTEMSScoreTimestamp 0043 * 0044 * @{ 0045 */ 0046 0047 #include <rtems/score/timestamp.h> 0048 #include <rtems/score/basedefs.h> 0049 0050 #include <sys/time.h> 0051 0052 #ifdef __cplusplus 0053 extern "C" { 0054 #endif 0055 0056 /** 0057 * @brief Sets timestamp to specified seconds and nanoseconds. 0058 * 0059 * This method sets the timestamp to the specified @a _seconds and @a _nanoseconds 0060 * value. 0061 * 0062 * @param[out] _time The timestamp instance to set. 0063 * @param _seconds The seconds portion of the timestamp. 0064 * @param _nanoseconds The nanoseconds portion of the timestamp. 0065 */ 0066 static inline void _Timestamp_Set( 0067 Timestamp_Control *_time, 0068 time_t _seconds, 0069 long _nanoseconds 0070 ) 0071 { 0072 struct timespec _ts; 0073 0074 _ts.tv_sec = _seconds; 0075 _ts.tv_nsec = _nanoseconds; 0076 0077 *_time = tstosbt(_ts); 0078 } 0079 0080 /** 0081 * @brief Sets the timestamp to zero. 0082 * 0083 * This method sets the timestamp to zero. 0084 * value. 0085 * 0086 * @param[out] _time The timestamp instance to zero. 0087 */ 0088 0089 static inline void _Timestamp_Set_to_zero( 0090 Timestamp_Control *_time 0091 ) 0092 { 0093 *_time = 0; 0094 } 0095 0096 /** 0097 * @brief Checks if the left hand side timestamp is less than the right one. 0098 * 0099 * This method is the less than operator for timestamps. 0100 * 0101 * @param _lhs The left hand side timestamp. 0102 * @param _rhs The right hand side timestamp. 0103 * 0104 * @retval true @a _lhs is less than the @a _rhs. 0105 * @retval false @a _lhs is greater or equal than @a rhs. 0106 */ 0107 0108 static inline bool _Timestamp_Less_than( 0109 const Timestamp_Control *_lhs, 0110 const Timestamp_Control *_rhs 0111 ) 0112 { 0113 return *_lhs < *_rhs; 0114 } 0115 0116 /** 0117 * @brief Checks if the left hand side timestamp is greater than the right one. 0118 * 0119 * This method is the greater than operator for timestamps. 0120 * 0121 * @param _lhs The left hand side timestamp. 0122 * @param _rhs The right hand side timestamp. 0123 * 0124 * @retval true @a _lhs is greater than the @a _rhs. 0125 * @retval false @a _lhs is less or equal than @a _rhs. 0126 */ 0127 0128 static inline bool _Timestamp_Greater_than( 0129 const Timestamp_Control *_lhs, 0130 const Timestamp_Control *_rhs 0131 ) 0132 { 0133 return *_lhs > *_rhs; 0134 } 0135 0136 /** 0137 * @brief Checks if the timestamps are equal. 0138 * 0139 * This method is the is equal to than operator for timestamps. 0140 * 0141 * @param _lhs The left hand side timestamp. 0142 * @param _rhs The right hand side timestamp. 0143 * 0144 * @retval true @a _lhs is equal to @a _rhs 0145 * @retval false @a _lhs is not equal to @a _rhs. 0146 */ 0147 0148 static inline bool _Timestamp_Equal_to( 0149 const Timestamp_Control *_lhs, 0150 const Timestamp_Control *_rhs 0151 ) 0152 { 0153 return *_lhs == *_rhs; 0154 } 0155 0156 /** 0157 * @brief Adds two timestamps. 0158 * 0159 * This routine adds two timestamps. The second argument is added 0160 * to the first. 0161 * 0162 * @param[in, out] _time The base time to be added to. 0163 * @param _add points The timestamp to add to the first argument. 0164 */ 0165 static inline void _Timestamp_Add_to( 0166 Timestamp_Control *_time, 0167 const Timestamp_Control *_add 0168 ) 0169 { 0170 *_time += *_add; 0171 } 0172 0173 /** 0174 * @brief Subtracts two timestamps. 0175 * 0176 * This routine subtracts two timestamps. @a result is set to 0177 * @a end - @a start. 0178 * 0179 * @param _start The starting time. 0180 * @param _end The ending time. 0181 * @param[out] _result Contains the difference between starting and ending 0182 * time after the method call. 0183 */ 0184 static inline void _Timestamp_Subtract( 0185 const Timestamp_Control *_start, 0186 const Timestamp_Control *_end, 0187 Timestamp_Control *_result 0188 ) 0189 { 0190 *_result = *_end - *_start; 0191 } 0192 0193 /** 0194 * @brief Divides a timestamp by another timestamp. 0195 * 0196 * This routine divides a timestamp by another timestamp. The 0197 * intended use is for calculating percentages to three decimal points. 0198 * 0199 * @param _lhs The left hand number. 0200 * @param _rhs The right hand number. 0201 * @param[out] _ival_percentage The integer portion of the average. 0202 * @param[out] _fval_percentage The thousandths of percentage. 0203 */ 0204 static inline void _Timestamp_Divide( 0205 const Timestamp_Control *_lhs, 0206 const Timestamp_Control *_rhs, 0207 uint32_t *_ival_percentage, 0208 uint32_t *_fval_percentage 0209 ) 0210 { 0211 struct timespec _ts_left; 0212 struct timespec _ts_right; 0213 0214 _ts_left = sbttots( *_lhs ); 0215 _ts_right = sbttots( *_rhs ); 0216 0217 _Timespec_Divide( 0218 &_ts_left, 0219 &_ts_right, 0220 _ival_percentage, 0221 _fval_percentage 0222 ); 0223 } 0224 0225 /** 0226 * @brief Gets seconds portion of timestamp. 0227 * 0228 * This method returns the seconds portion of the specified timestamp. 0229 * 0230 * @param _time The timestamp. 0231 * 0232 * @return The seconds portion of @a _time. 0233 */ 0234 static inline time_t _Timestamp_Get_seconds( 0235 const Timestamp_Control *_time 0236 ) 0237 { 0238 return (*_time >> 32); 0239 } 0240 0241 /** 0242 * @brief Gets nanoseconds portion of timestamp. 0243 * 0244 * This method returns the nanoseconds portion of the specified timestamp. 0245 * 0246 * @param _time The timestamp. 0247 * 0248 * @return The nanoseconds portion of @a _time. 0249 */ 0250 static inline uint32_t _Timestamp_Get_nanoseconds( 0251 const Timestamp_Control *_time 0252 ) 0253 { 0254 struct timespec _ts; 0255 0256 _ts = sbttots( *_time ); 0257 0258 return (uint32_t) _ts.tv_nsec; 0259 } 0260 0261 /** 0262 * @brief Gets the timestamp as nanoseconds. 0263 * 0264 * This method returns the timestamp as nanoseconds. 0265 * 0266 * @param _time The timestamp. 0267 * 0268 * @return The time in nanoseconds. 0269 */ 0270 static inline uint64_t _Timestamp_Get_as_nanoseconds( 0271 const Timestamp_Control *_time 0272 ) 0273 { 0274 struct timespec _ts; 0275 0276 _ts = sbttots( *_time ); 0277 0278 return _Timespec_Get_as_nanoseconds( &_ts ); 0279 } 0280 0281 /** 0282 * @brief Converts timestamp to struct timespec. 0283 * 0284 * @param _timestamp The timestamp. 0285 * @param[out] _timespec The timespec to be filled in by the method. 0286 */ 0287 static inline void _Timestamp_To_timespec( 0288 const Timestamp_Control *_timestamp, 0289 struct timespec *_timespec 0290 ) 0291 { 0292 *_timespec = sbttots( *_timestamp ); 0293 } 0294 0295 /** 0296 * @brief Converts timestamp to struct timeval. 0297 * 0298 * @param _timestamp The timestamp. 0299 * @param[out] _timeval The timeval to be filled in by the method. 0300 */ 0301 static inline void _Timestamp_To_timeval( 0302 const Timestamp_Control *_timestamp, 0303 struct timeval *_timeval 0304 ) 0305 { 0306 *_timeval = sbttotv( *_timestamp ); 0307 } 0308 0309 #ifdef __cplusplus 0310 } 0311 #endif 0312 0313 /** @} */ 0314 0315 #endif 0316 /* 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 |
![]() ![]() |