dspal_time.h
5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/****************************************************************************
* Copyright (c) 2015 Mark Charlebois. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#pragma once
/*==========================================================================
* FILE: time.h
*
* SERVICES: POSIX Timer API interface
*
* DESCRIPTION: POSIX Timer API interface based upon POSIX 1003.1-2004
*==========================================================================*/
#include "dspal_types.h"
#include <sys/timespec.h>
typedef int clockid_t; /* ignored */
#define _CLOCKID_T
typedef int timer_t;
#if !defined(CLOCK_REALTIME)
# define CLOCK_REALTIME 0
#endif
#if !defined(CLOCK_MONOTONIC)
# define CLOCK_MONOTONIC 1
#endif
/* have to move #include here to solve circular include problems between time.h and signal.h */
#include "dspal_signal.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Timer functions */
/** \details
* POSIX timers can be either of two types: a one-shot type or a periodic
* type.
*
* A one-shot is an armed timer that is set to an expiration time relative
* to either a current time or an absolute time. The timer expires once and
* is disarmed.
*
* A periodic timer is armed with an initial expiration time and a repetition
* interval. Every time the interval timer
* expires, the timer is reloaded with the repetition interval. The timer
* is then rearmed.
*/
/** \defgroup timer POSIX Timer API */
/** \ingroup timer */
/** @{ */
/** Create a POSIX timer.
* Please refer to POSIX standard for details.
* @param clockid [in] ignored in this implementation
* @param evp [in] if non-NULL, points to a sigevent structure. This
* structure, allocated by the application, defines the asynchronous
* notification to occur when the timer expires. If the evp argument is
* NULL, the effect is as if the evp argument pointed to a sigevent
* structure with the sigev_notify member having the value SIGEV_SIGNAL,
* the sigev_signo having a default signal number (SIGALRM), and the
* sigev_value member having the value of the timer ID.
*/
int timer_create(clockid_t clockid, struct sigevent *restrict evp,
timer_t *restrict timerid);
/** Delete a POSIX timer.
* Please refer to POSIX standard for details.
*/
int timer_delete(timer_t timerid);
/** Get the time remaining on a POSIX timer.
* Please refer to POSIX standard for details.
*/
int timer_gettime(timer_t timerid, struct itimerspec *value);
/** Set the time remaining on a POSIX timer.
* Please refer to POSIX standard for details.
* @param flags [in] ignored in this implementation
*/
int timer_settime(timer_t timerid, int flags,
const struct itimerspec *restrict value,
struct itimerspec *restrict ovalue);
/** Get the resolution of the specified clock
* Please refer to POSIX standard for details
*/
int clock_getres(clockid_t clk_id, struct timespec *res);
/**
* Get the time of the specified clock
* Please refer to POSIX standard for details
*/
int clock_gettime(clockid_t clk_id, struct timespec *tp);
/**
* Set the time of the specified clock
* Please refer to POSIX standard for details
*/
int clock_settime(clockid_t clk_id, const struct timespec *tp);
/** Returns the value of time in seconds since the epoch.
* This may return the value in seconds since last power up.
* Please refer to POSIX standard for details.
*/
/*
* Use the definition of the time provided by time.h to avoid conflicts. The implementation
* of time.h in the static image will still be called.
*/
time_t time(time_t *t);
/** @} */
#ifdef __cplusplus
}
#endif