Compare commits

...

21 Commits

Author SHA1 Message Date
Bernard Xiong
f4dc4179aa Update rtdef.h 2015-10-15 23:43:19 +08:00
Bernard Xiong
1f16147f69 Merge the patch to fix fd issue; lwIP protect issue 2015-10-09 09:34:32 +08:00
bernard
8e439999e8 Prepare for RT-Thread 1.2.4 release. 2015-01-19 13:21:09 +08:00
bernard
7e871b0ddd [LIBC] fix the open mode when using fopen in arm libc. 2014-11-03 22:32:15 +08:00
bernard
a00cc57487 Prepare RT-Thread 1.2.3 release. 2014-11-01 21:52:26 +08:00
Bernard Xiong
c7ee7f9858 Merge pull request #352 from grissiom/fix-tools-srcremove-st
tools: fix SrcRemove on empty src
2014-10-08 22:10:25 +08:00
Grissiom
4d2972a85f tools: fix SrcRemove on empty src
If the src is empty list, it will crash at:

    IndexError: list index out of range:
      File "/home/xxx/src/SConstruct", line 39:
        objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=True)
      ...
      File "/home/xxx/src/drivers/SConscript", line 12:
        SrcRemove(src, src_need_remove)
      File "/home/rt-thread-stable/tools/building.py", line 496:
        if type(src[0]) == type('str'):

Commit d33df46f19 in master.
2014-10-08 18:04:08 +08:00
Bernard Xiong
8b8d69f66e Merge pull request #350 from grissiom/fix-tools-stable
tools: preserve the order of CPPPATH/CPPDEFINES/LIBPATH/LIBS
2014-10-08 13:31:59 +08:00
Grissiom
84dcd2c313 tools: preserve the order of CPPPATH/CPPDEFINES/LIBPATH/LIBS
The order of them are important while the uniqueness has nothing to do
with the compiling.

commit 2c5eea4c21 in upstream.
2014-10-08 12:22:58 +08:00
Bernard Xiong
80b66ae25e Merge pull request #317 from grissiom/fix-mempool-st
[stable] kernel: mempool: fix race condition in rt_mp_alloc
2014-08-20 10:34:37 +08:00
Grissiom
7354a9fb78 kernel: mempool: fix race condition in rt_mp_alloc
When thread wake up from waiting for memory, there is a chance that
there is no memory available in high pressure. So use a loop to check
again. Otherwise, there will be a NULL reference.

Commit b8bf6bef76 from master.
2014-08-20 10:26:06 +08:00
Bernard Xiong
d57e880444 Update rtconfig.h 2014-08-01 16:14:29 +08:00
Bernard Xiong
f6c8e39167 Merge pull request #309 from BernardXiong/stable-v1.2.x
prepare RT-Thread 1.2.2 release
2014-08-01 13:38:38 +08:00
bernard
ea598b9ac8 [DFS] fix copy command issue. 2014-08-01 13:25:58 +08:00
bernard
8336654059 [newlib] Remove compiling warning. 2014-08-01 13:25:37 +08:00
bernard
277325c39e [pthreads] fix pthread_cond_init issue when attr is NULL. 2014-08-01 13:25:15 +08:00
bernard
fe2047ba11 [Kernel] fix spell wrong in comments. 2014-08-01 13:24:48 +08:00
bernard
a2e074e02b [building] fix command too long issue under win32. 2014-08-01 13:24:20 +08:00
bernard
5ccf1d4452 [libcpu] fix spell wrong. 2014-08-01 13:23:53 +08:00
bernard
4e96775e89 [bsp] Fix serial 3 issue in beaglebone. 2014-07-24 08:32:35 +08:00
bernard
7c2c3ddc34 [BSP] fix UART3 issue in STM32F40x. 2014-07-20 16:53:49 +08:00
47 changed files with 395 additions and 304 deletions

View File

@@ -426,7 +426,7 @@ int rt_hw_serial_init(void)
config.stop_bits = STOP_BITS_1;
config.invert = NRZ_NORMAL;
serial3.ops = &am33xx_uart_ops;
serial3.int_rx = &uart_3_int_rx;
serial3.int_rx = &uart3_int_rx;
serial3.config = config;
/* enable RX interrupt */
UART_IER_REG(uart3.base) = 0x01;
@@ -470,7 +470,7 @@ int rt_hw_serial_init(void)
config.parity = PARITY_NONE;
config.stop_bits = STOP_BITS_1;
config.invert = NRZ_NORMAL;
serial5.ops = &am33xx_uart_ops;
serial5.int_rx = &uart5_int_rx;
serial5.config = config;

View File

@@ -397,7 +397,19 @@ static rt_size_t rt_sdcard_write (rt_device_t dev, rt_off_t pos, const void* buf
static rt_err_t rt_sdcard_control(rt_device_t dev, rt_uint8_t cmd, void *args)
{
return RT_EOK;
if (cmd == RT_DEVICE_CTRL_BLK_GETGEOME)
{
struct rt_device_blk_geometry *geometry;
geometry = (struct rt_device_blk_geometry *)args;
if (geometry == RT_NULL) return -RT_ERROR;
geometry->bytes_per_sector = SDCfg.sectorsize;
geometry->block_size = SDCfg.blocksize;
geometry->sector_count = SDCfg.sectorcnt;
}
return RT_EOK;
}
void rt_hw_sdcard_init()

View File

@@ -151,8 +151,6 @@
// #define RT_LWIP_SNMP
// <bool name="RT_LWIP_DHCP" description="Enable DHCP client to get IP address" default="false" />
// #define RT_LWIP_DHCP
// <integer name="RT_LWIP_TCP_SEG_NUM" description="the number of simultaneously queued TCP" default="4" />
#define RT_LWIP_TCP_SEG_NUM 4
// <integer name="RT_LWIP_TCPTHREAD_PRIORITY" description="the thread priority of TCP thread" default="128" />
#define RT_LWIP_TCPTHREAD_PRIORITY 12
// <integer name="RT_LWIP_TCPTHREAD_MBOX_SIZE" description="the mail box size of TCP thread to wait for" default="32" />

View File

@@ -102,18 +102,18 @@ __cs3_interrupt_vector_cortex_m:
.long DMA_IRQHandler /* 42: General Purpose DMA */
.long I2S_IRQHandler /* 43: I2S */
.long ENET_IRQHandler /* 44: Ethernet */
.long MCI_IRQHandler /* 45: SD/MMC Card */
.long MCI_IRQHandler /* 45: SD/MMC Card */
.long MCPWM_IRQHandler /* 46: Motor Control PWM */
.long QEI_IRQHandler /* 47: Quadrature Encoder Interface */
.long PLL1_IRQHandler /* 48: PLL1 Lock (USB PLL) */
.long USBActivity_IRQHandler /* 49: USB Activity */
.long CANActivity_IRQHandler /* 50: CAN Activity */
.long UART4_IRQHandler /* 51: UART4 */
.long SSP2_IRQHandler /* 52: SSP2 */
.long LCD_IRQHandler /* 53: LCD */
.long GPIO_IRQHandler /* 54: GPIO */
.long PWM0_IRQHandler /* 55: PWM0 */
.long EEPROM_IRQHandler /* 56: EEPROM */
.long USBActivity_IRQHandler /* 49: USB Activity */
.long CANActivity_IRQHandler /* 50: CAN Activity */
.long UART4_IRQHandler /* 51: UART4 */
.long SSP2_IRQHandler /* 52: SSP2 */
.long LCD_IRQHandler /* 53: LCD */
.long GPIO_IRQHandler /* 54: GPIO */
.long PWM0_IRQHandler /* 55: PWM0 */
.long EEPROM_IRQHandler /* 56: EEPROM */
.size __cs3_interrupt_vector_cortex_m, . - __cs3_interrupt_vector_cortex_m
@@ -130,22 +130,24 @@ CRP_Value:
.section .cs3.reset,"x",%progbits
.thumb_func
.globl __cs3_reset_cortex_m
.globl Reset_Handler
.type __cs3_reset_cortex_m, %function
__cs3_reset_cortex_m:
Reset_Handler:
.fnstart
.ifdef RAM_MODE
/* Clear .bss section (Zero init) */
MOV R0, #0
LDR R1, =__bss_start__
LDR R2, =__bss_end__
CMP R1,R2
BEQ BSSIsEmpty
MOV R0, #0
LDR R1, =__bss_start__
LDR R2, =__bss_end__
CMP R1,R2
BEQ BSSIsEmpty
LoopZI:
CMP R1, R2
BHS BSSIsEmpty
STR R0, [R1]
ADD R1, #4
BLO LoopZI
CMP R1, R2
BHS BSSIsEmpty
STR R0, [R1]
ADD R1, #4
BLO LoopZI
BSSIsEmpty:
LDR R0, =SystemInit
BLX R0
@@ -154,7 +156,7 @@ BSSIsEmpty:
.else
LDR R0, =SystemInit
BLX R0
LDR R0,=_start
LDR R0,=main
BX R0
.endif
.pool

View File

@@ -165,8 +165,8 @@ static void GPIO_Configuration(void)
GPIO_Init(UART3_GPIO, &GPIO_InitStructure);
/* Connect alternate function */
GPIO_PinAFConfig(UART2_GPIO, UART3_TX_PIN_SOURCE, GPIO_AF_USART3);
GPIO_PinAFConfig(UART2_GPIO, UART3_RX_PIN_SOURCE, GPIO_AF_USART3);
GPIO_PinAFConfig(UART3_GPIO, UART3_TX_PIN_SOURCE, GPIO_AF_USART3);
GPIO_PinAFConfig(UART3_GPIO, UART3_RX_PIN_SOURCE, GPIO_AF_USART3);
#endif
}

View File

@@ -27,5 +27,6 @@
#include <rtthread.h>
int devfs_init(void);
void rt_console_init(const char* device_name);
#endif

View File

@@ -750,11 +750,12 @@ int nfs_open(struct dfs_fd *file)
if (file->flags & DFS_O_CREAT)
{
if (nfs_mkdir(nfs, file->path, 0755) < 0)
return -1;
return -DFS_STATUS_EAGAIN;
}
/* open directory */
dir = nfs_opendir(nfs, file->path);
if (dir == RT_NULL) return -DFS_STATUS_ENOENT;
file->data = dir;
}
else
@@ -766,20 +767,20 @@ int nfs_open(struct dfs_fd *file)
if (file->flags & DFS_O_CREAT)
{
if (nfs_create(nfs, file->path, 0664) < 0)
return -1;
return -DFS_STATUS_EAGAIN;
}
/* open file (get file handle ) */
fp = rt_malloc(sizeof(nfs_file));
if (fp == RT_NULL)
return -1;
return -DFS_STATUS_ENOMEM;
handle = get_handle(nfs, file->path);
if (handle == RT_NULL)
{
rt_free(fp);
return -1;
return -DFS_STATUS_ENOENT;
}
/* get size of file */
@@ -798,7 +799,7 @@ int nfs_open(struct dfs_fd *file)
/* set private file */
file->data = fp;
file->size = fp->size;
file->size = fp->size;
}
return 0;

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;
}
@@ -165,7 +166,7 @@ int dfs_file_ioctl(struct dfs_fd *fd, int cmd, void *args)
return -DFS_STATUS_EINVAL;
fs = fd->fs;
if (fs->ops->ioctl != RT_NULL)
if (fs->ops->ioctl != RT_NULL)
return fs->ops->ioctl(fd, cmd, args);
return -DFS_STATUS_ENOSYS;
@@ -335,6 +336,9 @@ int dfs_file_lseek(struct dfs_fd *fd, rt_off_t offset)
if (fd == RT_NULL)
return -DFS_STATUS_EINVAL;
fs = fd->fs;
if (fs == RT_NULL)
return -DFS_STATUS_EINVAL;
if (fs->ops->lseek == RT_NULL)
return -DFS_STATUS_ENOSYS;
@@ -555,7 +559,7 @@ void ls(const char *pathname)
if (pathname == RT_NULL)
rt_free(path);
}
FINSH_FUNCTION_EXPORT(ls, list directory contents)
FINSH_FUNCTION_EXPORT(ls, list directory contents);
void rm(const char *filename)
{
@@ -564,7 +568,7 @@ void rm(const char *filename)
rt_kprintf("Delete %s failed\n", filename);
}
}
FINSH_FUNCTION_EXPORT(rm, remove files or directories)
FINSH_FUNCTION_EXPORT(rm, remove files or directories);
void cat(const char* filename)
{
@@ -590,7 +594,7 @@ void cat(const char* filename)
dfs_file_close(&fd);
}
FINSH_FUNCTION_EXPORT(cat, print file)
FINSH_FUNCTION_EXPORT(cat, print file);
#define BUF_SZ 4096
static void copyfile(const char *src, const char *dst)
@@ -629,7 +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)
{
dfs_file_write(&fd, block_ptr, read_bytes);
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;
}
}
} while (read_bytes > 0);
@@ -641,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

@@ -85,6 +85,8 @@ struct dfs_filesystem *dfs_filesystem_lookup(const char *path)
prefixlen = 0;
RT_ASSERT(path);
/* lock filesystem */
dfs_lock();

View File

@@ -33,11 +33,11 @@
/**
* this function is a POSIX compliant version, which will open a file and
* return a file descriptor.
* return a file descriptor according specified flags.
*
* @param file the path name of file.
* @param flags the file open flags.
* @param mode
* @param mode ignored parameter
*
* @return the non-negative integer on successful open, others for failed.
*/
@@ -120,7 +120,8 @@ RTM_EXPORT(close);
* @param buf the buffer to save the read data.
* @param len the maximal length of data buffer
*
* @return the actual read data buffer length
* @return the actual read data buffer length. If the returned value is 0, it
* may be reach the end of file, please check errno.
*/
int read(int fd, void *buf, size_t len)
{
@@ -200,7 +201,7 @@ RTM_EXPORT(write);
* @param offset the offset to be seeked.
* @param whence the directory of seek.
*
* @return the current file position, or -1 on failed.
* @return the current read/write position in the file, or -1 on failed.
*/
off_t lseek(int fd, off_t offset, int whence)
{
@@ -229,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;
@@ -236,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;
@@ -336,6 +339,8 @@ RTM_EXPORT(stat);
*
* @param fildes the file description
* @param buf the data buffer to save stat description.
*
* @return 0 on successful, -1 on failed.
*/
int fstat(int fildes, struct stat *buf)
{
@@ -424,6 +429,7 @@ int mkdir(const char *path, mode_t mode)
if (result < 0)
{
fd_put(d);
fd_put(d);
rt_set_errno(result);
@@ -432,6 +438,7 @@ int mkdir(const char *path, mode_t mode)
dfs_file_close(d);
fd_put(d);
fd_put(d);
return 0;
}
@@ -470,7 +477,7 @@ RTM_EXPORT(rmdir);
*
* @param name the path name to be open.
*
* @return the DIR pointer of directory, NULL on open failed.
* @return the DIR pointer of directory, NULL on open directory failed.
*/
DIR *opendir(const char *name)
{
@@ -537,12 +544,17 @@ struct dirent *readdir(DIR *d)
if (fd == RT_NULL)
{
rt_set_errno(-DFS_STATUS_EBADF);
return RT_NULL;
}
if (!d->num ||
(d->cur += ((struct dirent *)(d->buf + d->cur))->d_reclen) >= d->num)
if (d->num)
{
struct dirent* dirent_ptr;
dirent_ptr = (struct dirent*)&d->buf[d->cur];
d->cur += dirent_ptr->d_reclen;
}
if (!d->num || d->cur >= d->num)
{
/* get a new entry */
result = dfs_file_getdents(fd,

View File

@@ -451,9 +451,6 @@ static const struct rt_i2c_bus_device_ops i2c_bit_bus_ops =
rt_err_t rt_i2c_bit_add_bus(struct rt_i2c_bus_device *bus,
const char *bus_name)
{
struct rt_i2c_bit_ops *bit_ops = bus->priv;
RT_ASSERT(bit_ops != RT_NULL);
bus->ops = &i2c_bit_bus_ops;
return rt_i2c_bus_device_register(bus, bus_name);

View File

@@ -24,8 +24,6 @@
#include <rtdevice.h>
static struct rt_mutex i2c_core_lock;
rt_err_t rt_i2c_bus_device_register(struct rt_i2c_bus_device *bus,
const char *bus_name)
{
@@ -33,17 +31,12 @@ rt_err_t rt_i2c_bus_device_register(struct rt_i2c_bus_device *bus,
rt_mutex_init(&bus->lock, "i2c_bus_lock", RT_IPC_FLAG_FIFO);
rt_mutex_take(&i2c_core_lock, RT_WAITING_FOREVER);
if (bus->timeout == 0)
bus->timeout = RT_TICK_PER_SECOND;
if (bus->timeout == 0) bus->timeout = RT_TICK_PER_SECOND;
res = rt_i2c_bus_device_device_init(bus, bus_name);
i2c_dbg("I2C bus [%s] registered\n", bus_name);
rt_mutex_release(&i2c_core_lock);
return res;
}
@@ -136,6 +129,6 @@ rt_size_t rt_i2c_master_recv(struct rt_i2c_bus_device *bus,
int rt_i2c_core_init(void)
{
return rt_mutex_init(&i2c_core_lock, "i2c_core_lock", RT_IPC_FLAG_FIFO);
return 0;
}
INIT_COMPONENT_EXPORT(rt_i2c_core_init);

View File

@@ -20,18 +20,11 @@
* Change Logs:
* Date Author Notes
* 2012-04-25 weety first version
* 2014-08-03 bernard fix some compiling warning
*/
#include <rtdevice.h>
static rt_err_t i2c_bus_device_init(rt_device_t dev)
{
struct rt_i2c_bus_device *bus = (struct rt_i2c_bus_device *)dev->user_data;
RT_ASSERT(bus != RT_NULL);
return RT_EOK;
}
static rt_size_t i2c_bus_device_read(rt_device_t dev,
rt_off_t pos,
void *buffer,
@@ -122,7 +115,7 @@ rt_err_t rt_i2c_bus_device_device_init(struct rt_i2c_bus_device *bus,
/* set device type */
device->type = RT_Device_Class_I2CBUS;
/* initialize device interface */
device->init = i2c_bus_device_init;
device->init = RT_NULL;
device->open = RT_NULL;
device->close = RT_NULL;
device->read = i2c_bus_device_read;

View File

@@ -30,9 +30,15 @@
#include <rtthread.h>
#define BAUD_RATE_2400 2400
#define BAUD_RATE_4800 4800
#define BAUD_RATE_9600 9600
#define BAUD_RATE_38400 38400
#define BAUD_RATE_57600 57600
#define BAUD_RATE_115200 115200
#define BAUD_RATE_230400 230400
#define BAUD_RATE_460800 460800
#define BAUD_RATE_921600 921600
#define DATA_BITS_5 5
#define DATA_BITS_6 6

View File

@@ -25,16 +25,6 @@
#include <drivers/spi.h>
/* SPI bus device interface, compatible with RT-Thread 0.3.x/1.0.x */
static rt_err_t _spi_bus_device_init(rt_device_t dev)
{
struct rt_spi_bus *bus;
bus = (struct rt_spi_bus *)dev;
RT_ASSERT(bus != RT_NULL);
return RT_EOK;
}
static rt_size_t _spi_bus_device_read(rt_device_t dev,
rt_off_t pos,
void *buffer,
@@ -67,11 +57,7 @@ static rt_err_t _spi_bus_device_control(rt_device_t dev,
rt_uint8_t cmd,
void *args)
{
struct rt_spi_bus *bus;
bus = (struct rt_spi_bus *)dev;
RT_ASSERT(bus != RT_NULL);
/* TODO: add control command handle */
switch (cmd)
{
case 0: /* set device */
@@ -93,7 +79,7 @@ rt_err_t rt_spi_bus_device_init(struct rt_spi_bus *bus, const char *name)
/* set device type */
device->type = RT_Device_Class_SPIBUS;
/* initialize device interface */
device->init = _spi_bus_device_init;
device->init = RT_NULL;
device->open = RT_NULL;
device->close = RT_NULL;
device->read = _spi_bus_device_read;
@@ -105,16 +91,6 @@ rt_err_t rt_spi_bus_device_init(struct rt_spi_bus *bus, const char *name)
}
/* SPI Dev device interface, compatible with RT-Thread 0.3.x/1.0.x */
static rt_err_t _spidev_device_init(rt_device_t dev)
{
struct rt_spi_device *device;
device = (struct rt_spi_device *)dev;
RT_ASSERT(device != RT_NULL);
return RT_EOK;
}
static rt_size_t _spidev_device_read(rt_device_t dev,
rt_off_t pos,
void *buffer,
@@ -147,11 +123,6 @@ static rt_err_t _spidev_device_control(rt_device_t dev,
rt_uint8_t cmd,
void *args)
{
struct rt_spi_device *device;
device = (struct rt_spi_device *)dev;
RT_ASSERT(device != RT_NULL);
switch (cmd)
{
case 0: /* set device */
@@ -172,7 +143,7 @@ rt_err_t rt_spidev_device_init(struct rt_spi_device *dev, const char *name)
/* set device type */
device->type = RT_Device_Class_SPIDevice;
device->init = _spidev_device_init;
device->init = RT_NULL;
device->open = RT_NULL;
device->close = RT_NULL;
device->read = _spidev_device_read;

View File

@@ -315,12 +315,15 @@ int msh_exec(char* cmd, rt_size_t length)
return 0;
}
#endif
#ifdef DFS_USING_WORKDIR
#if defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR)
/* change to this directory */
if (chdir(cmd) == 0)
{
return 0;
}
#endif
/* truncate the cmd at the first space. */
{
char *tcmd;
@@ -355,10 +358,12 @@ void msh_auto_complete_path(char *path)
struct dirent *dirent = RT_NULL;
char *full_path, *ptr, *index;
if (!path)
return;
full_path = (char*)rt_malloc(256);
if (full_path == RT_NULL) return; /* out of memory */
ptr = full_path;
if (*path != '/')
{
getcwd(full_path, 256);
@@ -367,7 +372,8 @@ void msh_auto_complete_path(char *path)
}
else *full_path = '\0';
index = RT_NULL; ptr = path;
index = RT_NULL;
ptr = path;
for (;;)
{
if (*ptr == '/') index = ptr + 1; if (!*ptr) break; ptr ++;

View File

@@ -206,14 +206,20 @@ int cmd_time(int argc, char** argv)
}
FINSH_FUNCTION_EXPORT_ALIAS(cmd_time, __cmd_time, Execute command with time.);
#ifdef RT_USING_HEAP
int cmd_free(int argc, char** argv)
{
extern void list_mem(void);
#ifdef RT_USING_MEMHEAP_AS_HEAP
list_memheap();
#else
list_mem();
#endif
return 0;
}
FINSH_FUNCTION_EXPORT_ALIAS(cmd_free, __cmd_free, Show the memory usage in the system.);
#endif
#endif

View File

@@ -70,10 +70,11 @@ const char* finsh_get_prompt()
#endif
strcpy(finsh_prompt, _PROMPT);
#ifdef DFS_USING_WORKDIR
#if defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR)
/* get current working directory */
getcwd(&finsh_prompt[rt_strlen(finsh_prompt)], RT_CONSOLEBUF_SIZE - rt_strlen(finsh_prompt));
#endif
strcat(finsh_prompt, ">");
return finsh_prompt;

View File

@@ -33,7 +33,17 @@
#include <rtthread.h>
#include "finsh.h"
#define FINSH_USING_HISTORY
/* For historical reasons, users don't define FINSH_USING_HISTORY in rtconfig.h
* but expect the history feature. So you sould define FINSH_USING_HISTORY to 0
* to disable it from the rtconfig.h. */
#ifdef FINSH_USING_HISTORY
# if FINSH_USING_HISTORY == 0
# undef FINSH_USING_HISTORY
# endif
#else
# define FINSH_USING_HISTORY
#endif
#ifndef FINSH_THREAD_PRIORITY
#define FINSH_THREAD_PRIORITY 20
#endif

View File

@@ -48,6 +48,7 @@ FILEHANDLE _sys_open(const char *name, int openmode)
{
#ifdef RT_USING_DFS
int fd;
int mode = O_RDONLY;
#endif
/* Register standard Input Output devices. */
@@ -61,8 +62,33 @@ FILEHANDLE _sys_open(const char *name, int openmode)
#ifndef RT_USING_DFS
return -1;
#else
/* TODO: adjust open file mode */
fd = open(name, openmode, 0);
/* 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)
return -1;
else
@@ -142,7 +168,8 @@ 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 len;
return 0;
#endif
}
@@ -196,7 +223,10 @@ char *_sys_command_string(char *cmd, int len)
void _ttywrch(int ch)
{
/* TODO */
char c;
c = (char)ch;
rt_kprintf(&c);
}
void _sys_exit(int return_code)

View File

@@ -54,6 +54,7 @@ long int atol(const char* s)
return sign?-v:v;
}
#ifdef RT_USING_HEAP
void *malloc(size_t size)
{
return rt_malloc(size);
@@ -73,5 +74,6 @@ void *calloc(size_t nelem, size_t elsize)
{
return rt_calloc(nelem, elsize);
}
#endif
#endif

View File

@@ -9,6 +9,15 @@
#include <pthread.h>
#endif
#ifdef RT_USING_DFS
#include <dfs_posix.h>
#ifdef RT_USING_DFS_DEVFS
#include <devfs.h>
#endif
#endif
void libc_system_init(const char* tty_name)
{
#ifdef RT_USING_DFS
@@ -18,13 +27,16 @@ void libc_system_init(const char* tty_name)
#error Please enable devfs by defining RT_USING_DFS_DEVFS in rtconfig.h
#endif
/* init console device */
/* initialize console device */
rt_console_init(tty_name);
/* open console as stdin/stdout/stderr */
fd = open("/dev/console", O_RDONLY, 0); /* for stdin */
fd = open("/dev/console", O_WRONLY, 0); /* for stdout */
fd = open("/dev/console", O_WRONLY, 0); /* for stderr */
/* skip warning */
fd = fd;
#endif
/* set PATH and HOME */

View File

@@ -3,6 +3,14 @@
#include <sys/time.h>
#include <rtthread.h>
#ifdef RT_USING_DFS
#include <dfs_posix.h>
#endif
#ifdef RT_USING_PTHREADS
#include <pthread.h>
#endif
/* Reentrant versions of system calls. */
int

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

@@ -98,7 +98,11 @@ int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
rt_snprintf(cond_name, sizeof(cond_name), "cond%02d", cond_num++);
cond->attr = *attr;
if (attr == RT_NULL) /* use default value */
cond->attr = PTHREAD_PROCESS_PRIVATE;
else
cond->attr = *attr;
result = rt_sem_init(&cond->sem, cond_name, 0, RT_IPC_FLAG_FIFO);
if (result != RT_EOK)
return EINVAL;

View File

@@ -174,6 +174,18 @@ static rt_err_t _rym_trans_data(
return -RYM_ERR_SEQ;
}
/* As we are sending C continuously, there is a chance that the
* sender(remote) receive an C after sending the first handshake package.
* So the sender will interpret it as NAK and re-send the package. So we
* just ignore it and proceed. */
if (ctx->stage == RYM_STAGE_ESTABLISHED && ctx->buf[1] == 0x00)
{
*code = RYM_CODE_NONE;
return RT_EOK;
}
ctx->stage = RYM_STAGE_TRANSMITTING;
/* sanity check */
recv_crc = (rt_uint16_t)(*(ctx->buf+tsz-1) << 8) | *(ctx->buf+tsz);
if (recv_crc != CRC16(ctx->buf+3, data_sz))
@@ -197,7 +209,7 @@ static rt_err_t _rym_do_trans(struct rym_ctx *ctx)
{
rt_err_t err;
enum rym_code code;
rt_size_t data_sz;
rt_size_t data_sz, i;
code = _rym_read_code(ctx,
RYM_WAIT_PKG_TICK);
@@ -214,7 +226,6 @@ static rt_err_t _rym_do_trans(struct rym_ctx *ctx)
default:
return -RYM_ERR_CODE;
};
ctx->stage = RYM_STAGE_TRANSMITTING;
err = _rym_trans_data(ctx, data_sz, &code);
if (err != RT_EOK)
@@ -223,8 +234,9 @@ static rt_err_t _rym_do_trans(struct rym_ctx *ctx)
{
case RYM_CODE_CAN:
/* the spec require multiple CAN */
_rym_putchar(ctx, RYM_CODE_CAN);
_rym_putchar(ctx, RYM_CODE_CAN);
for (i = 0; i < RYM_END_SESSION_SEND_CAN_NUM; i++) {
_rym_putchar(ctx, RYM_CODE_CAN);
}
return -RYM_ERR_CAN;
case RYM_CODE_ACK:
_rym_putchar(ctx, RYM_CODE_ACK);

View File

@@ -52,7 +52,12 @@ enum rym_code {
#endif
/* how many ticks between two handshake code. */
#ifndef RYM_CHD_INTV_TICK
#define RYM_CHD_INTV_TICK (RT_TICK_PER_SECOND / 4)
#define RYM_CHD_INTV_TICK (RT_TICK_PER_SECOND * 3)
#endif
/* how many CAN be sent when user active end the session. */
#ifndef RYM_END_SESSION_SEND_CAN_NUM
#define RYM_END_SESSION_SEND_CAN_NUM 0x07
#endif
enum rym_stage {
@@ -61,7 +66,8 @@ enum rym_stage {
RYM_STAGE_ESTABLISHING,
/* set when we've got the packet 0 and sent ACK and second C */
RYM_STAGE_ESTABLISHED,
/* set when the sender respond to our second C */
/* set when the sender respond to our second C and recviever got a real
* data packet. */
RYM_STAGE_TRANSMITTING,
/* set when the sender send a EOT */
RYM_STAGE_FINISHING,

View File

@@ -1,7 +1,7 @@
/*
* File : rtdef.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
* 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
@@ -50,7 +50,7 @@ extern "C" {
/* RT-Thread version information */
#define RT_VERSION 1L /**< major version number */
#define RT_SUBVERSION 2L /**< minor version number */
#define RT_REVISION 2L /**< revise version number */
#define RT_REVISION 5L /**< revise version number */
/* RT-Thread version */
#define RTTHREAD_VERSION ((RT_VERSION * 10000) + \

View File

@@ -79,8 +79,8 @@ _reswitch:
STR R1, [R0]
BX LR
/* R0 --> swith from thread stack
* R1 --> swith to thread stack
/* R0 --> switch from thread stack
* R1 --> switch to thread stack
* psr, pc, LR, R12, R3, R2, R1, R0 are pushed into [from] stack
*/
.global PendSV_Handler
@@ -103,7 +103,7 @@ PendSV_Handler:
LDR R0, =rt_interrupt_from_thread
LDR R1, [R0]
CMP R1, #0x00
BEQ swtich_to_thread /* skip register save at the first time */
BEQ switch_to_thread /* skip register save at the first time */
MRS R1, PSP /* get from thread stack pointer */
@@ -118,7 +118,7 @@ PendSV_Handler:
MOV R6, R10
MOV R7, R11
STMIA R1!, {R4 - R7} /* push thread {R8 - R11} high register to thread stack */
swtich_to_thread:
switch_to_thread:
LDR R1, =rt_interrupt_to_thread
LDR R1, [R1]
LDR R1, [R1] /* load thread stack pointer */

View File

@@ -81,8 +81,8 @@ _reswitch
STR r1, [r0]
BX LR
; r0 --> swith from thread stack
; r1 --> swith to thread stack
; r0 --> switch from thread stack
; r1 --> switch to thread stack
; psr, pc, lr, r12, r3, r2, r1, r0 are pushed into [from] stack
EXPORT PendSV_Handler
PendSV_Handler:
@@ -104,7 +104,7 @@ PendSV_Handler:
LDR r0, =rt_interrupt_from_thread
LDR r1, [r0]
CMP r1, #0x00
BEQ swtich_to_thread ; skip register save at the first time
BEQ switch_to_thread ; skip register save at the first time
MRS r1, psp ; get from thread stack pointer
@@ -120,7 +120,7 @@ PendSV_Handler:
MOV r7, r11
STMIA r1!, {r4 - r7} ; push thread {r8 - r11} high register to thread stack
swtich_to_thread
switch_to_thread
LDR r1, =rt_interrupt_to_thread
LDR r1, [r1]
LDR r1, [r1] ; load thread stack pointer

View File

@@ -85,8 +85,8 @@ _reswitch
BX LR
ENDP
; r0 --> swith from thread stack
; r1 --> swith to thread stack
; r0 --> switch from thread stack
; r1 --> switch to thread stack
; psr, pc, lr, r12, r3, r2, r1, r0 are pushed into [from] stack
PendSV_Handler PROC
EXPORT PendSV_Handler
@@ -108,7 +108,7 @@ PendSV_Handler PROC
LDR r0, =rt_interrupt_from_thread
LDR r1, [r0]
CMP r1, #0x00
BEQ swtich_to_thread ; skip register save at the first time
BEQ switch_to_thread ; skip register save at the first time
MRS r1, psp ; get from thread stack pointer
@@ -124,7 +124,7 @@ PendSV_Handler PROC
MOV r7, r11
STMIA r1!, {r4 - r7} ; push thread {r8 - r11} high register to thread stack
swtich_to_thread
switch_to_thread
LDR r1, =rt_interrupt_to_thread
LDR r1, [r1]
LDR r1, [r1] ; load thread stack pointer

View File

@@ -80,8 +80,8 @@ _reswitch:
STR R1, [R0]
BX LR
/* R0 --> swith from thread stack
* R1 --> swith to thread stack
/* R0 --> switch from thread stack
* R1 --> switch to thread stack
* psr, pc, LR, R12, R3, R2, R1, R0 are pushed into [from] stack
*/
.global PendSV_Handler
@@ -102,14 +102,14 @@ PendSV_Handler:
LDR R0, =rt_interrupt_from_thread
LDR R1, [R0]
CBZ R1, swtich_to_thread /* skip register save at the first time */
CBZ R1, switch_to_thread /* skip register save at the first time */
MRS R1, PSP /* get from thread stack pointer */
STMFD R1!, {R4 - R11} /* push R4 - R11 register */
LDR R0, [R0]
STR R1, [R0] /* update from thread stack pointer */
swtich_to_thread:
switch_to_thread:
LDR R1, =rt_interrupt_to_thread
LDR R1, [R1]
LDR R1, [R1] /* load thread stack pointer */

View File

@@ -81,8 +81,8 @@ _reswitch
STR r1, [r0]
BX LR
; r0 --> swith from thread stack
; r1 --> swith to thread stack
; r0 --> switch from thread stack
; r1 --> switch to thread stack
; psr, pc, lr, r12, r3, r2, r1, r0 are pushed into [from] stack
EXPORT PendSV_Handler
PendSV_Handler:
@@ -102,14 +102,14 @@ PendSV_Handler:
LDR r0, =rt_interrupt_from_thread
LDR r1, [r0]
CBZ r1, swtich_to_thread ; skip register save at the first time
CBZ r1, switch_to_thread ; skip register save at the first time
MRS r1, psp ; get from thread stack pointer
STMFD r1!, {r4 - r11} ; push r4 - r11 register
LDR r0, [r0]
STR r1, [r0] ; update from thread stack pointer
swtich_to_thread
switch_to_thread
LDR r1, =rt_interrupt_to_thread
LDR r1, [r1]
LDR r1, [r1] ; load thread stack pointer

View File

@@ -84,8 +84,8 @@ _reswitch
BX LR
ENDP
; r0 --> swith from thread stack
; r1 --> swith to thread stack
; r0 --> switch from thread stack
; r1 --> switch to thread stack
; psr, pc, lr, r12, r3, r2, r1, r0 are pushed into [from] stack
PendSV_Handler PROC
EXPORT PendSV_Handler
@@ -105,14 +105,14 @@ PendSV_Handler PROC
LDR r0, =rt_interrupt_from_thread
LDR r1, [r0]
CBZ r1, swtich_to_thread ; skip register save at the first time
CBZ r1, switch_to_thread ; skip register save at the first time
MRS r1, psp ; get from thread stack pointer
STMFD r1!, {r4 - r11} ; push r4 - r11 register
LDR r0, [r0]
STR r1, [r0] ; update from thread stack pointer
swtich_to_thread
switch_to_thread
LDR r1, =rt_interrupt_to_thread
LDR r1, [r1]
LDR r1, [r1] ; load thread stack pointer

View File

@@ -82,8 +82,8 @@ _reswitch:
STR r1, [r0]
BX LR
/* r0 --> swith from thread stack
* r1 --> swith to thread stack
/* r0 --> switch from thread stack
* r1 --> switch to thread stack
* psr, pc, lr, r12, r3, r2, r1, r0 are pushed into [from] stack
*/
.global PendSV_Handler
@@ -104,7 +104,7 @@ PendSV_Handler:
LDR r0, =rt_interrupt_from_thread
LDR r1, [r0]
CBZ r1, swtich_to_thread /* skip register save at the first time */
CBZ r1, switch_to_thread /* skip register save at the first time */
MRS r1, psp /* get from thread stack pointer */
@@ -127,7 +127,7 @@ PendSV_Handler:
LDR r0, [r0]
STR r1, [r0] /* update from thread stack pointer */
swtich_to_thread:
switch_to_thread:
LDR r1, =rt_interrupt_to_thread
LDR r1, [r1]
LDR r1, [r1] /* load thread stack pointer */

View File

@@ -82,8 +82,8 @@ _reswitch
STR r1, [r0]
BX LR
; r0 --> swith from thread stack
; r1 --> swith to thread stack
; r0 --> switch from thread stack
; r1 --> switch to thread stack
; psr, pc, lr, r12, r3, r2, r1, r0 are pushed into [from] stack
EXPORT PendSV_Handler
PendSV_Handler:
@@ -103,7 +103,7 @@ PendSV_Handler:
LDR r0, =rt_interrupt_from_thread
LDR r1, [r0]
CBZ r1, swtich_to_thread ; skip register save at the first time
CBZ r1, switch_to_thread ; skip register save at the first time
MRS r1, psp ; get from thread stack pointer
@@ -130,7 +130,7 @@ push_flag
LDR r0, [r0]
STR r1, [r0] ; update from thread stack pointer
swtich_to_thread
switch_to_thread
LDR r1, =rt_interrupt_to_thread
LDR r1, [r1]
LDR r1, [r1] ; load thread stack pointer

View File

@@ -85,8 +85,8 @@ _reswitch
BX LR
ENDP
; r0 --> swith from thread stack
; r1 --> swith to thread stack
; r0 --> switch from thread stack
; r1 --> switch to thread stack
; psr, pc, lr, r12, r3, r2, r1, r0 are pushed into [from] stack
PendSV_Handler PROC
EXPORT PendSV_Handler
@@ -106,7 +106,7 @@ PendSV_Handler PROC
LDR r0, =rt_interrupt_from_thread
LDR r1, [r0]
CBZ r1, swtich_to_thread ; skip register save at the first time
CBZ r1, switch_to_thread ; skip register save at the first time
MRS r1, psp ; get from thread stack pointer
@@ -129,7 +129,7 @@ PendSV_Handler PROC
LDR r0, [r0]
STR r1, [r0] ; update from thread stack pointer
swtich_to_thread
switch_to_thread
LDR r1, =rt_interrupt_to_thread
LDR r1, [r1]
LDR r1, [r1] ; load thread stack pointer

View File

@@ -79,45 +79,12 @@ RTM_EXPORT(rt_device_unregister);
* This function initializes all registered device driver
*
* @return the error code, RT_EOK on successfully.
*
* @deprecated since 1.2.3, this function is not needed because the initialization
* of a device is performed when applicaiton opens it.
*/
rt_err_t rt_device_init_all(void)
{
struct rt_device *device;
struct rt_list_node *node;
struct rt_object_information *information;
register rt_err_t result;
extern struct rt_object_information rt_object_container[];
information = &rt_object_container[RT_Object_Class_Device];
/* for each device */
for (node = information->object_list.next;
node != &(information->object_list);
node = node->next)
{
rt_err_t (*init)(rt_device_t dev);
device = (struct rt_device *)rt_list_entry(node,
struct rt_object,
list);
/* get device init handler */
init = device->init;
if (init != RT_NULL && !(device->flag & RT_DEVICE_FLAG_ACTIVATED))
{
result = init(device);
if (result != RT_EOK)
{
rt_kprintf("To initialize device:%s failed. The error code is %d\n",
device->parent.name, result);
}
else
{
device->flag |= RT_DEVICE_FLAG_ACTIVATED;
}
}
}
return RT_EOK;
}
@@ -395,8 +362,8 @@ rt_err_t rt_device_control(rt_device_t dev, rt_uint8_t cmd, void *arg)
RTM_EXPORT(rt_device_control);
/**
* This function will set the indication callback function when device receives
* data.
* This function will set the reception indication callback function. This callback function
* is invoked when this device receives data.
*
* @param dev the pointer of device driver structure
* @param rx_ind the indication callback function

View File

@@ -67,6 +67,20 @@ void rt_thread_idle_sethook(void (*hook)(void))
/*@}*/
#endif
/* Return whether there is defunctional thread to be deleted. */
rt_inline int _has_defunct_thread(void)
{
/* The rt_list_isempty has prototype of "int rt_list_isempty(const rt_list_t *l)".
* So the compiler has a good reason that the rt_thread_defunct list does
* not change within rt_thread_idle_excute thus optimize the "while" loop
* into a "if".
*
* So add the volatile qualifier here. */
const volatile rt_list_t *l = (const volatile rt_list_t*)&rt_thread_defunct;
return l->next != l;
}
/**
* @ingroup Thread
*
@@ -76,7 +90,7 @@ void rt_thread_idle_excute(void)
{
/* Loop until there is no dead thread. So one call to rt_thread_idle_excute
* will do all the cleanups. */
while (!rt_list_isempty(&rt_thread_defunct))
while (_has_defunct_thread())
{
rt_base_t lock;
rt_thread_t thread;
@@ -89,7 +103,7 @@ void rt_thread_idle_excute(void)
lock = rt_hw_interrupt_disable();
/* re-check whether list is empty */
if (!rt_list_isempty(&rt_thread_defunct))
if (_has_defunct_thread())
{
/* get defunct thread */
thread = rt_list_entry(rt_thread_defunct.next,
@@ -180,7 +194,7 @@ static void rt_thread_idle_entry(void *parameter)
}
/**
* @ingroup SymstemInit
* @ingroup SystemInit
*
* This function will initialize idle thread, then start it.
*

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);
}
return old;

View File

@@ -176,10 +176,10 @@ static void plug_holes(struct heap_mem *mem)
/**
* @ingroup SystemInit
*
* This function will init system heap
* This function will initialize system heap memory.
*
* @param begin_addr the beginning address of system page
* @param end_addr the end address of system page
* @param begin_addr the beginning address of system heap memory.
* @param end_addr the end address of system heap memory.
*/
void rt_system_heap_init(void *begin_addr, void *end_addr)
{

View File

@@ -517,6 +517,8 @@ void rt_memheap_free(void *ptr)
/* check magic */
RT_ASSERT((header_ptr->magic & RT_MEMHEAP_MASK) == RT_MEMHEAP_MAGIC);
/* check whether this block of memory has been over-written. */
RT_ASSERT((header_ptr->next->magic & RT_MEMHEAP_MASK) == RT_MEMHEAP_MAGIC);
/* get pool ptr */
heap = header_ptr->pool_ptr;

View File

@@ -323,23 +323,15 @@ void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time)
rt_uint8_t *block_ptr;
register rt_base_t level;
struct rt_thread *thread;
rt_uint32_t before_sleep = 0;
/* get current thread */
thread = rt_thread_self();
/* disable interrupt */
level = rt_hw_interrupt_disable();
if (mp->block_free_count)
{
/* memory block is available. decrease the free block counter */
mp->block_free_count --;
/* get block from block list */
block_ptr = mp->block_list;
mp->block_list = *(rt_uint8_t **)block_ptr;
/* point to memory pool */
*(rt_uint8_t **)block_ptr = (rt_uint8_t *)mp;
}
else
while (mp->block_free_count == 0)
{
/* memory block is unavailable. */
if (time == 0)
@@ -347,55 +339,64 @@ void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time)
/* enable interrupt */
rt_hw_interrupt_enable(level);
rt_set_errno(-RT_ETIMEOUT);
return RT_NULL;
}
else
RT_DEBUG_NOT_IN_INTERRUPT;
thread->error = RT_EOK;
/* need suspend thread */
rt_thread_suspend(thread);
rt_list_insert_after(&(mp->suspend_thread), &(thread->tlist));
mp->suspend_thread_count++;
if (time > 0)
{
RT_DEBUG_NOT_IN_INTERRUPT;
/* get the start tick of timer */
before_sleep = rt_tick_get();
/* get current thread */
thread = rt_thread_self();
thread->error = RT_EOK;
/* need suspend thread */
rt_thread_suspend(thread);
rt_list_insert_after(&(mp->suspend_thread), &(thread->tlist));
mp->suspend_thread_count ++;
if (time > 0)
{
/* init thread timer and start it */
rt_timer_control(&(thread->thread_timer),
RT_TIMER_CTRL_SET_TIME,
&time);
rt_timer_start(&(thread->thread_timer));
}
/* enable interrupt */
rt_hw_interrupt_enable(level);
/* do a schedule */
rt_schedule();
if (thread->error != RT_EOK)
return RT_NULL;
/* disable interrupt */
level = rt_hw_interrupt_disable();
/* decrease free block */
mp->block_free_count --;
/* get block from block list */
block_ptr = mp->block_list;
mp->block_list = *(rt_uint8_t **)block_ptr;
/* point to memory pool */
*(rt_uint8_t **)block_ptr = (rt_uint8_t *)mp;
/* init thread timer and start it */
rt_timer_control(&(thread->thread_timer),
RT_TIMER_CTRL_SET_TIME,
&time);
rt_timer_start(&(thread->thread_timer));
}
/* enable interrupt */
rt_hw_interrupt_enable(level);
/* do a schedule */
rt_schedule();
if (thread->error != RT_EOK)
return RT_NULL;
if (time > 0)
{
time -= rt_tick_get() - before_sleep;
if (time < 0)
time = 0;
}
/* disable interrupt */
level = rt_hw_interrupt_disable();
}
/* memory block is available. decrease the free block counter */
mp->block_free_count--;
/* get block from block list */
block_ptr = mp->block_list;
RT_ASSERT(block_ptr != RT_NULL);
/* Setup the next free node. */
mp->block_list = *(rt_uint8_t **)block_ptr;
/* point to memory pool */
*(rt_uint8_t **)block_ptr = (rt_uint8_t *)mp;
/* enable interrupt */
rt_hw_interrupt_enable(level);

View File

@@ -82,7 +82,7 @@ static struct rt_module_symtab *_rt_module_symtab_end = RT_NULL;
*/
int rt_system_module_init(void)
{
#ifdef __GNUC__
#if defined(__GNUC__) && !defined(__CC_ARM)
extern int __rtmsymtab_start;
extern int __rtmsymtab_end;
@@ -1120,8 +1120,8 @@ rt_module_t rt_module_open(const char *path)
* This function will do a excutable program with main function and parameters.
*
* @param path the full path of application module
* @cmd_line the command line of program
* @size the size of command line of program
* @param cmd_line the command line of program
* @param size the size of command line of program
*
* @return the module object
*/

View File

@@ -239,7 +239,7 @@ typedef struct
#define SHT_DYNAMIC 6 /* dynamic section */
#define SHT_NOTE 7 /* note section */
#define SHT_NOBITS 8 /* no space section */
#define SHT_REL 9 /* relation section without addends */
#define SHT_REL 9 /* relocation section without addends */
#define SHT_SHLIB 10 /* reserved - purpose unknown */
#define SHT_DYNSYM 11 /* dynamic symbol table section */
#define SHT_NUM 12 /* number of section types */

View File

@@ -12,24 +12,41 @@ Env = None
class Win32Spawn:
def spawn(self, sh, escape, cmd, args, env):
# deal with the cmd build-in commands which cannot be used in
# subprocess.Popen
if cmd == 'del':
for f in args[1:]:
try:
os.remove(f)
except Exception as e:
print 'Error removing file: %s' % e
return -1
return 0
import subprocess
newargs = string.join(args[1:], ' ')
cmdline = cmd + " " + newargs
startupinfo = subprocess.STARTUPINFO()
proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, startupinfo=startupinfo, shell = False)
data, err = proc.communicate()
rv = proc.wait()
if data:
print data
if err:
print err
# Make sure the env is constructed by strings
_e = dict([(k, str(v)) for k, v in env.items()])
if rv:
return rv
return 0
# Windows(tm) CreateProcess does not use the env passed to it to find
# the executables. So we have to modify our own PATH to make Popen
# work.
old_path = os.environ['PATH']
os.environ['PATH'] = _e['PATH']
try:
proc = subprocess.Popen(cmdline, env=_e, shell=False)
except Exception as e:
print 'Error in calling:\n%s' % cmdline
print 'Exception: %s: %s' % (e, os.strerror(e.errno))
return e.errno
finally:
os.environ['PATH'] = old_path
return proc.wait()
def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = []):
import SCons.cpp
@@ -59,11 +76,11 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
env['LIBDIRPREFIX'] = '--userlibpath '
# patch for win32 spawn
if env['PLATFORM'] == 'win32' and rtconfig.PLATFORM == 'gcc':
if env['PLATFORM'] == 'win32':
win32_spawn = Win32Spawn()
win32_spawn.env = env
env['SPAWN'] = win32_spawn.spawn
if env['PLATFORM'] == 'win32':
os.environ['PATH'] = rtconfig.EXEC_PATH + ";" + os.environ['PATH']
else:
@@ -192,18 +209,23 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
LINKCOMSTR = 'LINK $TARGET'
)
# we need to seperate the variant_dir for BSPs and the kernels. BSPs could
# have their own components etc. If they point to the same folder, SCons
# would find the wrong source code to compile.
bsp_vdir = 'build/bsp'
kernel_vdir = 'build/kernel'
# board build script
objs = SConscript('SConscript', variant_dir='build', duplicate=0)
Repository(Rtt_Root)
objs = SConscript('SConscript', variant_dir=bsp_vdir, duplicate=0)
# include kernel
objs.extend(SConscript(Rtt_Root + '/src/SConscript', variant_dir='build/src', duplicate=0))
objs.extend(SConscript(Rtt_Root + '/src/SConscript', variant_dir=kernel_vdir + '/src', duplicate=0))
# include libcpu
if not has_libcpu:
objs.extend(SConscript(Rtt_Root + '/libcpu/SConscript', variant_dir='build/libcpu', duplicate=0))
objs.extend(SConscript(Rtt_Root + '/libcpu/SConscript',
variant_dir=kernel_vdir + '/libcpu', duplicate=0))
# include components
objs.extend(SConscript(Rtt_Root + '/components/SConscript',
variant_dir='build/components',
variant_dir=kernel_vdir + '/components',
duplicate=0,
exports='remove_components'))
@@ -415,12 +437,6 @@ def DoBuilding(target, objects):
break
else:
# merge the repeated items in the Env
if Env.has_key('CPPPATH') : Env['CPPPATH'] = list(set(Env['CPPPATH']))
if Env.has_key('CPPDEFINES'): Env['CPPDEFINES'] = list(set(Env['CPPDEFINES']))
if Env.has_key('LIBPATH') : Env['LIBPATH'] = list(set(Env['LIBPATH']))
if Env.has_key('LIBS') : Env['LIBS'] = list(set(Env['LIBS']))
program = Env.Program(target, objects)
EndBuilding(target, program)
@@ -479,6 +495,9 @@ def EndBuilding(target, program = None):
CscopeDatabase(Projects)
def SrcRemove(src, remove):
if not src:
return
if type(src[0]) == type('str'):
for item in src:
if os.path.basename(item) in remove:

View File

@@ -107,6 +107,7 @@ def MDK4Project(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)
@@ -142,33 +143,20 @@ def MDK4Project(target, script):
if lib_path != '':
MDK4AddGroupForFN(ProjectFiles, groups, group['name'], lib_path, project_path)
# remove repeat path
paths = set()
for path in CPPPATH:
inc = _make_path_relative(project_path, os.path.normpath(path))
paths.add(inc) #.replace('\\', '/')
paths = [i for i in paths]
paths.sort()
CPPPATH = string.join(paths, ';')
definitions = [i for i in set(CPPDEFINES)]
CPPDEFINES = string.join(definitions, ', ')
# write include path, definitions and link flags
IncludePath = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/IncludePath')
IncludePath.text = CPPPATH
IncludePath.text = ';'.join([_make_path_relative(project_path, os.path.normpath(i)) for i in CPPPATH])
Define = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/Define')
Define.text = CPPDEFINES
Define.text = ', '.join(set(CPPDEFINES))
Misc = tree.find('Targets/Target/TargetOption/TargetArmAds/LDads/Misc')
Misc.text = LINKFLAGS
xml_indent(root)
out.write(etree.tostring(root, encoding='utf-8'))
out.close()
# copy uvopt file
if os.path.exists('template.uvopt'):
import shutil