diff options
| author | Bernard Xiong <[email protected]> | 2015-09-24 17:23:00 +0800 |
|---|---|---|
| committer | Bernard Xiong <[email protected]> | 2015-09-24 17:23:00 +0800 |
| commit | 9413a61499a98cd86df0e4abb39da9f681dbdd81 (patch) | |
| tree | b794148debd7b1668a8c7fbfdf67571cb608ea25 /components | |
| parent | 6a7638599ca0d23d5e40f7a36a13d8be3e47543a (diff) | |
| parent | a8dc960ba1f1bbe7758cd8db24b886d96ae2c96c (diff) | |
Merge branch 'master' of https://git.coding.net/RT-Thread/rt-thread
Diffstat (limited to 'components')
| -rw-r--r-- | components/dfs/src/dfs_posix.c | 4 | ||||
| -rw-r--r-- | components/drivers/hwtimer/README_CN.md | 98 | ||||
| -rw-r--r-- | components/drivers/hwtimer/SConscript | 8 | ||||
| -rw-r--r-- | components/drivers/hwtimer/hwtimer.c | 355 | ||||
| -rw-r--r-- | components/drivers/include/drivers/hwtimer.h | 78 | ||||
| -rw-r--r-- | components/drivers/include/drivers/spi.h | 5 | ||||
| -rw-r--r-- | components/drivers/include/rtdevice.h | 4 | ||||
| -rw-r--r-- | components/finsh/cmd.c | 1 | ||||
| -rw-r--r-- | components/finsh/finsh.h | 8 | ||||
| -rw-r--r-- | components/finsh/shell.c | 139 | ||||
| -rw-r--r-- | components/libc/newlib/syscalls.c | 5 |
11 files changed, 634 insertions, 71 deletions
diff --git a/components/dfs/src/dfs_posix.c b/components/dfs/src/dfs_posix.c index 250f6eaf7f..c379d5c969 100644 --- a/components/dfs/src/dfs_posix.c +++ b/components/dfs/src/dfs_posix.c @@ -230,6 +230,7 @@ off_t lseek(int fd, off_t offset, int whence) break; default: + fd_put(d); rt_set_errno(-DFS_STATUS_EINVAL); return -1; @@ -237,6 +238,7 @@ off_t lseek(int fd, off_t offset, int whence) if (offset < 0) { + fd_put(d); rt_set_errno(-DFS_STATUS_EINVAL); return -1; @@ -458,6 +460,7 @@ int mkdir(const char *path, mode_t mode) if (result < 0) { fd_put(d); + fd_put(d); rt_set_errno(result); return -1; @@ -465,6 +468,7 @@ int mkdir(const char *path, mode_t mode) dfs_file_close(d); fd_put(d); + fd_put(d); return 0; } diff --git a/components/drivers/hwtimer/README_CN.md b/components/drivers/hwtimer/README_CN.md new file mode 100644 index 0000000000..fb3b4fa60a --- /dev/null +++ b/components/drivers/hwtimer/README_CN.md @@ -0,0 +1,98 @@ +定时器设备 +=== + +##功能 +--- +* 时间测量 +* 周期或单次执行回调函数 + +##编译 +--- +1. 在rtconfig.h添加 `#define RT_USING_HWTIMER` + +##使用流程 +--- +1. 以读写方式打开设备 +2. 设置超时回调函数(如果需要) +3. 根据需要设置定时模式(单次/周期) +4. 设置计数频率(可选) +5. 写入超时值,定时器随即启动 +6. 停止定时器(可选) +7. 关闭设备(如果需要) + +应用参考 [hwtimer_test] (/examples/test/hwtimer\_test.c) + +##驱动编写指南 +--- +###操作接口 + +``` +struct rt_hwtimer_ops +{ + void (*init)(struct rt_hwtimer_device *timer, rt_uint32_t state); + rt_err_t (*start)(struct rt_hwtimer_device *timer, rt_uint32_t cnt, rt_hwtimer_mode_t mode); + void (*stop)(struct rt_hwtimer_device *timer); + rt_uint32_t (*count_get)(struct rt_hwtimer_device *timer); + rt_err_t (*control)(struct rt_hwtimer_device *timer, rt_uint32_t cmd, void *args); +}; +``` + +* init - state <1 打开设备 0 关闭设备> +* start - cnt <超时值> - mode <单次/周期> +* stop - <停止计数> +* count_get - <读取计数器值> +* control - <设置计数频率 > + +###定时器特征信息 + +``` +struct rt_hwtimer_info +{ + rt_int32_t maxfreq; + rt_int32_t minfreq; + rt_uint32_t maxcnt; + rt_uint8_t cntmode; + }; +``` + +* maxfreq <设备支持的最大计数频率> +* minfreq <设备支持的最小计数频率> +* maxcnt <计数器最大计数值> +* cntmode <递增计数/递减计数> + +###注册设备 +``` +static rt_hwtimer_t _timer0; +int stm32_hwtimer_init(void) +{ + _timer0.info = &_info; + _timer0.ops = &_ops; + + rt_device_hwtimer_register(&_timer0, "timer0", TIM2); + + return 0; +} +``` + +###定时器中断 +``` +void timer_irq_handler(void) +{ + //其它操作 + + rt_device_hwtimer_isr(&_timer0); +} +``` + +##注意事项 +--- + +<font color="#FF0000">可能出现定时误差</font> + + +误差原因: + +假设计数器最大值0xFFFF,计数频率1Mhz,定时时间1秒又1微秒。 + +由于定时器一次最多只能计时到65535us,对于1000001us的定时要求。 +可以50000us定时20次完成,此时将会出现计算误差1us。 diff --git a/components/drivers/hwtimer/SConscript b/components/drivers/hwtimer/SConscript new file mode 100644 index 0000000000..534e04b6c0 --- /dev/null +++ b/components/drivers/hwtimer/SConscript @@ -0,0 +1,8 @@ +from building import * + +cwd = GetCurrentDir() +src = Glob('*.c') +CPPPATH = [cwd + '/../include'] +group = DefineGroup('DeviceDrivers', src, depend = ['RT_USING_HWTIMER'], CPPPATH = CPPPATH) + +Return('group') diff --git a/components/drivers/hwtimer/hwtimer.c b/components/drivers/hwtimer/hwtimer.c new file mode 100644 index 0000000000..22b8d6262c --- /dev/null +++ b/components/drivers/hwtimer/hwtimer.c @@ -0,0 +1,355 @@ +/* + * File : hwtimer.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Change Logs: + * Date Author Notes + * 2015-08-31 heyuanjie87 first version + */ + +#include <rtthread.h> +#include <rtdevice.h> + +rt_inline rt_uint32_t timeout_calc(rt_hwtimer_t *timer, rt_hwtimerval_t *tv) +{ + float overflow; + float timeout; + rt_uint32_t counter; + int i, index; + float tv_sec; + float devi_min = 1; + float devi; + + /* �Ѷ�ʱ�����ʱ��Ͷ�ʱʱ�任����� */ + overflow = timer->info->maxcnt/(float)timer->freq; + tv_sec = tv->sec + tv->usec/(float)1000000; + + if (tv_sec < (1/(float)timer->freq)) + { + /* ��ʱʱ��С�ڼ������� */ + i = 0; + timeout = 1/(float)timer->freq; + } + else + { + for (i = 1; i > 0; i ++) + { + timeout = tv_sec/i; + + if (timeout <= overflow) + { + counter = timeout*timer->freq; + devi = tv_sec - (counter/(float)timer->freq)*i; + /* ������С��� */ + if (devi > devi_min) + { + i = index; + timeout = tv_sec/i; + break; + } + else if (devi == 0) + { + break; + } + else if (devi < devi_min) + { + devi_min = devi; + index = i; + } + } + } + } + + timer->cycles = i; + timer->reload = i; + timer->period_sec = timeout; + counter = timeout*timer->freq; + + return counter; +} + +static rt_err_t rt_hwtimer_init(struct rt_device *dev) +{ + rt_err_t result = RT_EOK; + rt_hwtimer_t *timer; + + timer = (rt_hwtimer_t *)dev; + /* ���Խ�Ĭ�ϼ���Ƶ����Ϊ1Mhz */ + if ((1000000 <= timer->info->maxfreq) && (1000000 >= timer->info->minfreq)) + { + timer->freq = 1000000; + } + else + { + timer->freq = timer->info->minfreq; + } + timer->mode = HWTIMER_MODE_ONESHOT; + timer->cycles = 0; + timer->overflow = 0; + + if (timer->ops->init) + { + timer->ops->init(timer, 1); + } + else + { + result = -RT_ENOSYS; + } + + return result; +} + +static rt_err_t rt_hwtimer_open(struct rt_device *dev, rt_uint16_t oflag) +{ + rt_err_t result = RT_EOK; + rt_hwtimer_t *timer; + + timer = (rt_hwtimer_t *)dev; + if (timer->ops->control != RT_NULL) + { + timer->ops->control(timer, HWTIMER_CTRL_FREQ_SET, &timer->freq); + } + else + { + result = -RT_ENOSYS; + } + + return result; +} + +static rt_err_t rt_hwtimer_close(struct rt_device *dev) +{ + rt_err_t result = RT_EOK; + rt_hwtimer_t *timer; + + timer = (rt_hwtimer_t*)dev; + if (timer->ops->init != RT_NULL) + { + timer->ops->init(timer, 0); + } + else + { + result = -RT_ENOSYS; + } + + dev->flag &= ~RT_DEVICE_FLAG_ACTIVATED; + dev->rx_indicate = RT_NULL; + + return result; +} + +static rt_size_t rt_hwtimer_read(struct rt_device *dev, rt_off_t pos, void *buffer, rt_size_t size) +{ + rt_hwtimer_t *timer; + rt_hwtimerval_t tv; + rt_uint32_t cnt; + float t; + + timer = (rt_hwtimer_t *)dev; + if (timer->ops->count_get == RT_NULL) + return 0; + + cnt = timer->ops->count_get(timer); + if (timer->info->cntmode == HWTIMER_CNTMODE_DW) + { + cnt = timer->info->maxcnt - cnt; + } + + t = timer->overflow * timer->period_sec + cnt/(float)timer->freq; + tv.sec = t; + tv.usec = (t - tv.sec) * 1000000; + size = size > sizeof(tv)? sizeof(tv) : size; + rt_memcpy(buffer, &tv, size); + + return size; +} + +static rt_size_t rt_hwtimer_write(struct rt_device *dev, rt_off_t pos, const void *buffer, rt_size_t size) +{ + rt_uint32_t t; + rt_hwtimer_mode_t opm = HWTIMER_MODE_PERIOD; + rt_hwtimer_t *timer; + + timer = (rt_hwtimer_t *)dev; + if ((timer->ops->start == RT_NULL) || (timer->ops->stop == RT_NULL)) + return 0; + + if (size != sizeof(rt_hwtimerval_t)) + return 0; + + if ((timer->cycles <= 1) && (timer->mode == HWTIMER_MODE_ONESHOT)) + { + opm = HWTIMER_MODE_ONESHOT; + } + timer->ops->stop(timer); + timer->overflow = 0; + + t = timeout_calc(timer, (rt_hwtimerval_t*)buffer); + if (timer->ops->start(timer, t, opm) != RT_EOK) + size = 0; + + return size; +} + +static rt_err_t rt_hwtimer_control(struct rt_device *dev, rt_uint8_t cmd, void *args) +{ + rt_err_t result = RT_EOK; + rt_hwtimer_t *timer; + + timer = (rt_hwtimer_t *)dev; + + switch (cmd) + { + case HWTIMER_CTRL_STOP: + { + if (timer->ops->stop != RT_NULL) + { + timer->ops->stop(timer); + } + else + { + result = -RT_ENOSYS; + } + } + break; + case HWTIMER_CTRL_FREQ_SET: + { + rt_uint32_t *f; + + if (args == RT_NULL) + { + result = -RT_EEMPTY; + break; + } + + f = (rt_uint32_t*)args; + if ((*f > timer->info->maxfreq) || (*f < timer->info->minfreq)) + { + result = -RT_ERROR; + break; + } + + if (timer->ops->control != RT_NULL) + { + result = timer->ops->control(timer, cmd, args); + if (result == RT_EOK) + { + timer->freq = *f; + } + } + else + { + result = -RT_ENOSYS; + } + } + break; + case HWTIMER_CTRL_INFO_GET: + { + if (args == RT_NULL) + { + result = -RT_EEMPTY; + break; + } + + *((struct rt_hwtimer_info*)args) = *timer->info; + } + case HWTIMER_CTRL_MODE_SET: + { + rt_hwtimer_mode_t *m; + + if (args == RT_NULL) + { + result = -RT_EEMPTY; + break; + } + + m = (rt_hwtimer_mode_t*)args; + + if ((*m != HWTIMER_MODE_ONESHOT) && (*m != HWTIMER_MODE_PERIOD)) + { + result = -RT_ERROR; + break; + } + + timer->mode = *m; + } + break; + default: + { + result = -RT_ENOSYS; + } + break; + } + + return result; +} + +void rt_device_hwtimer_isr(rt_hwtimer_t *timer) +{ + RT_ASSERT(timer != RT_NULL); + + timer->overflow ++; + + if (timer->cycles != 0) + { + timer->cycles --; + } + + if (timer->cycles == 0) + { + timer->cycles = timer->reload; + + if (timer->mode == HWTIMER_MODE_ONESHOT) + { + if (timer->ops->stop != RT_NULL) + { + timer->ops->stop(timer); + } + } + + if (timer->parent.rx_indicate != RT_NULL) + { + timer->parent.rx_indicate(&timer->parent, sizeof(struct rt_hwtimerval)); + } + } +} + +rt_err_t rt_device_hwtimer_register(rt_hwtimer_t *timer, const char *name, void *user_data) +{ + struct rt_device *device; + + RT_ASSERT(timer != RT_NULL); + RT_ASSERT(timer->ops != RT_NULL); + RT_ASSERT(timer->info != RT_NULL); + + device = &(timer->parent); + + device->type = RT_Device_Class_Timer; + device->rx_indicate = RT_NULL; + device->tx_complete = RT_NULL; + + device->init = rt_hwtimer_init; + device->open = rt_hwtimer_open; + device->close = rt_hwtimer_close; + device->read = rt_hwtimer_read; + device->write = rt_hwtimer_write; + device->control = rt_hwtimer_control; + device->user_data = user_data; + + return rt_device_register(device, name, RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STANDALONE); +} diff --git a/components/drivers/include/drivers/hwtimer.h b/components/drivers/include/drivers/hwtimer.h new file mode 100644 index 0000000000..24cec74d32 --- /dev/null +++ b/components/drivers/include/drivers/hwtimer.h @@ -0,0 +1,78 @@ +#ifndef __HWTIMER_H__ +#define __HWTIMER_H__ + +#include <rtthread.h> +#include <rtdevice.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* Timer Control Command */ +typedef enum +{ + HWTIMER_CTRL_FREQ_SET = 0x01, /* set the count frequency */ + HWTIMER_CTRL_STOP, /* stop timer */ + HWTIMER_CTRL_INFO_GET, /* get a timer feature information */ + HWTIMER_CTRL_MODE_SET /* Setting the timing mode(oneshot/period) */ +} rt_hwtimer_ctrl_t; + +/* Timing Mode */ +typedef enum +{ + HWTIMER_MODE_ONESHOT = 0x01, + HWTIMER_MODE_PERIOD +} rt_hwtimer_mode_t; + +/* Time Value */ +typedef struct rt_hwtimerval +{ + rt_int32_t sec; /* second */ + rt_int32_t usec; /* microsecond */ +} rt_hwtimerval_t; + +#define HWTIMER_CNTMODE_UP 0x01 /* increment count mode */ +#define HWTIMER_CNTMODE_DW 0x02 /* decreasing count mode */ + +struct rt_hwtimer_device; + +struct rt_hwtimer_ops +{ + void (*init)(struct rt_hwtimer_device *timer, rt_uint32_t state); + rt_err_t (*start)(struct rt_hwtimer_device *timer, rt_uint32_t cnt, rt_hwtimer_mode_t mode); + void (*stop)(struct rt_hwtimer_device *timer); + rt_uint32_t (*count_get)(struct rt_hwtimer_device *timer); + rt_err_t (*control)(struct rt_hwtimer_device *timer, rt_uint32_t cmd, void *args); +}; + +/* Timer Feature Information */ +struct rt_hwtimer_info +{ + rt_int32_t maxfreq; /* the maximum count frequency timer support */ + rt_int32_t minfreq; /* the minimum count frequency timer support */ + rt_uint32_t maxcnt; /* counter maximum value */ + rt_uint8_t cntmode; /* count mode (inc/dec) */ +}; + +typedef struct rt_hwtimer_device +{ + struct rt_device parent; + const struct rt_hwtimer_ops *ops; + const struct rt_hwtimer_info *info; + + rt_int32_t freq; /* counting frequency set by the user */ + rt_int32_t overflow; /* timer overflows */ + float period_sec; + rt_int32_t cycles; /* how many times will generate a timeout event after overflow */ + rt_int32_t reload; /* reload cycles(using in period mode) */ + rt_hwtimer_mode_t mode; /* timing mode(oneshot/period) */ +} rt_hwtimer_t; + +rt_err_t rt_device_hwtimer_register(rt_hwtimer_t *timer, const char *name, void *user_data); +void rt_device_hwtimer_isr(rt_hwtimer_t *timer); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/components/drivers/include/drivers/spi.h b/components/drivers/include/drivers/spi.h index cfa4b73ca3..f76b329cab 100644 --- a/components/drivers/include/drivers/spi.h +++ b/components/drivers/include/drivers/spi.h @@ -59,6 +59,11 @@ extern "C"{ #define RT_SPI_MODE_MASK (RT_SPI_CPHA | RT_SPI_CPOL | RT_SPI_MSB) +#define RT_SPI_CS_HIGH (1<<4) /* Chipselect active high */ +#define RT_SPI_NO_CS (1<<5) /* No chipselect */ +#define RT_SPI_3WIRE (1<<6) /* SI/SO pin shared */ +#define RT_SPI_READY (1<<7) /* Slave pulls low to pause */ + /** * SPI message structure */ diff --git a/components/drivers/include/rtdevice.h b/components/drivers/include/rtdevice.h index f4d967831c..475adebf80 100644 --- a/components/drivers/include/rtdevice.h +++ b/components/drivers/include/rtdevice.h @@ -370,6 +370,10 @@ rt_inline void rt_work_init(struct rt_work* work, void (*work_func)(struct rt_wo #include "drivers/can.h" #endif +#ifdef RT_USING_HWTIMER +#include "drivers/hwtimer.h" +#endif + #ifdef __cplusplus } #endif diff --git a/components/finsh/cmd.c b/components/finsh/cmd.c index 7d24a33d6a..c42b412f23 100644 --- a/components/finsh/cmd.c +++ b/components/finsh/cmd.c @@ -467,6 +467,7 @@ static long _list_device(struct rt_list_node *list) "PM Pseudo Device", "Pipe", "Portal Device", + "Timer Device", "Miscellaneous Device", "Unknown" }; diff --git a/components/finsh/finsh.h b/components/finsh/finsh.h index 4f3a887bc3..71b788f9f3 100644 --- a/components/finsh/finsh.h +++ b/components/finsh/finsh.h @@ -229,8 +229,8 @@ struct finsh_sysvar* finsh_sysvar_lookup(const char* name); #else #define FINSH_FUNCTION_EXPORT_CMD(name, cmd, desc) \ - const char __fsym_##cmd##_name[] SECTION(".name") = #cmd; \ - const char __fsym_##cmd##_desc[] SECTION(".name") = #desc; \ + const char __fsym_##cmd##_name[] SECTION(".rodata.name") = #cmd; \ + const char __fsym_##cmd##_desc[] SECTION(".rodata.name") = #desc; \ const struct finsh_syscall __fsym_##cmd SECTION("FSymTab")= \ { \ __fsym_##cmd##_name, \ @@ -239,8 +239,8 @@ struct finsh_sysvar* finsh_sysvar_lookup(const char* name); }; #define FINSH_VAR_EXPORT(name, type, desc) \ - const char __vsym_##name##_name[] SECTION(".name") = #name; \ - const char __vsym_##name##_desc[] SECTION(".name") = #desc; \ + const char __vsym_##name##_name[] SECTION(".rodata.name") = #name; \ + const char __vsym_##name##_desc[] SECTION(".rodata.name") = #desc; \ const struct finsh_sysvar __vsym_##name SECTION("VSymTab")= \ { \ __vsym_##name##_name, \ diff --git a/components/finsh/shell.c b/components/finsh/shell.c index c4708cee11..ce80e4dec2 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -52,23 +52,23 @@ static struct rt_thread finsh_thread; ALIGN(RT_ALIGN_SIZE) static char finsh_thread_stack[FINSH_THREAD_STACK_SIZE]; -struct finsh_shell* shell; +struct finsh_shell *shell; #if defined(FINSH_USING_MSH) || (defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR)) #if defined(RT_USING_DFS) #include <dfs_posix.h> #endif -const char* finsh_get_prompt() +const char *finsh_get_prompt() { - #define _MSH_PROMPT "msh " - #define _PROMPT "finsh " +#define _MSH_PROMPT "msh " +#define _PROMPT "finsh " static char finsh_prompt[RT_CONSOLEBUF_SIZE + 1] = {0}; #ifdef FINSH_USING_MSH if (msh_is_used()) strcpy(finsh_prompt, _MSH_PROMPT); else #endif - strcpy(finsh_prompt, _PROMPT); + strcpy(finsh_prompt, _PROMPT); #if defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR) /* get current working directory */ @@ -98,7 +98,7 @@ static rt_err_t finsh_rx_ind(rt_device_t dev, rt_size_t size) * * @param device_name the name of new input device. */ -void finsh_set_device(const char* device_name) +void finsh_set_device(const char *device_name) { rt_device_t dev = RT_NULL; @@ -113,7 +113,7 @@ void finsh_set_device(const char* device_name) /* check whether it's a same device */ if (dev == shell->device) return; /* open this device and set the new device in finsh shell */ - if (rt_device_open(dev, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX |\ + if (rt_device_open(dev, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX | \ RT_DEVICE_FLAG_STREAM) == RT_EOK) { if (shell->device != RT_NULL) @@ -122,11 +122,11 @@ void finsh_set_device(const char* device_name) rt_device_close(shell->device); rt_device_set_rx_indicate(shell->device, RT_NULL); } - + /* clear line buffer before switch to new device */ memset(shell->line, 0, sizeof(shell->line)); shell->line_curpos = shell->line_position = 0; - + shell->device = dev; rt_device_set_rx_indicate(dev, finsh_rx_ind); } @@ -139,7 +139,7 @@ void finsh_set_device(const char* device_name) * * @return the finsh shell input device name is returned. */ -const char* finsh_get_device() +const char *finsh_get_device() { RT_ASSERT(shell != RT_NULL); return shell->device->parent.name; @@ -174,7 +174,7 @@ rt_uint32_t finsh_get_echo() return shell->echo_mode; } -static void shell_auto_complete(char* prefix) +static void shell_auto_complete(char *prefix) { rt_kprintf("\n"); @@ -183,11 +183,11 @@ static void shell_auto_complete(char* prefix) { msh_auto_complete(prefix); } - else + else #endif { -#ifndef FINSH_USING_MSH_ONLY - extern void list_prefix(char* prefix); +#ifndef FINSH_USING_MSH_ONLY + extern void list_prefix(char * prefix); list_prefix(prefix); #endif } @@ -196,12 +196,12 @@ static void shell_auto_complete(char* prefix) } #ifndef FINSH_USING_MSH_ONLY -void finsh_run_line(struct finsh_parser* parser, const char *line) +void finsh_run_line(struct finsh_parser *parser, const char *line) { - const char* err_str; + const char *err_str; rt_kprintf("\n"); - finsh_parser_run(parser, (unsigned char*)line); + finsh_parser_run(parser, (unsigned char *)line); /* compile node root */ if (finsh_errno() == 0) @@ -224,15 +224,15 @@ void finsh_run_line(struct finsh_parser* parser, const char *line) if (ch > 0x20 && ch < 0x7e) { rt_kprintf("\t'%c', %d, 0x%08x\n", - (unsigned char)finsh_stack_bottom(), - (unsigned int)finsh_stack_bottom(), - (unsigned int)finsh_stack_bottom()); + (unsigned char)finsh_stack_bottom(), + (unsigned int)finsh_stack_bottom(), + (unsigned int)finsh_stack_bottom()); } else { rt_kprintf("\t%d, 0x%08x\n", - (unsigned int)finsh_stack_bottom(), - (unsigned int)finsh_stack_bottom()); + (unsigned int)finsh_stack_bottom(), + (unsigned int)finsh_stack_bottom()); } } @@ -241,13 +241,13 @@ void finsh_run_line(struct finsh_parser* parser, const char *line) #endif #ifdef FINSH_USING_HISTORY -static rt_bool_t shell_handle_history(struct finsh_shell* shell) +static rt_bool_t shell_handle_history(struct finsh_shell *shell) { #if defined(_WIN32) int i; rt_kprintf("\r"); - for(i=0; i<= 60; i++) + for (i = 0; i <= 60; i++) putchar(' '); rt_kprintf("\r"); @@ -258,7 +258,7 @@ static rt_bool_t shell_handle_history(struct finsh_shell* shell) return RT_FALSE; } -static void shell_push_history(struct finsh_shell* shell) +static void shell_push_history(struct finsh_shell *shell) { if (shell->line_position != 0) { @@ -270,7 +270,7 @@ static void shell_push_history(struct finsh_shell* shell) for (index = 0; index < FINSH_HISTORY_LINES - 1; index ++) { memcpy(&shell->cmd_history[index][0], - &shell->cmd_history[index + 1][0], FINSH_CMD_SIZE); + &shell->cmd_history[index + 1][0], FINSH_CMD_SIZE); } memset(&shell->cmd_history[index][0], 0, FINSH_CMD_SIZE); memcpy(&shell->cmd_history[index][0], shell->line, shell->line_position); @@ -294,7 +294,7 @@ static void shell_push_history(struct finsh_shell* shell) #ifndef RT_USING_HEAP struct finsh_shell _shell; #endif -void finsh_thread_entry(void* parameter) +void finsh_thread_entry(void *parameter) { char ch; @@ -424,7 +424,10 @@ void finsh_thread_entry(void* parameter) char next; if (rt_device_read(shell->device, 0, &next, 1) == 1) - ch = next; + { + if (next == '\0') ch = 'r'; /* linux telnet will issue '\0' */ + else ch = next; + } else ch = '\r'; } /* handle tab key */ @@ -479,26 +482,26 @@ void finsh_thread_entry(void* parameter) /* handle end of line, break */ if (ch == '\r' || ch == '\n') { - #ifdef FINSH_USING_HISTORY +#ifdef FINSH_USING_HISTORY shell_push_history(shell); - #endif +#endif - #ifdef FINSH_USING_MSH +#ifdef FINSH_USING_MSH if (msh_is_used() == RT_TRUE) { rt_kprintf("\n"); msh_exec(shell->line, shell->line_position); } else - #endif +#endif { - #ifndef FINSH_USING_MSH_ONLY +#ifndef FINSH_USING_MSH_ONLY /* add ';' and run the command line */ shell->line[shell->line_position] = ';'; if (shell->line_position != 0) finsh_run_line(&shell->parser, shell->line); else rt_kprintf("\n"); - #endif +#endif } rt_kprintf(FINSH_PROMPT); @@ -537,45 +540,45 @@ 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; - } + if (shell->line_position >= 80) + { + /* clear command line */ + shell->line_position = 0; + shell->line_curpos = 0; + } } /* end of device read */ } } -void finsh_system_function_init(const void* begin, const void* end) +void finsh_system_function_init(const void *begin, const void *end) { - _syscall_table_begin = (struct finsh_syscall*) begin; - _syscall_table_end = (struct finsh_syscall*) end; + _syscall_table_begin = (struct finsh_syscall *) begin; + _syscall_table_end = (struct finsh_syscall *) end; } -void finsh_system_var_init(const void* begin, const void* end) +void finsh_system_var_init(const void *begin, const void *end) { - _sysvar_table_begin = (struct finsh_sysvar*) begin; - _sysvar_table_end = (struct finsh_sysvar*) end; + _sysvar_table_begin = (struct finsh_sysvar *) begin; + _sysvar_table_end = (struct finsh_sysvar *) end; } #if defined(__ICCARM__) || defined(__ICCRX__) /* for IAR compiler */ - #ifdef FINSH_USING_SYMTAB - #pragma section="FSymTab" - #pragma section="VSymTab" - #endif +#ifdef FINSH_USING_SYMTAB +#pragma section="FSymTab" +#pragma section="VSymTab" +#endif #elif defined(__ADSPBLACKFIN__) /* for VisaulDSP++ Compiler*/ - #ifdef FINSH_USING_SYMTAB - extern "asm" int __fsymtab_start; - extern "asm" int __fsymtab_end; - extern "asm" int __vsymtab_start; - extern "asm" int __vsymtab_end; - #endif +#ifdef FINSH_USING_SYMTAB +extern "asm" int __fsymtab_start; +extern "asm" int __fsymtab_end; +extern "asm" int __vsymtab_start; +extern "asm" int __vsymtab_end; +#endif #elif defined(_MSC_VER) #pragma section("FSymTab$a", read) const char __fsym_begin_name[] = "__start"; const char __fsym_begin_desc[] = "begin of finsh"; -__declspec(allocate("FSymTab$a")) const struct finsh_syscall __fsym_begin = +__declspec(allocate("FSymTab$a")) const struct finsh_syscall __fsym_begin = { __fsym_begin_name, __fsym_begin_desc, @@ -585,7 +588,7 @@ __declspec(allocate("FSymTab$a")) const struct finsh_syscall __fsym_begin = #pragma section("FSymTab$z", read) const char __fsym_end_name[] = "__end"; const char __fsym_end_desc[] = "end of finsh"; -__declspec(allocate("FSymTab$z")) const struct finsh_syscall __fsym_end = +__declspec(allocate("FSymTab$z")) const struct finsh_syscall __fsym_end = { __fsym_end_name, __fsym_end_desc, @@ -609,9 +612,9 @@ int finsh_system_init(void) extern const int VSymTab$$Base; extern const int VSymTab$$Limit; finsh_system_function_init(&FSymTab$$Base, &FSymTab$$Limit); - #ifndef FINSH_USING_MSH_ONLY +#ifndef FINSH_USING_MSH_ONLY finsh_system_var_init(&VSymTab$$Base, &VSymTab$$Limit); - #endif +#endif #elif defined (__ICCARM__) || defined(__ICCRX__) /* for IAR Compiler */ finsh_system_function_init(__section_begin("FSymTab"), __section_end("FSymTab")); @@ -631,10 +634,12 @@ int finsh_system_init(void) #elif defined(_MSC_VER) unsigned int *ptr_begin, *ptr_end; - ptr_begin = (unsigned int*)&__fsym_begin; ptr_begin += (sizeof(struct finsh_syscall)/sizeof(unsigned int)); + ptr_begin = (unsigned int *)&__fsym_begin; + ptr_begin += (sizeof(struct finsh_syscall) / sizeof(unsigned int)); while (*ptr_begin == 0) ptr_begin ++; - ptr_end = (unsigned int*) &__fsym_end; ptr_end --; + ptr_end = (unsigned int *) &__fsym_end; + ptr_end --; while (*ptr_end == 0) ptr_end --; finsh_system_function_init(ptr_begin, ptr_end); @@ -643,7 +648,7 @@ int finsh_system_init(void) /* create or set shell structure */ #ifdef RT_USING_HEAP - shell = (struct finsh_shell*)rt_malloc(sizeof(struct finsh_shell)); + shell = (struct finsh_shell *)rt_malloc(sizeof(struct finsh_shell)); if (shell == RT_NULL) { rt_kprintf("no memory for shell\n"); @@ -657,10 +662,10 @@ int finsh_system_init(void) rt_sem_init(&(shell->rx_sem), "shrx", 0, 0); result = rt_thread_init(&finsh_thread, - "tshell", - finsh_thread_entry, RT_NULL, - &finsh_thread_stack[0], sizeof(finsh_thread_stack), - FINSH_THREAD_PRIORITY, 10); + "tshell", + finsh_thread_entry, RT_NULL, + &finsh_thread_stack[0], sizeof(finsh_thread_stack), + FINSH_THREAD_PRIORITY, 10); if (result == RT_EOK) rt_thread_startup(&finsh_thread); diff --git a/components/libc/newlib/syscalls.c b/components/libc/newlib/syscalls.c index 388d240c94..239d208520 100644 --- a/components/libc/newlib/syscalls.c +++ b/components/libc/newlib/syscalls.c @@ -442,3 +442,8 @@ _system(const char *s) /* not support this call */ return; } + +void __libc_init_array(void) +{ + /* we not use __libc init_aray to initialize C++ objects */ +} |
