summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
Diffstat (limited to 'components')
-rw-r--r--components/dfs/KConfig3
-rw-r--r--components/dfs/SConscript2
-rw-r--r--components/dfs/filesystems/devfs/devfs.c2
-rw-r--r--components/dfs/filesystems/net/dfs_net.c1
-rw-r--r--components/dfs/filesystems/net/net_sockets.c1
-rw-r--r--components/dfs/include/dfs_poll.h37
-rw-r--r--components/dfs/include/dfs_posix.h91
-rw-r--r--components/dfs/include/dfs_select.h65
-rw-r--r--components/dfs/src/poll.c3
-rw-r--r--components/dfs/src/select.c3
-rw-r--r--components/drivers/serial/serial.c15
-rw-r--r--components/drivers/src/pipe.c30
-rw-r--r--components/finsh/shell.c6
-rw-r--r--components/libc/KConfig8
-rw-r--r--components/libc/compilers/armlibc/stubs.c6
-rw-r--r--components/libc/compilers/dlib/syscall_read.c2
-rw-r--r--components/libc/compilers/dlib/syscall_write.c2
-rw-r--r--components/libc/compilers/newlib/libc.c2
18 files changed, 152 insertions, 127 deletions
diff --git a/components/dfs/KConfig b/components/dfs/KConfig
index 5be74c7874..59adb46c71 100644
--- a/components/dfs/KConfig
+++ b/components/dfs/KConfig
@@ -87,7 +87,8 @@ if RT_USING_DFS
config RT_USING_DFS_NET
bool "Enable BSD socket operated by file system API"
- depends on RT_USING_LWIP
+ select RT_USING_LWIP
+ select RT_USING_POSIX
default n
help
Let BSD socket operated by file system API, such as read/write and involveed in select/poll POSIX APIs.
diff --git a/components/dfs/SConscript b/components/dfs/SConscript
index 5c7c8bf6a1..3ccaeb1080 100644
--- a/components/dfs/SConscript
+++ b/components/dfs/SConscript
@@ -10,7 +10,7 @@ src/dfs_posix.c
cwd = GetCurrentDir()
CPPPATH = [cwd + "/include"]
-if GetDepend('RT_USING_DFS_NET'):
+if GetDepend('RT_USING_POSIX'):
src += ['src/poll.c', 'src/select.c']
group = DefineGroup('Filesystem', src, depend = ['RT_USING_DFS'], CPPPATH = CPPPATH)
diff --git a/components/dfs/filesystems/devfs/devfs.c b/components/dfs/filesystems/devfs/devfs.c
index e61da02179..6bfeccb578 100644
--- a/components/dfs/filesystems/devfs/devfs.c
+++ b/components/dfs/filesystems/devfs/devfs.c
@@ -190,6 +190,7 @@ int dfs_device_fs_open(struct dfs_fd *file)
if (device == RT_NULL)
return -ENODEV;
+#ifdef RT_USING_POSIX
if (device->fops)
{
/* use device fops */
@@ -207,6 +208,7 @@ int dfs_device_fs_open(struct dfs_fd *file)
}
}
else
+#endif
{
result = rt_device_open(device, RT_DEVICE_OFLAG_RDWR);
if (result == RT_EOK || result == -RT_ENOSYS)
diff --git a/components/dfs/filesystems/net/dfs_net.c b/components/dfs/filesystems/net/dfs_net.c
index 2a91434ef0..5e84c40540 100644
--- a/components/dfs/filesystems/net/dfs_net.c
+++ b/components/dfs/filesystems/net/dfs_net.c
@@ -32,6 +32,7 @@
#include <rtdevice.h>
#include <sys/socket.h>
+#include <dfs_poll.h>
#include "dfs_net.h"
int dfs_net_getsocket(int fd)
diff --git a/components/dfs/filesystems/net/net_sockets.c b/components/dfs/filesystems/net/net_sockets.c
index 0161cb0be5..a22fbdc9ad 100644
--- a/components/dfs/filesystems/net/net_sockets.c
+++ b/components/dfs/filesystems/net/net_sockets.c
@@ -24,6 +24,7 @@
#include <dfs.h>
#include <dfs_posix.h>
+#include <dfs_poll.h>
#include <sys/socket.h>
#include "dfs_net.h"
diff --git a/components/dfs/include/dfs_poll.h b/components/dfs/include/dfs_poll.h
new file mode 100644
index 0000000000..cfdf74fbe4
--- /dev/null
+++ b/components/dfs/include/dfs_poll.h
@@ -0,0 +1,37 @@
+#ifndef DFS_POLL_H__
+#define DFS_POLL_H__
+
+#include <rtthread.h>
+
+#ifdef RT_USING_POSIX
+#include <sys/time.h> /* for struct timeval */
+
+#define POLLIN (0x01)
+#define POLLRDNORM (0x01)
+#define POLLRDBAND (0x01)
+#define POLLPRI (0x01)
+
+#define POLLOUT (0x02)
+#define POLLWRNORM (0x02)
+#define POLLWRBAND (0x02)
+
+#define POLLERR (0x04)
+#define POLLHUP (0x08)
+#define POLLNVAL (0x10)
+
+#define POLLMASK_DEFAULT (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)
+
+typedef unsigned int nfds_t;
+
+struct pollfd
+{
+ int fd;
+ short events;
+ short revents;
+};
+
+int poll(struct pollfd *fds, nfds_t nfds, int timeout);
+#endif
+
+#endif
+
diff --git a/components/dfs/include/dfs_posix.h b/components/dfs/include/dfs_posix.h
index e775474f0a..b0fe2041ab 100644
--- a/components/dfs/include/dfs_posix.h
+++ b/components/dfs/include/dfs_posix.h
@@ -28,7 +28,6 @@
#define __DFS_POSIX_H__
#include <dfs_file.h>
-#include <sys/time.h> /* for struct timeval */
#ifdef __cplusplus
extern "C" {
@@ -81,96 +80,6 @@ int access(const char *path, int amode);
int pipe(int fildes[2]);
int mkfifo(const char *path, mode_t mode);
-/* poll and select */
-
-#define POLLIN (0x01)
-#define POLLRDNORM (0x01)
-#define POLLRDBAND (0x01)
-#define POLLPRI (0x01)
-
-#define POLLOUT (0x02)
-#define POLLWRNORM (0x02)
-#define POLLWRBAND (0x02)
-
-#define POLLERR (0x04)
-#define POLLHUP (0x08)
-#define POLLNVAL (0x10)
-
-#define POLLMASK_DEFAULT (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)
-
-typedef unsigned int nfds_t;
-
-struct pollfd
-{
- int fd;
- short events;
- short revents;
-};
-
-int poll(struct pollfd *fds, nfds_t nfds, int timeout);
-
-
-#ifdef RT_USING_LWIP
-/* we use lwIP's structure definitions. */
-#include <lwip/sockets.h>
-#else
-
-#ifndef FD_SET
-
-/* Get the total number of descriptors that we will have to support */
-
-#define FD_SETSIZE (12)
-
-/* We will use a 32-bit bitsets to represent the set of descriptors. How
- * many uint32_t's do we need to span all descriptors?
- */
-
-#if FD_SETSIZE <= 32
-# define __SELECT_NUINT32 1
-#elif FD_SETSIZE <= 64
-# define __SELECT_NUINT32 2
-#elif FD_SETSIZE <= 96
-# define __SELECT_NUINT32 3
-#elif FD_SETSIZE <= 128
-# define __SELECT_NUINT32 4
-#elif FD_SETSIZE <= 160
-# define __SELECT_NUINT32 5
-#elif FD_SETSIZE <= 192
-# define __SELECT_NUINT32 6
-#elif FD_SETSIZE <= 224
-# define __SELECT_NUINT32 7
-#elif FD_SETSIZE <= 256
-# define __SELECT_NUINT32 8
-#else
-# warning "Larger fd_set needed"
-#endif
-
-/* These macros map a file descriptor to an index and bit number */
-
-#define _FD_NDX(fd) ((fd) >> 5)
-#define _FD_BIT(fd) ((fd) & 0x1f)
-
-/* Standard helper macros */
-
-#define FD_CLR(fd,set) \
- ((((fd_set*)(set))->arr)[_FD_NDX(fd)] &= ~(1 << _FD_BIT(fd)))
-#define FD_SET(fd,set) \
- ((((fd_set*)(set))->arr)[_FD_NDX(fd)] |= (1 << _FD_BIT(fd)))
-#define FD_ISSET(fd,set) \
- (((((fd_set*)(set))->arr)[_FD_NDX(fd)] & (1 << _FD_BIT(fd))) != 0)
-#define FD_ZERO(set) \
- memset((set), 0, sizeof(fd_set))
-
-typedef struct
-{
- uint32_t arr[__SELECT_NUINT32];
-}fd_set;
-#endif
-
-#endif
-
-int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
-
#ifdef __cplusplus
}
#endif
diff --git a/components/dfs/include/dfs_select.h b/components/dfs/include/dfs_select.h
new file mode 100644
index 0000000000..0b5d6cef17
--- /dev/null
+++ b/components/dfs/include/dfs_select.h
@@ -0,0 +1,65 @@
+#ifndef DFS_SELECT_H__
+#define DFS_SELECT_H__
+
+#ifdef RT_USING_LWIP
+/* we use lwIP's structure definitions. */
+#include <lwip/sockets.h>
+#elif defined(RT_USING_POSIX)
+
+#ifndef FD_SET
+
+/* Get the total number of descriptors that we will have to support */
+
+#define FD_SETSIZE (12)
+
+/* We will use a 32-bit bitsets to represent the set of descriptors. How
+ * many uint32_t's do we need to span all descriptors?
+ */
+
+#if FD_SETSIZE <= 32
+# define __SELECT_NUINT32 1
+#elif FD_SETSIZE <= 64
+# define __SELECT_NUINT32 2
+#elif FD_SETSIZE <= 96
+# define __SELECT_NUINT32 3
+#elif FD_SETSIZE <= 128
+# define __SELECT_NUINT32 4
+#elif FD_SETSIZE <= 160
+# define __SELECT_NUINT32 5
+#elif FD_SETSIZE <= 192
+# define __SELECT_NUINT32 6
+#elif FD_SETSIZE <= 224
+# define __SELECT_NUINT32 7
+#elif FD_SETSIZE <= 256
+# define __SELECT_NUINT32 8
+#else
+# warning "Larger fd_set needed"
+#endif
+
+/* These macros map a file descriptor to an index and bit number */
+
+#define _FD_NDX(fd) ((fd) >> 5)
+#define _FD_BIT(fd) ((fd) & 0x1f)
+
+/* Standard helper macros */
+
+#define FD_CLR(fd,set) \
+ ((((fd_set*)(set))->arr)[_FD_NDX(fd)] &= ~(1 << _FD_BIT(fd)))
+#define FD_SET(fd,set) \
+ ((((fd_set*)(set))->arr)[_FD_NDX(fd)] |= (1 << _FD_BIT(fd)))
+#define FD_ISSET(fd,set) \
+ (((((fd_set*)(set))->arr)[_FD_NDX(fd)] & (1 << _FD_BIT(fd))) != 0)
+#define FD_ZERO(set) \
+ memset((set), 0, sizeof(fd_set))
+
+typedef struct
+{
+ uint32_t arr[__SELECT_NUINT32];
+}fd_set;
+#endif
+
+int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
+
+#endif /* end of RT_USING_LWIP */
+
+#endif
diff --git a/components/dfs/src/poll.c b/components/dfs/src/poll.c
index b0bd234647..f95a9b1845 100644
--- a/components/dfs/src/poll.c
+++ b/components/dfs/src/poll.c
@@ -23,11 +23,14 @@
*/
#include <stdint.h>
+#include <rthw.h>
#include <rtdevice.h>
+#include <rtthread.h>
#include <dfs.h>
#include <dfs_file.h>
#include <dfs_posix.h>
+#include <dfs_poll.h>
struct rt_poll_node;
diff --git a/components/dfs/src/select.c b/components/dfs/src/select.c
index 44ba9f68a2..36a8942331 100644
--- a/components/dfs/src/select.c
+++ b/components/dfs/src/select.c
@@ -25,6 +25,9 @@
#include <dfs_fs.h>
#include <dfs_posix.h>
+#include <dfs_poll.h>
+#include <dfs_select.h>
+
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
{
int fd;
diff --git a/components/drivers/serial/serial.c b/components/drivers/serial/serial.c
index c279490dec..52dd65e17b 100644
--- a/components/drivers/serial/serial.c
+++ b/components/drivers/serial/serial.c
@@ -44,14 +44,14 @@
#define DEBUG_COLOR
#include <rtdbg.h>
+#ifdef RT_USING_POSIX
+#include <dfs_posix.h>
+#include <dfs_poll.h>
+
#ifdef RT_USING_POSIX_TERMIOS
#include <posix_termios.h>
#endif
-#ifdef RT_USING_DFS
-#ifdef RT_USING_DFS_DEVFS
-#include <dfs_posix.h>
-
/* it's possible the 'getc/putc' is defined by stdio.h in gcc/newlib. */
#ifdef getc
#undef getc
@@ -97,7 +97,8 @@ static int serial_fops_open(struct dfs_fd *fd)
break;
}
- rt_device_set_rx_indicate(device, serial_fops_rx_ind);
+ if ((fd->flags & O_ACCMODE) != O_WRONLY)
+ rt_device_set_rx_indicate(device, serial_fops_rx_ind);
ret = rt_device_open(device, flags);
if (ret == RT_EOK) return 0;
@@ -210,7 +211,7 @@ const static struct dfs_file_ops _serial_fops =
serial_fops_poll,
};
#endif
-#endif
+
/*
* Serial poll routines
*/
@@ -993,7 +994,7 @@ rt_err_t rt_hw_serial_register(struct rt_serial_device *serial,
/* register a character device */
ret = rt_device_register(device, name, flag);
-#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS)
+#if defined(RT_USING_POSIX)
/* set fops */
device->fops = &_serial_fops;
#endif
diff --git a/components/drivers/src/pipe.c b/components/drivers/src/pipe.c
index bc9ed5f9a2..0553c500ee 100644
--- a/components/drivers/src/pipe.c
+++ b/components/drivers/src/pipe.c
@@ -23,13 +23,13 @@
*/
#include <rthw.h>
#include <rtdevice.h>
-#if defined(RT_USING_DFS)
+
+#if defined(RT_USING_POSIX)
#include <dfs_file.h>
#include <dfs_posix.h>
-#endif
+#include <dfs_poll.h>
-#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS)
-static int pipe_open(struct dfs_fd *fd)
+static int pipe_fops_open(struct dfs_fd *fd)
{
rt_device_t device;
rt_pipe_t *pipe;
@@ -65,7 +65,7 @@ static int pipe_open(struct dfs_fd *fd)
return 0;
}
-static int pipe_close(struct dfs_fd *fd)
+static int pipe_fops_close(struct dfs_fd *fd)
{
rt_device_t device;
rt_pipe_t *pipe;
@@ -112,7 +112,7 @@ static int pipe_close(struct dfs_fd *fd)
return 0;
}
-static int pipe_ioctl(struct dfs_fd *fd, int cmd, void *args)
+static int pipe_fops_ioctl(struct dfs_fd *fd, int cmd, void *args)
{
rt_pipe_t *pipe;
int ret = 0;
@@ -135,7 +135,7 @@ static int pipe_ioctl(struct dfs_fd *fd, int cmd, void *args)
return ret;
}
-static int pipe_read(struct dfs_fd *fd, void *buf, size_t count)
+static int pipe_fops_read(struct dfs_fd *fd, void *buf, size_t count)
{
int len = 0;
rt_pipe_t *pipe;
@@ -185,7 +185,7 @@ out:
return len;
}
-static int pipe_write(struct dfs_fd *fd, const void *buf, size_t count)
+static int pipe_fops_write(struct dfs_fd *fd, const void *buf, size_t count)
{
int len;
rt_pipe_t *pipe;
@@ -256,7 +256,7 @@ out:
return ret;
}
-static int pipe_poll(struct dfs_fd *fd, rt_pollreq_t *req)
+static int pipe_fops_poll(struct dfs_fd *fd, rt_pollreq_t *req)
{
int mask = 0;
rt_pipe_t *pipe;
@@ -308,15 +308,15 @@ static int pipe_poll(struct dfs_fd *fd, rt_pollreq_t *req)
static const struct dfs_file_ops pipe_fops =
{
- pipe_open,
- pipe_close,
- pipe_ioctl,
- pipe_read,
- pipe_write,
+ pipe_fops_open,
+ pipe_fops_close,
+ pipe_fops_ioctl,
+ pipe_fops_read,
+ pipe_fops_write,
RT_NULL,
RT_NULL,
RT_NULL,
- pipe_poll,
+ pipe_fops_poll,
};
rt_pipe_t *rt_pipe_create(const char *name)
diff --git a/components/finsh/shell.c b/components/finsh/shell.c
index 8e1f814560..4c20b3c640 100644
--- a/components/finsh/shell.c
+++ b/components/finsh/shell.c
@@ -84,7 +84,7 @@ const char *finsh_get_prompt()
static char finsh_getchar(void)
{
-#ifdef RT_USING_POSIX_STDIN
+#ifdef RT_USING_POSIX
return getchar();
#else
char ch;
@@ -97,7 +97,7 @@ static char finsh_getchar(void)
#endif
}
-#ifndef RT_USING_POSIX_STDIN
+#ifndef RT_USING_POSIX
static rt_err_t finsh_rx_ind(rt_device_t dev, rt_size_t size)
{
RT_ASSERT(shell != RT_NULL);
@@ -420,7 +420,7 @@ void finsh_thread_entry(void *parameter)
finsh_init(&shell->parser);
#endif
-#ifndef RT_USING_POSIX_STDIN
+#ifndef RT_USING_POSIX
/* set console device as shell device */
if (shell->device == RT_NULL)
{
diff --git a/components/libc/KConfig b/components/libc/KConfig
index c245069e30..79bc78d205 100644
--- a/components/libc/KConfig
+++ b/components/libc/KConfig
@@ -1,4 +1,4 @@
-menu "libc"
+menu "POSIX layer and C standard library"
config RT_USING_LIBC
bool "Enable libc APIs from toolchain"
@@ -9,12 +9,13 @@ config RT_USING_PTHREADS
default n
if RT_USING_LIBC
- config RT_USING_POSIX_STDIN
- bool "Enable stdin"
+ config RT_USING_POSIX
+ bool "Enable POSIX layer for poll/select, stdin etc"
select RT_USING_DFS
select RT_USING_DFS_DEVFS
default y
+ if RT_USING_POSIX
config RT_USING_POSIX_MMAP
bool "Enable mmap() api"
default n
@@ -22,6 +23,7 @@ if RT_USING_LIBC
config RT_USING_POSIX_TERMIOS
bool "Enable termios feature"
default n
+ endif
endif
endmenu
diff --git a/components/libc/compilers/armlibc/stubs.c b/components/libc/compilers/armlibc/stubs.c
index 719665b78e..74ca5fd1f6 100644
--- a/components/libc/compilers/armlibc/stubs.c
+++ b/components/libc/compilers/armlibc/stubs.c
@@ -153,7 +153,7 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
if (fh == STDIN)
{
-#ifdef RT_USING_POSIX_STDIN
+#ifdef RT_USING_POSIX
size = libc_stdio_read(buf, len);
return len - size;
#else
@@ -192,7 +192,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
#ifndef RT_USING_CONSOLE
return 0;
#else
-#ifdef RT_USING_POSIX_STDIN
+#ifdef RT_USING_POSIX
size = libc_stdio_write(buf, len);
return len - size;
#else
@@ -319,7 +319,7 @@ int fgetc(FILE *f)
{
char ch;
-#ifdef RT_USING_POSIX_STDIN
+#ifdef RT_USING_POSIX
if (libc_stdio_read(&ch, 1) == 1)
return ch;
#endif
diff --git a/components/libc/compilers/dlib/syscall_read.c b/components/libc/compilers/dlib/syscall_read.c
index 9dcaa9df65..e7e99629d7 100644
--- a/components/libc/compilers/dlib/syscall_read.c
+++ b/components/libc/compilers/dlib/syscall_read.c
@@ -38,7 +38,7 @@ size_t __read(int handle, unsigned char *buf, size_t len)
if (handle == _LLIO_STDIN)
{
-#ifdef RT_USING_POSIX_STDIN
+#ifdef RT_USING_POSIX
return libc_stdio_read(buf, len);
#else
return _LLIO_ERROR;
diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c
index e2cb04000b..79d702339a 100644
--- a/components/libc/compilers/dlib/syscall_write.c
+++ b/components/libc/compilers/dlib/syscall_write.c
@@ -43,7 +43,7 @@ size_t __write(int handle, const unsigned char *buf, size_t len)
return _LLIO_ERROR;
#else
-#ifdef RT_USING_POSIX_STDIN
+#ifdef RT_USING_POSIX
return libc_stdio_write((void*)buf, len);
#else
rt_device_t console_device;
diff --git a/components/libc/compilers/newlib/libc.c b/components/libc/compilers/newlib/libc.c
index c06ded705e..f8fbbb5e8f 100644
--- a/components/libc/compilers/newlib/libc.c
+++ b/components/libc/compilers/newlib/libc.c
@@ -43,7 +43,7 @@ int libc_system_init(void)
dev_console = rt_console_get_device();
if (dev_console)
{
- #if defined(RT_USING_DFS_DEVFS) && defined(RT_USING_POSIX_STDIN)
+ #if defined(RT_USING_POSIX)
libc_stdio_set_console(dev_console->parent.name, O_RDWR);
#else
libc_stdio_set_console(dev_console->parent.name, O_WRONLY);