[libc] Add IAR dlib porting
This commit is contained in:
parent
a1252f67f5
commit
918b790882
4
components/libc/dlib/README.md
Normal file
4
components/libc/dlib/README.md
Normal file
@ -0,0 +1,4 @@
|
||||
Dlib(IAR) porting for RT-Thread.
|
||||
|
||||
Please define RT_USING_LIBC and compile RT-Thread with IAR compiler.
|
||||
|
15
components/libc/dlib/SConscript
Normal file
15
components/libc/dlib/SConscript
Normal file
@ -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, LIBS = LIBS)
|
||||
|
||||
Return('group')
|
25
components/libc/dlib/environ.c
Normal file
25
components/libc/dlib/environ.c
Normal file
@ -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";
|
||||
|
73
components/libc/dlib/rmtx.c
Normal file
73
components/libc/dlib/rmtx.c
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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
|
||||
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
|
||||
|
64
components/libc/dlib/syscall_open.c
Normal file
64
components/libc/dlib/syscall_open.c
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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)
|
||||
{
|
||||
if (mode & _LLIO_CREAT)
|
||||
{
|
||||
}
|
||||
|
||||
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. */
|
||||
break;
|
||||
|
||||
case _LLIO_RDWR:
|
||||
/* The file should be opened for both reads and writes. */
|
||||
break;
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
51
components/libc/dlib/syscall_read.c
Normal file
51
components/libc/dlib/syscall_read.c
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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>
|
||||
#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 - STDERR - 1, buf, len);
|
||||
return size;
|
||||
#endif
|
||||
}
|
||||
|
59
components/libc/dlib/syscall_write.c
Normal file
59
components/libc/dlib/syscall_write.c
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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>
|
||||
#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 == STDIN) return -1;
|
||||
|
||||
#ifndef RT_USING_DFS
|
||||
return _LLIO_ERROR;
|
||||
#else
|
||||
size = write(handle - STDERR - 1, buf, len);
|
||||
return size;
|
||||
#endif
|
||||
}
|
||||
|
68
components/libc/dlib/syscalls.c
Normal file
68
components/libc/dlib/syscalls.c
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* File : syscalls.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 = "?__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;
|
||||
|
||||
return lseek(handle, offset, whence);
|
||||
}
|
||||
|
23
components/libc/dlib/syscalls.h
Normal file
23
components/libc/dlib/syscalls.h
Normal file
@ -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
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user