mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-16 01:53:51 +01:00
Merge pull request #4321 from kaspar030/cleanup_posix
sys: cleanup posix compat code
This commit is contained in:
commit
ab3345ac5a
@ -283,8 +283,7 @@ ifneq (,$(filter uart_stdio,$(USEMODULE)))
|
||||
endif
|
||||
|
||||
ifneq (,$(filter posix,$(USEMODULE)))
|
||||
USEMODULE += timex
|
||||
USEMODULE += vtimer
|
||||
USEMODULE += xtimer
|
||||
endif
|
||||
|
||||
ifneq (,$(filter posix_semaphore,$(USEMODULE)))
|
||||
|
||||
32
cpu/atmega_common/avr-libc-extra/unistd.h
Normal file
32
cpu/atmega_common/avr-libc-extra/unistd.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#ifndef UNISTD_H_
|
||||
#define UNISTD_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define STDIN_FILENO 0 ///< stdin file descriptor
|
||||
#define STDOUT_FILENO 1 ///< stdout file descriptor
|
||||
#define STDERR_FILENO 2 ///< stderr file descriptor
|
||||
|
||||
int close(int fildes);
|
||||
|
||||
typedef uint32_t useconds_t;
|
||||
int usleep(useconds_t usec);
|
||||
unsigned int sleep(unsigned int seconds);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* UNISTD_H_ */
|
||||
32
cpu/msp430-common/include/unistd.h
Normal file
32
cpu/msp430-common/include/unistd.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#ifndef UNISTD_H_
|
||||
#define UNISTD_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define STDIN_FILENO 0 ///< stdin file descriptor
|
||||
#define STDOUT_FILENO 1 ///< stdout file descriptor
|
||||
#define STDERR_FILENO 2 ///< stderr file descriptor
|
||||
|
||||
int close(int fildes);
|
||||
|
||||
typedef uint32_t useconds_t;
|
||||
int usleep(useconds_t usec);
|
||||
unsigned int sleep(unsigned int seconds);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* UNISTD_H_ */
|
||||
@ -1,92 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 INRIA.
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup posix
|
||||
* @{
|
||||
* @file
|
||||
* @brief POSIX-like IO
|
||||
*
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
* @author Stephan Zeisberg <zeisberg@mi.fu-berlin.de>
|
||||
* @author Oliver Hahm <oleg@hobbykeller.org>
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
#ifndef __READ_H
|
||||
#define __READ_H
|
||||
|
||||
#include "kernel_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define OPEN 0
|
||||
#define CLOSE 1
|
||||
#define READ 2
|
||||
#define WRITE 3
|
||||
|
||||
/**
|
||||
* @brief POSIX IO ringbuffer
|
||||
*/
|
||||
struct posix_iop_t {
|
||||
/** number of bytes */
|
||||
int nbytes;
|
||||
/** array for the ringbuffer */
|
||||
char *buffer;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Opens a file descriptor - represented by a corresponding thread
|
||||
*
|
||||
* @param[in] pid The thread managing the fd to open
|
||||
* @param[in] flags Access modes
|
||||
*
|
||||
* @return 0 on success
|
||||
* @return a negative value in error case
|
||||
*/
|
||||
int posix_open(int pid, int flags);
|
||||
|
||||
/**
|
||||
* @brief Closes an open file descriptor
|
||||
*
|
||||
* @param[in] pid The opened thread
|
||||
*
|
||||
* @return 0 on success
|
||||
* @return a negative value in error case
|
||||
*/
|
||||
int posix_close(int pid);
|
||||
|
||||
/**
|
||||
* @brief Reads from an open file descriptor
|
||||
*
|
||||
* @param[in] pid The thread managing the open fd
|
||||
* @param[out] buffer Buffer to fill
|
||||
* @param[in] bufsize Read up to that many bytes into @p buffer
|
||||
*
|
||||
* @return the number of read bytes
|
||||
*/
|
||||
int posix_read(int pid, char *buffer, int bufsize);
|
||||
|
||||
/**
|
||||
* @brief Writes to an open file descriptor
|
||||
*
|
||||
* @param[in] pid The thread managing the open fd
|
||||
* @param[in] buffer Buffer to write
|
||||
* @param[in] bufsize Write that many bytes from @p buffer
|
||||
*
|
||||
* @return the number of written bytes
|
||||
*/
|
||||
int posix_write(int pid, char *buffer, int bufsize);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif /* __READ_H */
|
||||
@ -20,7 +20,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "posix_io.h"
|
||||
#include "unistd.h"
|
||||
|
||||
#include "fd.h"
|
||||
|
||||
@ -1,119 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup posix
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief standard symbolic constants and types
|
||||
* @see <a href="http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/unistd.h.html">
|
||||
* The Open Group Base Specifications Issue 7, <unistd.h>
|
||||
* </a>
|
||||
*
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
#ifndef _UNISTD_H
|
||||
#define _UNISTD_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "timex.h"
|
||||
#include "vtimer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define STDIN_FILENO 0 ///< stdin file descriptor
|
||||
#define STDOUT_FILENO 1 ///< stdout file descriptor
|
||||
#define STDERR_FILENO 2 ///< stderr file descriptor
|
||||
|
||||
/**
|
||||
* @brief Close a file descriptor.
|
||||
* @details shall deallocate the file descriptor indicated by *fildes*. To
|
||||
* deallocate means to make the file descriptor available for return
|
||||
* by subsequent calls to open() or other functions that allocate file
|
||||
* descriptors. All outstanding record locks owned by the process on
|
||||
* the file associated with the file descriptor shall be removed (that
|
||||
* is, unlocked).
|
||||
*
|
||||
* @see <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/close.html">
|
||||
* The Open Group Base Specification Issue 7, close
|
||||
* </a>
|
||||
*
|
||||
* @param[in] fildes The file descriptor to the file which is to close.
|
||||
* @return Upon successful completion, 0 shall be returned; otherwise, -1
|
||||
* shall be returned and errno set to indicate the error.
|
||||
*/
|
||||
int close(int fildes);
|
||||
|
||||
/**
|
||||
* @name Microseconds data type
|
||||
* @{
|
||||
*/
|
||||
#ifndef __USECONDS_T_TYPE
|
||||
#if !(defined(__MACH__) || defined(__FreeBSD__))
|
||||
typedef unsigned long __USECONDS_T_TYPE;
|
||||
typedef __USECONDS_T_TYPE __useconds_t;
|
||||
#else
|
||||
#ifdef __MACH__
|
||||
typedef __darwin_useconds_t __useconds_t;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
typedef __useconds_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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
#endif /* _UNISTD_H */
|
||||
@ -1,69 +0,0 @@
|
||||
/**
|
||||
* POSIX implementation of basic IO operations.
|
||||
*
|
||||
* Copyright (C) 2013, INRIA.
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*
|
||||
* @ingroup sys_posix
|
||||
* @{
|
||||
* @file
|
||||
* @brief Implementation of basic POSIX IO functionality.
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "thread.h"
|
||||
#include "msg.h"
|
||||
|
||||
#include "posix_io.h"
|
||||
|
||||
|
||||
static int _posix_fileop(kernel_pid_t pid, int op, int flags)
|
||||
{
|
||||
msg_t m;
|
||||
m.type = op;
|
||||
m.content.value = flags;
|
||||
msg_send_receive(&m, &m, pid);
|
||||
return m.content.value;
|
||||
}
|
||||
|
||||
static int _posix_fileop_data(kernel_pid_t pid, int op, char *buffer, int nbytes)
|
||||
{
|
||||
struct posix_iop_t r;
|
||||
r.nbytes = nbytes;
|
||||
r.buffer = buffer;
|
||||
|
||||
msg_t m;
|
||||
m.type = op;
|
||||
m.content.ptr = (char *) &r;
|
||||
|
||||
msg_send_receive(&m, &m, pid);
|
||||
|
||||
return r.nbytes;
|
||||
}
|
||||
|
||||
int posix_open(int pid, int flags)
|
||||
{
|
||||
if (pid == KERNEL_PID_UNDEF) {
|
||||
return -1;
|
||||
}
|
||||
return _posix_fileop((kernel_pid_t) pid, OPEN, flags);
|
||||
}
|
||||
|
||||
int posix_close(int pid)
|
||||
{
|
||||
return _posix_fileop((kernel_pid_t) pid, CLOSE, 0);
|
||||
}
|
||||
|
||||
int posix_read(int pid, char *buffer, int bufsize)
|
||||
{
|
||||
return _posix_fileop_data((kernel_pid_t) pid, READ, buffer, bufsize);
|
||||
}
|
||||
|
||||
int posix_write(int pid, char *buffer, int bufsize)
|
||||
{
|
||||
return _posix_fileop_data((kernel_pid_t) pid, WRITE, buffer, bufsize);
|
||||
}
|
||||
@ -14,9 +14,9 @@
|
||||
* @author Christian Mehlis <mehlis@inf.fu-berlin.de>
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "fd.h"
|
||||
#include "unistd.h"
|
||||
|
||||
int close(int fildes)
|
||||
{
|
||||
@ -37,21 +37,6 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
30
sys/xtimer/xtimer_posix.c
Normal file
30
sys/xtimer/xtimer_posix.c
Normal file
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*
|
||||
* @ingroup xtimer
|
||||
* @{
|
||||
* @file
|
||||
* @brief xtimer posix wrapper
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "xtimer.h"
|
||||
|
||||
unsigned int sleep(unsigned int seconds)
|
||||
{
|
||||
xtimer_usleep64(seconds*SEC_IN_USEC);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usleep(useconds_t usec)
|
||||
{
|
||||
xtimer_usleep64(usec);
|
||||
return 0;
|
||||
}
|
||||
@ -1,12 +1,6 @@
|
||||
APPLICATION = posix_sleep
|
||||
include ../Makefile.tests_common
|
||||
|
||||
BOARD_BLACKLIST := arduino-mega2560
|
||||
# arduino-mega2560: warning: iteration 2u invokes undefined behavior
|
||||
# [-Waggressive-loop-optimizations]
|
||||
|
||||
USEMODULE += posix
|
||||
|
||||
DISABLE_MODULE += auto_init
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
||||
@ -25,7 +25,7 @@ int main(void)
|
||||
{
|
||||
puts("usleep 1 x 1000*1000");
|
||||
for (int i = 0; i < 10; i++) {
|
||||
useconds_t us = i*1000*1000;
|
||||
useconds_t us = i*1000u*1000u;
|
||||
printf("calling usleep(%u)\n", (unsigned int) us);
|
||||
usleep(us);
|
||||
puts("wake up");
|
||||
|
||||
@ -7,6 +7,4 @@ BOARD_BLACKLIST := arduino-mega2560
|
||||
USEMODULE += posix
|
||||
USEMODULE += pthread
|
||||
|
||||
DISABLE_MODULE += auto_init
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
||||
@ -7,6 +7,4 @@ BOARD_BLACKLIST := arduino-mega2560
|
||||
USEMODULE += posix
|
||||
USEMODULE += pthread
|
||||
|
||||
DISABLE_MODULE += auto_init
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
||||
@ -7,6 +7,4 @@ BOARD_BLACKLIST := arduino-mega2560
|
||||
USEMODULE += posix
|
||||
USEMODULE += pthread
|
||||
|
||||
DISABLE_MODULE += auto_init
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user