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.
timing.h
00001 /** 00002 * \file timing.h 00003 * 00004 * \brief Portable interface to timeouts and to the CPU cycle counter 00005 */ 00006 /* 00007 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 00008 * SPDX-License-Identifier: Apache-2.0 00009 * 00010 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00011 * not use this file except in compliance with the License. 00012 * You may obtain a copy of the License at 00013 * 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * 00016 * Unless required by applicable law or agreed to in writing, software 00017 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00018 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00019 * See the License for the specific language governing permissions and 00020 * limitations under the License. 00021 * 00022 * This file is part of mbed TLS (https://tls.mbed.org) 00023 */ 00024 #ifndef MBEDTLS_TIMING_H 00025 #define MBEDTLS_TIMING_H 00026 00027 #if !defined(MBEDTLS_CONFIG_FILE) 00028 #include "config.h" 00029 #else 00030 #include MBEDTLS_CONFIG_FILE 00031 #endif 00032 00033 #if !defined(MBEDTLS_TIMING_ALT) 00034 // Regular implementation 00035 // 00036 00037 #include <stdint.h> 00038 00039 #ifdef __cplusplus 00040 extern "C" { 00041 #endif 00042 00043 /** 00044 * \brief timer structure 00045 */ 00046 struct mbedtls_timing_hr_time 00047 { 00048 unsigned char opaque[32]; 00049 }; 00050 00051 /** 00052 * \brief Context for mbedtls_timing_set/get_delay() 00053 */ 00054 typedef struct 00055 { 00056 struct mbedtls_timing_hr_time timer; 00057 uint32_t int_ms; 00058 uint32_t fin_ms; 00059 } mbedtls_timing_delay_context; 00060 00061 extern volatile int mbedtls_timing_alarmed; 00062 00063 /** 00064 * \brief Return the CPU cycle counter value 00065 * 00066 * \warning This is only a best effort! Do not rely on this! 00067 * In particular, it is known to be unreliable on virtual 00068 * machines. 00069 * 00070 * \note This value starts at an unspecified origin and 00071 * may wrap around. 00072 */ 00073 unsigned long mbedtls_timing_hardclock( void ); 00074 00075 /** 00076 * \brief Return the elapsed time in milliseconds 00077 * 00078 * \param val points to a timer structure 00079 * \param reset If 0, query the elapsed time. Otherwise (re)start the timer. 00080 * 00081 * \return Elapsed time since the previous reset in ms. When 00082 * restarting, this is always 0. 00083 * 00084 * \note To initialize a timer, call this function with reset=1. 00085 * 00086 * Determining the elapsed time and resetting the timer is not 00087 * atomic on all platforms, so after the sequence 00088 * `{ get_timer(1); ...; time1 = get_timer(1); ...; time2 = 00089 * get_timer(0) }` the value time1+time2 is only approximately 00090 * the delay since the first reset. 00091 */ 00092 unsigned long mbedtls_timing_get_timer( struct mbedtls_timing_hr_time *val, int reset ); 00093 00094 /** 00095 * \brief Setup an alarm clock 00096 * 00097 * \param seconds delay before the "mbedtls_timing_alarmed" flag is set 00098 * (must be >=0) 00099 * 00100 * \warning Only one alarm at a time is supported. In a threaded 00101 * context, this means one for the whole process, not one per 00102 * thread. 00103 */ 00104 void mbedtls_set_alarm( int seconds ); 00105 00106 /** 00107 * \brief Set a pair of delays to watch 00108 * (See \c mbedtls_timing_get_delay().) 00109 * 00110 * \param data Pointer to timing data. 00111 * Must point to a valid \c mbedtls_timing_delay_context struct. 00112 * \param int_ms First (intermediate) delay in milliseconds. 00113 * The effect if int_ms > fin_ms is unspecified. 00114 * \param fin_ms Second (final) delay in milliseconds. 00115 * Pass 0 to cancel the current delay. 00116 * 00117 * \note To set a single delay, either use \c mbedtls_timing_set_timer 00118 * directly or use this function with int_ms == fin_ms. 00119 */ 00120 void mbedtls_timing_set_delay( void *data, uint32_t int_ms, uint32_t fin_ms ); 00121 00122 /** 00123 * \brief Get the status of delays 00124 * (Memory helper: number of delays passed.) 00125 * 00126 * \param data Pointer to timing data 00127 * Must point to a valid \c mbedtls_timing_delay_context struct. 00128 * 00129 * \return -1 if cancelled (fin_ms = 0), 00130 * 0 if none of the delays are passed, 00131 * 1 if only the intermediate delay is passed, 00132 * 2 if the final delay is passed. 00133 */ 00134 int mbedtls_timing_get_delay( void *data ); 00135 00136 #ifdef __cplusplus 00137 } 00138 #endif 00139 00140 #else /* MBEDTLS_TIMING_ALT */ 00141 #include "timing_alt.h" 00142 #endif /* MBEDTLS_TIMING_ALT */ 00143 00144 #ifdef __cplusplus 00145 extern "C" { 00146 #endif 00147 00148 #if defined(MBEDTLS_SELF_TEST) 00149 /** 00150 * \brief Checkup routine 00151 * 00152 * \return 0 if successful, or 1 if a test failed 00153 */ 00154 int mbedtls_timing_self_test( int verbose ); 00155 #endif 00156 00157 #ifdef __cplusplus 00158 } 00159 #endif 00160 00161 #endif /* timing.h */
Generated on Tue Jul 12 2022 13:31:44 by
