diff options
| author | 陈豪 | Jacob Chen <[email protected]> | 2015-03-29 18:35:44 +0800 |
|---|---|---|
| committer | 陈豪 | Jacob Chen <[email protected]> | 2015-03-29 18:35:44 +0800 |
| commit | 9a4dacaad743801c9be2dbae49251c4e1b8f99a9 (patch) | |
| tree | 34def3bef5c5fc4a9b7594eba5a2729f8c86aab0 /components/libc | |
| parent | daac5388afe5a18d51e9839719de8423b62b00c1 (diff) | |
| parent | 5af7abd8c2e8b8a39c0bf096bdf9b5cb08f266fa (diff) | |
Merge pull request #3 from RT-Thread/master
111
Diffstat (limited to 'components/libc')
| -rw-r--r-- | components/libc/SConscript | 19 | ||||
| -rw-r--r-- | components/libc/armlibc/SConscript | 14 | ||||
| -rw-r--r-- | components/libc/armlibc/stubs.c | 61 | ||||
| -rw-r--r-- | components/libc/dlib/README.md | 4 | ||||
| -rw-r--r-- | components/libc/dlib/SConscript | 15 | ||||
| -rw-r--r-- | components/libc/dlib/environ.c | 25 | ||||
| -rw-r--r-- | components/libc/dlib/rmtx.c | 74 | ||||
| -rw-r--r-- | components/libc/dlib/syscall_close.c | 43 | ||||
| -rw-r--r-- | components/libc/dlib/syscall_lseek.c | 43 | ||||
| -rw-r--r-- | components/libc/dlib/syscall_mem.c | 44 | ||||
| -rw-r--r-- | components/libc/dlib/syscall_open.c | 88 | ||||
| -rw-r--r-- | components/libc/dlib/syscall_read.c | 53 | ||||
| -rw-r--r-- | components/libc/dlib/syscall_remove.c | 38 | ||||
| -rw-r--r-- | components/libc/dlib/syscall_write.c | 62 | ||||
| -rw-r--r-- | components/libc/dlib/syscalls.h | 23 | ||||
| -rw-r--r-- | components/libc/minilibc/SConscript | 12 | ||||
| -rw-r--r-- | components/libc/minilibc/stdlib.c | 2 | ||||
| -rw-r--r-- | components/libc/newlib/SConscript | 15 | ||||
| -rw-r--r-- | components/libc/newlib/libc.c | 14 |
19 files changed, 600 insertions, 49 deletions
diff --git a/components/libc/SConscript b/components/libc/SConscript index 19494ea7c2..4ca00c5b86 100644 --- a/components/libc/SConscript +++ b/components/libc/SConscript @@ -1,13 +1,20 @@ # for libc component import os -Import('RTT_ROOT') +Import('rtconfig') + +from building import * objs = [] -list = os.listdir(os.path.join(RTT_ROOT, 'components', 'libc')) -for d in list: - path = os.path.join(RTT_ROOT, 'components', 'libc', d) - if os.path.isfile(os.path.join(path, 'SConscript')): - objs = objs + SConscript(os.path.join(d, 'SConscript')) +if GetDepend('RT_USING_LIBC'): + if rtconfig.PLATFORM == 'gcc': + 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') Return('objs') diff --git a/components/libc/armlibc/SConscript b/components/libc/armlibc/SConscript index 11aba6b4f8..29f342a1c1 100644 --- a/components/libc/armlibc/SConscript +++ b/components/libc/armlibc/SConscript @@ -1,16 +1,12 @@ -Import('rtconfig') from building import * -if GetDepend('RT_USING_ARM_LIBC') and rtconfig.CROSS_TOOL != 'keil': - print '================ERROR==============================' - print 'Please use ARM CC compiler if using ARM C library' - print '===================================================' - exit(0) - -cwd = GetCurrentDir() src = Glob('*.c') +cwd = GetCurrentDir() + CPPPATH = [cwd] +CPPDEFINES = ['RT_USING_ARM_LIBC'] -group = DefineGroup('libc', src, depend = ['RT_USING_ARM_LIBC'], CPPPATH = CPPPATH) +group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], + CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) Return('group') diff --git a/components/libc/armlibc/stubs.c b/components/libc/armlibc/stubs.c index 1f9e01ba3c..bd57ca4c54 100644 --- a/components/libc/armlibc/stubs.c +++ b/components/libc/armlibc/stubs.c @@ -13,7 +13,7 @@ * Date Author Notes * 2012-11-23 Yihui The first version * 2013-11-24 aozima fixed _sys_read()/_sys_write() issues. - * 2014-08-03 bernard If using msh, use system() implementation + * 2014-08-03 bernard If using msh, use system() implementation * in msh. */ @@ -48,10 +48,11 @@ const char __stderr_name[] = "STDERR"; */ FILEHANDLE _sys_open(const char *name, int openmode) { -#ifdef RT_USING_DFS +#ifdef RT_USING_DFS int fd; + int mode = O_RDONLY; #endif - + /* Register standard Input Output devices. */ if (strcmp(name, __stdin_name) == 0) return (STDIN); @@ -63,9 +64,34 @@ FILEHANDLE _sys_open(const char *name, int openmode) #ifndef RT_USING_DFS return -1; #else - /* TODO: adjust open file mode */ - fd = open(name, openmode, 0); - if(fd < 0) + /* Correct openmode from fopen to open */ + if (openmode & OPEN_PLUS) + { + if (openmode & OPEN_W) + { + mode |= (O_RDWR | O_TRUNC | O_CREAT); + } + else if (openmode & OPEN_A) + { + mode |= (O_RDWR | O_APPEND | O_CREAT); + } + else + mode |= O_RDWR; + } + else + { + if (openmode & OPEN_W) + { + mode |= (O_WRONLY | O_TRUNC | O_CREAT); + } + else if (openmode & OPEN_A) + { + mode |= (O_WRONLY | O_APPEND | O_CREAT); + } + } + + fd = open(name, mode, 0); + if (fd < 0) return -1; else return fd + STDERR + 1; @@ -95,10 +121,10 @@ int _sys_close(FILEHANDLE fh) */ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) { -#ifdef RT_USING_DFS +#ifdef RT_USING_DFS int size; #endif - + if (fh == STDIN) { /* TODO */ @@ -112,7 +138,7 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) return 0; #else size = read(fh - STDERR - 1, buf, len); - if(size >= 0) + if (size >= 0) return len - size; else return -1; @@ -133,29 +159,29 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) #ifdef RT_USING_DFS int size; #endif - + if ((fh == STDOUT) || (fh == STDERR)) { #ifndef RT_USING_CONSOLE return 0; #else rt_device_t console_device; - extern rt_device_t rt_console_get_device(void); console_device = rt_console_get_device(); if (console_device != 0) rt_device_write(console_device, 0, buf, len); - return len; + + return 0; #endif } - if(fh == STDIN) + if (fh == STDIN) return -1; #ifndef RT_USING_DFS return 0; #else size = write(fh - STDERR - 1, buf, len); - if(size >= 0) + if (size >= 0) return len - size; else return -1; @@ -199,10 +225,12 @@ char *_sys_command_string(char *cmd, int len) /* This function writes a character to the console. */ void _ttywrch(int ch) { +#ifdef RT_USING_CONSOLE char c; c = (char)ch; rt_kprintf(&c); +#endif } void _sys_exit(int return_code) @@ -227,7 +255,6 @@ int _sys_istty(FILEHANDLE fh) return 0; } - int remove(const char *filename) { #ifndef RT_USING_DFS @@ -238,11 +265,11 @@ int remove(const char *filename) } #if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) && defined(RT_USING_MODULE) && defined(RT_USING_DFS) -/* use system implementation in the msh */ +/* use system(const char *string) implementation in the msh */ #else int system(const char *string) { RT_ASSERT(0); - for(;;); + for (;;); } #endif 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 + */ + diff --git a/components/libc/minilibc/SConscript b/components/libc/minilibc/SConscript index 42f41a311d..b0c82a7125 100644 --- a/components/libc/minilibc/SConscript +++ b/components/libc/minilibc/SConscript @@ -2,12 +2,12 @@ Import('RTT_ROOT') from building import * src = Glob('*.c') -CPPPATH = [RTT_ROOT + '/components/libc/minilibc'] +cwd = GetCurrentDir() + +CPPPATH = [cwd] CPPDEFINES = ['RT_USING_MINILIBC'] -group = DefineGroup('minilibc', src, - depend = ['RT_USING_MINILIBC'], - CPPPATH = CPPPATH, - CPPDEFINES = CPPDEFINES - ) + +group = DefineGroup('libc', src, depend = ['RT_USING_MINILIBC'], + CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) Return('group') diff --git a/components/libc/minilibc/stdlib.c b/components/libc/minilibc/stdlib.c index 51cb07fee0..e29ae9bc2e 100644 --- a/components/libc/minilibc/stdlib.c +++ b/components/libc/minilibc/stdlib.c @@ -54,6 +54,7 @@ long int atol(const char* s) return sign?-v:v; } +#ifdef RT_USING_HEAP void *malloc(size_t size) { return rt_malloc(size); @@ -73,5 +74,6 @@ void *calloc(size_t nelem, size_t elsize) { return rt_calloc(nelem, elsize); } +#endif #endif diff --git a/components/libc/newlib/SConscript b/components/libc/newlib/SConscript index ae8e8756e1..574c2a8d1f 100644 --- a/components/libc/newlib/SConscript +++ b/components/libc/newlib/SConscript @@ -1,15 +1,10 @@ -Import('rtconfig') from building import * -if GetDepend('RT_USING_NEWLIB') and rtconfig.CROSS_TOOL != 'gcc': - print '================ERROR============================' - print 'Please use GNU GCC compiler if using newlib' - print '=================================================' - exit(0) - +src = Glob('*.c') cwd = GetCurrentDir() -src = Glob('*.c') + CPPPATH = [cwd] +CPPDEFINES = ['RT_USING_NEWLIB'] # link with libc and libm: # libm is a frequently used lib. Newlib is compiled with -ffunction-sections in @@ -17,7 +12,7 @@ CPPPATH = [cwd] # been referenced. So setting this won't result in bigger text size. LIBS = ['c', 'm'] -group = DefineGroup('newlib', src, depend = ['RT_USING_NEWLIB'], - CPPPATH = CPPPATH, LIBS = LIBS) +group = DefineGroup('newlib', src, depend = ['RT_USING_LIBC'], + CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS) Return('group') diff --git a/components/libc/newlib/libc.c b/components/libc/newlib/libc.c index f7bb8e3f9b..73270969b8 100644 --- a/components/libc/newlib/libc.c +++ b/components/libc/newlib/libc.c @@ -9,6 +9,15 @@ #include <pthread.h> #endif +#ifdef RT_USING_DFS +#include <dfs_posix.h> + +#ifdef RT_USING_DFS_DEVFS +#include <devfs.h> +#endif + +#endif + void libc_system_init(const char* tty_name) { #ifdef RT_USING_DFS @@ -18,13 +27,16 @@ void libc_system_init(const char* tty_name) #error Please enable devfs by defining RT_USING_DFS_DEVFS in rtconfig.h #endif - /* init console device */ + /* initialize console device */ rt_console_init(tty_name); /* open console as stdin/stdout/stderr */ fd = open("/dev/console", O_RDONLY, 0); /* for stdin */ fd = open("/dev/console", O_WRONLY, 0); /* for stdout */ fd = open("/dev/console", O_WRONLY, 0); /* for stderr */ + + /* skip warning */ + fd = fd; #endif /* set PATH and HOME */ |
