mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-11-16 12:34:33 +00:00
Compare commits
25 Commits
v1.2.1
...
stable-v1.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f4dc4179aa | ||
|
|
1f16147f69 | ||
|
|
8e439999e8 | ||
|
|
7e871b0ddd | ||
|
|
a00cc57487 | ||
|
|
c7ee7f9858 | ||
|
|
4d2972a85f | ||
|
|
8b8d69f66e | ||
|
|
84dcd2c313 | ||
|
|
80b66ae25e | ||
|
|
7354a9fb78 | ||
|
|
d57e880444 | ||
|
|
f6c8e39167 | ||
|
|
ea598b9ac8 | ||
|
|
8336654059 | ||
|
|
277325c39e | ||
|
|
fe2047ba11 | ||
|
|
a2e074e02b | ||
|
|
5ccf1d4452 | ||
|
|
4e96775e89 | ||
|
|
7c2c3ddc34 | ||
|
|
350b1080ea | ||
|
|
50e7ae7e87 | ||
|
|
61712bbd13 | ||
|
|
3ea936e80c |
@@ -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;
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -46,6 +46,12 @@ SECTIONS
|
||||
KEEP(*(VSymTab))
|
||||
__vsymtab_end = .;
|
||||
. = ALIGN(4);
|
||||
|
||||
. = ALIGN(4);
|
||||
__rt_init_start = .;
|
||||
KEEP(*(SORT(.rti_fn*)))
|
||||
__rt_init_end = .;
|
||||
. = ALIGN(4);
|
||||
}
|
||||
|
||||
. = ALIGN(4);
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
/* Program Entry, set to mark it as "used" and avoid gc */
|
||||
MEMORY
|
||||
{
|
||||
CODE (rx) : ORIGIN = 0x08000000, LENGTH = 512k /* 512KB flash */
|
||||
DATA (rw) : ORIGIN = 0x20000000, LENGTH = 64k /* 64K sram */
|
||||
CODE (rx) : ORIGIN = 0x08000000, LENGTH = 1024k /* 1024KB flash */
|
||||
DATA (rw) : ORIGIN = 0x20000000, LENGTH = 128k /* 128K sram */
|
||||
}
|
||||
ENTRY(Reset_Handler)
|
||||
_system_stack_size = 0x100;
|
||||
|
||||
@@ -27,5 +27,6 @@
|
||||
#include <rtthread.h>
|
||||
|
||||
int devfs_init(void);
|
||||
void rt_console_init(const char* device_name);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -85,6 +85,8 @@ struct dfs_filesystem *dfs_filesystem_lookup(const char *path)
|
||||
|
||||
prefixlen = 0;
|
||||
|
||||
RT_ASSERT(path);
|
||||
|
||||
/* lock filesystem */
|
||||
dfs_lock();
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
2
components/external/libpng/pngconf.h
vendored
2
components/external/libpng/pngconf.h
vendored
@@ -23,6 +23,8 @@
|
||||
#include <rtthread.h>
|
||||
#define PNG_MAX_MALLOC_64K
|
||||
#define PNG_NO_STDIO
|
||||
#define PNG_NO_ERROR_NUMBERS
|
||||
#define PNG_ABORT() do { rt_kprintf("libpng abort.\n"); } while (0)
|
||||
|
||||
#ifndef RT_USING_NEWLIB
|
||||
#define PNG_NO_WRITE_SUPPORTED
|
||||
|
||||
2
components/external/tjpgd1a/SConscript
vendored
2
components/external/tjpgd1a/SConscript
vendored
@@ -8,7 +8,7 @@ tjpgd.c
|
||||
|
||||
CPPPATH = [RTT_ROOT + '/components/external/tjpgd1a']
|
||||
|
||||
group = DefineGroup('tjpgd', src, depend = ['RTGUI_IMAGE_TJPGD'], CPPPATH = CPPPATH)
|
||||
group = DefineGroup('RTGUI', src, depend = ['RT_USING_RTGUI', 'RTGUI_IMAGE_TJPGD'], CPPPATH = CPPPATH)
|
||||
|
||||
Return('group')
|
||||
|
||||
|
||||
2
components/external/tjpgd1a/tjpgd.c
vendored
2
components/external/tjpgd1a/tjpgd.c
vendored
@@ -525,7 +525,7 @@ JRESULT mcu_load (
|
||||
} while (++i < 64); /* Next AC element */
|
||||
|
||||
if (JD_USE_SCALE && jd->scale == 3)
|
||||
*bp = (*tmp / 256) + 128; /* If scale ratio is 1/8, IDCT can be ommited and only DC element is used */
|
||||
*bp = (BYTE)((*tmp / 256) + 128); /* If scale ratio is 1/8, IDCT can be ommited and only DC element is used */
|
||||
else
|
||||
block_idct(tmp, bp); /* Apply IDCT and store the block to the MCU buffer */
|
||||
|
||||
|
||||
@@ -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 ++;
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -530,6 +531,12 @@ void finsh_thread_entry(void* parameter)
|
||||
ch = 0;
|
||||
shell->line_position ++;
|
||||
shell->line_curpos++;
|
||||
if (shell->line_position >= 80)
|
||||
{
|
||||
/* clear command line */
|
||||
shell->line_position = 0;
|
||||
shell->line_curpos = 0;
|
||||
}
|
||||
} /* end of device read */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -46,8 +46,11 @@ const char __stderr_name[] = "STDERR";
|
||||
*/
|
||||
FILEHANDLE _sys_open(const char *name, int openmode)
|
||||
{
|
||||
#ifdef RT_USING_DFS
|
||||
int fd;
|
||||
|
||||
int mode = O_RDONLY;
|
||||
#endif
|
||||
|
||||
/* Register standard Input Output devices. */
|
||||
if (strcmp(name, __stdin_name) == 0)
|
||||
return (STDIN);
|
||||
@@ -59,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
|
||||
@@ -91,12 +119,13 @@ int _sys_close(FILEHANDLE fh)
|
||||
*/
|
||||
int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
|
||||
{
|
||||
#ifdef RT_USING_DFS
|
||||
int size;
|
||||
|
||||
#endif
|
||||
|
||||
if (fh == STDIN)
|
||||
{
|
||||
/* TODO */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -125,8 +154,10 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
|
||||
*/
|
||||
int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
|
||||
{
|
||||
#ifdef RT_USING_DFS
|
||||
int size;
|
||||
|
||||
#endif
|
||||
|
||||
if ((fh == STDOUT) || (fh == STDERR))
|
||||
{
|
||||
#ifndef RT_USING_CONSOLE
|
||||
@@ -137,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
|
||||
}
|
||||
|
||||
@@ -191,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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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__ */
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ static void tcpip_init_done_callback(void *arg)
|
||||
netif_set_up(ethif->netif);
|
||||
}
|
||||
|
||||
#ifdef LWIP_NETIF_LINK_CALLBACK
|
||||
#if LWIP_NETIF_LINK_CALLBACK
|
||||
netif_set_link_up(ethif->netif);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
#include <rtthread.h>
|
||||
|
||||
#define NIOCTL_GADDR 0x01
|
||||
#ifndef RT_LWIP_ETH_MTU
|
||||
#define ETHERNET_MTU 1500
|
||||
#else
|
||||
#define ETHERNET_MTU RT_LWIP_ETH_MTU
|
||||
#endif
|
||||
|
||||
struct eth_device
|
||||
{
|
||||
|
||||
@@ -38,8 +38,9 @@
|
||||
#define LWIP_PLATFORM_BYTESWAP 0
|
||||
#define BYTE_ORDER LITTLE_ENDIAN
|
||||
|
||||
/* Enable SO_RCVTIMEO processing. */
|
||||
/* Enable SO_RCVTIMEO/LWIP_SO_SNDTIMEO processing. */
|
||||
#define LWIP_SO_RCVTIMEO 1
|
||||
#define LWIP_SO_SNDTIMEO 1
|
||||
|
||||
/* #define RT_LWIP_DEBUG */
|
||||
|
||||
@@ -117,6 +118,8 @@
|
||||
|
||||
/* the number of simultaneously queued TCP */
|
||||
#ifdef RT_LWIP_TCP_SEG_NUM
|
||||
#define MEMP_NUM_TCP_SEG RT_LWIP_TCP_SEG_NUM
|
||||
#else
|
||||
#define MEMP_NUM_TCP_SEG TCP_SND_QUEUELEN
|
||||
#endif
|
||||
|
||||
@@ -135,12 +138,12 @@
|
||||
/* ---------- Pbuf options ---------- */
|
||||
/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
|
||||
#ifdef RT_LWIP_PBUF_NUM
|
||||
#define PBUF_POOL_SIZE RT_LWIP_PBUF_NUM
|
||||
#define PBUF_POOL_SIZE RT_LWIP_PBUF_NUM
|
||||
#endif
|
||||
|
||||
/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */
|
||||
#ifdef RT_LWIP_PBUF_POOL_BUFSIZE
|
||||
#define PBUF_POOL_BUFSIZE RT_LWIP_PBUF_POOL_BUFSIZE
|
||||
#define PBUF_POOL_BUFSIZE RT_LWIP_PBUF_POOL_BUFSIZE
|
||||
#endif
|
||||
|
||||
/* PBUF_LINK_HLEN: the number of bytes that should be allocated for a
|
||||
@@ -176,7 +179,7 @@
|
||||
|
||||
/* TCP sender buffer space (bytes). */
|
||||
#ifdef RT_LWIP_TCP_SND_BUF
|
||||
#define TCP_SND_BUF RT_LWIP_TCP_SND_BUF
|
||||
#define TCP_SND_BUF RT_LWIP_TCP_SND_BUF
|
||||
#else
|
||||
#define TCP_SND_BUF (TCP_MSS * 2)
|
||||
#endif
|
||||
@@ -230,10 +233,15 @@
|
||||
|
||||
/* IP reassembly and segmentation.These are orthogonal even
|
||||
* if they both deal with IP fragments */
|
||||
#define IP_REASSEMBLY 0
|
||||
#ifdef RT_LWIP_REASSEMBLY_FRAG
|
||||
#define IP_REASSEMBLY 1
|
||||
#define IP_FRAG 1
|
||||
#define IP_REASS_MAX_PBUFS 10
|
||||
#define MEMP_NUM_REASSDATA 10
|
||||
#else
|
||||
#define IP_REASSEMBLY 0
|
||||
#define IP_FRAG 0
|
||||
#endif
|
||||
|
||||
/* ---------- ICMP options ---------- */
|
||||
#define ICMP_TTL 255
|
||||
@@ -307,7 +315,7 @@
|
||||
* in this file.
|
||||
*/
|
||||
#ifdef RT_LWIP_PPPOE
|
||||
#define PPPOE_SUPPORT 1
|
||||
#define PPPOE_SUPPORT 1
|
||||
#else
|
||||
#define PPPOE_SUPPORT 0
|
||||
#endif
|
||||
@@ -315,7 +323,7 @@
|
||||
#ifdef RT_LWIP_PPPOS
|
||||
#define PPPOS_SUPPORT 1
|
||||
#else
|
||||
#define PPPOS_SUPPORT 0
|
||||
#define PPPOS_SUPPORT 0
|
||||
#endif
|
||||
|
||||
#define PAP_SUPPORT 1 /* Set > 0 for PAP. */
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -42,7 +42,7 @@ static rt_device_t _traceout_device = RT_NULL;
|
||||
|
||||
/* define a default lg session. The name is empty. */
|
||||
static struct log_trace_session _def_session = {{"\0"}, LOG_TRACE_LEVEL_INFO};
|
||||
static struct log_trace_session *_the_sessions[LOG_TRACE_MAX_SESSION] = {&_def_session};
|
||||
static const struct log_trace_session *_the_sessions[LOG_TRACE_MAX_SESSION] = {&_def_session};
|
||||
/* there is a default session at least */
|
||||
static rt_uint16_t _the_sess_nr = 1;
|
||||
|
||||
@@ -83,11 +83,11 @@ rt_inline int _idname_len(log_trace_idnum_t id)
|
||||
*/
|
||||
static struct log_trace_session* _lg_lookup_session(log_trace_idnum_t num)
|
||||
{
|
||||
static struct log_trace_session *_cache = &_def_session;
|
||||
static const struct log_trace_session *_cache = &_def_session;
|
||||
rt_uint16_t first, last;
|
||||
|
||||
if (_cache->id.num == num)
|
||||
return _cache;
|
||||
return (struct log_trace_session *)_cache;
|
||||
|
||||
first = 0;
|
||||
last = _the_sess_nr;
|
||||
@@ -104,7 +104,7 @@ static struct log_trace_session* _lg_lookup_session(log_trace_idnum_t num)
|
||||
* process and we wrote the old one to _cache. But it doesn't harm
|
||||
* a lot because it will be flushed in the next time. */
|
||||
_cache = _the_sessions[i];
|
||||
return _the_sessions[i];
|
||||
return (struct log_trace_session *)_the_sessions[i];
|
||||
}
|
||||
else if (_the_sessions[i]->id.num > num)
|
||||
{
|
||||
@@ -119,7 +119,7 @@ static struct log_trace_session* _lg_lookup_session(log_trace_idnum_t num)
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
rt_err_t log_trace_register_session(struct log_trace_session *session)
|
||||
rt_err_t log_trace_register_session(const struct log_trace_session *session)
|
||||
{
|
||||
unsigned int lvl, i;
|
||||
|
||||
@@ -255,8 +255,9 @@ static rt_size_t _lg_parse_session(
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void _lg_fmtout(
|
||||
struct log_trace_session *session, const char *fmt, va_list argptr)
|
||||
void __logtrace_vfmtout(const struct log_trace_session *session,
|
||||
const char *fmt,
|
||||
va_list argptr)
|
||||
{
|
||||
/* 1 for ']' */
|
||||
static char _trace_buf[1+LOG_TRACE_BUFSZ];
|
||||
@@ -303,12 +304,12 @@ void log_trace(const char *fmt, ...)
|
||||
return;
|
||||
|
||||
va_start(args, fmt);
|
||||
_lg_fmtout(session, fmt, args);
|
||||
__logtrace_vfmtout(session, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT(log_trace, log trace);
|
||||
|
||||
void log_session(struct log_trace_session *session, const char *fmt, ...)
|
||||
void log_session(const struct log_trace_session *session, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
int level;
|
||||
@@ -321,7 +322,7 @@ void log_session(struct log_trace_session *session, const char *fmt, ...)
|
||||
return;
|
||||
|
||||
va_start(args, fmt);
|
||||
_lg_fmtout(session, fmt, args);
|
||||
__logtrace_vfmtout(session, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* File : log_trace.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2013, RT-Thread Development Team
|
||||
* COPYRIGHT (C) 2013-2014, 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
|
||||
@@ -95,7 +95,7 @@ void log_trace_init(void);
|
||||
*
|
||||
* @return RT_EOK on success. -RT_EFULL if there is no space for registration.
|
||||
*/
|
||||
rt_err_t log_trace_register_session(struct log_trace_session *session);
|
||||
rt_err_t log_trace_register_session(const struct log_trace_session *session);
|
||||
|
||||
/** find a session with name
|
||||
*
|
||||
@@ -130,7 +130,43 @@ void log_trace(const char *fmt, ...);
|
||||
* "[systick][name]log messages". The name is the name of the session. It is
|
||||
* faster than bare log_trace.
|
||||
*/
|
||||
void log_session(struct log_trace_session *session, const char *fmt, ...);
|
||||
void log_session(const struct log_trace_session *session, const char *fmt, ...);
|
||||
|
||||
extern void __logtrace_vfmtout(const struct log_trace_session *session,
|
||||
const char *fmt,
|
||||
va_list argptr);
|
||||
|
||||
rt_inline void __logtrace_fmtout(const struct log_trace_session *session,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
__logtrace_vfmtout(session, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* log with numeric level
|
||||
*
|
||||
* The prototype of this function is:
|
||||
*
|
||||
* void log_session_lvl(struct log_trace_session *session,
|
||||
* int lvl,
|
||||
* const char *fmt, ...);
|
||||
*
|
||||
* If the @session is const and @level is greater than @session->lvl, the whole
|
||||
* function will be optimized out. This is suitable for performance critical
|
||||
* places where in most cases, the log is turned off by level.
|
||||
*/
|
||||
#define log_session_lvl(session, level, fmt, ...) \
|
||||
do { \
|
||||
if ((level) > (session)->lvl) \
|
||||
{ \
|
||||
break; \
|
||||
} \
|
||||
__logtrace_fmtout(session, fmt, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
/* here comes the global part. All sessions share the some output backend. */
|
||||
|
||||
|
||||
@@ -70,18 +70,23 @@ static enum rym_code _rym_read_code(
|
||||
struct rym_ctx *ctx,
|
||||
rt_tick_t timeout)
|
||||
{
|
||||
/* consume the available sem and read the data in buffer if possible */
|
||||
while (rt_sem_trytake(&ctx->sem) == RT_EOK)
|
||||
;
|
||||
/* Fast path */
|
||||
if (rt_device_read(ctx->dev, 0, ctx->buf, 1) == 1)
|
||||
return *ctx->buf;
|
||||
/* no data yet, wait for one */
|
||||
if (rt_sem_take(&ctx->sem, timeout) != RT_EOK)
|
||||
return RYM_CODE_NONE;
|
||||
/* read one */
|
||||
if (rt_device_read(ctx->dev, 0, ctx->buf, 1) == 1)
|
||||
return *ctx->buf;
|
||||
return RYM_CODE_NONE;
|
||||
|
||||
/* Slow path */
|
||||
do {
|
||||
rt_size_t rsz;
|
||||
|
||||
/* No data yet, wait for one */
|
||||
if (rt_sem_take(&ctx->sem, timeout) != RT_EOK)
|
||||
return RYM_CODE_NONE;
|
||||
|
||||
/* Try to read one */
|
||||
rsz = rt_device_read(ctx->dev, 0, ctx->buf, 1);
|
||||
if (rsz == 1)
|
||||
return *ctx->buf;
|
||||
} while (1);
|
||||
}
|
||||
|
||||
/* the caller should at least alloc _RYM_STX_PKG_SZ buffer */
|
||||
@@ -169,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))
|
||||
@@ -192,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);
|
||||
@@ -209,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)
|
||||
@@ -218,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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 1L /**< revise version number */
|
||||
#define RT_REVISION 5L /**< revise version number */
|
||||
|
||||
/* RT-Thread version */
|
||||
#define RTTHREAD_VERSION ((RT_VERSION * 10000) + \
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
55
src/device.c
55
src/device.c
@@ -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;
|
||||
}
|
||||
|
||||
@@ -239,11 +206,6 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
|
||||
return -RT_EBUSY;
|
||||
}
|
||||
|
||||
dev->ref_count++;
|
||||
/* don't let bad things happen silently. If you are bitten by this assert,
|
||||
* please set the ref_count to a bigger type. */
|
||||
RT_ASSERT(dev->ref_count != 0);
|
||||
|
||||
/* call device open interface */
|
||||
if (dev->open != RT_NULL)
|
||||
{
|
||||
@@ -252,8 +214,15 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
|
||||
|
||||
/* set open flag */
|
||||
if (result == RT_EOK || result == -RT_ENOSYS)
|
||||
{
|
||||
dev->open_flag = oflag | RT_DEVICE_OFLAG_OPEN;
|
||||
|
||||
dev->ref_count++;
|
||||
/* don't let bad things happen silently. If you are bitten by this assert,
|
||||
* please set the ref_count to a bigger type. */
|
||||
RT_ASSERT(dev->ref_count != 0);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
RTM_EXPORT(rt_device_open);
|
||||
@@ -393,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
|
||||
|
||||
20
src/idle.c
20
src/idle.c
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
109
src/mempool.c
109
src/mempool.c
@@ -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,53 +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();
|
||||
|
||||
/* 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);
|
||||
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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 */
|
||||
|
||||
12
src/timer.c
12
src/timer.c
@@ -128,6 +128,7 @@ rt_inline void _rt_timer_remove(rt_timer_t timer)
|
||||
}
|
||||
}
|
||||
|
||||
#if RT_DEBUG_TIMER
|
||||
static int rt_timer_count_height(struct rt_timer *timer)
|
||||
{
|
||||
int i, cnt = 0;
|
||||
@@ -155,6 +156,7 @@ void rt_timer_dump(rt_list_t timer_heads[])
|
||||
}
|
||||
rt_kprintf("\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @addtogroup Clock
|
||||
@@ -298,8 +300,14 @@ rt_err_t rt_timer_start(rt_timer_t timer)
|
||||
|
||||
/* timer check */
|
||||
RT_ASSERT(timer != RT_NULL);
|
||||
if (timer->parent.flag & RT_TIMER_FLAG_ACTIVATED)
|
||||
return -RT_ERROR;
|
||||
|
||||
/* stop timer firstly */
|
||||
level = rt_hw_interrupt_disable();
|
||||
/* remove timer from list */
|
||||
_rt_timer_remove(timer);
|
||||
/* change status of timer */
|
||||
timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
|
||||
rt_hw_interrupt_enable(level);
|
||||
|
||||
RT_OBJECT_HOOK_CALL(rt_object_take_hook, (&(timer->parent)));
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user