Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions components/dfs/filesystems/devfs/devfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ int dfs_device_fs_close(struct dfs_fd *file)

int dfs_device_fs_open(struct dfs_fd *file)
{
rt_err_t result;
rt_device_t device;

if (file->flags & DFS_O_CREAT)
Expand Down Expand Up @@ -186,9 +187,16 @@ int dfs_device_fs_open(struct dfs_fd *file)
if (device == RT_NULL)
return -DFS_STATUS_ENODEV;

file->data = device;

return DFS_STATUS_OK;
/* to open device */
result = rt_device_open(device, RT_DEVICE_OFLAG_RDWR);
if (result == RT_EOK || result == -RT_ENOSYS)
{
file->data = device;
return DFS_STATUS_OK;
}

/* open device failed. */
return -DFS_STATUS_EIO;
}

int dfs_device_fs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
Expand Down
2 changes: 2 additions & 0 deletions components/libc/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
72 changes: 36 additions & 36 deletions components/libc/armlibc/stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/

Expand Down Expand Up @@ -48,11 +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);
Expand All @@ -64,34 +64,34 @@ FILEHANDLE _sys_open(const char *name, int openmode)
#ifndef RT_USING_DFS
return -1;
#else
/* 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)
{
/* 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)
if (fd < 0)
return -1;
else
return fd + STDERR + 1;
Expand Down Expand Up @@ -121,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 */
Expand All @@ -138,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;
Expand All @@ -159,7 +159,7 @@ 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
Expand All @@ -170,18 +170,18 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
console_device = rt_console_get_device();
if (console_device != 0) rt_device_write(console_device, 0, buf, len);

return 0;
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;
Expand Down Expand Up @@ -270,6 +270,6 @@ int remove(const char *filename)
int system(const char *string)
{
RT_ASSERT(0);
for(;;);
for (;;);
}
#endif
4 changes: 4 additions & 0 deletions components/libc/dlib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Dlib(IAR) porting for RT-Thread.

Please define RT_USING_LIBC and compile RT-Thread with IAR compiler.

15 changes: 15 additions & 0 deletions components/libc/dlib/SConscript
Original file line number Diff line number Diff line change
@@ -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')
25 changes: 25 additions & 0 deletions components/libc/dlib/environ.c
Original file line number Diff line number Diff line change
@@ -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";

74 changes: 74 additions & 0 deletions components/libc/dlib/rmtx.c
Original file line number Diff line number Diff line change
@@ -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

43 changes: 43 additions & 0 deletions components/libc/dlib/syscall_close.c
Original file line number Diff line number Diff line change
@@ -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
}
43 changes: 43 additions & 0 deletions components/libc/dlib/syscall_lseek.c
Original file line number Diff line number Diff line change
@@ -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
}
Loading