Merge remote-tracking branch 'china/master'

This commit is contained in:
Bernard Xiong 2015-01-31 14:00:44 +00:00
commit ca18a17180
10 changed files with 204 additions and 72 deletions

View File

@ -11,6 +11,8 @@ if GetDepend('RT_USING_LIBC'):
objs = objs + SConscript('newlib/SConscript') objs = objs + SConscript('newlib/SConscript')
elif rtconfig.PLATFORM == 'armcc': elif rtconfig.PLATFORM == 'armcc':
objs = objs + SConscript('armlibc/SConscript') objs = objs + SConscript('armlibc/SConscript')
elif rtconfig.PLATFORM == 'iar':
objs = objs + SConscript('dlib/SConscript')
else: else:
if rtconfig.PLATFORM == 'gcc': if rtconfig.PLATFORM == 'gcc':
objs = objs + SConscript('minilibc/SConscript') objs = objs + SConscript('minilibc/SConscript')

View File

@ -10,6 +10,6 @@ CPPDEFINES = ['RT_USING_DLIBC']
if rtconfig.PLATFORM == 'iar': if rtconfig.PLATFORM == 'iar':
group = DefineGroup('dlib', src, depend = ['RT_USING_LIBC'], group = DefineGroup('dlib', src, depend = ['RT_USING_LIBC'],
CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS) CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
Return('group') Return('group')

View File

@ -30,6 +30,7 @@
*/ */
#if _DLIB_THREAD_SUPPORT #if _DLIB_THREAD_SUPPORT
typedef void* _Rmtx;
void _Mtxinit(_Rmtx *m) void _Mtxinit(_Rmtx *m)
{ {
rt_mutex_t mutex; rt_mutex_t mutex;

View File

@ -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
}

View File

@ -1,5 +1,5 @@
/* /*
* File : syscalls.c * File : syscall_lseek.c
* This file is part of RT-Thread RTOS * This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team * COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
* *
@ -23,46 +23,21 @@
*/ */
#include <rtthread.h> #include <rtthread.h>
#ifdef RT_USING_DFS #ifdef RT_USING_DFS
#include <dfs_file.h> #include <dfs_posix.h>
#endif #endif
#include <yfuns.h> #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
}
#pragma module_name = "?remove"
int remove(const char *val)
{
#ifdef RT_USING_DFS
dfs_file_unlink(val);
#endif
return 0;
}
#pragma module_name = "?__lseek" #pragma module_name = "?__lseek"
long __lseek(int handle, long offset, int whence) long __lseek(int handle, long offset, int whence)
{ {
#ifdef RT_USING_DFS
#endif
if (handle == _LLIO_STDOUT || if (handle == _LLIO_STDOUT ||
handle == _LLIO_STDERR || handle == _LLIO_STDERR ||
handle == _LLIO_STDIN) handle == _LLIO_STDIN)
return _LLIO_ERROR; return _LLIO_ERROR;
#ifdef RT_USING_DFS
return lseek(handle, offset, whence); return lseek(handle, offset, whence);
#else
return _LLIO_ERROR;
#endif
} }

View File

@ -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);
}

View File

@ -32,8 +32,28 @@
int __open(const char *filename, int mode) 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) 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) if (mode & _LLIO_TEXT)
@ -44,21 +64,25 @@ int __open(const char *filename, int mode)
switch (mode & _LLIO_RDWRMASK) switch (mode & _LLIO_RDWRMASK)
{ {
case _LLIO_RDONLY: case _LLIO_RDONLY:
/* The file should be opened for read only. */
break; break;
case _LLIO_WRONLY: case _LLIO_WRONLY:
/* The file should be opened for write only. */ open_mode |= O_WRONLY;
break; break;
case _LLIO_RDWR: case _LLIO_RDWR:
/* The file should be opened for both reads and writes. */ /* The file should be opened for both reads and writes. */
open_mode |= O_RDWR;
break; break;
default: default:
return -1; return -1;
} }
return handle; handle = open(filename, open_mode, 0);
} if (handle < 0)
return -1;
return handle + _LLIO_STDERR + 1;
#endif
}

View File

@ -23,6 +23,9 @@
*/ */
#include <rtthread.h> #include <rtthread.h>
#ifdef RT_USING_DFS
#include <dfs_posix.h>
#endif
#include <yfuns.h> #include <yfuns.h>
#pragma module_name = "?__read" #pragma module_name = "?__read"
@ -44,8 +47,7 @@ size_t __read(int handle, unsigned char *buf, size_t len)
#ifndef RT_USING_DFS #ifndef RT_USING_DFS
return _LLIO_ERROR; return _LLIO_ERROR;
#else #else
size = read(handle - STDERR - 1, buf, len); size = read(handle - _LLIO_STDERR - 1, buf, len);
return size; return size;
#endif #endif
} }

View File

@ -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;
}

View File

@ -23,6 +23,9 @@
*/ */
#include <rtthread.h> #include <rtthread.h>
#ifdef RT_USING_DFS
#include <dfs_posix.h>
#endif
#include <yfuns.h> #include <yfuns.h>
#pragma module_name = "?__write" #pragma module_name = "?__write"
@ -47,12 +50,12 @@ size_t __write(int handle, const unsigned char *buf, size_t len)
#endif #endif
} }
if (handle == STDIN) return -1; if (handle == _LLIO_STDIN) return -1;
#ifndef RT_USING_DFS #ifndef RT_USING_DFS
return _LLIO_ERROR; return _LLIO_ERROR;
#else #else
size = write(handle - STDERR - 1, buf, len); size = write(handle - _LLIO_STDERR - 1, buf, len);
return size; return size;
#endif #endif
} }