blob: cb6abe35e16cfbbb04669affb2ead2083822cc9a [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
Paul Bakkerf2561b32014-02-06 15:11:55 +010030#include "config.h"
31
32#if !defined(POLARSSL_TIMING_ALT)
33// Regular implementation
34//
35
Paul Bakker407a0da2013-06-27 14:29:21 +020036#ifdef __cplusplus
37extern "C" {
38#endif
39
Paul Bakker5121ce52009-01-03 21:22:43 +000040/**
41 * \brief timer structure
42 */
43struct hr_time
44{
45 unsigned char opaque[32];
46};
47
Paul Bakker2eee9022011-04-24 15:28:55 +000048extern volatile int alarmed;
Paul Bakker5121ce52009-01-03 21:22:43 +000049
50/**
51 * \brief Return the CPU cycle counter value
52 */
53unsigned long hardclock( void );
54
55/**
56 * \brief Return the elapsed time in milliseconds
57 *
58 * \param val points to a timer structure
59 * \param reset if set to 1, the timer is restarted
60 */
61unsigned long get_timer( struct hr_time *val, int reset );
62
63/**
64 * \brief Setup an alarm clock
65 *
66 * \param seconds delay before the "alarmed" flag is set
67 */
68void set_alarm( int seconds );
69
70/**
71 * \brief Sleep for a certain amount of time
Paul Bakker13e2dfe2009-07-28 07:18:38 +000072 *
Paul Bakker37ca75d2011-01-06 12:28:03 +000073 * \param milliseconds delay in milliseconds
Paul Bakker5121ce52009-01-03 21:22:43 +000074 */
75void m_sleep( int milliseconds );
76
77#ifdef __cplusplus
78}
79#endif
80
Paul Bakkerf2561b32014-02-06 15:11:55 +010081#else /* POLARSSL_TIMING_ALT */
82#include "timing_alt.h"
83#endif /* POLARSSL_TIMING_ALT */
84
Paul Bakker5121ce52009-01-03 21:22:43 +000085#endif /* timing.h */