mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
posix: added sleep and usleep
This commit is contained in:
parent
8760ea8f73
commit
1a438b64a5
@ -20,6 +20,12 @@ ifneq (,$(filter posix,$(USEMODULE)))
|
||||
ifeq (,$(filter uart0,$(USEMODULE)))
|
||||
USEMODULE += uart0
|
||||
endif
|
||||
ifeq (,$(filter timex,$(USEMODULE)))
|
||||
USEMODULE += timex
|
||||
endif
|
||||
ifeq (,$(filter vtimer,$(USEMODULE)))
|
||||
USEMODULE += vtimer
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq (,$(filter uart0,$(USEMODULE)))
|
||||
|
@ -1,3 +1,3 @@
|
||||
MODULE =posix
|
||||
MODULE = posix
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
|
@ -24,6 +24,11 @@
|
||||
#ifndef _UNISTD_H
|
||||
#define _UNISTD_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "timex.h"
|
||||
#include "vtimer.h"
|
||||
|
||||
#define STDIN_FILENO 0 ///< stdin file descriptor
|
||||
#define STDOUT_FILENO 1 ///< stdout file descriptor
|
||||
#define STDERR_FILENO 2 ///< stderr file descriptor
|
||||
@ -47,6 +52,45 @@
|
||||
*/
|
||||
int close(int fildes);
|
||||
|
||||
typedef uint32_t useconds_t;
|
||||
|
||||
/**
|
||||
* @brief the caller will sleep for given amount of micro seconds
|
||||
* @details The usleep() function will cause the calling thread to be
|
||||
* suspended from execution until either the number of real-time microseconds
|
||||
* specified by the argument useconds has elapsed or a signal is delivered to
|
||||
* the calling thread and its action is to invoke a signal-catching function
|
||||
* or to terminate the process. The suspension time may be longer than
|
||||
* requested due to the scheduling of other activity by the system.
|
||||
*
|
||||
* @see <a href="http://pubs.opengroup.org/onlinepubs/7908799/xsh/usleep.html">
|
||||
* The Open Group Base Specification Issue 2, usleep
|
||||
* </a>
|
||||
*
|
||||
* @param useconds time to sleep in micro seconds
|
||||
* @return 0 on success
|
||||
*/
|
||||
int usleep(useconds_t useconds);
|
||||
|
||||
/**
|
||||
* @brief the caller will sleep for given amount of seconds
|
||||
* @details The sleep() function shall cause the calling thread to be suspended
|
||||
* from execution until either the number of realtime seconds
|
||||
* specified by the argument seconds has elapsed or a signal is
|
||||
* delivered to the calling thread and its action is to invoke a
|
||||
* signal-catching function or to terminate the process. The
|
||||
* suspension time may be longer than requested due to the scheduling
|
||||
* of other activity by the system.
|
||||
*
|
||||
* @see <a href="http://pubs.opengroup.org/onlinepubs/009695399/functions/sleep.html">
|
||||
* The Open Group Base Specification Issue 6, sleep
|
||||
* </a>
|
||||
*
|
||||
* @param seconds time to sleep in seconds
|
||||
* @return 0 on success
|
||||
*/
|
||||
unsigned int sleep(unsigned int seconds);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
@ -11,6 +11,7 @@
|
||||
* @file fd.c
|
||||
* @brief Providing implementation for close for fds defined in fd.h.
|
||||
* @author Martin Lenders <mlenders@inf.fu-berlin.de>
|
||||
* @author Christian Mehlis <mehlis@inf.fu-berlin.de>
|
||||
*/
|
||||
#include <errno.h>
|
||||
|
||||
@ -36,6 +37,21 @@ int close(int fildes)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usleep(useconds_t useconds)
|
||||
{
|
||||
timex_t time = timex_set(0, useconds);
|
||||
timex_normalize(&time);
|
||||
vtimer_sleep(time);
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int sleep(unsigned int seconds)
|
||||
{
|
||||
timex_t time = timex_set(seconds, 0);
|
||||
vtimer_sleep(time);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user