Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers timing.h Source File

timing.h

Go to the documentation of this file.
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 "mbedtls/config.h"
00029 #else
00030 #include MBEDTLS_CONFIG_FILE
00031 #endif
00032 
00033 #include <stdint.h>
00034 
00035 #ifdef __cplusplus
00036 extern "C" {
00037 #endif
00038 
00039 #if !defined(MBEDTLS_TIMING_ALT)
00040 // Regular implementation
00041 //
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 mbedtls_timing_delay_context
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 #else  /* MBEDTLS_TIMING_ALT */
00062 #include "timing_alt.h"
00063 #endif /* MBEDTLS_TIMING_ALT */
00064 
00065 extern volatile int mbedtls_timing_alarmed;
00066 
00067 /**
00068  * \brief          Return the CPU cycle counter value
00069  *
00070  * \warning        This is only a best effort! Do not rely on this!
00071  *                 In particular, it is known to be unreliable on virtual
00072  *                 machines.
00073  *
00074  * \note           This value starts at an unspecified origin and
00075  *                 may wrap around.
00076  */
00077 unsigned long mbedtls_timing_hardclock( void );
00078 
00079 /**
00080  * \brief          Return the elapsed time in milliseconds
00081  *
00082  * \param val      points to a timer structure
00083  * \param reset    If 0, query the elapsed time. Otherwise (re)start the timer.
00084  *
00085  * \return         Elapsed time since the previous reset in ms. When
00086  *                 restarting, this is always 0.
00087  *
00088  * \note           To initialize a timer, call this function with reset=1.
00089  *
00090  *                 Determining the elapsed time and resetting the timer is not
00091  *                 atomic on all platforms, so after the sequence
00092  *                 `{ get_timer(1); ...; time1 = get_timer(1); ...; time2 =
00093  *                 get_timer(0) }` the value time1+time2 is only approximately
00094  *                 the delay since the first reset.
00095  */
00096 unsigned long mbedtls_timing_get_timer( struct mbedtls_timing_hr_time *val, int reset );
00097 
00098 /**
00099  * \brief          Setup an alarm clock
00100  *
00101  * \param seconds  delay before the "mbedtls_timing_alarmed" flag is set
00102  *                 (must be >=0)
00103  *
00104  * \warning        Only one alarm at a time  is supported. In a threaded
00105  *                 context, this means one for the whole process, not one per
00106  *                 thread.
00107  */
00108 void mbedtls_set_alarm( int seconds );
00109 
00110 /**
00111  * \brief          Set a pair of delays to watch
00112  *                 (See \c mbedtls_timing_get_delay().)
00113  *
00114  * \param data     Pointer to timing data.
00115  *                 Must point to a valid \c mbedtls_timing_delay_context struct.
00116  * \param int_ms   First (intermediate) delay in milliseconds.
00117  *                 The effect if int_ms > fin_ms is unspecified.
00118  * \param fin_ms   Second (final) delay in milliseconds.
00119  *                 Pass 0 to cancel the current delay.
00120  *
00121  * \note           To set a single delay, either use \c mbedtls_timing_set_timer
00122  *                 directly or use this function with int_ms == fin_ms.
00123  */
00124 void mbedtls_timing_set_delay( void *data, uint32_t int_ms, uint32_t fin_ms );
00125 
00126 /**
00127  * \brief          Get the status of delays
00128  *                 (Memory helper: number of delays passed.)
00129  *
00130  * \param data     Pointer to timing data
00131  *                 Must point to a valid \c mbedtls_timing_delay_context struct.
00132  *
00133  * \return         -1 if cancelled (fin_ms = 0),
00134  *                  0 if none of the delays are passed,
00135  *                  1 if only the intermediate delay is passed,
00136  *                  2 if the final delay is passed.
00137  */
00138 int mbedtls_timing_get_delay( void *data );
00139 
00140 #if defined(MBEDTLS_SELF_TEST)
00141 /**
00142  * \brief          Checkup routine
00143  *
00144  * \return         0 if successful, or 1 if a test failed
00145  */
00146 int mbedtls_timing_self_test( int verbose );
00147 #endif
00148 
00149 #ifdef __cplusplus
00150 }
00151 #endif
00152 
00153 #endif /* timing.h */