2009-07-03 06:48:23 +08:00
|
|
|
/*
|
|
|
|
* File : shell.c
|
|
|
|
* This file is part of RT-Thread RTOS
|
|
|
|
* COPYRIGHT (C) 2006, RT-Thread Development Team
|
|
|
|
*
|
|
|
|
* The license and distribution terms for this file may be
|
|
|
|
* found in the file LICENSE in this distribution or at
|
2010-04-01 06:50:55 +08:00
|
|
|
* http://www.rt-thread.org/license/LICENSE
|
2009-07-03 06:48:23 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2006-04-30 Bernard the first verion for FinSH
|
|
|
|
* 2006-05-08 Bernard change finsh thread stack to 2048
|
|
|
|
* 2006-06-03 Bernard add support for skyeye
|
|
|
|
* 2006-09-24 Bernard remove the code related with hardware
|
2010-01-18 21:44:19 +08:00
|
|
|
* 2010-01-18 Bernard fix down then up key bug.
|
2010-03-19 16:32:54 +08:00
|
|
|
* 2010-03-19 Bernard fix backspace issue and fix device read in shell.
|
2010-04-01 06:50:55 +08:00
|
|
|
* 2010-04-01 Bernard add prompt output when start and remove the empty history
|
2009-07-03 06:48:23 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
|
|
|
#include <rthw.h>
|
|
|
|
|
|
|
|
#include "finsh.h"
|
2010-05-26 07:54:45 +08:00
|
|
|
#include "shell.h"
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
/* finsh thread */
|
2010-05-26 07:54:45 +08:00
|
|
|
static struct rt_thread finsh_thread;
|
|
|
|
static char finsh_thread_stack[FINSH_THREAD_STACK_SIZE];
|
|
|
|
struct finsh_shell* shell;
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
#if !defined (RT_USING_NEWLIB) && !defined (RT_USING_MINILIBC)
|
|
|
|
int strcmp (const char *s1, const char *s2)
|
|
|
|
{
|
|
|
|
while (*s1 && *s1 == *s2) s1++, s2++;
|
|
|
|
|
|
|
|
return (*s1 - *s2);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef RT_USING_HEAP
|
|
|
|
char *strdup(const char *s)
|
|
|
|
{
|
|
|
|
size_t len = strlen(s) + 1;
|
|
|
|
char *tmp = (char *)rt_malloc(len);
|
|
|
|
|
|
|
|
if(!tmp) return NULL;
|
|
|
|
|
|
|
|
rt_memcpy(tmp, s, len);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
#endif
|
2010-01-18 21:44:19 +08:00
|
|
|
|
2010-04-14 08:40:20 +08:00
|
|
|
#if !defined(__CC_ARM) && !defined(__ICCARM__) && !defined(__ICCM16C__)
|
2009-07-03 06:48:23 +08:00
|
|
|
int isalpha( int ch )
|
|
|
|
{
|
|
|
|
return (unsigned int)((ch | 0x20) - 'a') < 26u;
|
|
|
|
}
|
|
|
|
|
|
|
|
int atoi(const char* s)
|
|
|
|
{
|
|
|
|
long int v=0;
|
|
|
|
int sign=1;
|
|
|
|
while ( *s == ' ' || (unsigned int)(*s - 9) < 5u) s++;
|
|
|
|
|
|
|
|
switch (*s)
|
|
|
|
{
|
|
|
|
case '-': sign=-1;
|
|
|
|
case '+': ++s;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((unsigned int) (*s - '0') < 10u)
|
|
|
|
{
|
|
|
|
v=v*10+*s-'0'; ++s;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sign==-1?-v:v;
|
|
|
|
}
|
|
|
|
|
|
|
|
int isprint(unsigned char ch)
|
|
|
|
{
|
|
|
|
return (unsigned int)(ch - ' ') < 127u - ' ';
|
2010-01-18 21:44:19 +08:00
|
|
|
}
|
2010-01-15 21:13:10 +08:00
|
|
|
#endif
|
2009-07-03 06:48:23 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static rt_err_t finsh_rx_ind(rt_device_t dev, rt_size_t size)
|
|
|
|
{
|
2010-05-26 07:54:45 +08:00
|
|
|
RT_ASSERT(shell != RT_NULL);
|
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
/* release semaphore to let finsh thread rx data */
|
2010-05-26 07:54:45 +08:00
|
|
|
rt_sem_release(&shell->rx_sem);
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
return RT_EOK;
|
|
|
|
}
|
|
|
|
|
2010-04-14 08:40:20 +08:00
|
|
|
void finsh_set_device(const char* device_name)
|
2009-07-03 06:48:23 +08:00
|
|
|
{
|
|
|
|
rt_device_t dev = RT_NULL;
|
|
|
|
|
2010-05-26 07:54:45 +08:00
|
|
|
RT_ASSERT(shell != RT_NULL);
|
2009-07-03 06:48:23 +08:00
|
|
|
dev = rt_device_find(device_name);
|
|
|
|
if (dev != RT_NULL && rt_device_open(dev, RT_DEVICE_OFLAG_RDWR) == RT_EOK)
|
|
|
|
{
|
2010-05-26 07:54:45 +08:00
|
|
|
if (shell->device != RT_NULL)
|
2009-07-03 06:48:23 +08:00
|
|
|
{
|
|
|
|
/* close old finsh device */
|
2010-05-26 07:54:45 +08:00
|
|
|
rt_device_close(shell->device);
|
2009-07-03 06:48:23 +08:00
|
|
|
}
|
|
|
|
|
2010-05-26 07:54:45 +08:00
|
|
|
shell->device = dev;
|
2009-07-03 06:48:23 +08:00
|
|
|
rt_device_set_rx_indicate(dev, finsh_rx_ind);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rt_kprintf("finsh: can not find device:%s\n", device_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-26 07:54:45 +08:00
|
|
|
const char* finsh_get_device()
|
|
|
|
{
|
|
|
|
RT_ASSERT(shell != RT_NULL);
|
|
|
|
return shell->device->parent.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void finsh_set_echo(rt_uint32_t enable)
|
|
|
|
{
|
|
|
|
RT_ASSERT(shell != RT_NULL);
|
|
|
|
shell->echo_mode = enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
rt_uint32_t finsh_get_echo()
|
|
|
|
{
|
|
|
|
RT_ASSERT(shell != RT_NULL);
|
|
|
|
|
|
|
|
return shell->echo_mode;
|
|
|
|
}
|
|
|
|
|
2009-09-29 21:07:29 +08:00
|
|
|
void finsh_auto_complete(char* prefix)
|
|
|
|
{
|
|
|
|
extern void list_prefix(char* prefix);
|
|
|
|
|
|
|
|
rt_kprintf("\n");
|
|
|
|
list_prefix(prefix);
|
|
|
|
rt_kprintf("finsh>>%s", prefix);
|
2010-04-01 06:50:55 +08:00
|
|
|
}
|
2010-03-19 16:32:54 +08:00
|
|
|
|
2010-04-14 08:40:20 +08:00
|
|
|
extern const char* finsh_error_string_table[];
|
2010-05-26 07:54:45 +08:00
|
|
|
void finsh_run_line(struct finsh_parser* parser, const char *line)
|
2010-04-01 06:50:55 +08:00
|
|
|
{
|
2010-03-19 16:32:54 +08:00
|
|
|
rt_kprintf("\n");
|
|
|
|
finsh_parser_run(parser, (unsigned char*)line);
|
|
|
|
|
|
|
|
/* compile node root */
|
|
|
|
if (finsh_errno() == 0)
|
|
|
|
{
|
|
|
|
finsh_compiler_run(parser->root);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rt_kprintf("%s\n", finsh_error_string(finsh_errno()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* run virtual machine */
|
|
|
|
if (finsh_errno() == 0)
|
|
|
|
{
|
|
|
|
char ch;
|
|
|
|
finsh_vm_run();
|
|
|
|
|
|
|
|
ch = (unsigned char)finsh_stack_bottom();
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rt_kprintf("\t%d, 0x%08x\n",
|
|
|
|
(unsigned int)finsh_stack_bottom(),
|
|
|
|
(unsigned int)finsh_stack_bottom());
|
|
|
|
}
|
|
|
|
}
|
2009-09-29 21:07:29 +08:00
|
|
|
|
2010-04-01 06:50:55 +08:00
|
|
|
finsh_flush(parser);
|
|
|
|
}
|
|
|
|
|
2009-09-29 21:07:29 +08:00
|
|
|
#ifdef FINSH_USING_HISTORY
|
2010-05-26 07:54:45 +08:00
|
|
|
rt_bool_t finsh_handle_history(struct finsh_shell* shell, char ch)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* handle up and down key
|
|
|
|
* up key : 0x1b 0x5b 0x41
|
|
|
|
* down key: 0x1b 0x5b 0x42
|
|
|
|
*/
|
|
|
|
if (ch == 0x1b)
|
|
|
|
{
|
|
|
|
shell->stat = WAIT_SPEC_KEY;
|
|
|
|
return RT_TRUE;
|
|
|
|
}
|
2009-09-29 21:07:29 +08:00
|
|
|
|
2010-05-26 07:54:45 +08:00
|
|
|
if ((shell->stat == WAIT_SPEC_KEY))
|
|
|
|
{
|
|
|
|
if (ch == 0x5b)
|
|
|
|
{
|
|
|
|
shell->stat = WAIT_FUNC_KEY;
|
|
|
|
return RT_TRUE;
|
|
|
|
}
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2010-05-26 07:54:45 +08:00
|
|
|
shell->stat = WAIT_NORMAL;
|
|
|
|
return RT_FALSE;
|
|
|
|
}
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2010-05-26 07:54:45 +08:00
|
|
|
if (shell->stat == WAIT_FUNC_KEY)
|
2009-07-03 06:48:23 +08:00
|
|
|
{
|
2010-05-26 07:54:45 +08:00
|
|
|
shell->stat = WAIT_NORMAL;
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2010-05-26 07:54:45 +08:00
|
|
|
if (ch == 0x41) /* up key */
|
2009-07-03 06:48:23 +08:00
|
|
|
{
|
2010-05-26 07:54:45 +08:00
|
|
|
/* prev history */
|
|
|
|
if (shell->current_history > 0)shell->current_history --;
|
|
|
|
else
|
2009-07-03 06:48:23 +08:00
|
|
|
{
|
2010-05-26 07:54:45 +08:00
|
|
|
shell->current_history = 0;
|
|
|
|
return RT_TRUE;
|
2010-03-19 16:32:54 +08:00
|
|
|
}
|
2009-09-29 21:07:29 +08:00
|
|
|
|
2010-05-26 07:54:45 +08:00
|
|
|
/* copy the history command */
|
|
|
|
memcpy(shell->line, &shell->cmd_history[shell->current_history][0],
|
|
|
|
FINSH_CMD_SIZE);
|
|
|
|
shell->line_position = strlen(shell->line);
|
|
|
|
shell->use_history = 1;
|
|
|
|
}
|
|
|
|
else if (ch == 0x42) /* down key */
|
|
|
|
{
|
|
|
|
/* next history */
|
|
|
|
if (shell->current_history < shell->history_count - 1)
|
|
|
|
shell->current_history ++;
|
|
|
|
else
|
2010-03-19 16:32:54 +08:00
|
|
|
{
|
2010-05-26 07:54:45 +08:00
|
|
|
/* set to the end of history */
|
|
|
|
if (shell->history_count != 0)
|
2010-03-19 16:32:54 +08:00
|
|
|
{
|
2010-05-26 07:54:45 +08:00
|
|
|
shell->current_history = shell->history_count - 1;
|
2010-03-19 16:32:54 +08:00
|
|
|
}
|
2010-05-26 07:54:45 +08:00
|
|
|
else return RT_TRUE;
|
2010-03-19 16:32:54 +08:00
|
|
|
}
|
2009-10-23 14:14:21 +08:00
|
|
|
|
2010-05-26 07:54:45 +08:00
|
|
|
memcpy(shell->line, &shell->cmd_history[shell->current_history][0],
|
|
|
|
FINSH_CMD_SIZE);
|
|
|
|
shell->line_position = strlen(shell->line);
|
|
|
|
shell->use_history = 1;
|
|
|
|
}
|
2010-01-18 21:44:19 +08:00
|
|
|
|
2010-05-26 07:54:45 +08:00
|
|
|
if (shell->use_history)
|
|
|
|
{
|
|
|
|
rt_kprintf("\033[2K\r");
|
|
|
|
rt_kprintf("%s%s", FINSH_PROMPT, shell->line);
|
|
|
|
return RT_TRUE;;
|
|
|
|
}
|
|
|
|
}
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2010-05-26 07:54:45 +08:00
|
|
|
return RT_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void finsh_push_history(struct finsh_shell* shell)
|
|
|
|
{
|
|
|
|
if ((shell->use_history == 0) && (shell->line_position != 0))
|
|
|
|
{
|
|
|
|
/* push history */
|
|
|
|
if (shell->history_count >= FINSH_HISTORY_LINES)
|
|
|
|
{
|
|
|
|
/* move history */
|
|
|
|
int index;
|
|
|
|
for (index = 0; index < FINSH_HISTORY_LINES - 1; index ++)
|
|
|
|
{
|
|
|
|
memcpy(&shell->cmd_history[index][0],
|
|
|
|
&shell->cmd_history[index + 1][0], FINSH_CMD_SIZE);
|
2009-07-03 06:48:23 +08:00
|
|
|
}
|
2010-05-26 07:54:45 +08:00
|
|
|
memset(&shell->cmd_history[index][0], 0, FINSH_CMD_SIZE);
|
|
|
|
memcpy(&shell->cmd_history[index][0], shell->line, shell->line_position);
|
|
|
|
|
|
|
|
/* it's the maximum history */
|
|
|
|
shell->history_count = FINSH_HISTORY_LINES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memset(&shell->cmd_history[shell->history_count][0], 0, FINSH_CMD_SIZE);
|
|
|
|
memcpy(&shell->cmd_history[shell->history_count][0], shell->line, shell->line_position);
|
|
|
|
|
|
|
|
/* increase count and set current history position */
|
|
|
|
shell->history_count ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
shell->current_history = shell->history_count;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef RT_USING_HEAP
|
|
|
|
struct finsh_shell _shell;
|
|
|
|
#endif
|
|
|
|
void finsh_thread_entry(void* parameter)
|
|
|
|
{
|
|
|
|
char ch;
|
|
|
|
|
|
|
|
/* normal is echo mode */
|
|
|
|
shell->echo_mode = 1;
|
|
|
|
|
|
|
|
finsh_init(&shell->parser);
|
|
|
|
rt_kprintf(FINSH_PROMPT);
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
/* wait receive */
|
|
|
|
if (rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER) != RT_EOK) continue;
|
|
|
|
|
|
|
|
/* read one character from device */
|
|
|
|
while (rt_device_read(shell->device, 0, &ch, 1) == 1)
|
|
|
|
{
|
|
|
|
/* handle history key */
|
|
|
|
#ifdef FINSH_USING_HISTORY
|
|
|
|
if (finsh_handle_history(shell, ch) == RT_TRUE) continue;
|
2010-03-19 16:32:54 +08:00
|
|
|
#endif
|
2009-09-29 21:07:29 +08:00
|
|
|
|
2010-05-26 07:54:45 +08:00
|
|
|
/* handle CR key */
|
|
|
|
if (ch == '\r')
|
|
|
|
{
|
|
|
|
char next;
|
|
|
|
|
|
|
|
if (rt_device_read(shell->device, 0, &next, 1) == 1)
|
|
|
|
ch = next;
|
|
|
|
else ch = '\r';
|
|
|
|
}
|
2010-03-19 16:32:54 +08:00
|
|
|
/* handle tab key */
|
2010-05-26 07:54:45 +08:00
|
|
|
else if (ch == '\t')
|
2009-09-29 21:07:29 +08:00
|
|
|
{
|
2010-03-19 16:32:54 +08:00
|
|
|
/* auto complete */
|
2010-05-26 07:54:45 +08:00
|
|
|
finsh_auto_complete(&shell->line[0]);
|
2010-03-19 16:32:54 +08:00
|
|
|
/* re-calculate position */
|
2010-05-26 07:54:45 +08:00
|
|
|
shell->line_position = strlen(shell->line);
|
2010-03-19 16:32:54 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* handle backspace key */
|
|
|
|
else if (ch == 0x7f || ch == 0x08)
|
|
|
|
{
|
2010-05-26 07:54:45 +08:00
|
|
|
if (shell->line_position != 0)
|
2009-09-29 21:07:29 +08:00
|
|
|
{
|
2010-03-19 16:32:54 +08:00
|
|
|
rt_kprintf("%c %c", ch, ch);
|
2009-10-23 14:14:21 +08:00
|
|
|
}
|
2010-05-26 07:54:45 +08:00
|
|
|
if (shell->line_position <= 0) shell->line_position = 0;
|
|
|
|
else shell->line_position --;
|
|
|
|
shell->line[shell->line_position] = 0;
|
2010-03-19 16:32:54 +08:00
|
|
|
continue;
|
2009-10-23 14:14:21 +08:00
|
|
|
}
|
2010-05-26 07:54:45 +08:00
|
|
|
|
2010-03-19 16:32:54 +08:00
|
|
|
/* handle end of line, break */
|
2010-05-26 07:54:45 +08:00
|
|
|
if (ch == '\r' || ch == '\n')
|
2009-09-29 21:07:29 +08:00
|
|
|
{
|
2010-03-19 16:32:54 +08:00
|
|
|
/* change to ';' and break */
|
2010-05-26 07:54:45 +08:00
|
|
|
shell->line[shell->line_position] = ';';
|
2009-10-23 14:14:21 +08:00
|
|
|
|
2010-03-19 16:32:54 +08:00
|
|
|
#ifdef FINSH_USING_HISTORY
|
2010-05-26 07:54:45 +08:00
|
|
|
finsh_push_history(shell);
|
2010-04-01 06:50:55 +08:00
|
|
|
#endif
|
|
|
|
|
2010-05-26 07:54:45 +08:00
|
|
|
if (shell->line_position != 0) finsh_run_line(&shell->parser, shell->line);
|
2010-04-01 06:50:55 +08:00
|
|
|
else rt_kprintf("\n");
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2010-05-26 07:54:45 +08:00
|
|
|
rt_kprintf(FINSH_PROMPT);
|
|
|
|
memset(shell->line, 0, sizeof(shell->line));
|
|
|
|
shell->line_position = 0;
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2010-03-19 16:32:54 +08:00
|
|
|
break;
|
2009-07-03 06:48:23 +08:00
|
|
|
}
|
|
|
|
|
2010-03-19 16:32:54 +08:00
|
|
|
/* it's a large line, discard it */
|
2010-05-26 07:54:45 +08:00
|
|
|
if (shell->line_position >= FINSH_CMD_SIZE) shell->line_position = 0;
|
2010-03-19 16:32:54 +08:00
|
|
|
|
|
|
|
/* normal character */
|
2010-05-26 07:54:45 +08:00
|
|
|
shell->line[shell->line_position] = ch; ch = 0;
|
|
|
|
if (shell->echo_mode) rt_kprintf("%c", shell->line[shell->line_position]);
|
|
|
|
shell->line_position ++;
|
|
|
|
shell->use_history = 0; /* it's a new command */
|
2010-03-19 16:32:54 +08:00
|
|
|
} /* end of device read */
|
2009-07-03 06:48:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void finsh_system_function_init(void* begin, void* end)
|
|
|
|
{
|
|
|
|
_syscall_table_begin = (struct finsh_syscall*) begin;
|
|
|
|
_syscall_table_end = (struct finsh_syscall*) end;
|
|
|
|
}
|
|
|
|
|
|
|
|
void finsh_system_var_init(void* begin, void* end)
|
|
|
|
{
|
|
|
|
_sysvar_table_begin = (struct finsh_sysvar*) begin;
|
|
|
|
_sysvar_table_end = (struct finsh_sysvar*) end;
|
|
|
|
}
|
|
|
|
|
2010-05-26 07:54:45 +08:00
|
|
|
#if defined(__ICCARM__) /* for IAR compiler */
|
|
|
|
#ifdef FINSH_USING_SYMTAB
|
|
|
|
#pragma section="FSymTab"
|
|
|
|
#pragma section="VSymTab"
|
|
|
|
#endif
|
|
|
|
#endif
|
2009-07-03 06:48:23 +08:00
|
|
|
/* init finsh */
|
2010-04-14 08:40:20 +08:00
|
|
|
void finsh_system_init(void)
|
2009-07-03 06:48:23 +08:00
|
|
|
{
|
2010-05-22 21:35:35 +08:00
|
|
|
rt_err_t result;
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
#ifdef FINSH_USING_SYMTAB
|
|
|
|
#ifdef __CC_ARM /* ARM C Compiler */
|
2010-05-26 07:54:45 +08:00
|
|
|
extern int FSymTab$$Base;
|
|
|
|
extern int FSymTab$$Limit;
|
|
|
|
extern int VSymTab$$Base;
|
|
|
|
extern int VSymTab$$Limit;
|
2009-07-03 06:48:23 +08:00
|
|
|
finsh_system_function_init(&FSymTab$$Base, &FSymTab$$Limit);
|
|
|
|
finsh_system_var_init(&VSymTab$$Base, &VSymTab$$Limit);
|
|
|
|
#elif defined (__ICCARM__) /* for IAR Compiler */
|
|
|
|
finsh_system_function_init(__section_begin("FSymTab"),
|
|
|
|
__section_end("FSymTab"));
|
|
|
|
finsh_system_var_init(__section_begin("VSymTab"),
|
|
|
|
__section_end("VSymTab"));
|
|
|
|
#elif defined (__GNUC__) /* GNU GCC Compiler */
|
2010-05-26 07:54:45 +08:00
|
|
|
extern int __fsymtab_start;
|
|
|
|
extern int __fsymtab_end;
|
|
|
|
extern int __vsymtab_start;
|
|
|
|
extern int __vsymtab_end;
|
2009-10-23 14:14:21 +08:00
|
|
|
finsh_system_function_init(&__fsymtab_start, &__fsymtab_end);
|
|
|
|
finsh_system_var_init(&__vsymtab_start, &__vsymtab_start);
|
2009-07-03 06:48:23 +08:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2010-05-26 07:54:45 +08:00
|
|
|
/* create or set shell structure */
|
|
|
|
#ifdef RT_USING_HEAP
|
|
|
|
shell = (struct finsh_shell*)rt_malloc(sizeof(struct finsh_shell));
|
|
|
|
#else
|
|
|
|
shell = &_shell;
|
2010-06-09 15:54:40 +08:00
|
|
|
#endif
|
|
|
|
if (shell == RT_NULL)
|
|
|
|
{
|
|
|
|
rt_kprintf("no memory for shell\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-26 07:54:45 +08:00
|
|
|
memset(shell, 0, sizeof(struct finsh_shell));
|
|
|
|
|
|
|
|
rt_sem_init(&(shell->rx_sem), "shrx", 0, 0);
|
2010-05-22 21:35:35 +08:00
|
|
|
result = rt_thread_init(&finsh_thread,
|
2010-04-01 07:20:10 +08:00
|
|
|
"tshell",
|
|
|
|
finsh_thread_entry, RT_NULL,
|
|
|
|
&finsh_thread_stack[0], sizeof(finsh_thread_stack),
|
2010-05-22 21:35:35 +08:00
|
|
|
FINSH_THREAD_PRIORITY, 10);
|
2010-04-01 07:20:10 +08:00
|
|
|
|
2010-05-22 21:35:35 +08:00
|
|
|
if (result == RT_EOK)
|
|
|
|
rt_thread_startup(&finsh_thread);
|
2009-07-03 06:48:23 +08:00
|
|
|
}
|