Skip to content

Commit 0f9139e

Browse files
committed
Merge pull request #422 from BernardXiong/master
Add lwIP/NAT, DHCP server and dlib(LIBC of IAR)
2 parents 588682a + ca18a17 commit 0f9139e

File tree

24 files changed

+2329
-44
lines changed

24 files changed

+2329
-44
lines changed

components/dfs/filesystems/devfs/devfs.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ int dfs_device_fs_close(struct dfs_fd *file)
131131

132132
int dfs_device_fs_open(struct dfs_fd *file)
133133
{
134+
rt_err_t result;
134135
rt_device_t device;
135136

136137
if (file->flags & DFS_O_CREAT)
@@ -186,9 +187,16 @@ int dfs_device_fs_open(struct dfs_fd *file)
186187
if (device == RT_NULL)
187188
return -DFS_STATUS_ENODEV;
188189

189-
file->data = device;
190-
191-
return DFS_STATUS_OK;
190+
/* to open device */
191+
result = rt_device_open(device, RT_DEVICE_OFLAG_RDWR);
192+
if (result == RT_EOK || result == -RT_ENOSYS)
193+
{
194+
file->data = device;
195+
return DFS_STATUS_OK;
196+
}
197+
198+
/* open device failed. */
199+
return -DFS_STATUS_EIO;
192200
}
193201

194202
int dfs_device_fs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)

components/libc/SConscript

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ if GetDepend('RT_USING_LIBC'):
1111
objs = objs + SConscript('newlib/SConscript')
1212
elif rtconfig.PLATFORM == 'armcc':
1313
objs = objs + SConscript('armlibc/SConscript')
14+
elif rtconfig.PLATFORM == 'iar':
15+
objs = objs + SConscript('dlib/SConscript')
1416
else:
1517
if rtconfig.PLATFORM == 'gcc':
1618
objs = objs + SConscript('minilibc/SConscript')

components/libc/armlibc/stubs.c

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Date Author Notes
1414
* 2012-11-23 Yihui The first version
1515
* 2013-11-24 aozima fixed _sys_read()/_sys_write() issues.
16-
* 2014-08-03 bernard If using msh, use system() implementation
16+
* 2014-08-03 bernard If using msh, use system() implementation
1717
* in msh.
1818
*/
1919

@@ -48,11 +48,11 @@ const char __stderr_name[] = "STDERR";
4848
*/
4949
FILEHANDLE _sys_open(const char *name, int openmode)
5050
{
51-
#ifdef RT_USING_DFS
51+
#ifdef RT_USING_DFS
5252
int fd;
5353
int mode = O_RDONLY;
5454
#endif
55-
55+
5656
/* Register standard Input Output devices. */
5757
if (strcmp(name, __stdin_name) == 0)
5858
return (STDIN);
@@ -64,34 +64,34 @@ FILEHANDLE _sys_open(const char *name, int openmode)
6464
#ifndef RT_USING_DFS
6565
return -1;
6666
#else
67-
/* Correct openmode from fopen to open */
68-
if (openmode & OPEN_PLUS)
69-
{
70-
if (openmode & OPEN_W)
71-
{
72-
mode |= (O_RDWR | O_TRUNC | O_CREAT);
73-
}
74-
else if (openmode & OPEN_A)
75-
{
76-
mode |= (O_RDWR | O_APPEND | O_CREAT);
77-
}
78-
else
79-
mode |= O_RDWR;
80-
}
81-
else
82-
{
83-
if (openmode & OPEN_W)
84-
{
85-
mode |= (O_WRONLY | O_TRUNC | O_CREAT);
86-
}
87-
else if (openmode & OPEN_A)
88-
{
67+
/* Correct openmode from fopen to open */
68+
if (openmode & OPEN_PLUS)
69+
{
70+
if (openmode & OPEN_W)
71+
{
72+
mode |= (O_RDWR | O_TRUNC | O_CREAT);
73+
}
74+
else if (openmode & OPEN_A)
75+
{
76+
mode |= (O_RDWR | O_APPEND | O_CREAT);
77+
}
78+
else
79+
mode |= O_RDWR;
80+
}
81+
else
82+
{
83+
if (openmode & OPEN_W)
84+
{
85+
mode |= (O_WRONLY | O_TRUNC | O_CREAT);
86+
}
87+
else if (openmode & OPEN_A)
88+
{
8989
mode |= (O_WRONLY | O_APPEND | O_CREAT);
90-
}
91-
}
90+
}
91+
}
9292

9393
fd = open(name, mode, 0);
94-
if(fd < 0)
94+
if (fd < 0)
9595
return -1;
9696
else
9797
return fd + STDERR + 1;
@@ -121,10 +121,10 @@ int _sys_close(FILEHANDLE fh)
121121
*/
122122
int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
123123
{
124-
#ifdef RT_USING_DFS
124+
#ifdef RT_USING_DFS
125125
int size;
126126
#endif
127-
127+
128128
if (fh == STDIN)
129129
{
130130
/* TODO */
@@ -138,7 +138,7 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
138138
return 0;
139139
#else
140140
size = read(fh - STDERR - 1, buf, len);
141-
if(size >= 0)
141+
if (size >= 0)
142142
return len - size;
143143
else
144144
return -1;
@@ -159,7 +159,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
159159
#ifdef RT_USING_DFS
160160
int size;
161161
#endif
162-
162+
163163
if ((fh == STDOUT) || (fh == STDERR))
164164
{
165165
#ifndef RT_USING_CONSOLE
@@ -170,18 +170,18 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
170170
console_device = rt_console_get_device();
171171
if (console_device != 0) rt_device_write(console_device, 0, buf, len);
172172

173-
return 0;
173+
return 0;
174174
#endif
175175
}
176176

177-
if(fh == STDIN)
177+
if (fh == STDIN)
178178
return -1;
179179

180180
#ifndef RT_USING_DFS
181181
return 0;
182182
#else
183183
size = write(fh - STDERR - 1, buf, len);
184-
if(size >= 0)
184+
if (size >= 0)
185185
return len - size;
186186
else
187187
return -1;
@@ -270,6 +270,6 @@ int remove(const char *filename)
270270
int system(const char *string)
271271
{
272272
RT_ASSERT(0);
273-
for(;;);
273+
for (;;);
274274
}
275275
#endif

components/libc/dlib/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Dlib(IAR) porting for RT-Thread.
2+
3+
Please define RT_USING_LIBC and compile RT-Thread with IAR compiler.
4+

components/libc/dlib/SConscript

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from building import *
2+
import rtconfig
3+
4+
src = Glob('*.c')
5+
cwd = GetCurrentDir()
6+
group = []
7+
8+
CPPPATH = [cwd]
9+
CPPDEFINES = ['RT_USING_DLIBC']
10+
11+
if rtconfig.PLATFORM == 'iar':
12+
group = DefineGroup('dlib', src, depend = ['RT_USING_LIBC'],
13+
CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
14+
15+
Return('group')

components/libc/dlib/environ.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* File: environ.c
2+
* this file is part of RT-Thread RTOS
3+
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 2 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License along
16+
* with this program; if not, write to the Free Software Foundation, Inc.,
17+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Change Logs:
20+
* Date Author Notes
21+
* 2015-01-28 Bernard first version
22+
*/
23+
24+
const char *__environ = "OS=RT-Thread";
25+

components/libc/dlib/rmtx.c

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* File : rmtx.c
3+
* This file is part of RT-Thread RTOS
4+
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License along
17+
* with this program; if not, write to the Free Software Foundation, Inc.,
18+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Change Logs:
21+
* Date Author Notes
22+
* 2015-01-28 Bernard first version
23+
*/
24+
#include <rtthread.h>
25+
#include <yfuns.h>
26+
27+
/*
28+
* for IAR compiler, we recommand to define _DLIB_THREAD_SUPPORT
29+
* as 2 for dlib multi-thread support.
30+
*/
31+
32+
#if _DLIB_THREAD_SUPPORT
33+
typedef void* _Rmtx;
34+
void _Mtxinit(_Rmtx *m)
35+
{
36+
rt_mutex_t mutex;
37+
38+
RT_ASSERT(m != RT_NULL);
39+
40+
mutex = (rt_mutex_t)m;
41+
rt_mutex_init(mutex, "iarMtx", RT_IPC_FLAG_FIFO);
42+
}
43+
44+
void _Mtxdst(_Rmtx *m)
45+
{
46+
rt_mutex_t mutex;
47+
48+
RT_ASSERT(m != RT_NULL);
49+
50+
mutex = (rt_mutex_t)m;
51+
rt_mutex_detach(mutex);
52+
}
53+
54+
void _Mtxlock(_Rmtx *m)
55+
{
56+
rt_mutex_t mutex;
57+
58+
RT_ASSERT(m != RT_NULL);
59+
60+
mutex = (rt_mutex_t)m;
61+
rt_mutex_take(mutex, RT_WAITING_FOREVER);
62+
}
63+
64+
void _Mtxunlock(_Rmtx *m)
65+
{
66+
rt_mutex_t mutex;
67+
68+
RT_ASSERT(m != RT_NULL);
69+
70+
mutex = (rt_mutex_t)m;
71+
rt_mutex_release(mutex);
72+
}
73+
#endif
74+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* File : syscall_close.c
3+
* This file is part of RT-Thread RTOS
4+
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License along
17+
* with this program; if not, write to the Free Software Foundation, Inc.,
18+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Change Logs:
21+
* Date Author Notes
22+
* 2015-01-28 Bernard first version
23+
*/
24+
#include <rtthread.h>
25+
#ifdef RT_USING_DFS
26+
#include <dfs_posix.h>
27+
#endif
28+
#include <yfuns.h>
29+
30+
#pragma module_name = "?__close"
31+
int __close(int handle)
32+
{
33+
if (handle == _LLIO_STDOUT ||
34+
handle == _LLIO_STDERR ||
35+
handle == _LLIO_STDIN)
36+
return _LLIO_ERROR;
37+
38+
#ifdef RT_USING_DFS
39+
return close(handle);
40+
#else
41+
return 0;
42+
#endif
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* File : syscall_lseek.c
3+
* This file is part of RT-Thread RTOS
4+
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License along
17+
* with this program; if not, write to the Free Software Foundation, Inc.,
18+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Change Logs:
21+
* Date Author Notes
22+
* 2015-01-28 Bernard first version
23+
*/
24+
#include <rtthread.h>
25+
#ifdef RT_USING_DFS
26+
#include <dfs_posix.h>
27+
#endif
28+
#include <yfuns.h>
29+
30+
#pragma module_name = "?__lseek"
31+
long __lseek(int handle, long offset, int whence)
32+
{
33+
if (handle == _LLIO_STDOUT ||
34+
handle == _LLIO_STDERR ||
35+
handle == _LLIO_STDIN)
36+
return _LLIO_ERROR;
37+
38+
#ifdef RT_USING_DFS
39+
return lseek(handle, offset, whence);
40+
#else
41+
return _LLIO_ERROR;
42+
#endif
43+
}

0 commit comments

Comments
 (0)