summaryrefslogtreecommitdiff
path: root/components/libc/dlib
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2015-01-31 22:11:44 +0800
committerBernard Xiong <[email protected]>2015-01-31 22:11:44 +0800
commit0f9139ecfc3fcc909130c73eb0e2bb9eff912ad3 (patch)
tree27ccb23ace2bb9a6ba5cc893240a6456ea3e303a /components/libc/dlib
parent588682a1f520e3e781f8e237e39d51887b01d506 (diff)
parentca18a17180528b5ed408a591bdd302f64940105b (diff)
Merge pull request #422 from BernardXiong/master
Add lwIP/NAT, DHCP server and dlib(LIBC of IAR)
Diffstat (limited to 'components/libc/dlib')
-rw-r--r--components/libc/dlib/README.md4
-rw-r--r--components/libc/dlib/SConscript15
-rw-r--r--components/libc/dlib/environ.c25
-rw-r--r--components/libc/dlib/rmtx.c74
-rw-r--r--components/libc/dlib/syscall_close.c43
-rw-r--r--components/libc/dlib/syscall_lseek.c43
-rw-r--r--components/libc/dlib/syscall_mem.c44
-rw-r--r--components/libc/dlib/syscall_open.c88
-rw-r--r--components/libc/dlib/syscall_read.c53
-rw-r--r--components/libc/dlib/syscall_remove.c38
-rw-r--r--components/libc/dlib/syscall_write.c62
-rw-r--r--components/libc/dlib/syscalls.h23
12 files changed, 512 insertions, 0 deletions
diff --git a/components/libc/dlib/README.md b/components/libc/dlib/README.md
new file mode 100644
index 0000000000..846eb3f5c0
--- /dev/null
+++ b/components/libc/dlib/README.md
@@ -0,0 +1,4 @@
+Dlib(IAR) porting for RT-Thread.
+
+Please define RT_USING_LIBC and compile RT-Thread with IAR compiler.
+
diff --git a/components/libc/dlib/SConscript b/components/libc/dlib/SConscript
new file mode 100644
index 0000000000..a6b7554a07
--- /dev/null
+++ b/components/libc/dlib/SConscript
@@ -0,0 +1,15 @@
+from building import *
+import rtconfig
+
+src = Glob('*.c')
+cwd = GetCurrentDir()
+group = []
+
+CPPPATH = [cwd]
+CPPDEFINES = ['RT_USING_DLIBC']
+
+if rtconfig.PLATFORM == 'iar':
+ group = DefineGroup('dlib', src, depend = ['RT_USING_LIBC'],
+ CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
+
+Return('group')
diff --git a/components/libc/dlib/environ.c b/components/libc/dlib/environ.c
new file mode 100644
index 0000000000..1e44eb1627
--- /dev/null
+++ b/components/libc/dlib/environ.c
@@ -0,0 +1,25 @@
+/* File: environ.c
+ * this file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2015-01-28 Bernard first version
+ */
+
+const char *__environ = "OS=RT-Thread";
+
diff --git a/components/libc/dlib/rmtx.c b/components/libc/dlib/rmtx.c
new file mode 100644
index 0000000000..4bf7140271
--- /dev/null
+++ b/components/libc/dlib/rmtx.c
@@ -0,0 +1,74 @@
+/*
+ * File : rmtx.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2015-01-28 Bernard first version
+ */
+#include <rtthread.h>
+#include <yfuns.h>
+
+/*
+ * for IAR compiler, we recommand to define _DLIB_THREAD_SUPPORT
+ * as 2 for dlib multi-thread support.
+ */
+
+#if _DLIB_THREAD_SUPPORT
+typedef void* _Rmtx;
+void _Mtxinit(_Rmtx *m)
+{
+ rt_mutex_t mutex;
+
+ RT_ASSERT(m != RT_NULL);
+
+ mutex = (rt_mutex_t)m;
+ rt_mutex_init(mutex, "iarMtx", RT_IPC_FLAG_FIFO);
+}
+
+void _Mtxdst(_Rmtx *m)
+{
+ rt_mutex_t mutex;
+
+ RT_ASSERT(m != RT_NULL);
+
+ mutex = (rt_mutex_t)m;
+ rt_mutex_detach(mutex);
+}
+
+void _Mtxlock(_Rmtx *m)
+{
+ rt_mutex_t mutex;
+
+ RT_ASSERT(m != RT_NULL);
+
+ mutex = (rt_mutex_t)m;
+ rt_mutex_take(mutex, RT_WAITING_FOREVER);
+}
+
+void _Mtxunlock(_Rmtx *m)
+{
+ rt_mutex_t mutex;
+
+ RT_ASSERT(m != RT_NULL);
+
+ mutex = (rt_mutex_t)m;
+ rt_mutex_release(mutex);
+}
+#endif
+
diff --git a/components/libc/dlib/syscall_close.c b/components/libc/dlib/syscall_close.c
new file mode 100644
index 0000000000..5792bb3806
--- /dev/null
+++ b/components/libc/dlib/syscall_close.c
@@ -0,0 +1,43 @@
+/*
+ * File : syscall_close.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2015-01-28 Bernard first version
+ */
+#include <rtthread.h>
+#ifdef RT_USING_DFS
+#include <dfs_posix.h>
+#endif
+#include <yfuns.h>
+
+#pragma module_name = "?__close"
+int __close(int handle)
+{
+ if (handle == _LLIO_STDOUT ||
+ handle == _LLIO_STDERR ||
+ handle == _LLIO_STDIN)
+ return _LLIO_ERROR;
+
+#ifdef RT_USING_DFS
+ return close(handle);
+#else
+ return 0;
+#endif
+}
diff --git a/components/libc/dlib/syscall_lseek.c b/components/libc/dlib/syscall_lseek.c
new file mode 100644
index 0000000000..950ba52f65
--- /dev/null
+++ b/components/libc/dlib/syscall_lseek.c
@@ -0,0 +1,43 @@
+/*
+ * File : syscall_lseek.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2015-01-28 Bernard first version
+ */
+#include <rtthread.h>
+#ifdef RT_USING_DFS
+#include <dfs_posix.h>
+#endif
+#include <yfuns.h>
+
+#pragma module_name = "?__lseek"
+long __lseek(int handle, long offset, int whence)
+{
+ if (handle == _LLIO_STDOUT ||
+ handle == _LLIO_STDERR ||
+ handle == _LLIO_STDIN)
+ return _LLIO_ERROR;
+
+#ifdef RT_USING_DFS
+ return lseek(handle, offset, whence);
+#else
+ return _LLIO_ERROR;
+#endif
+}
diff --git a/components/libc/dlib/syscall_mem.c b/components/libc/dlib/syscall_mem.c
new file mode 100644
index 0000000000..10eb298b9c
--- /dev/null
+++ b/components/libc/dlib/syscall_mem.c
@@ -0,0 +1,44 @@
+/*
+ * File : syscall_mem.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2015-01-28 Bernard first version
+ */
+#include <rtthread.h>
+
+void *malloc(rt_size_t n)
+{
+ return rt_malloc(n);
+}
+
+void *realloc(void *rmem, rt_size_t newsize)
+{
+ return rt_realloc(rmem, newsize);
+}
+
+void *calloc(rt_size_t nelem, rt_size_t elsize)
+{
+ return rt_calloc(nelem, elsize);
+}
+
+void free(void *rmem)
+{
+ rt_free(rmem);
+}
diff --git a/components/libc/dlib/syscall_open.c b/components/libc/dlib/syscall_open.c
new file mode 100644
index 0000000000..95fa43b9c6
--- /dev/null
+++ b/components/libc/dlib/syscall_open.c
@@ -0,0 +1,88 @@
+/*
+* File : syscall_open.c
+* This file is part of RT-Thread RTOS
+* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License along
+* with this program; if not, write to the Free Software Foundation, Inc.,
+* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*
+* Change Logs:
+* Date Author Notes
+* 2015-01-28 Bernard first version
+*/
+
+#include <rtthread.h>
+#include <yfuns.h>
+#ifdef RT_USING_DFS
+#include <dfs_posix.h>
+#endif
+
+#pragma module_name = "?__open"
+
+int __open(const char *filename, int mode)
+{
+#ifndef RT_USING_DFS
+ return -1;
+#else
+ int handle;
+ int open_mode = O_RDONLY;
+
+ if (mode & _LLIO_CREAT)
+ {
+ open_mode |= O_CREAT;
+
+ /* Check what we should do with it if it exists. */
+ if (mode & _LLIO_APPEND)
+ {
+ /* Append to the existing file. */
+ open_mode |= O_APPEND;
+ }
+
+ if (mode & _LLIO_TRUNC)
+ {
+ /* Truncate the existsing file. */
+ open_mode |= O_TRUNC;
+ }
+ }
+
+ if (mode & _LLIO_TEXT)
+ {
+ /* we didn't support text mode */
+ }
+
+ switch (mode & _LLIO_RDWRMASK)
+ {
+ case _LLIO_RDONLY:
+ break;
+
+ case _LLIO_WRONLY:
+ open_mode |= O_WRONLY;
+ break;
+
+ case _LLIO_RDWR:
+ /* The file should be opened for both reads and writes. */
+ open_mode |= O_RDWR;
+ break;
+
+ default:
+ return -1;
+ }
+
+ handle = open(filename, open_mode, 0);
+ if (handle < 0)
+ return -1;
+
+ return handle + _LLIO_STDERR + 1;
+#endif
+}
diff --git a/components/libc/dlib/syscall_read.c b/components/libc/dlib/syscall_read.c
new file mode 100644
index 0000000000..aa13654189
--- /dev/null
+++ b/components/libc/dlib/syscall_read.c
@@ -0,0 +1,53 @@
+/*
+ * File : syscall_read.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2015-01-28 Bernard first version
+ */
+
+#include <rtthread.h>
+#ifdef RT_USING_DFS
+#include <dfs_posix.h>
+#endif
+#include <yfuns.h>
+
+#pragma module_name = "?__read"
+size_t __read(int handle, unsigned char *buf, size_t len)
+{
+#ifdef RT_USING_DFS
+ int size;
+#endif
+
+ if (handle == _LLIO_STDIN)
+ {
+ /* TODO */
+ return 0;
+ }
+
+ if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
+ return _LLIO_ERROR;
+
+#ifndef RT_USING_DFS
+ return _LLIO_ERROR;
+#else
+ size = read(handle - _LLIO_STDERR - 1, buf, len);
+ return size;
+#endif
+}
diff --git a/components/libc/dlib/syscall_remove.c b/components/libc/dlib/syscall_remove.c
new file mode 100644
index 0000000000..b7dd9477b7
--- /dev/null
+++ b/components/libc/dlib/syscall_remove.c
@@ -0,0 +1,38 @@
+/*
+ * File : syscall_remove.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2015-01-28 Bernard first version
+ */
+#include <rtthread.h>
+#ifdef RT_USING_DFS
+#include <dfs_file.h>
+#endif
+#include <yfuns.h>
+
+#pragma module_name = "?remove"
+int remove(const char *val)
+{
+#ifdef RT_USING_DFS
+ dfs_file_unlink(val);
+#endif
+
+ return 0;
+}
diff --git a/components/libc/dlib/syscall_write.c b/components/libc/dlib/syscall_write.c
new file mode 100644
index 0000000000..a7140b9818
--- /dev/null
+++ b/components/libc/dlib/syscall_write.c
@@ -0,0 +1,62 @@
+/*
+ * File : syscall_write.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2015-01-28 Bernard first version
+ */
+
+#include <rtthread.h>
+#ifdef RT_USING_DFS
+#include <dfs_posix.h>
+#endif
+#include <yfuns.h>
+
+#pragma module_name = "?__write"
+
+size_t __write(int handle, const unsigned char *buf, size_t len)
+{
+#ifdef RT_USING_DFS
+ int size;
+#endif
+
+ if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
+ {
+#ifndef RT_USING_CONSOLE
+ return _LLIO_ERROR;
+#else
+ rt_device_t console_device;
+
+ console_device = rt_console_get_device();
+ if (console_device != 0) rt_device_write(console_device, 0, buf, len);
+
+ return len;
+#endif
+ }
+
+ if (handle == _LLIO_STDIN) return -1;
+
+#ifndef RT_USING_DFS
+ return _LLIO_ERROR;
+#else
+ size = write(handle - _LLIO_STDERR - 1, buf, len);
+ return size;
+#endif
+}
+
diff --git a/components/libc/dlib/syscalls.h b/components/libc/dlib/syscalls.h
new file mode 100644
index 0000000000..2c38854f72
--- /dev/null
+++ b/components/libc/dlib/syscalls.h
@@ -0,0 +1,23 @@
+/* File: syscalls.h
+ * this file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2015-01-28 Bernard first version
+ */
+