blob: 5f3acfa17a07663edad6ed0311dad4fb72a0c971 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file timing.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker37ca75d2011-01-06 12:28:03 +00004 * \brief Portable interface to the CPU cycle counter
5 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00006 * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
Manuel Pégourié-Gonnard860b5162015-01-28 17:12:07 +00008 * This file is part of mbed TLS (https://polarssl.org)
Paul Bakkerb96f1542010-07-18 20:36:00 +00009 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000010 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Paul Bakker5121ce52009-01-03 21:22:43 +000023 */
Paul Bakker40e46942009-01-03 21:51:57 +000024#ifndef POLARSSL_TIMING_H
25#define POLARSSL_TIMING_H
Paul Bakker5121ce52009-01-03 21:22:43 +000026
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020027#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakkerf2561b32014-02-06 15:11:55 +010028#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#else
30#include POLARSSL_CONFIG_FILE
31#endif
Paul Bakkerf2561b32014-02-06 15:11:55 +010032
33#if !defined(POLARSSL_TIMING_ALT)
34// Regular implementation
35//
36
Paul Bakker407a0da2013-06-27 14:29:21 +020037#ifdef __cplusplus
38extern "C" {
39#endif
40
Paul Bakker5121ce52009-01-03 21:22:43 +000041/**
42 * \brief timer structure
43 */
44struct hr_time
45{
46 unsigned char opaque[32];
47};
48
Paul Bakker2eee9022011-04-24 15:28:55 +000049extern volatile int alarmed;
Paul Bakker5121ce52009-01-03 21:22:43 +000050
51/**
52 * \brief Return the CPU cycle counter value
53 */
54unsigned long hardclock( void );
55
56/**
57 * \brief Return the elapsed time in milliseconds
58 *
59 * \param val points to a timer structure
60 * \param reset if set to 1, the timer is restarted
61 */
62unsigned long get_timer( struct hr_time *val, int reset );
63
64/**
65 * \brief Setup an alarm clock
66 *
67 * \param seconds delay before the "alarmed" flag is set
Manuel Pégourié-Gonnarddda52132015-02-11 11:36:31 +000068 *
69 * \warning Only one alarm at a time is supported. In a threaded
70 * context, this means one for the whole process, not one per
71 * thread.
Paul Bakker5121ce52009-01-03 21:22:43 +000072 */
73void set_alarm( int seconds );
74
75/**
76 * \brief Sleep for a certain amount of time
Paul Bakker13e2dfe2009-07-28 07:18:38 +000077 *
Paul Bakker37ca75d2011-01-06 12:28:03 +000078 * \param milliseconds delay in milliseconds
Paul Bakker5121ce52009-01-03 21:22:43 +000079 */
80void m_sleep( int milliseconds );
81
Manuel Pégourié-Gonnard470fc932014-03-27 20:07:08 +010082#if defined(POLARSSL_SELF_TEST)
83/**
84 * \brief Checkup routine
85 *
86 * \return 0 if successful, or 1 if a test failed
87 */
88int timing_self_test( int verbose );
89#endif
90
Paul Bakker5121ce52009-01-03 21:22:43 +000091#ifdef __cplusplus
92}
93#endif
94
Paul Bakkerf2561b32014-02-06 15:11:55 +010095#else /* POLARSSL_TIMING_ALT */
96#include "timing_alt.h"
97#endif /* POLARSSL_TIMING_ALT */
98
Paul Bakker5121ce52009-01-03 21:22:43 +000099#endif /* timing.h */