blob: 524b5197205fb595d3a910a12b4225206c6c5342 [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é-Gonnard967a2a52015-01-22 14:28:16 +00008 * This file is part of mbed TLS (http://www.polarssl.org)
Paul Bakker84f12b72010-07-18 10:13:04 +00009 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakkerb96f1542010-07-18 20:36:00 +000010 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000011 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Paul Bakker5121ce52009-01-03 21:22:43 +000024 */
Paul Bakker40e46942009-01-03 21:51:57 +000025#ifndef POLARSSL_TIMING_H
26#define POLARSSL_TIMING_H
Paul Bakker5121ce52009-01-03 21:22:43 +000027
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020028#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakkerf2561b32014-02-06 15:11:55 +010029#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020030#else
31#include POLARSSL_CONFIG_FILE
32#endif
Paul Bakkerf2561b32014-02-06 15:11:55 +010033
34#if !defined(POLARSSL_TIMING_ALT)
35// Regular implementation
36//
37
Paul Bakker407a0da2013-06-27 14:29:21 +020038#ifdef __cplusplus
39extern "C" {
40#endif
41
Paul Bakker5121ce52009-01-03 21:22:43 +000042/**
43 * \brief timer structure
44 */
45struct hr_time
46{
47 unsigned char opaque[32];
48};
49
Paul Bakker2eee9022011-04-24 15:28:55 +000050extern volatile int alarmed;
Paul Bakker5121ce52009-01-03 21:22:43 +000051
52/**
53 * \brief Return the CPU cycle counter value
54 */
55unsigned long hardclock( void );
56
57/**
58 * \brief Return the elapsed time in milliseconds
59 *
60 * \param val points to a timer structure
61 * \param reset if set to 1, the timer is restarted
62 */
63unsigned long get_timer( struct hr_time *val, int reset );
64
65/**
66 * \brief Setup an alarm clock
67 *
68 * \param seconds delay before the "alarmed" flag is set
69 */
70void set_alarm( int seconds );
71
72/**
73 * \brief Sleep for a certain amount of time
Paul Bakker13e2dfe2009-07-28 07:18:38 +000074 *
Paul Bakker37ca75d2011-01-06 12:28:03 +000075 * \param milliseconds delay in milliseconds
Paul Bakker5121ce52009-01-03 21:22:43 +000076 */
77void m_sleep( int milliseconds );
78
Manuel Pégourié-Gonnard470fc932014-03-27 20:07:08 +010079#if defined(POLARSSL_SELF_TEST)
80/**
81 * \brief Checkup routine
82 *
83 * \return 0 if successful, or 1 if a test failed
84 */
85int timing_self_test( int verbose );
86#endif
87
Paul Bakker5121ce52009-01-03 21:22:43 +000088#ifdef __cplusplus
89}
90#endif
91
Paul Bakkerf2561b32014-02-06 15:11:55 +010092#else /* POLARSSL_TIMING_ALT */
93#include "timing_alt.h"
94#endif /* POLARSSL_TIMING_ALT */
95
Paul Bakker5121ce52009-01-03 21:22:43 +000096#endif /* timing.h */