2013-11-27 16:28:31 +01:00
|
|
|
/*
|
2013-11-03 14:32:25 +01:00
|
|
|
* Copyright (C) 2013 INRIA.
|
|
|
|
*
|
2014-08-23 15:43:13 +02:00
|
|
|
* 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.
|
2013-11-03 14:32:25 +01:00
|
|
|
*/
|
|
|
|
|
2013-11-27 16:28:31 +01:00
|
|
|
/**
|
2014-12-06 02:05:51 +01:00
|
|
|
* @ingroup posix
|
2013-11-03 14:32:25 +01:00
|
|
|
* @{
|
2013-11-28 13:25:33 +01:00
|
|
|
* @file posix_io.h
|
|
|
|
* @brief POSIX-like IO
|
2013-11-03 14:32:25 +01:00
|
|
|
*
|
2013-11-28 13:25:33 +01:00
|
|
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
|
|
|
* @author Stephan Zeisberg <zeisberg@mi.fu-berlin.de>
|
|
|
|
* @author Oliver Hahm <oleg@hobbykeller.org>
|
2015-02-08 18:51:25 +01:00
|
|
|
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
2013-11-03 14:32:25 +01:00
|
|
|
*/
|
2010-09-24 16:28:34 +02:00
|
|
|
#ifndef __READ_H
|
2013-06-22 05:11:53 +02:00
|
|
|
#define __READ_H
|
2010-09-24 16:28:34 +02:00
|
|
|
|
2014-07-06 22:57:56 +02:00
|
|
|
#include "kernel_types.h"
|
|
|
|
|
2014-10-10 11:51:11 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2010-09-24 16:28:34 +02:00
|
|
|
#define OPEN 0
|
|
|
|
#define CLOSE 1
|
|
|
|
#define READ 2
|
|
|
|
#define WRITE 3
|
|
|
|
|
2014-12-06 02:05:51 +01:00
|
|
|
/**
|
|
|
|
* @brief POSIX IO ringbuffer
|
|
|
|
*/
|
2011-03-08 11:43:21 +01:00
|
|
|
struct posix_iop_t {
|
2014-12-06 02:05:51 +01:00
|
|
|
/** number of bytes */
|
2010-09-24 16:28:34 +02:00
|
|
|
int nbytes;
|
2014-12-06 02:05:51 +01:00
|
|
|
/** array for the ringbuffer */
|
2010-09-24 16:28:34 +02:00
|
|
|
char *buffer;
|
|
|
|
};
|
|
|
|
|
2014-12-06 02:05:51 +01:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
2014-08-11 13:10:12 +02:00
|
|
|
int posix_open(int pid, int flags);
|
2014-12-06 02:05:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Closes an open file descriptor
|
|
|
|
*
|
|
|
|
* @param[in] pid The opened thread
|
|
|
|
*
|
|
|
|
* @return 0 on success
|
|
|
|
* @return a negative value in error case
|
|
|
|
*/
|
2014-08-11 13:10:12 +02:00
|
|
|
int posix_close(int pid);
|
2014-12-06 02:05:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
2014-08-11 13:10:12 +02:00
|
|
|
int posix_read(int pid, char *buffer, int bufsize);
|
2014-12-06 02:05:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
2014-08-11 13:10:12 +02:00
|
|
|
int posix_write(int pid, char *buffer, int bufsize);
|
2013-11-28 13:25:33 +01:00
|
|
|
|
2014-10-10 11:51:11 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-11-28 13:25:33 +01:00
|
|
|
/** @} */
|
2010-09-24 16:28:34 +02:00
|
|
|
#endif /* __READ_H */
|