Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
fnet_timer.h
00001 /************************************************************************** 00002 * 00003 * Copyright 2011-2015 by Andrey Butok. FNET Community. 00004 * Copyright 2008-2010 by Andrey Butok. Freescale Semiconductor, Inc. 00005 * 00006 *************************************************************************** 00007 * 00008 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00009 * not use this file except in compliance with the License. 00010 * You may obtain a copy of the License at 00011 * 00012 * http://www.apache.org/licenses/LICENSE-2.0 00013 * 00014 * Unless required by applicable law or agreed to in writing, software 00015 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00016 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00017 * See the License for the specific language governing permissions and 00018 * limitations under the License. 00019 * 00020 **********************************************************************/ 00021 /*! 00022 * @brief FNET Timer API. 00023 * 00024 ***************************************************************************/ 00025 00026 #ifndef _FNET_TIMER_H 00027 00028 #define _FNET_TIMER_H 00029 00030 /*! @addtogroup fnet_timer 00031 * An application can use the @ref fnet_timer_get_ticks() function to get a number of 00032 * ticks (periods, defined by the @ref FNET_TIMER_PERIOD_MS) since the 00033 * hardware timer startup. 00034 */ 00035 00036 /*! @{ */ 00037 00038 /**************************************************************************/ /*! 00039 * @brief Timer period in milliseconds (period of one timer tick). 00040 ******************************************************************************/ 00041 #define FNET_TIMER_PERIOD_MS (100U) /* Do not change it.*/ 00042 00043 /**************************************************************************/ /*! 00044 * @brief Number of timer ticks in one hour. 00045 ******************************************************************************/ 00046 #define FNET_TIMER_TICKS_IN_HOUR ((1000U*60U*60U)/FNET_TIMER_PERIOD_MS) 00047 00048 /**************************************************************************/ /*! 00049 * @brief Number of timer ticks in one minute. 00050 ******************************************************************************/ 00051 #define FNET_TIMER_TICKS_IN_MIN ((1000U*60U)/FNET_TIMER_PERIOD_MS) 00052 00053 /**************************************************************************/ /*! 00054 * @brief Number of timer ticks in one second. 00055 ******************************************************************************/ 00056 #define FNET_TIMER_TICKS_IN_SEC (1000U/FNET_TIMER_PERIOD_MS) 00057 00058 #if defined(__cplusplus) 00059 extern "C" { 00060 #endif 00061 00062 /**************************************************************************/ /*! 00063 * @brief Unsigned integer type representing time uinits. 00064 * It can be ticks, seconds or milliseconds. 00065 ******************************************************************************/ 00066 typedef fnet_uint32_t fnet_time_t; 00067 00068 /***************************************************************************/ /*! 00069 * 00070 * @brief Gets the timer counter value in ticks. 00071 * 00072 * @return This function returns a current value of the timer counter in ticks. 00073 * 00074 * @see fnet_timer_get_seconds() 00075 * 00076 ****************************************************************************** 00077 * 00078 * This function returns a current value of the timer counter that 00079 * contains a number of periods from the moment of the hardware 00080 * timer initialization (it's done in the FNET stack initialization).@n 00081 * The period of one timer tick is defined by the @ref FNET_TIMER_PERIOD_MS. 00082 * 00083 ******************************************************************************/ 00084 fnet_time_t fnet_timer_get_ticks( void ); 00085 00086 /***************************************************************************/ /*! 00087 * 00088 * @brief Gets the timer counter value in seconds. 00089 * 00090 * @return This function returns a current value of the timer counter 00091 * in seconds. 00092 * 00093 * @see fnet_timer_get_ticks() 00094 * 00095 ****************************************************************************** 00096 * 00097 * This function returns a current value of the timer counter in seconds, 00098 * from the moment of the hardware timer initialization 00099 * (it's done in the FNET stack initialization). 00100 * 00101 ******************************************************************************/ 00102 fnet_time_t fnet_timer_get_seconds( void ); 00103 00104 /***************************************************************************/ /*! 00105 * 00106 * @brief Gets the timer counter value in milliseconds. 00107 * 00108 * @return This function returns a current value of the timer counter 00109 * in milliseconds. 00110 * 00111 * @see fnet_timer_get_ms() 00112 * 00113 ****************************************************************************** 00114 * 00115 * This function returns a current value of the timer counter in milliseconds, 00116 * from the moment of the hardware timer initialization 00117 * (it's done in the FNET stack initialization).@n 00118 * 00119 ******************************************************************************/ 00120 fnet_time_t fnet_timer_get_ms( void ); 00121 00122 /***************************************************************************/ /*! 00123 * 00124 * @brief Converts milliseconds to timer ticks. 00125 * 00126 * @param time_ms Time value in milliseconds. 00127 * 00128 * @return This function returns the time value in timer ticks. 00129 * 00130 ****************************************************************************** 00131 * 00132 * This function converts the time value @c time_ms in milliseconds to the time 00133 * value in timer ticks.@n 00134 * The period of one timer tick is defined by the @ref FNET_TIMER_PERIOD_MS. 00135 * 00136 ******************************************************************************/ 00137 fnet_time_t fnet_timer_ms2ticks( fnet_time_t time_ms ); 00138 00139 /***************************************************************************/ /*! 00140 * 00141 * @brief Calculates an interval between two moments in time. 00142 * 00143 * @param start Start time in ticks. 00144 * 00145 * @param end End time in ticks. 00146 * 00147 * @return This function returns an interval value between two time moments 00148 * (in timer ticks). 00149 * 00150 ****************************************************************************** 00151 * 00152 * This function calculates an interval between two moments in time, @c start 00153 * and @c end. 00154 * This function takes into account also a possible counter overrun @c (start>end). 00155 * 00156 ******************************************************************************/ 00157 fnet_time_t fnet_timer_get_interval( fnet_time_t start, fnet_time_t end ); 00158 00159 /***************************************************************************/ /*! 00160 * 00161 * @brief Performs a delay for the given number of timer ticks. 00162 * 00163 * @param delay_ticks Time value used for delay, in ticks. 00164 * 00165 ****************************************************************************** 00166 * 00167 * This function performs a delay for a given number of timer ticks. 00168 * The function is blocked, till the @c delay_ticks expires. 00169 * 00170 ******************************************************************************/ 00171 void fnet_timer_delay( fnet_time_t delay_ticks ); 00172 00173 /*! @} */ 00174 00175 #ifndef FNET_HW_TIMER_INIT 00176 #define FNET_HW_TIMER_INIT fnet_cpu_timer_init 00177 #endif 00178 #ifndef FNET_HW_TIMER_RELEASE 00179 #define FNET_HW_TIMER_RELEASE fnet_cpu_timer_release 00180 #endif 00181 00182 #if defined(__cplusplus) 00183 } 00184 #endif 00185 00186 #endif /* _FNET_TIMER_H */
Generated on Tue Jul 12 2022 13:54:22 by
