diff --git a/components/libc/SConscript b/components/libc/SConscript index 799ecccb365a7f9a3e519ed8666ca77b74beff48..4ca00c5b8686ae13de5171c819f931448d7cf004 100644 --- a/components/libc/SConscript +++ b/components/libc/SConscript @@ -11,6 +11,8 @@ if GetDepend('RT_USING_LIBC'): objs = objs + SConscript('newlib/SConscript') elif rtconfig.PLATFORM == 'armcc': objs = objs + SConscript('armlibc/SConscript') + elif rtconfig.PLATFORM == 'iar': + objs = objs + SConscript('dlib/SConscript') else: if rtconfig.PLATFORM == 'gcc': objs = objs + SConscript('minilibc/SConscript') diff --git a/components/libc/dlib/SConscript b/components/libc/dlib/SConscript index f0e53a9f3e9333e790b515adb259cbbe698c8450..a6b7554a07784076fc12a3595903303357c2ca8b 100644 --- a/components/libc/dlib/SConscript +++ b/components/libc/dlib/SConscript @@ -10,6 +10,6 @@ CPPDEFINES = ['RT_USING_DLIBC'] if rtconfig.PLATFORM == 'iar': group = DefineGroup('dlib', src, depend = ['RT_USING_LIBC'], - CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS) + CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) Return('group') diff --git a/components/libc/dlib/rmtx.c b/components/libc/dlib/rmtx.c index d6ce920d67d6208b5c1a5ea917bb61635ed755c0..4bf714027181219f13a7118aabd877861decc8f2 100644 --- a/components/libc/dlib/rmtx.c +++ b/components/libc/dlib/rmtx.c @@ -30,6 +30,7 @@ */ #if _DLIB_THREAD_SUPPORT +typedef void* _Rmtx; void _Mtxinit(_Rmtx *m) { rt_mutex_t mutex; diff --git a/components/libc/dlib/syscall_close.c b/components/libc/dlib/syscall_close.c new file mode 100644 index 0000000000000000000000000000000000000000..5792bb3806fd3bb0d1ba8b10f52867f7755b3cad --- /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 +#ifdef RT_USING_DFS +#include +#endif +#include + +#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/syscalls.c b/components/libc/dlib/syscall_lseek.c similarity index 74% rename from components/libc/dlib/syscalls.c rename to components/libc/dlib/syscall_lseek.c index f1802a98b8fb2593b2fbba757cea9e12f7905d85..950ba52f652a2872758fdb9b9121559365dd926c 100644 --- a/components/libc/dlib/syscalls.c +++ b/components/libc/dlib/syscall_lseek.c @@ -1,5 +1,5 @@ /* - * File : syscalls.c + * File : syscall_lseek.c * This file is part of RT-Thread RTOS * COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team * @@ -23,46 +23,21 @@ */ #include #ifdef RT_USING_DFS -#include +#include #endif #include -#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 -} - -#pragma module_name = "?remove" -int remove(const char *val) -{ -#ifdef RT_USING_DFS - dfs_file_unlink(val); -#endif - - return 0; -} - #pragma module_name = "?__lseek" long __lseek(int handle, long offset, int whence) { -#ifdef RT_USING_DFS -#endif - 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 0000000000000000000000000000000000000000..10eb298b9ca5442d1725c128d41d1c8c9d8fc3c0 --- /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 + +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 index 0aa0caf0cda5a1d0c218531da3447ab828ebc446..95fa43b9c619e231768903a8f2fe685040e8ab6c 100644 --- a/components/libc/dlib/syscall_open.c +++ b/components/libc/dlib/syscall_open.c @@ -1,26 +1,26 @@ /* - * 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 - */ +* 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 #include @@ -32,33 +32,57 @@ int __open(const char *filename, int mode) { - if (mode & _LLIO_CREAT) +#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_TEXT) + if (mode & _LLIO_TRUNC) { - /* we didn't support text mode */ + /* Truncate the existsing file. */ + open_mode |= O_TRUNC; } - - switch (mode & _LLIO_RDWRMASK) - { + } + + if (mode & _LLIO_TEXT) + { + /* we didn't support text mode */ + } + + switch (mode & _LLIO_RDWRMASK) + { case _LLIO_RDONLY: - /* The file should be opened for read only. */ break; - + case _LLIO_WRONLY: - /* The file should be opened for write only. */ + 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; } - - return handle; + + 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 index f109badb55237cda25b38f1cc4900f70452cd3a9..aa13654189be702ea1881d06216065e321a18ef0 100644 --- a/components/libc/dlib/syscall_read.c +++ b/components/libc/dlib/syscall_read.c @@ -23,6 +23,9 @@ */ #include +#ifdef RT_USING_DFS +#include +#endif #include #pragma module_name = "?__read" @@ -44,8 +47,7 @@ size_t __read(int handle, unsigned char *buf, size_t len) #ifndef RT_USING_DFS return _LLIO_ERROR; #else - size = read(handle - STDERR - 1, buf, len); + 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 0000000000000000000000000000000000000000..b7dd9477b739dc2817ce1d2714d4d278cfe7bf01 --- /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 +#ifdef RT_USING_DFS +#include +#endif +#include + +#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 index 5f21bf9bb9cd95adf6b91083c7495a735cf267dd..a7140b9818cfd7879d422ec7855e906b02ec2d12 100644 --- a/components/libc/dlib/syscall_write.c +++ b/components/libc/dlib/syscall_write.c @@ -23,6 +23,9 @@ */ #include +#ifdef RT_USING_DFS +#include +#endif #include #pragma module_name = "?__write" @@ -47,12 +50,12 @@ size_t __write(int handle, const unsigned char *buf, size_t len) #endif } - if (handle == STDIN) return -1; + if (handle == _LLIO_STDIN) return -1; #ifndef RT_USING_DFS return _LLIO_ERROR; #else - size = write(handle - STDERR - 1, buf, len); + size = write(handle - _LLIO_STDERR - 1, buf, len); return size; #endif }