Merge remote-tracking branch 'china/master'

This commit is contained in:
Bernard Xiong committed 2015-01-31 12:58:24 +00:00
commit 390973a755
14 files changed
+848 -13

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
Dlib(IAR) porting for RT-Thread.
Please define RT_USING_LIBC and compile RT-Thread with IAR compiler.
+15
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
*/
+2 -2
View File
@@ -162,9 +162,9 @@
#define SYS_LIGHTWEIGHT_PROT (NO_SYS==0)
#ifdef LWIP_USING_NAT
#define LWIP_NAT 1
#define IP_NAT 1
#else
#define LWIP_NAT 0
#define IP_NAT 0
#endif
/* ---------- TCP options ---------- */
+10
View File
@@ -0,0 +1,10 @@
from building import *
cwd = GetCurrentDir()
src = Glob('*.c')
CPPPATH = [cwd]
group = DefineGroup('LwIP', src, depend = ['RT_USING_LWIP', 'LWIP_USING_DHCPD'], CPPPATH = CPPPATH)
Return('group')
File diff suppressed because it is too large. Load diff
+36
View File
@@ -0,0 +1,36 @@
/*
* File : dhcp_server.h
* A simple DHCP server implementation
*
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2013-2015, Shanghai Real-Thread Technology Co., Ltd
* http://www.rt-thread.com
*
* 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
* 2013-01-30 aozima the first version
* 2013-08-08 aozima support different network segments.
* 2015-01-30 bernard release to RT-Thread RTOS.
*/
#ifndef DHCPV4_SERVER_H__
#define DHCPV4_SERVER_H__
void dhcpd_start(char* netif_name);
#endif
+20 -11
View File
@@ -103,6 +103,7 @@
#include "lwip/udp.h"
#include "lwip/mem.h"
#include "lwip/sys.h"
#include "lwip/timers.h"
#include "netif/etharp.h"
#include <limits.h>
@@ -116,9 +117,10 @@
#define LWIP_NAT_TTL_INFINITE (INT_MAX)
#define LWIP_NAT_DEFAULT_TTL_SECONDS (128)
#define LWIP_NAT_FORWARD_HEADER_SIZE_MIN (sizeof(struct eth_hdr))
#define LWIP_NAT_DEFAULT_STATE_TABLES_ICMP (2)
#define LWIP_NAT_DEFAULT_STATE_TABLES_TCP (16)
#define LWIP_NAT_DEFAULT_STATE_TABLES_UDP (16)
#define LWIP_NAT_DEFAULT_STATE_TABLES_ICMP (4)
#define LWIP_NAT_DEFAULT_STATE_TABLES_TCP (32)
#define LWIP_NAT_DEFAULT_STATE_TABLES_UDP (32)
#define LWIP_NAT_DEFAULT_TCP_SOURCE_PORT (40000)
#define LWIP_NAT_DEFAULT_UDP_SOURCE_PORT (40000)
@@ -249,12 +251,12 @@ ip_nat_init(void)
IPNAT_ENTRY_RESET(&ip_nat_udp_table[i].common);
}
/* we must lock scheduler to protect following code */
/* we must lock scheduler to protect following code */
rt_enter_critical();
/* add a lwip timer for NAT */
sys_timeout(LWIP_NAT_TMR_INTERVAL_SEC, nat_timer, NULL);
/* un-protect */
rt_exit_critical();
}
@@ -360,7 +362,7 @@ ip_nat_reset_state(ip_nat_conf_t *cfg)
{
int i;
/* @todo: optimize this!!!
/* @todo: optimize this!!!
why do we search for it anyway, if we have the pointer??? */
for (i = 0; i < LWIP_NAT_DEFAULT_STATE_TABLES_ICMP; i++) {
if(ip_nat_icmp_table[i].common.cfg == cfg) {
@@ -391,7 +393,7 @@ ip_nat_shallnat(const struct ip_hdr *iphdr)
ip_nat_conf_t *nat_config = ip_nat_cfg;
for (nat_config = ip_nat_cfg; nat_config != NULL; nat_config = nat_config->next) {
if (ip_addr_netcmp(&(iphdr->dest), &(nat_config->entry.dest_net),
if (ip_addr_netcmp(&(iphdr->dest), &(nat_config->entry.dest_net),
&(nat_config->entry.dest_netmask)) ||
ip_addr_netcmp(&(iphdr->src), &(nat_config->entry.source_net),
&(nat_config->entry.source_netmask))) {
@@ -434,7 +436,7 @@ ip_nat_check_header(struct pbuf *p, u16_t min_size)
* @return 1 if the packet has been consumed (it was a NAT packet),
* 0 if the packet has not been consumed (no NAT packet)
*/
u8_t
u8_t
ip_nat_input(struct pbuf *p)
{
struct ip_hdr *iphdr = (struct ip_hdr*)p->payload;
@@ -537,6 +539,7 @@ ip_nat_input(struct pbuf *p)
q = pbuf_alloc(PBUF_LINK, 0, PBUF_RAM);
if (q == NULL) {
LWIP_DEBUGF(LWIP_NAT_DEBUG, ("ip_nat_input: no pbuf for outgoing header\n"));
// rt_kprintf("ip_nat_input: no pbuf for outgoing header\n");
/* @todo: stats? */
pbuf_free(p);
p = NULL;
@@ -548,11 +551,13 @@ ip_nat_input(struct pbuf *p)
/* restore p->payload to IP header */
if (pbuf_header(p, -PBUF_LINK_HLEN)) {
LWIP_DEBUGF(LWIP_NAT_DEBUG, ("ip_nat_input: restoring header failed\n"));
// rt_kprintf("ip_nat_input: restoring header failed\n");
/* @todo: stats? */
pbuf_free(p);
p = NULL;
return 1;
}
else q = p;
}
/* if we come here, q is the pbuf to send (either points to p or to a chain) */
in_if = nat_entry.cmn->cfg->entry.in_if;
@@ -571,6 +576,7 @@ ip_nat_input(struct pbuf *p)
LWIP_DEBUGF(LWIP_NAT_DEBUG,
("ip_nat_input: failed to send rewritten packet. link layer returned %d\n",
err));
// rt_kprintf("ip_nat_input: failed to send rewritten packet. link layer returned %d\n", err);
}
/* now that q (and/or p) is sent (or not), give up the reference to it
this frees the input pbuf (p) as we have consumed it. */
@@ -735,6 +741,7 @@ ip_nat_out(struct pbuf *p)
if (err != ERR_OK) {
LWIP_DEBUGF(LWIP_NAT_DEBUG,
("ip_nat_out: failed to send rewritten packet. link layer returned %d\n", err));
// rt_kprintf("ip_nat_out: failed to send rewritten packet. link layer returned %d\n", err);
} else {
sent = 1;
}
@@ -841,6 +848,7 @@ ip_nat_udp_lookup_outgoing(ip_nat_conf_t *nat_config, const struct ip_hdr *iphdr
nat_entry.udp);
} else {
LWIP_DEBUGF(LWIP_NAT_DEBUG, ("ip_nat_udp_lookup_outgoing: no more NAT entries available\n"));
// rt_kprintf("ip_nat_udp_lookup_outgoing: no more NAT entries available\n");
}
}
}
@@ -925,6 +933,7 @@ ip_nat_tcp_lookup_outgoing(ip_nat_conf_t *nat_config, const struct ip_hdr *iphdr
nat_entry.tcp);
} else {
LWIP_DEBUGF(LWIP_NAT_DEBUG, ("ip_nat_udp_lookup_outgoing: no more NAT entries available\n"));
// rt_kprintf("ip_nat_udp_lookup_outgoing: no more NAT entries available\n");
}
}
}
@@ -1004,9 +1013,9 @@ ip_nat_dbg_dump(const char *msg, const struct ip_hdr *iphdr)
LWIP_ASSERT("NULL != msg", NULL != msg);
LWIP_ASSERT("NULL != iphdr", NULL != iphdr);
LWIP_DEBUGF(LWIP_NAT_DEBUG, ("%s: IP: (", msg));
ip_nat_dbg_dump_ip(&iphdr->src);
ip_nat_dbg_dump_ip((ip_addr_t *)&(iphdr->src));
LWIP_DEBUGF(LWIP_NAT_DEBUG, (" --> "));
ip_nat_dbg_dump_ip(&iphdr->dest);
ip_nat_dbg_dump_ip((ip_addr_t *)&(iphdr->dest));
LWIP_DEBUGF(LWIP_NAT_DEBUG, (" id=%" U16_F ", chksum=%" U16_F ")\n",
ntohs(IPH_ID(iphdr)), ntohs(IPH_CHKSUM(iphdr))));
}