2009-07-03 06:48:23 +08:00
|
|
|
/*
|
2021-03-08 18:19:04 +08:00
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
2009-07-03 06:48:23 +08:00
|
|
|
*
|
2018-10-14 19:28:18 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2009-07-03 06:48:23 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
2013-03-30 16:14:38 +08:00
|
|
|
* 2006-04-30 Bernard the first version for FinSH
|
2009-07-03 06:48:23 +08:00
|
|
|
* 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
|
2011-02-23 07:30:59 +08:00
|
|
|
* 2011-02-23 Bernard fix variable section end issue of finsh shell
|
|
|
|
* initialization when use GNU GCC compiler.
|
2016-11-26 16:45:54 +08:00
|
|
|
* 2016-11-26 armink add password authentication
|
2019-12-07 13:47:03 +08:00
|
|
|
* 2018-07-02 aozima add custom prompt support.
|
2009-07-03 06:48:23 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rthw.h>
|
2021-08-23 17:30:05 +08:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2018-11-07 14:31:32 +08:00
|
|
|
#ifdef RT_USING_FINSH
|
|
|
|
|
2010-05-26 07:54:45 +08:00
|
|
|
#include "shell.h"
|
2013-03-30 16:14:38 +08:00
|
|
|
#include "msh.h"
|
|
|
|
|
2021-11-16 00:22:49 +08:00
|
|
|
#ifdef DFS_USING_POSIX
|
2021-10-21 09:44:01 +08:00
|
|
|
#include <dfs_posix.h>
|
2021-11-16 00:22:49 +08:00
|
|
|
#endif /* DFS_USING_POSIX */
|
2012-12-31 12:17:31 +08:00
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
/* finsh thread */
|
2018-04-23 13:28:44 +08:00
|
|
|
#ifndef RT_USING_HEAP
|
2021-08-23 17:30:05 +08:00
|
|
|
static struct rt_thread finsh_thread;
|
|
|
|
ALIGN(RT_ALIGN_SIZE)
|
|
|
|
static char finsh_thread_stack[FINSH_THREAD_STACK_SIZE];
|
|
|
|
struct finsh_shell _shell;
|
2018-04-23 13:28:44 +08:00
|
|
|
#endif
|
2018-09-23 12:08:44 +08:00
|
|
|
|
2019-09-25 20:08:53 +08:00
|
|
|
/* finsh symtab */
|
|
|
|
#ifdef FINSH_USING_SYMTAB
|
2021-08-23 17:30:05 +08:00
|
|
|
struct finsh_syscall *_syscall_table_begin = NULL;
|
|
|
|
struct finsh_syscall *_syscall_table_end = NULL;
|
2019-09-25 20:08:53 +08:00
|
|
|
#endif
|
|
|
|
|
2015-09-24 11:06:26 +08:00
|
|
|
struct finsh_shell *shell;
|
2018-07-02 16:23:00 +08:00
|
|
|
static char *finsh_prompt_custom = RT_NULL;
|
|
|
|
|
2019-07-19 15:44:36 +08:00
|
|
|
#if defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__))
|
2021-08-23 17:30:05 +08:00
|
|
|
struct finsh_syscall *finsh_syscall_next(struct finsh_syscall *call)
|
2019-07-19 15:44:36 +08:00
|
|
|
{
|
|
|
|
unsigned int *ptr;
|
2021-08-23 17:30:05 +08:00
|
|
|
ptr = (unsigned int *)(call + 1);
|
|
|
|
while ((*ptr == 0) && ((unsigned int *)ptr < (unsigned int *) _syscall_table_end))
|
2019-07-19 15:44:36 +08:00
|
|
|
ptr ++;
|
|
|
|
|
2021-08-23 17:30:05 +08:00
|
|
|
return (struct finsh_syscall *)ptr;
|
2019-07-19 15:44:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__)) */
|
|
|
|
|
2018-07-02 16:23:00 +08:00
|
|
|
#ifdef RT_USING_HEAP
|
2021-08-23 17:30:05 +08:00
|
|
|
int finsh_set_prompt(const char *prompt)
|
2018-07-02 16:23:00 +08:00
|
|
|
{
|
2021-08-23 17:30:05 +08:00
|
|
|
if (finsh_prompt_custom)
|
2018-07-02 16:23:00 +08:00
|
|
|
{
|
|
|
|
rt_free(finsh_prompt_custom);
|
|
|
|
finsh_prompt_custom = RT_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* strdup */
|
2021-08-23 17:30:05 +08:00
|
|
|
if (prompt)
|
2018-07-02 16:23:00 +08:00
|
|
|
{
|
2021-08-23 17:30:05 +08:00
|
|
|
finsh_prompt_custom = (char *)rt_malloc(strlen(prompt) + 1);
|
|
|
|
if (finsh_prompt_custom)
|
2018-07-02 16:23:00 +08:00
|
|
|
{
|
|
|
|
strcpy(finsh_prompt_custom, prompt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* RT_USING_HEAP */
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2021-08-23 17:30:05 +08:00
|
|
|
#define _MSH_PROMPT "msh "
|
2018-07-02 16:23:00 +08:00
|
|
|
|
2020-07-24 15:19:12 +08:00
|
|
|
const char *finsh_get_prompt(void)
|
2010-12-09 08:05:50 +08:00
|
|
|
{
|
2014-03-12 16:25:59 +08:00
|
|
|
static char finsh_prompt[RT_CONSOLEBUF_SIZE + 1] = {0};
|
2014-03-11 15:54:21 +08:00
|
|
|
|
2018-07-02 15:10:11 +08:00
|
|
|
/* check prompt mode */
|
|
|
|
if (!shell->prompt_mode)
|
|
|
|
{
|
|
|
|
finsh_prompt[0] = '\0';
|
|
|
|
return finsh_prompt;
|
|
|
|
}
|
|
|
|
|
2021-08-23 17:30:05 +08:00
|
|
|
if (finsh_prompt_custom)
|
2018-07-02 16:23:00 +08:00
|
|
|
{
|
2021-08-23 17:30:05 +08:00
|
|
|
strncpy(finsh_prompt, finsh_prompt_custom, sizeof(finsh_prompt) - 1);
|
2018-07-02 16:23:00 +08:00
|
|
|
return finsh_prompt;
|
|
|
|
}
|
2021-08-23 17:30:05 +08:00
|
|
|
strcpy(finsh_prompt, _MSH_PROMPT);
|
2014-03-11 15:54:21 +08:00
|
|
|
|
2021-11-16 00:22:49 +08:00
|
|
|
#if defined(DFS_USING_POSIX) && defined(DFS_USING_WORKDIR)
|
2014-01-03 07:15:25 +08:00
|
|
|
/* get current working directory */
|
2014-03-12 16:25:59 +08:00
|
|
|
getcwd(&finsh_prompt[rt_strlen(finsh_prompt)], RT_CONSOLEBUF_SIZE - rt_strlen(finsh_prompt));
|
2014-04-08 15:12:44 +08:00
|
|
|
#endif
|
2014-09-11 12:47:25 +08:00
|
|
|
|
2014-01-03 07:15:25 +08:00
|
|
|
strcat(finsh_prompt, ">");
|
|
|
|
|
|
|
|
return finsh_prompt;
|
2010-12-09 08:05:50 +08:00
|
|
|
}
|
|
|
|
|
2018-07-02 15:10:11 +08:00
|
|
|
/**
|
|
|
|
* @ingroup finsh
|
|
|
|
*
|
|
|
|
* This function get the prompt mode of finsh shell.
|
|
|
|
*
|
|
|
|
* @return prompt the prompt mode, 0 disable prompt mode, other values enable prompt mode.
|
|
|
|
*/
|
|
|
|
rt_uint32_t finsh_get_prompt_mode(void)
|
|
|
|
{
|
|
|
|
RT_ASSERT(shell != RT_NULL);
|
|
|
|
return shell->prompt_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup finsh
|
|
|
|
*
|
|
|
|
* This function set the prompt mode of finsh shell.
|
|
|
|
*
|
|
|
|
* The parameter 0 disable prompt mode, other values enable prompt mode.
|
|
|
|
*
|
|
|
|
* @param prompt the prompt mode
|
|
|
|
*/
|
|
|
|
void finsh_set_prompt_mode(rt_uint32_t prompt_mode)
|
|
|
|
{
|
|
|
|
RT_ASSERT(shell != RT_NULL);
|
|
|
|
shell->prompt_mode = prompt_mode;
|
|
|
|
}
|
|
|
|
|
2021-10-14 10:38:01 +08:00
|
|
|
int finsh_getchar(void)
|
2017-10-10 14:27:34 +08:00
|
|
|
{
|
2019-09-25 20:08:53 +08:00
|
|
|
#ifdef RT_USING_DEVICE
|
2021-10-27 17:39:22 +08:00
|
|
|
char ch = 0;
|
2022-01-03 06:51:44 +08:00
|
|
|
#ifdef RT_USING_POSIX_STDIO
|
2021-10-27 17:39:22 +08:00
|
|
|
if(read(STDIN_FILENO, &ch, 1) > 0)
|
2021-10-27 14:52:04 +08:00
|
|
|
{
|
2021-10-27 17:39:22 +08:00
|
|
|
return ch;
|
2021-10-27 14:52:04 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return -1; /* EOF */
|
|
|
|
}
|
2017-10-10 14:27:34 +08:00
|
|
|
#else
|
2021-10-14 10:38:01 +08:00
|
|
|
rt_device_t device;
|
2017-10-10 14:27:34 +08:00
|
|
|
|
2017-10-17 09:45:17 +08:00
|
|
|
RT_ASSERT(shell != RT_NULL);
|
2021-10-14 10:38:01 +08:00
|
|
|
|
|
|
|
device = shell->device;
|
|
|
|
if (device == RT_NULL)
|
2021-10-13 18:04:46 +08:00
|
|
|
{
|
2021-10-14 10:38:01 +08:00
|
|
|
return -1; /* EOF */
|
2021-10-13 18:04:46 +08:00
|
|
|
}
|
2021-10-14 10:38:01 +08:00
|
|
|
|
|
|
|
while (rt_device_read(device, -1, &ch, 1) != 1)
|
2017-10-10 14:27:34 +08:00
|
|
|
rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER);
|
|
|
|
|
2021-08-21 06:14:37 +08:00
|
|
|
return ch;
|
2022-01-03 06:51:44 +08:00
|
|
|
#endif /* RT_USING_POSIX_STDIO */
|
2019-09-25 20:08:53 +08:00
|
|
|
#else
|
|
|
|
extern char rt_hw_console_getchar(void);
|
|
|
|
return rt_hw_console_getchar();
|
2021-10-13 18:04:46 +08:00
|
|
|
#endif /* RT_USING_DEVICE */
|
2017-10-10 14:27:34 +08:00
|
|
|
}
|
|
|
|
|
2022-01-03 06:51:44 +08:00
|
|
|
#if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE)
|
2009-07-03 06:48:23 +08:00
|
|
|
static rt_err_t finsh_rx_ind(rt_device_t dev, rt_size_t size)
|
|
|
|
{
|
2014-01-03 07:15:25 +08:00
|
|
|
RT_ASSERT(shell != RT_NULL);
|
2010-05-26 07:54:45 +08:00
|
|
|
|
2014-01-03 07:15:25 +08:00
|
|
|
/* release semaphore to let finsh thread rx data */
|
|
|
|
rt_sem_release(&shell->rx_sem);
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2014-01-03 07:15:25 +08:00
|
|
|
return RT_EOK;
|
2009-07-03 06:48:23 +08:00
|
|
|
}
|
|
|
|
|
2010-11-29 08:04:55 +08:00
|
|
|
/**
|
|
|
|
* @ingroup finsh
|
|
|
|
*
|
|
|
|
* This function sets the input device of finsh shell.
|
|
|
|
*
|
|
|
|
* @param device_name the name of new input device.
|
|
|
|
*/
|
2015-09-24 11:06:26 +08:00
|
|
|
void finsh_set_device(const char *device_name)
|
2009-07-03 06:48:23 +08:00
|
|
|
{
|
2014-01-03 07:15:25 +08:00
|
|
|
rt_device_t dev = RT_NULL;
|
|
|
|
|
|
|
|
RT_ASSERT(shell != RT_NULL);
|
|
|
|
dev = rt_device_find(device_name);
|
|
|
|
if (dev == RT_NULL)
|
|
|
|
{
|
|
|
|
rt_kprintf("finsh: can not find device: %s\n", device_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check whether it's a same device */
|
|
|
|
if (dev == shell->device) return;
|
|
|
|
/* open this device and set the new device in finsh shell */
|
2015-09-24 11:06:26 +08:00
|
|
|
if (rt_device_open(dev, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX | \
|
2015-01-04 19:42:58 +08:00
|
|
|
RT_DEVICE_FLAG_STREAM) == RT_EOK)
|
2014-01-03 07:15:25 +08:00
|
|
|
{
|
|
|
|
if (shell->device != RT_NULL)
|
|
|
|
{
|
|
|
|
/* close old finsh device */
|
|
|
|
rt_device_close(shell->device);
|
2014-08-26 23:36:16 +08:00
|
|
|
rt_device_set_rx_indicate(shell->device, RT_NULL);
|
2014-01-03 07:15:25 +08:00
|
|
|
}
|
2015-09-24 11:06:26 +08:00
|
|
|
|
2015-05-22 16:35:01 +08:00
|
|
|
/* clear line buffer before switch to new device */
|
2021-12-31 08:38:20 +08:00
|
|
|
rt_memset(shell->line, 0, sizeof(shell->line));
|
2015-05-22 16:35:01 +08:00
|
|
|
shell->line_curpos = shell->line_position = 0;
|
2015-09-24 11:06:26 +08:00
|
|
|
|
2014-01-03 07:15:25 +08:00
|
|
|
shell->device = dev;
|
|
|
|
rt_device_set_rx_indicate(dev, finsh_rx_ind);
|
|
|
|
}
|
2009-07-03 06:48:23 +08:00
|
|
|
}
|
|
|
|
|
2010-11-29 08:04:55 +08:00
|
|
|
/**
|
|
|
|
* @ingroup finsh
|
|
|
|
*
|
|
|
|
* This function returns current finsh shell input device.
|
|
|
|
*
|
|
|
|
* @return the finsh shell input device name is returned.
|
|
|
|
*/
|
2015-09-24 11:06:26 +08:00
|
|
|
const char *finsh_get_device()
|
2010-05-26 07:54:45 +08:00
|
|
|
{
|
2014-01-03 07:15:25 +08:00
|
|
|
RT_ASSERT(shell != RT_NULL);
|
|
|
|
return shell->device->parent.name;
|
2010-05-26 07:54:45 +08:00
|
|
|
}
|
2022-01-03 06:51:44 +08:00
|
|
|
#endif /* !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE) */
|
2010-05-26 07:54:45 +08:00
|
|
|
|
2010-11-29 08:04:55 +08:00
|
|
|
/**
|
|
|
|
* @ingroup finsh
|
|
|
|
*
|
|
|
|
* This function set the echo mode of finsh shell.
|
|
|
|
*
|
|
|
|
* FINSH_OPTION_ECHO=0x01 is echo mode, other values are none-echo mode.
|
|
|
|
*
|
|
|
|
* @param echo the echo mode
|
|
|
|
*/
|
|
|
|
void finsh_set_echo(rt_uint32_t echo)
|
2010-05-26 07:54:45 +08:00
|
|
|
{
|
2014-01-03 07:15:25 +08:00
|
|
|
RT_ASSERT(shell != RT_NULL);
|
|
|
|
shell->echo_mode = (rt_uint8_t)echo;
|
2010-05-26 07:54:45 +08:00
|
|
|
}
|
|
|
|
|
2010-11-29 08:04:55 +08:00
|
|
|
/**
|
|
|
|
* @ingroup finsh
|
|
|
|
*
|
|
|
|
* This function gets the echo mode of finsh shell.
|
|
|
|
*
|
|
|
|
* @return the echo mode
|
|
|
|
*/
|
2010-05-26 07:54:45 +08:00
|
|
|
rt_uint32_t finsh_get_echo()
|
|
|
|
{
|
2014-01-03 07:15:25 +08:00
|
|
|
RT_ASSERT(shell != RT_NULL);
|
2010-05-26 07:54:45 +08:00
|
|
|
|
2014-01-03 07:15:25 +08:00
|
|
|
return shell->echo_mode;
|
2010-05-26 07:54:45 +08:00
|
|
|
}
|
|
|
|
|
2016-11-26 15:23:12 +08:00
|
|
|
#ifdef FINSH_USING_AUTH
|
|
|
|
/**
|
|
|
|
* set a new password for finsh
|
|
|
|
*
|
|
|
|
* @param password new password
|
|
|
|
*
|
2016-11-26 16:45:54 +08:00
|
|
|
* @return result, RT_EOK on OK, -RT_ERROR on the new password length is less than
|
|
|
|
* FINSH_PASSWORD_MIN or greater than FINSH_PASSWORD_MAX
|
2016-11-26 15:23:12 +08:00
|
|
|
*/
|
2021-08-23 17:30:05 +08:00
|
|
|
rt_err_t finsh_set_password(const char *password)
|
|
|
|
{
|
2016-11-26 15:23:12 +08:00
|
|
|
rt_ubase_t level;
|
2016-11-26 16:45:54 +08:00
|
|
|
rt_size_t pw_len = rt_strlen(password);
|
2016-11-26 15:23:12 +08:00
|
|
|
|
2016-11-26 16:45:54 +08:00
|
|
|
if (pw_len < FINSH_PASSWORD_MIN || pw_len > FINSH_PASSWORD_MAX)
|
2016-11-26 15:23:12 +08:00
|
|
|
return -RT_ERROR;
|
|
|
|
|
|
|
|
level = rt_hw_interrupt_disable();
|
|
|
|
rt_strncpy(shell->password, password, FINSH_PASSWORD_MAX);
|
|
|
|
rt_hw_interrupt_enable(level);
|
|
|
|
|
|
|
|
return RT_EOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the finsh password
|
|
|
|
*
|
|
|
|
* @return password
|
|
|
|
*/
|
|
|
|
const char *finsh_get_password(void)
|
|
|
|
{
|
|
|
|
return shell->password;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void finsh_wait_auth(void)
|
|
|
|
{
|
2019-02-21 21:18:30 +08:00
|
|
|
int ch;
|
2016-11-26 15:23:12 +08:00
|
|
|
rt_bool_t input_finish = RT_FALSE;
|
|
|
|
char password[FINSH_PASSWORD_MAX] = { 0 };
|
|
|
|
rt_size_t cur_pos = 0;
|
2017-08-30 20:42:36 +08:00
|
|
|
/* password not set */
|
|
|
|
if (rt_strlen(finsh_get_password()) == 0) return;
|
2018-03-01 21:01:20 +08:00
|
|
|
|
2016-11-26 15:23:12 +08:00
|
|
|
while (1)
|
|
|
|
{
|
2017-10-10 14:27:34 +08:00
|
|
|
rt_kprintf("Password for login: ");
|
2016-11-26 15:23:12 +08:00
|
|
|
while (!input_finish)
|
|
|
|
{
|
2017-10-10 14:27:34 +08:00
|
|
|
while (1)
|
2016-11-26 15:23:12 +08:00
|
|
|
{
|
2017-10-10 14:27:34 +08:00
|
|
|
/* read one character from device */
|
2021-08-21 06:14:37 +08:00
|
|
|
ch = (int)finsh_getchar();
|
2019-02-21 21:18:30 +08:00
|
|
|
if (ch < 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2017-10-10 14:27:34 +08:00
|
|
|
|
2016-11-26 15:23:12 +08:00
|
|
|
if (ch >= ' ' && ch <= '~' && cur_pos < FINSH_PASSWORD_MAX)
|
|
|
|
{
|
|
|
|
/* change the printable characters to '*' */
|
|
|
|
rt_kprintf("*");
|
|
|
|
password[cur_pos++] = ch;
|
|
|
|
}
|
|
|
|
else if (ch == '\b' && cur_pos > 0)
|
|
|
|
{
|
|
|
|
/* backspace */
|
2019-05-29 20:34:03 +08:00
|
|
|
cur_pos--;
|
2016-11-26 15:23:12 +08:00
|
|
|
password[cur_pos] = '\0';
|
|
|
|
rt_kprintf("\b \b");
|
|
|
|
}
|
|
|
|
else if (ch == '\r' || ch == '\n')
|
|
|
|
{
|
|
|
|
rt_kprintf("\n");
|
|
|
|
input_finish = RT_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!rt_strncmp(shell->password, password, FINSH_PASSWORD_MAX)) return;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* authentication failed, delay 2S for retry */
|
|
|
|
rt_thread_delay(2 * RT_TICK_PER_SECOND);
|
|
|
|
rt_kprintf("Sorry, try again.\n");
|
|
|
|
cur_pos = 0;
|
|
|
|
input_finish = RT_FALSE;
|
|
|
|
rt_memset(password, '\0', FINSH_PASSWORD_MAX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* FINSH_USING_AUTH */
|
|
|
|
|
2015-09-24 11:06:26 +08:00
|
|
|
static void shell_auto_complete(char *prefix)
|
2009-09-29 21:07:29 +08:00
|
|
|
{
|
2014-01-03 07:15:25 +08:00
|
|
|
rt_kprintf("\n");
|
2021-08-23 17:30:05 +08:00
|
|
|
msh_auto_complete(prefix);
|
2013-03-30 16:14:38 +08:00
|
|
|
|
2014-01-03 07:15:25 +08:00
|
|
|
rt_kprintf("%s%s", FINSH_PROMPT, prefix);
|
2010-04-01 06:50:55 +08:00
|
|
|
}
|
2010-03-19 16:32:54 +08:00
|
|
|
|
2009-09-29 21:07:29 +08:00
|
|
|
#ifdef FINSH_USING_HISTORY
|
2015-09-24 11:06:26 +08:00
|
|
|
static rt_bool_t shell_handle_history(struct finsh_shell *shell)
|
2010-05-26 07:54:45 +08:00
|
|
|
{
|
2012-10-22 11:12:21 +08:00
|
|
|
#if defined(_WIN32)
|
2014-01-03 07:15:25 +08:00
|
|
|
int i;
|
|
|
|
rt_kprintf("\r");
|
2012-10-22 11:12:21 +08:00
|
|
|
|
2015-09-24 11:06:26 +08:00
|
|
|
for (i = 0; i <= 60; i++)
|
2014-01-03 07:15:25 +08:00
|
|
|
putchar(' ');
|
|
|
|
rt_kprintf("\r");
|
2012-10-22 11:12:21 +08:00
|
|
|
|
|
|
|
#else
|
2014-01-03 07:15:25 +08:00
|
|
|
rt_kprintf("\033[2K\r");
|
2012-10-22 11:12:21 +08:00
|
|
|
#endif
|
2014-01-03 07:15:25 +08:00
|
|
|
rt_kprintf("%s%s", FINSH_PROMPT, shell->line);
|
|
|
|
return RT_FALSE;
|
2010-05-26 07:54:45 +08:00
|
|
|
}
|
|
|
|
|
2015-09-24 11:06:26 +08:00
|
|
|
static void shell_push_history(struct finsh_shell *shell)
|
2010-05-26 07:54:45 +08:00
|
|
|
{
|
2014-01-03 07:15:25 +08:00
|
|
|
if (shell->line_position != 0)
|
|
|
|
{
|
|
|
|
/* push history */
|
|
|
|
if (shell->history_count >= FINSH_HISTORY_LINES)
|
|
|
|
{
|
2017-10-13 10:21:40 +08:00
|
|
|
/* if current cmd is same as last cmd, don't push */
|
2017-11-01 10:25:17 +08:00
|
|
|
if (memcmp(&shell->cmd_history[FINSH_HISTORY_LINES - 1], shell->line, FINSH_CMD_SIZE))
|
2014-01-03 07:15:25 +08:00
|
|
|
{
|
2017-10-13 10:21:40 +08:00
|
|
|
/* move history */
|
|
|
|
int index;
|
|
|
|
for (index = 0; index < FINSH_HISTORY_LINES - 1; index ++)
|
|
|
|
{
|
2021-12-31 08:38:20 +08:00
|
|
|
rt_memcpy(&shell->cmd_history[index][0],
|
2017-10-13 10:21:40 +08:00
|
|
|
&shell->cmd_history[index + 1][0], FINSH_CMD_SIZE);
|
|
|
|
}
|
2021-12-31 08:38:20 +08:00
|
|
|
rt_memset(&shell->cmd_history[index][0], 0, FINSH_CMD_SIZE);
|
|
|
|
rt_memcpy(&shell->cmd_history[index][0], shell->line, shell->line_position);
|
2014-01-03 07:15:25 +08:00
|
|
|
|
2017-10-13 10:21:40 +08:00
|
|
|
/* it's the maximum history */
|
|
|
|
shell->history_count = FINSH_HISTORY_LINES;
|
|
|
|
}
|
2014-01-03 07:15:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-13 10:21:40 +08:00
|
|
|
/* if current cmd is same as last cmd, don't push */
|
2017-11-01 10:25:17 +08:00
|
|
|
if (shell->history_count == 0 || memcmp(&shell->cmd_history[shell->history_count - 1], shell->line, FINSH_CMD_SIZE))
|
2017-10-13 10:21:40 +08:00
|
|
|
{
|
|
|
|
shell->current_history = shell->history_count;
|
2021-12-31 08:38:20 +08:00
|
|
|
rt_memset(&shell->cmd_history[shell->history_count][0], 0, FINSH_CMD_SIZE);
|
|
|
|
rt_memcpy(&shell->cmd_history[shell->history_count][0], shell->line, shell->line_position);
|
2014-01-03 07:15:25 +08:00
|
|
|
|
2017-10-13 10:21:40 +08:00
|
|
|
/* increase count and set current history position */
|
|
|
|
shell->history_count ++;
|
|
|
|
}
|
2014-01-03 07:15:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
shell->current_history = shell->history_count;
|
2010-05-26 07:54:45 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-09-24 11:06:26 +08:00
|
|
|
void finsh_thread_entry(void *parameter)
|
2010-05-26 07:54:45 +08:00
|
|
|
{
|
2019-02-21 21:18:30 +08:00
|
|
|
int ch;
|
2010-05-26 07:54:45 +08:00
|
|
|
|
2014-01-03 07:15:25 +08:00
|
|
|
/* normal is echo mode */
|
2018-03-16 16:26:22 +08:00
|
|
|
#ifndef FINSH_ECHO_DISABLE_DEFAULT
|
2018-03-15 12:13:40 +08:00
|
|
|
shell->echo_mode = 1;
|
|
|
|
#else
|
|
|
|
shell->echo_mode = 0;
|
|
|
|
#endif
|
2010-05-26 07:54:45 +08:00
|
|
|
|
2022-01-03 06:51:44 +08:00
|
|
|
#if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE)
|
2014-01-03 07:15:25 +08:00
|
|
|
/* set console device as shell device */
|
|
|
|
if (shell->device == RT_NULL)
|
|
|
|
{
|
2017-10-10 14:27:34 +08:00
|
|
|
rt_device_t console = rt_console_get_device();
|
|
|
|
if (console)
|
|
|
|
{
|
|
|
|
finsh_set_device(console->parent.name);
|
|
|
|
}
|
2014-01-03 07:15:25 +08:00
|
|
|
}
|
2022-01-03 06:51:44 +08:00
|
|
|
#endif /* !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE) */
|
2014-01-03 07:15:25 +08:00
|
|
|
|
2016-11-26 15:23:12 +08:00
|
|
|
#ifdef FINSH_USING_AUTH
|
|
|
|
/* set the default password when the password isn't setting */
|
|
|
|
if (rt_strlen(finsh_get_password()) == 0)
|
2017-08-30 20:42:36 +08:00
|
|
|
{
|
|
|
|
if (finsh_set_password(FINSH_DEFAULT_PASSWORD) != RT_EOK)
|
|
|
|
{
|
|
|
|
rt_kprintf("Finsh password set failed.\n");
|
|
|
|
}
|
|
|
|
}
|
2016-11-26 15:23:12 +08:00
|
|
|
/* waiting authenticate success */
|
|
|
|
finsh_wait_auth();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
rt_kprintf(FINSH_PROMPT);
|
|
|
|
|
2014-01-03 07:15:25 +08:00
|
|
|
while (1)
|
|
|
|
{
|
2021-08-21 06:14:37 +08:00
|
|
|
ch = (int)finsh_getchar();
|
2019-02-21 21:18:30 +08:00
|
|
|
if (ch < 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2017-10-10 14:27:34 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* handle control key
|
|
|
|
* up key : 0x1b 0x5b 0x41
|
|
|
|
* down key: 0x1b 0x5b 0x42
|
|
|
|
* right key:0x1b 0x5b 0x43
|
|
|
|
* left key: 0x1b 0x5b 0x44
|
|
|
|
*/
|
|
|
|
if (ch == 0x1b)
|
|
|
|
{
|
|
|
|
shell->stat = WAIT_SPEC_KEY;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (shell->stat == WAIT_SPEC_KEY)
|
2014-01-03 07:15:25 +08:00
|
|
|
{
|
2017-10-10 14:27:34 +08:00
|
|
|
if (ch == 0x5b)
|
2014-01-03 07:15:25 +08:00
|
|
|
{
|
2017-10-10 14:27:34 +08:00
|
|
|
shell->stat = WAIT_FUNC_KEY;
|
2014-01-03 07:15:25 +08:00
|
|
|
continue;
|
|
|
|
}
|
2017-10-10 14:27:34 +08:00
|
|
|
|
|
|
|
shell->stat = WAIT_NORMAL;
|
|
|
|
}
|
|
|
|
else if (shell->stat == WAIT_FUNC_KEY)
|
|
|
|
{
|
|
|
|
shell->stat = WAIT_NORMAL;
|
|
|
|
|
|
|
|
if (ch == 0x41) /* up key */
|
2014-01-03 07:15:25 +08:00
|
|
|
{
|
2017-10-10 14:27:34 +08:00
|
|
|
#ifdef FINSH_USING_HISTORY
|
|
|
|
/* prev history */
|
|
|
|
if (shell->current_history > 0)
|
|
|
|
shell->current_history --;
|
|
|
|
else
|
2014-01-03 07:15:25 +08:00
|
|
|
{
|
2017-10-10 14:27:34 +08:00
|
|
|
shell->current_history = 0;
|
2014-01-03 07:15:25 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-10-10 14:27:34 +08:00
|
|
|
/* copy the history command */
|
2021-12-31 08:38:20 +08:00
|
|
|
rt_memcpy(shell->line, &shell->cmd_history[shell->current_history][0],
|
2017-10-10 14:27:34 +08:00
|
|
|
FINSH_CMD_SIZE);
|
|
|
|
shell->line_curpos = shell->line_position = strlen(shell->line);
|
|
|
|
shell_handle_history(shell);
|
|
|
|
#endif
|
|
|
|
continue;
|
2014-01-03 07:15:25 +08:00
|
|
|
}
|
2017-10-10 14:27:34 +08:00
|
|
|
else if (ch == 0x42) /* down key */
|
2014-01-03 07:15:25 +08:00
|
|
|
{
|
2013-10-16 14:54:13 +08:00
|
|
|
#ifdef FINSH_USING_HISTORY
|
2017-10-10 14:27:34 +08:00
|
|
|
/* next history */
|
|
|
|
if (shell->current_history < shell->history_count - 1)
|
|
|
|
shell->current_history ++;
|
|
|
|
else
|
2014-01-03 07:15:25 +08:00
|
|
|
{
|
2017-10-10 14:27:34 +08:00
|
|
|
/* set to the end of history */
|
|
|
|
if (shell->history_count != 0)
|
|
|
|
shell->current_history = shell->history_count - 1;
|
2014-01-03 07:15:25 +08:00
|
|
|
else
|
2017-10-10 14:27:34 +08:00
|
|
|
continue;
|
2014-01-03 07:15:25 +08:00
|
|
|
}
|
|
|
|
|
2021-12-31 08:38:20 +08:00
|
|
|
rt_memcpy(shell->line, &shell->cmd_history[shell->current_history][0],
|
2017-10-10 14:27:34 +08:00
|
|
|
FINSH_CMD_SIZE);
|
|
|
|
shell->line_curpos = shell->line_position = strlen(shell->line);
|
|
|
|
shell_handle_history(shell);
|
|
|
|
#endif
|
|
|
|
continue;
|
2014-01-03 07:15:25 +08:00
|
|
|
}
|
2017-10-10 14:27:34 +08:00
|
|
|
else if (ch == 0x44) /* left key */
|
2014-01-03 07:15:25 +08:00
|
|
|
{
|
2017-10-10 14:27:34 +08:00
|
|
|
if (shell->line_curpos)
|
2015-09-24 11:06:26 +08:00
|
|
|
{
|
2014-01-03 07:15:25 +08:00
|
|
|
rt_kprintf("\b");
|
2017-10-10 14:27:34 +08:00
|
|
|
shell->line_curpos --;
|
|
|
|
}
|
2014-01-03 07:15:25 +08:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
2017-10-10 14:27:34 +08:00
|
|
|
else if (ch == 0x43) /* right key */
|
2014-01-03 07:15:25 +08:00
|
|
|
{
|
2017-10-10 14:27:34 +08:00
|
|
|
if (shell->line_curpos < shell->line_position)
|
2014-01-03 07:15:25 +08:00
|
|
|
{
|
2017-10-10 14:27:34 +08:00
|
|
|
rt_kprintf("%c", shell->line[shell->line_curpos]);
|
|
|
|
shell->line_curpos ++;
|
2014-01-03 07:15:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
2017-10-10 14:27:34 +08:00
|
|
|
}
|
2014-01-03 07:15:25 +08:00
|
|
|
|
2018-02-23 15:24:27 +08:00
|
|
|
/* received null or error */
|
|
|
|
if (ch == '\0' || ch == 0xFF) continue;
|
2017-10-10 14:27:34 +08:00
|
|
|
/* handle tab key */
|
|
|
|
else if (ch == '\t')
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
/* move the cursor to the beginning of line */
|
|
|
|
for (i = 0; i < shell->line_curpos; i++)
|
|
|
|
rt_kprintf("\b");
|
2014-01-03 07:15:25 +08:00
|
|
|
|
2017-10-10 14:27:34 +08:00
|
|
|
/* auto complete */
|
|
|
|
shell_auto_complete(&shell->line[0]);
|
|
|
|
/* re-calculate position */
|
|
|
|
shell->line_curpos = shell->line_position = strlen(shell->line);
|
2014-01-03 07:15:25 +08:00
|
|
|
|
2017-10-10 14:27:34 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* handle backspace key */
|
|
|
|
else if (ch == 0x7f || ch == 0x08)
|
|
|
|
{
|
|
|
|
/* note that shell->line_curpos >= 0 */
|
|
|
|
if (shell->line_curpos == 0)
|
|
|
|
continue;
|
2014-01-03 07:15:25 +08:00
|
|
|
|
2017-10-10 14:27:34 +08:00
|
|
|
shell->line_position--;
|
|
|
|
shell->line_curpos--;
|
2014-01-03 07:15:25 +08:00
|
|
|
|
2017-10-10 14:27:34 +08:00
|
|
|
if (shell->line_position > shell->line_curpos)
|
2014-01-03 07:15:25 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2017-10-10 14:27:34 +08:00
|
|
|
rt_memmove(&shell->line[shell->line_curpos],
|
|
|
|
&shell->line[shell->line_curpos + 1],
|
2014-01-03 07:15:25 +08:00
|
|
|
shell->line_position - shell->line_curpos);
|
2017-10-10 14:27:34 +08:00
|
|
|
shell->line[shell->line_position] = 0;
|
|
|
|
|
|
|
|
rt_kprintf("\b%s \b", &shell->line[shell->line_curpos]);
|
2014-01-03 07:15:25 +08:00
|
|
|
|
2017-10-10 14:27:34 +08:00
|
|
|
/* move the cursor to the origin position */
|
|
|
|
for (i = shell->line_curpos; i <= shell->line_position; i++)
|
2014-01-03 07:15:25 +08:00
|
|
|
rt_kprintf("\b");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-10 14:27:34 +08:00
|
|
|
rt_kprintf("\b \b");
|
|
|
|
shell->line[shell->line_position] = 0;
|
2014-01-03 07:15:25 +08:00
|
|
|
}
|
|
|
|
|
2017-10-10 14:27:34 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle end of line, break */
|
|
|
|
if (ch == '\r' || ch == '\n')
|
|
|
|
{
|
|
|
|
#ifdef FINSH_USING_HISTORY
|
|
|
|
shell_push_history(shell);
|
|
|
|
#endif
|
2021-08-23 17:30:05 +08:00
|
|
|
if (shell->echo_mode)
|
|
|
|
rt_kprintf("\n");
|
|
|
|
msh_exec(shell->line, shell->line_position);
|
2017-10-10 14:27:34 +08:00
|
|
|
|
|
|
|
rt_kprintf(FINSH_PROMPT);
|
2021-12-31 08:38:20 +08:00
|
|
|
rt_memset(shell->line, 0, sizeof(shell->line));
|
2017-10-10 14:27:34 +08:00
|
|
|
shell->line_curpos = shell->line_position = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* it's a large line, discard it */
|
|
|
|
if (shell->line_position >= FINSH_CMD_SIZE)
|
|
|
|
shell->line_position = 0;
|
|
|
|
|
|
|
|
/* normal character */
|
|
|
|
if (shell->line_curpos < shell->line_position)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
rt_memmove(&shell->line[shell->line_curpos + 1],
|
|
|
|
&shell->line[shell->line_curpos],
|
|
|
|
shell->line_position - shell->line_curpos);
|
|
|
|
shell->line[shell->line_curpos] = ch;
|
|
|
|
if (shell->echo_mode)
|
|
|
|
rt_kprintf("%s", &shell->line[shell->line_curpos]);
|
|
|
|
|
|
|
|
/* move the cursor to new position */
|
|
|
|
for (i = shell->line_curpos; i < shell->line_position; i++)
|
|
|
|
rt_kprintf("\b");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
shell->line[shell->line_position] = ch;
|
|
|
|
if (shell->echo_mode)
|
|
|
|
rt_kprintf("%c", ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
ch = 0;
|
|
|
|
shell->line_position ++;
|
|
|
|
shell->line_curpos++;
|
|
|
|
if (shell->line_position >= FINSH_CMD_SIZE)
|
|
|
|
{
|
|
|
|
/* clear command line */
|
|
|
|
shell->line_position = 0;
|
|
|
|
shell->line_curpos = 0;
|
|
|
|
}
|
|
|
|
} /* end of device read */
|
2009-07-03 06:48:23 +08:00
|
|
|
}
|
|
|
|
|
2015-09-24 11:06:26 +08:00
|
|
|
void finsh_system_function_init(const void *begin, const void *end)
|
2009-07-03 06:48:23 +08:00
|
|
|
{
|
2015-09-24 11:06:26 +08:00
|
|
|
_syscall_table_begin = (struct finsh_syscall *) begin;
|
|
|
|
_syscall_table_end = (struct finsh_syscall *) end;
|
2009-07-03 06:48:23 +08:00
|
|
|
}
|
|
|
|
|
2014-11-12 01:09:43 +08:00
|
|
|
#if defined(__ICCARM__) || defined(__ICCRX__) /* for IAR compiler */
|
2015-09-24 11:06:26 +08:00
|
|
|
#ifdef FINSH_USING_SYMTAB
|
2021-08-23 17:30:05 +08:00
|
|
|
#pragma section="FSymTab"
|
2015-09-24 11:06:26 +08:00
|
|
|
#endif
|
2012-05-30 14:50:06 +08:00
|
|
|
#elif defined(__ADSPBLACKFIN__) /* for VisaulDSP++ Compiler*/
|
2015-09-24 11:06:26 +08:00
|
|
|
#ifdef FINSH_USING_SYMTAB
|
2021-08-23 17:30:05 +08:00
|
|
|
extern "asm" int __fsymtab_start;
|
|
|
|
extern "asm" int __fsymtab_end;
|
2015-09-24 11:06:26 +08:00
|
|
|
#endif
|
2012-10-22 11:12:21 +08:00
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
#pragma section("FSymTab$a", read)
|
|
|
|
const char __fsym_begin_name[] = "__start";
|
|
|
|
const char __fsym_begin_desc[] = "begin of finsh";
|
2015-09-24 11:06:26 +08:00
|
|
|
__declspec(allocate("FSymTab$a")) const struct finsh_syscall __fsym_begin =
|
2012-10-22 11:12:21 +08:00
|
|
|
{
|
2014-01-03 07:15:25 +08:00
|
|
|
__fsym_begin_name,
|
|
|
|
__fsym_begin_desc,
|
|
|
|
NULL
|
2012-10-22 11:12:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#pragma section("FSymTab$z", read)
|
|
|
|
const char __fsym_end_name[] = "__end";
|
|
|
|
const char __fsym_end_desc[] = "end of finsh";
|
2015-09-24 11:06:26 +08:00
|
|
|
__declspec(allocate("FSymTab$z")) const struct finsh_syscall __fsym_end =
|
2012-10-22 11:12:21 +08:00
|
|
|
{
|
2014-01-03 07:15:25 +08:00
|
|
|
__fsym_end_name,
|
|
|
|
__fsym_end_desc,
|
|
|
|
NULL
|
2012-10-22 11:12:21 +08:00
|
|
|
};
|
2010-05-26 07:54:45 +08:00
|
|
|
#endif
|
2010-11-29 08:04:55 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @ingroup finsh
|
|
|
|
*
|
|
|
|
* This function will initialize finsh shell
|
|
|
|
*/
|
2013-06-23 07:48:42 +08:00
|
|
|
int finsh_system_init(void)
|
2009-07-03 06:48:23 +08:00
|
|
|
{
|
2018-04-23 13:28:44 +08:00
|
|
|
rt_err_t result = RT_EOK;
|
|
|
|
rt_thread_t tid;
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
#ifdef FINSH_USING_SYMTAB
|
2021-06-13 17:36:42 +08:00
|
|
|
#ifdef __ARMCC_VERSION /* ARM C Compiler */
|
2011-09-02 18:54:01 +08:00
|
|
|
extern const int FSymTab$$Base;
|
|
|
|
extern const int FSymTab$$Limit;
|
2014-01-03 07:15:25 +08:00
|
|
|
finsh_system_function_init(&FSymTab$$Base, &FSymTab$$Limit);
|
2014-11-12 01:09:43 +08:00
|
|
|
#elif defined (__ICCARM__) || defined(__ICCRX__) /* for IAR Compiler */
|
2009-07-03 06:48:23 +08:00
|
|
|
finsh_system_function_init(__section_begin("FSymTab"),
|
|
|
|
__section_end("FSymTab"));
|
2021-03-26 17:39:40 +08:00
|
|
|
#elif defined (__GNUC__) || defined(__TI_COMPILER_VERSION__) || defined(__TASKING__)
|
2013-05-29 23:37:43 +08:00
|
|
|
/* GNU GCC Compiler and TI CCS */
|
2014-01-03 07:15:25 +08:00
|
|
|
extern const int __fsymtab_start;
|
|
|
|
extern const int __fsymtab_end;
|
|
|
|
finsh_system_function_init(&__fsymtab_start, &__fsymtab_end);
|
2012-05-30 14:50:06 +08:00
|
|
|
#elif defined(__ADSPBLACKFIN__) /* for VisualDSP++ Compiler */
|
|
|
|
finsh_system_function_init(&__fsymtab_start, &__fsymtab_end);
|
2012-10-22 11:12:21 +08:00
|
|
|
#elif defined(_MSC_VER)
|
2014-01-03 07:15:25 +08:00
|
|
|
unsigned int *ptr_begin, *ptr_end;
|
2021-03-08 18:19:04 +08:00
|
|
|
|
2021-08-23 17:30:05 +08:00
|
|
|
if (shell)
|
2018-07-17 12:52:02 +08:00
|
|
|
{
|
|
|
|
rt_kprintf("finsh shell already init.\n");
|
|
|
|
return RT_EOK;
|
|
|
|
}
|
2012-10-22 11:12:21 +08:00
|
|
|
|
2015-09-24 11:06:26 +08:00
|
|
|
ptr_begin = (unsigned int *)&__fsym_begin;
|
|
|
|
ptr_begin += (sizeof(struct finsh_syscall) / sizeof(unsigned int));
|
2014-01-03 07:15:25 +08:00
|
|
|
while (*ptr_begin == 0) ptr_begin ++;
|
2012-10-22 11:12:21 +08:00
|
|
|
|
2015-09-24 11:06:26 +08:00
|
|
|
ptr_end = (unsigned int *) &__fsym_end;
|
|
|
|
ptr_end --;
|
2014-01-03 07:15:25 +08:00
|
|
|
while (*ptr_end == 0) ptr_end --;
|
2012-10-22 11:12:21 +08:00
|
|
|
|
2014-01-03 07:15:25 +08:00
|
|
|
finsh_system_function_init(ptr_begin, ptr_end);
|
2009-07-03 06:48:23 +08:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2010-05-26 07:54:45 +08:00
|
|
|
#ifdef RT_USING_HEAP
|
2018-04-23 13:28:44 +08:00
|
|
|
/* create or set shell structure */
|
|
|
|
shell = (struct finsh_shell *)rt_calloc(1, sizeof(struct finsh_shell));
|
2014-01-03 07:15:25 +08:00
|
|
|
if (shell == RT_NULL)
|
|
|
|
{
|
|
|
|
rt_kprintf("no memory for shell\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2018-04-23 13:28:44 +08:00
|
|
|
tid = rt_thread_create(FINSH_THREAD_NAME,
|
|
|
|
finsh_thread_entry, RT_NULL,
|
|
|
|
FINSH_THREAD_STACK_SIZE, FINSH_THREAD_PRIORITY, 10);
|
2014-01-01 23:14:45 +08:00
|
|
|
#else
|
2014-01-03 07:15:25 +08:00
|
|
|
shell = &_shell;
|
2018-04-23 13:28:44 +08:00
|
|
|
tid = &finsh_thread;
|
2014-01-03 07:15:25 +08:00
|
|
|
result = rt_thread_init(&finsh_thread,
|
2018-01-12 17:19:57 +08:00
|
|
|
FINSH_THREAD_NAME,
|
2015-09-24 11:06:26 +08:00
|
|
|
finsh_thread_entry, RT_NULL,
|
|
|
|
&finsh_thread_stack[0], sizeof(finsh_thread_stack),
|
|
|
|
FINSH_THREAD_PRIORITY, 10);
|
2018-04-23 13:28:44 +08:00
|
|
|
#endif /* RT_USING_HEAP */
|
|
|
|
|
|
|
|
rt_sem_init(&(shell->rx_sem), "shrx", 0, 0);
|
2018-07-02 19:46:37 +08:00
|
|
|
finsh_set_prompt_mode(1);
|
2010-04-01 07:20:10 +08:00
|
|
|
|
2018-04-23 13:28:44 +08:00
|
|
|
if (tid != NULL && result == RT_EOK)
|
|
|
|
rt_thread_startup(tid);
|
2014-01-03 07:15:25 +08:00
|
|
|
return 0;
|
2009-07-03 06:48:23 +08:00
|
|
|
}
|
2017-10-10 14:27:34 +08:00
|
|
|
INIT_APP_EXPORT(finsh_system_init);
|
2018-11-07 14:31:32 +08:00
|
|
|
|
|
|
|
#endif /* RT_USING_FINSH */
|
|
|
|
|