2 * Amazon FreeRTOS POSIX V1.1.0
\r
3 * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://aws.amazon.com/freertos
\r
23 * http://www.FreeRTOS.org
\r
28 * @brief Time types.
\r
30 * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/time.h.html
\r
33 #ifndef _FREERTOS_POSIX_TIME_H_
\r
34 #define _FREERTOS_POSIX_TIME_H_
\r
36 /* FreeRTOS+POSIX includes. */
\r
37 #include "FreeRTOS_POSIX/sys/types.h"
\r
38 #include "FreeRTOS_POSIX/signal.h"
\r
41 * @name Unit conversion constants.
\r
44 #define MICROSECONDS_PER_SECOND ( 1000000LL ) /**< Microseconds per second. */
\r
45 #define NANOSECONDS_PER_SECOND ( 1000000000LL ) /**< Nanoseconds per second. */
\r
46 #define NANOSECONDS_PER_TICK ( NANOSECONDS_PER_SECOND / configTICK_RATE_HZ ) /**< Nanoseconds per FreeRTOS tick. */
\r
50 * @name Clock identifiers.
\r
53 #define CLOCK_REALTIME 0 /**< The identifier of the system-wide clock measuring real time. */
\r
54 #define CLOCK_MONOTONIC 1 /**< The identifier for the system-wide monotonic clock.*/
\r
58 * @name A number used to convert the value returned by the clock() function into seconds.
\r
61 #define CLOCKS_PER_SEC ( ( clock_t ) configTICK_RATE_HZ )
\r
65 * @name Flag indicating time is absolute.
\r
67 * For functions taking timer objects, this refers to the clock associated with the timer.
\r
70 #define TIMER_ABSTIME 0x01
\r
73 #if !defined( posixconfigENABLE_TIMESPEC ) || ( posixconfigENABLE_TIMESPEC == 1 )
\r
76 * @brief represents an elapsed time
\r
80 time_t tv_sec; /**< Seconds. */
\r
81 long tv_nsec; /**< Nanoseconds. */
\r
85 #if !defined( posixconfigENABLE_ITIMERSPEC ) || ( posixconfigENABLE_ITIMERSPEC == 1 )
\r
92 struct timespec it_interval; /**< Timer period. */
\r
93 struct timespec it_value; /**< Timer expiration. */
\r
98 * @brief Report CPU time used.
\r
100 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock.html
\r
102 * @return The number of FreeRTOS ticks since the scheduler
\r
103 * was started minus the ticks spent in the idle task.
\r
105 * @note This function does NOT report the number of ticks spent by the calling thread.
\r
107 clock_t clock( void );
\r
110 * @brief Access a process CPU-time clock.
\r
112 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_getcpuclockid.html
\r
116 * @note This function is currently unsupported.
\r
119 int clock_getcpuclockid( pid_t pid,
\r
120 clockid_t * clock_id );
\r
123 * @brief Returns the resolution of a clock.
\r
125 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_getres.html
\r
127 * @note clock_id is ignored
\r
128 * @note This function stores the resolution of the FreeRTOS tick count in the object res points to.
\r
130 * @retval 0 - Upon successful execution
\r
132 int clock_getres( clockid_t clock_id,
\r
133 struct timespec * res );
\r
136 * @brief Returns the current value for the specified clock, clock_id.
\r
138 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_gettime.html
\r
140 * @note clock_id is ignored
\r
141 * @note this function does not check for overflows of time_t.
\r
143 * @retval 0 - Upon successful completion.
\r
145 int clock_gettime( clockid_t clock_id,
\r
146 struct timespec * tp );
\r
149 * @brief High resolution sleep with specifiable clock.
\r
151 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_nanosleep.html
\r
153 * @note clock_id is ignored, as this function uses the FreeRTOS tick count as its clock.
\r
154 * @note flags is ignored, if INCLUDE_vTaskDelayUntil is 0. i.e. the FreeRTOS function vTaskDelayUntil isn't available.
\r
155 * @note rmtp is also ignored, as signals are not implemented.
\r
157 * @retval 0 - Upon successful completion.
\r
158 * @retval EINVAL - The rqtp argument specified a nanosecond value less than zero or greater than or equal to 1000 million.
\r
160 int clock_nanosleep( clockid_t clock_id,
\r
162 const struct timespec * rqtp,
\r
163 struct timespec * rmtp );
\r
166 * @brief Sets the time for the specified clock.
\r
168 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_settime.html
\r
170 * @retval -1 with errno set to EPERM.
\r
172 * @note This function is currently unsupported, as FreeRTOS does not provide a function to modify the tick count.
\r
174 int clock_settime( clockid_t clock_id,
\r
175 const struct timespec * tp );
\r
178 * @brief High resolution sleep.
\r
180 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/nanosleep.html
\r
182 * @note rmtp is ignored, as signals are not implemented.
\r
184 * @retval 0 - Upon successful completion.
\r
185 * @retval -1 - The rqtp argument is invalid OR the rqtp argument specified a nanosecond value less than zero or greater than or equal to 1000 million.
\r
188 int nanosleep( const struct timespec * rqtp,
\r
189 struct timespec * rmtp );
\r
192 * @brief Create a per-process timer.
\r
194 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_create.html
\r
196 * @note clock_id is ignored, as this function used the FreeRTOS tick count as its clock.
\r
197 * @note evp.sigev_notify must be set to SIGEV_THREAD, since signals are currently not supported.
\r
199 * @retval 0 - Upon successful completion, with location referenced by timerid updated.
\r
200 * @retval -1 - If an error occurs. errno is also set.
\r
202 * @sideeffect Possible errno values
\r
204 * ENOTSUP - If evp is NULL OR evp->sigen_notify == SIGEV_SIGNAL.
\r
206 * EAGAIN - The system lacks sufficient signal queuing resources to honor the request.
\r
208 int timer_create( clockid_t clockid,
\r
209 struct sigevent * evp,
\r
210 timer_t * timerid );
\r
213 * @brief Delete a per-process timer.
\r
215 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_delete.html
\r
217 * @retval 0 - Upon successful completion.
\r
219 int timer_delete( timer_t timerid );
\r
222 * @brief Get the timer overrun count.
\r
224 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_getoverrun.html
\r
226 * @retval 0 - Always return 0, since signals are not supported.
\r
228 int timer_getoverrun( timer_t timerid );
\r
231 * @brief Get the amount of time until the timer expires.
\r
233 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_gettime.html
\r
235 * @retval 0 - Upon successful completion.
\r
237 int timer_gettime( timer_t timerid,
\r
238 struct itimerspec * value );
\r
241 * @brief Set the time until the next expiration of the timer.
\r
243 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/timer_settime.html
\r
245 * @retval 0 - Upon successful completion.
\r
246 * @retval -1 - An error occurred, errno is also set.
\r
248 * @sideeffect Possible errno values
\r
250 * EINVAL - A value structure specified a nanosecond value less than zero or greater than or equal to 1000 million,
\r
251 * AND the it_value member of that structure did not specify zero seconds and nanoseconds.
\r
253 int timer_settime( timer_t timerid,
\r
255 const struct itimerspec * value,
\r
256 struct itimerspec * ovalue );
\r
258 #endif /* ifndef _FREERTOS_POSIX_TIME_H_ */
\r