blob: 383120efea991a6d62e0584b18f25a5ab25a6f06 [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 *
Paul Bakkerf2561b32014-02-06 15:11:55 +01006 * Copyright (C) 2006-2014, Brainspark B.V.
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
8 * This file is part of PolarSSL (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 Bakker77b385e2009-07-28 17:23:11 +000011 * All rights reserved.
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000012 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000013 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Paul Bakker5121ce52009-01-03 21:22:43 +000026 */
Paul Bakker40e46942009-01-03 21:51:57 +000027#ifndef POLARSSL_TIMING_H
28#define POLARSSL_TIMING_H
Paul Bakker5121ce52009-01-03 21:22:43 +000029
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020030#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakkerf2561b32014-02-06 15:11:55 +010031#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020032#else
33#include POLARSSL_CONFIG_FILE
34#endif
Paul Bakkerf2561b32014-02-06 15:11:55 +010035
36#if !defined(POLARSSL_TIMING_ALT)
37// Regular implementation
38//
39
Paul Bakker407a0da2013-06-27 14:29:21 +020040#ifdef __cplusplus
41extern "C" {
42#endif
43
Paul Bakker5121ce52009-01-03 21:22:43 +000044/**
45 * \brief timer structure
46 */
47struct hr_time
48{
49 unsigned char opaque[32];
50};
51
Paul Bakker2eee9022011-04-24 15:28:55 +000052extern volatile int alarmed;
Paul Bakker5121ce52009-01-03 21:22:43 +000053
54/**
55 * \brief Return the CPU cycle counter value
56 */
57unsigned long hardclock( void );
58
59/**
60 * \brief Return the elapsed time in milliseconds
61 *
62 * \param val points to a timer structure
63 * \param reset if set to 1, the timer is restarted
64 */
65unsigned long get_timer( struct hr_time *val, int reset );
66
67/**
68 * \brief Setup an alarm clock
69 *
70 * \param seconds delay before the "alarmed" flag is set
71 */
72void set_alarm( int seconds );
73
74/**
75 * \brief Sleep for a certain amount of time
Paul Bakker13e2dfe2009-07-28 07:18:38 +000076 *
Paul Bakker37ca75d2011-01-06 12:28:03 +000077 * \param milliseconds delay in milliseconds
Paul Bakker5121ce52009-01-03 21:22:43 +000078 */
79void m_sleep( int milliseconds );
80
Manuel Pégourié-Gonnard470fc932014-03-27 20:07:08 +010081#if defined(POLARSSL_SELF_TEST)
82/**
83 * \brief Checkup routine
84 *
85 * \return 0 if successful, or 1 if a test failed
86 */
87int timing_self_test( int verbose );
88#endif
89
Paul Bakker5121ce52009-01-03 21:22:43 +000090#ifdef __cplusplus
91}
92#endif
93
Paul Bakkerf2561b32014-02-06 15:11:55 +010094#else /* POLARSSL_TIMING_ALT */
95#include "timing_alt.h"
96#endif /* POLARSSL_TIMING_ALT */
97
Paul Bakker5121ce52009-01-03 21:22:43 +000098#endif /* timing.h */