blob: 5ab000e10c19a99983e3cdd5b9bc08332bbdb4b0 [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 Bakker407a0da2013-06-27 14:29:21 +02006 * Copyright (C) 2006-2013, 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 Bakker407a0da2013-06-27 14:29:21 +020030#ifdef __cplusplus
31extern "C" {
32#endif
33
Paul Bakker5121ce52009-01-03 21:22:43 +000034/**
35 * \brief timer structure
36 */
37struct hr_time
38{
39 unsigned char opaque[32];
40};
41
Paul Bakker2eee9022011-04-24 15:28:55 +000042extern volatile int alarmed;
Paul Bakker5121ce52009-01-03 21:22:43 +000043
44/**
45 * \brief Return the CPU cycle counter value
46 */
47unsigned long hardclock( void );
48
49/**
50 * \brief Return the elapsed time in milliseconds
51 *
52 * \param val points to a timer structure
53 * \param reset if set to 1, the timer is restarted
54 */
55unsigned long get_timer( struct hr_time *val, int reset );
56
57/**
58 * \brief Setup an alarm clock
59 *
60 * \param seconds delay before the "alarmed" flag is set
61 */
62void set_alarm( int seconds );
63
64/**
65 * \brief Sleep for a certain amount of time
Paul Bakker13e2dfe2009-07-28 07:18:38 +000066 *
Paul Bakker37ca75d2011-01-06 12:28:03 +000067 * \param milliseconds delay in milliseconds
Paul Bakker5121ce52009-01-03 21:22:43 +000068 */
69void m_sleep( int milliseconds );
70
71#ifdef __cplusplus
72}
73#endif
74
75#endif /* timing.h */