Merge patch from master to prepare release v2.0.2

This commit is contained in:
Bernard Xiong 2015-10-09 09:26:17 +08:00
parent 8483352591
commit 1bebbecd22
23 changed files with 214 additions and 50 deletions

View File

@ -1,3 +1,27 @@
/*
* File : crt.cpp
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2008-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-03-07 Bernard Add copyright header.
*/
#include <rtthread.h>
#include "crt.h"

View File

@ -1,3 +1,27 @@
/*
* File : crt.h
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2008-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-03-07 Bernard Add copyright header.
*/
#ifndef CRT_H_
#define CRT_H_

View File

@ -1,7 +1,7 @@
/*
* File : crt_init.c
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2008-2011, RT-Thread Development Team
* COPYRIGHT (C) 2008-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

View File

@ -21,6 +21,7 @@
* Date Author Notes
* 2005-02-22 Bernard The first version.
* 2011-12-08 Bernard Merges rename patch from iamcacy.
* 2015-05-27 Bernard Fix the fd clear issue.
*/
#include <dfs.h>
@ -97,7 +98,7 @@ int dfs_file_open(struct dfs_fd *fd, const char *path, int flags)
{
/* clear fd */
rt_free(fd->path);
rt_memset(fd, 0, sizeof(*fd));
fd->path = RT_NULL;
return -DFS_STATUS_ENOSYS;
}
@ -106,7 +107,7 @@ int dfs_file_open(struct dfs_fd *fd, const char *path, int flags)
{
/* clear fd */
rt_free(fd->path);
rt_memset(fd, 0, sizeof(*fd));
fd->path = RT_NULL;
dfs_log(DFS_DEBUG_INFO, ("open failed"));
@ -143,7 +144,7 @@ int dfs_file_close(struct dfs_fd *fd)
return result;
rt_free(fd->path);
rt_memset(fd, 0, sizeof(struct dfs_fd));
fd->path = RT_NULL;
return result;
}
@ -632,15 +633,15 @@ static void copyfile(const char *src, const char *dst)
read_bytes = dfs_file_read(&src_fd, block_ptr, BUF_SZ);
if (read_bytes > 0)
{
int length;
int length;
length = dfs_file_write(&fd, block_ptr, read_bytes);
if (length != read_bytes)
{
/* write failed. */
rt_kprintf("Write file data failed, errno=%d\n", length);
break;
}
if (length != read_bytes)
{
/* write failed. */
rt_kprintf("Write file data failed, errno=%d\n", length);
break;
}
}
} while (read_bytes > 0);
@ -652,7 +653,6 @@ static void copyfile(const char *src, const char *dst)
extern int mkdir(const char *path, mode_t mode);
static void copydir(const char * src, const char * dst)
{
struct dfs_fd fd;
struct dirent dirent;
struct stat stat;
int length;

View File

@ -230,6 +230,7 @@ off_t lseek(int fd, off_t offset, int whence)
break;
default:
fd_put(d);
rt_set_errno(-DFS_STATUS_EINVAL);
return -1;
@ -237,6 +238,7 @@ off_t lseek(int fd, off_t offset, int whence)
if (offset < 0)
{
fd_put(d);
rt_set_errno(-DFS_STATUS_EINVAL);
return -1;
@ -374,6 +376,36 @@ int fstat(int fildes, struct stat *buf)
}
RTM_EXPORT(fstat);
/**
* this function is a POSIX compliant version, which shall request that all data
* for the open file descriptor named by fildes is to be transferred to the storage
* device associated with the file described by fildes.
*
* @param fildes the file description
*
* @return 0 on successful completion. Otherwise, -1 shall be returned and errno
* set to indicate the error.
*/
int fsync(int fildes)
{
int ret;
struct dfs_fd *d;
/* get the fd */
d = fd_get(fildes);
if (d == RT_NULL)
{
rt_set_errno(-DFS_STATUS_EBADF);
return -1;
}
ret = dfs_file_flush(d);
fd_put(d);
return ret;
}
RTM_EXPORT(fsync);
/**
* this function is a POSIX compliant version, which will return the
* information about a mounted file system.
@ -427,6 +459,7 @@ int mkdir(const char *path, mode_t mode)
if (result < 0)
{
fd_put(d);
fd_put(d);
rt_set_errno(result);
@ -435,6 +468,7 @@ int mkdir(const char *path, mode_t mode)
dfs_file_close(d);
fd_put(d);
fd_put(d);
return 0;
}

View File

@ -279,7 +279,7 @@ static rt_err_t rt_serial_open(struct rt_device *dev, rt_uint16_t oflag)
serial->config.bufsz);
RT_ASSERT(rx_fifo != RT_NULL);
rx_fifo->buffer = (rt_uint8_t*) (rx_fifo + 1);
rt_memset(rx_fifo->buffer, 0, RT_SERIAL_RB_BUFSZ);
rt_memset(rx_fifo->buffer, 0, serial->config.bufsz);
rx_fifo->put_index = 0;
rx_fifo->get_index = 0;
@ -302,6 +302,7 @@ static rt_err_t rt_serial_open(struct rt_device *dev, rt_uint16_t oflag)
tx_dma = (struct rt_serial_tx_dma*) rt_malloc (sizeof(struct rt_serial_tx_dma));
RT_ASSERT(tx_dma != RT_NULL);
tx_dma->activated = RT_FALSE;
rt_data_queue_init(&(tx_dma->data_queue), 8, 4, RT_NULL);
serial->serial_tx = tx_dma;
@ -519,12 +520,10 @@ void rt_hw_serial_isr(struct rt_serial_device *serial, int event)
rt_base_t level;
struct rt_serial_rx_fifo* rx_fifo;
/* interrupt mode receive */
rx_fifo = (struct rt_serial_rx_fifo*)serial->serial_rx;
RT_ASSERT(rx_fifo != RT_NULL);
/* interrupt mode receive */
RT_ASSERT(serial->parent.open_flag & RT_DEVICE_FLAG_INT_RX);
while (1)
{
ch = serial->ops->getc(serial);

View File

@ -39,6 +39,7 @@ void rt_completion_init(struct rt_completion *completion)
rt_list_init(&completion->suspended_list);
rt_hw_interrupt_enable(level);
}
RTM_EXPORT(rt_completion_init);
rt_err_t rt_completion_wait(struct rt_completion *completion,
rt_int32_t timeout)
@ -105,6 +106,7 @@ __exit:
return result;
}
RTM_EXPORT(rt_completion_wait);
void rt_completion_done(struct rt_completion *completion)
{
@ -139,3 +141,5 @@ void rt_completion_done(struct rt_completion *completion)
rt_hw_interrupt_enable(level);
}
}
RTM_EXPORT(rt_completion_done);

View File

@ -253,6 +253,7 @@ int system(const char *command)
{
return msh_exec_module(command, rt_strlen(command));
}
RTM_EXPORT(system);
#endif
static int _msh_exec_cmd(char* cmd, rt_size_t length, int *retp)

View File

@ -123,6 +123,10 @@ void finsh_set_device(const char *device_name)
rt_device_set_rx_indicate(shell->device, RT_NULL);
}
/* clear line buffer before switch to new device */
memset(shell->line, 0, sizeof(shell->line));
shell->line_curpos = shell->line_position = 0;
shell->device = dev;
rt_device_set_rx_indicate(dev, finsh_rx_ind);
}

View File

@ -50,7 +50,9 @@
#ifndef FINSH_THREAD_STACK_SIZE
#define FINSH_THREAD_STACK_SIZE 2048
#endif
#ifndef FINSH_CMD_SIZE
#define FINSH_CMD_SIZE 80
#endif
#define FINSH_OPTION_ECHO 0x01
#if defined(FINSH_USING_MSH) || (defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR))

View File

@ -103,5 +103,9 @@ void sys_arch_assert(const char* file, int line);
#include "string.h"
#define SYS_ARCH_DECL_PROTECT(level)
#define SYS_ARCH_PROTECT(level) rt_enter_critical()
#define SYS_ARCH_UNPROTECT(level) rt_exit_critical()
#endif /* __ARCH_CC_H__ */

View File

@ -695,3 +695,17 @@ RTM_EXPORT(dhcp_stop);
#include <lwip/netifapi.h>
RTM_EXPORT(netifapi_netif_set_addr);
#endif
#if LWIP_NETIF_LINK_CALLBACK
RTM_EXPORT(netif_set_link_callback);
#endif
#if LWIP_NETIF_STATUS_CALLBACK
RTM_EXPORT(netif_set_status_callback);
#endif
RTM_EXPORT(netif_find);
RTM_EXPORT(netif_set_addr);
RTM_EXPORT(netif_set_ipaddr);
RTM_EXPORT(netif_set_gw);
RTM_EXPORT(netif_set_netmask);

View File

@ -67,6 +67,12 @@
#define netifapi_netif_set_link_up(n) netifapi_netif_common(n, netif_set_link_up, NULL)
#define netifapi_netif_set_link_down(n) netifapi_netif_common(n, netif_set_link_down, NULL)
#ifndef RT_LWIP_ETHTHREAD_PRIORITY
#define RT_ETHERNETIF_THREAD_PREORITY 0x90
#else
#define RT_ETHERNETIF_THREAD_PREORITY RT_LWIP_ETHTHREAD_PRIORITY
#endif
#ifndef LWIP_NO_TX_THREAD
/**
* Tx message structure for Ethernet interface
@ -79,7 +85,7 @@ struct eth_tx_msg
static struct rt_mailbox eth_tx_thread_mb;
static struct rt_thread eth_tx_thread;
#ifndef RT_LWIP_ETHTHREAD_PRIORITY
#ifndef RT_LWIP_ETHTHREAD_MBOX_SIZE
static char eth_tx_thread_mb_pool[32 * 4];
static char eth_tx_thread_stack[512];
#else
@ -91,12 +97,10 @@ static char eth_tx_thread_stack[RT_LWIP_ETHTHREAD_STACKSIZE];
#ifndef LWIP_NO_RX_THREAD
static struct rt_mailbox eth_rx_thread_mb;
static struct rt_thread eth_rx_thread;
#ifndef RT_LWIP_ETHTHREAD_PRIORITY
#define RT_ETHERNETIF_THREAD_PREORITY 0x90
#ifndef RT_LWIP_ETHTHREAD_MBOX_SIZE
static char eth_rx_thread_mb_pool[48 * 4];
static char eth_rx_thread_stack[1024];
#else
#define RT_ETHERNETIF_THREAD_PREORITY RT_LWIP_ETHTHREAD_PRIORITY
static char eth_rx_thread_mb_pool[RT_LWIP_ETHTHREAD_MBOX_SIZE * 4];
static char eth_rx_thread_stack[RT_LWIP_ETHTHREAD_STACKSIZE];
#endif
@ -318,7 +322,7 @@ static void eth_tx_thread_entry(void* parameter)
/* call driver's interface */
if (enetif->eth_tx(&(enetif->parent), msg->buf) != RT_EOK)
{
rt_kprintf("transmit eth packet failed\n");
/* transmit eth packet failed */
}
}
@ -397,7 +401,7 @@ int eth_system_device_init(void)
result = rt_thread_init(&eth_rx_thread, "erx", eth_rx_thread_entry, RT_NULL,
&eth_rx_thread_stack[0], sizeof(eth_rx_thread_stack),
RT_LWIP_ETHTHREAD_PRIORITY, 16);
RT_ETHERNETIF_THREAD_PREORITY, 16);
RT_ASSERT(result == RT_EOK);
result = rt_thread_startup(&eth_rx_thread);
RT_ASSERT(result == RT_EOK);

View File

@ -50,7 +50,7 @@ extern "C" {
/* RT-Thread version information */
#define RT_VERSION 2L /**< major version number */
#define RT_SUBVERSION 0L /**< minor version number */
#define RT_REVISION 1L /**< revise version number */
#define RT_REVISION 2L /**< revise version number */
/* RT-Thread version */
#define RTTHREAD_VERSION ((RT_VERSION * 10000) + \

View File

@ -183,13 +183,11 @@ rt_hw_context_switch_to PROC
LDR r0, =NVIC_INT_CTRL
LDR r1, =NVIC_PENDSVSET
STR r1, [r0]
NOP
; restore MSP
LDR r0, =SCB_VTOR
LDR r0, [r0]
LDR r0, [r0]
NOP
MSR msp, r0
; enable interrupts at processor level
@ -216,4 +214,6 @@ HardFault_Handler PROC
POP {pc}
ENDP
ALIGN 4
END

View File

@ -177,7 +177,6 @@ rt_hw_context_switch_to PROC
rt_hw_interrupt_thread_switch PROC
EXPORT rt_hw_interrupt_thread_switch
BX lr
NOP
ENDP
IMPORT rt_hw_hard_fault_exception
@ -203,4 +202,6 @@ HardFault_Handler PROC
BX lr
ENDP
ALIGN 4
END

View File

@ -205,7 +205,6 @@ rt_hw_context_switch_to PROC
LDR r0, =SCB_VTOR
LDR r0, [r0]
LDR r0, [r0]
NOP
MSR msp, r0
; enable interrupts at processor level
@ -218,7 +217,6 @@ rt_hw_context_switch_to PROC
rt_hw_interrupt_thread_switch PROC
EXPORT rt_hw_interrupt_thread_switch
BX lr
NOP
ENDP
IMPORT rt_hw_hard_fault_exception
@ -235,4 +233,6 @@ HardFault_Handler PROC
BX lr
ENDP
ALIGN 4
END

View File

@ -1072,8 +1072,8 @@ rt_device_t rt_console_set_device(const char *name)
}
/* set new console device */
rt_device_open(new, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_STREAM);
_console_device = new;
rt_device_open(_console_device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_STREAM);
}
return old;

View File

@ -304,6 +304,7 @@ void *rt_malloc(rt_size_t size)
/* create mem2 struct */
mem2 = (struct heap_mem *)&heap_ptr[ptr2];
mem2->magic = HEAP_MAGIC;
mem2->used = 0;
mem2->next = mem->next;
mem2->prev = ptr;
@ -540,7 +541,7 @@ void rt_free(void *rmem)
RT_ASSERT(mem->magic == HEAP_MAGIC);
/* ... and is now unused. */
mem->used = 0;
mem->magic = 0;
mem->magic = HEAP_MAGIC;
if (mem < lfree)
{

View File

@ -401,8 +401,8 @@ rt_bool_t rt_object_is_systemobject(rt_object_t object)
*/
rt_object_t rt_object_find(const char *name, rt_uint8_t type)
{
struct rt_object *object;
struct rt_list_node *node;
struct rt_object *object = RT_NULL;
struct rt_list_node *node = RT_NULL;
struct rt_object_information *information = RT_NULL;
/* parameter check */

View File

@ -371,6 +371,7 @@ void rt_enter_critical(void)
/* enable interrupt */
rt_hw_interrupt_enable(level);
}
RTM_EXPORT(rt_enter_critical);
/**
* This function will unlock the thread scheduler.
@ -398,6 +399,7 @@ void rt_exit_critical(void)
rt_hw_interrupt_enable(level);
}
}
RTM_EXPORT(rt_exit_critical);
/**
* Get the scheduler lock level
@ -408,5 +410,6 @@ rt_uint16_t rt_critical_level(void)
{
return rt_scheduler_lock_nest;
}
RTM_EXPORT(rt_critical_level);
/*@}*/

View File

@ -66,9 +66,21 @@ def MDK4AddGroupForFN(ProjectFiles, parent, name, filename, project_path):
file = SubElement(files, 'File')
file_name = SubElement(file, 'FileName')
name = os.path.basename(path)
if ProjectFiles.count(name):
if name.find('.cpp') != -1:
obj_name = name.replace('.cpp', '.o')
elif name.find('.c') != -1:
obj_name = name.replace('.c', '.o')
elif name.find('.s') != -1:
obj_name = name.replace('.s', '.o')
elif name.find('.S') != -1:
obj_name = name.replace('.s', '.o')
else:
obj_name = name
if ProjectFiles.count(obj_name):
name = basename + '_' + name
ProjectFiles.append(name)
ProjectFiles.append(obj_name)
file_name.text = name.decode(fs_encoding)
file_type = SubElement(file, 'FileType')
file_type.text = '%d' % _get_filetype(name)
@ -98,9 +110,19 @@ def MDK4AddGroup(ProjectFiles, parent, name, files, project_path):
file = SubElement(files, 'File')
file_name = SubElement(file, 'FileName')
name = os.path.basename(path)
if ProjectFiles.count(name):
if name.find('.cpp') != -1:
obj_name = name.replace('.cpp', '.o')
elif name.find('.c') != -1:
obj_name = name.replace('.c', '.o')
elif name.find('.s') != -1:
obj_name = name.replace('.s', '.o')
elif name.find('.S') != -1:
obj_name = name.replace('.s', '.o')
if ProjectFiles.count(obj_name):
name = basename + '_' + name
ProjectFiles.append(name)
ProjectFiles.append(obj_name)
file_name.text = name.decode(fs_encoding)
file_type = SubElement(file, 'FileType')
file_type.text = '%d' % _get_filetype(name)
@ -201,9 +223,19 @@ def MDK5AddGroupForFN(ProjectFiles, parent, name, filename, project_path):
file = SubElement(files, 'File')
file_name = SubElement(file, 'FileName')
name = os.path.basename(path)
if ProjectFiles.count(name):
if name.find('.cpp') != -1:
obj_name = name.replace('.cpp', '.o')
elif name.find('.c') != -1:
obj_name = name.replace('.c', '.o')
elif name.find('.s') != -1:
obj_name = name.replace('.s', '.o')
elif name.find('.S') != -1:
obj_name = name.replace('.s', '.o')
if ProjectFiles.count(obj_name):
name = basename + '_' + name
ProjectFiles.append(name)
ProjectFiles.append(obj_name)
file_name.text = name.decode(fs_encoding)
file_type = SubElement(file, 'FileType')
file_type.text = '%d' % _get_filetype(name)
@ -233,9 +265,21 @@ def MDK5AddGroup(ProjectFiles, parent, name, files, project_path):
file = SubElement(files, 'File')
file_name = SubElement(file, 'FileName')
name = os.path.basename(path)
if ProjectFiles.count(name):
if name.find('.cpp') != -1:
obj_name = name.replace('.cpp', '.o')
elif name.find('.c') != -1:
obj_name = name.replace('.c', '.o')
elif name.find('.s') != -1:
obj_name = name.replace('.s', '.o')
elif name.find('.S') != -1:
obj_name = name.replace('.s', '.o')
else:
obj_name = name
if ProjectFiles.count(obj_name):
name = basename + '_' + name
ProjectFiles.append(name)
ProjectFiles.append(obj_name)
file_name.text = name.decode(fs_encoding)
file_type = SubElement(file, 'FileType')
file_type.text = '%d' % _get_filetype(name)
@ -266,6 +310,7 @@ def MDK5Project(target, script):
groups = tree.find('Targets/Target/Groups')
if groups is None:
groups = SubElement(tree.find('Targets/Target'), 'Groups')
groups.clear() # clean old groups
for group in script:
group_xml = MDK4AddGroup(ProjectFiles, groups, group['name'], group['src'], project_path)

View File

@ -40,7 +40,7 @@ SConscript_com = '''# RT-Thread building script for component
from building import *
cwd = GetCurrentDir()
src = Glob('*.c')
src = Glob('*.c') + Glob('*.cpp')
CPPPATH = [cwd]
group = DefineGroup('COMPONENT_NAME', src, depend = [''], CPPPATH = CPPPATH)