2012-09-20 13:07:14 +08:00
|
|
|
/*
|
2013-03-30 16:14:38 +08:00
|
|
|
* shell implementation for finsh shell.
|
2012-09-20 13:07:14 +08:00
|
|
|
*
|
2013-03-30 16:14:38 +08:00
|
|
|
* COPYRIGHT (C) 2006 - 2013, RT-Thread Development Team
|
|
|
|
*
|
|
|
|
* This file is part of RT-Thread (http://www.rt-thread.org)
|
|
|
|
* Maintainer: bernard.xiong <bernard.xiong at gmail.com>
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
2012-09-20 13:07:14 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2011-06-02 Bernard Add finsh_get_prompt function declaration
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __SHELL_H__
|
|
|
|
#define __SHELL_H__
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
2013-01-08 22:40:58 +08:00
|
|
|
#include "finsh.h"
|
2012-09-20 13:07:14 +08:00
|
|
|
|
2014-10-21 16:01:08 +08:00
|
|
|
/* 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
|
|
|
|
|
2012-09-20 13:07:14 +08:00
|
|
|
#ifndef FINSH_THREAD_PRIORITY
|
|
|
|
#define FINSH_THREAD_PRIORITY 20
|
|
|
|
#endif
|
|
|
|
#ifndef FINSH_THREAD_STACK_SIZE
|
|
|
|
#define FINSH_THREAD_STACK_SIZE 2048
|
|
|
|
#endif
|
2015-10-09 09:26:17 +08:00
|
|
|
#ifndef FINSH_CMD_SIZE
|
2012-09-20 13:07:14 +08:00
|
|
|
#define FINSH_CMD_SIZE 80
|
2015-10-09 09:26:17 +08:00
|
|
|
#endif
|
2012-09-20 13:07:14 +08:00
|
|
|
|
|
|
|
#define FINSH_OPTION_ECHO 0x01
|
2014-04-08 15:12:44 +08:00
|
|
|
#if defined(FINSH_USING_MSH) || (defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR))
|
2012-09-20 13:07:14 +08:00
|
|
|
#define FINSH_PROMPT finsh_get_prompt()
|
|
|
|
const char* finsh_get_prompt(void);
|
|
|
|
#else
|
|
|
|
#define FINSH_PROMPT "finsh>>"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef FINSH_USING_HISTORY
|
2013-10-16 14:54:13 +08:00
|
|
|
#ifndef FINSH_HISTORY_LINES
|
|
|
|
#define FINSH_HISTORY_LINES 5
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2012-09-20 13:07:14 +08:00
|
|
|
enum input_stat
|
|
|
|
{
|
|
|
|
WAIT_NORMAL,
|
|
|
|
WAIT_SPEC_KEY,
|
|
|
|
WAIT_FUNC_KEY,
|
|
|
|
};
|
|
|
|
struct finsh_shell
|
|
|
|
{
|
|
|
|
struct rt_semaphore rx_sem;
|
|
|
|
|
|
|
|
enum input_stat stat;
|
|
|
|
|
|
|
|
rt_uint8_t echo_mode:1;
|
|
|
|
|
|
|
|
#ifdef FINSH_USING_HISTORY
|
2012-12-29 12:12:14 +08:00
|
|
|
rt_uint16_t current_history;
|
2012-09-20 13:07:14 +08:00
|
|
|
rt_uint16_t history_count;
|
|
|
|
|
|
|
|
char cmd_history[FINSH_HISTORY_LINES][FINSH_CMD_SIZE];
|
|
|
|
#endif
|
|
|
|
|
2014-01-01 23:14:45 +08:00
|
|
|
#ifndef FINSH_USING_MSH_ONLY
|
2012-09-20 13:07:14 +08:00
|
|
|
struct finsh_parser parser;
|
2014-01-01 23:14:45 +08:00
|
|
|
#endif
|
2012-09-20 13:07:14 +08:00
|
|
|
|
|
|
|
char line[FINSH_CMD_SIZE];
|
|
|
|
rt_uint8_t line_position;
|
2013-10-16 14:54:13 +08:00
|
|
|
rt_uint8_t line_curpos;
|
2012-09-20 13:07:14 +08:00
|
|
|
|
|
|
|
rt_device_t device;
|
|
|
|
};
|
|
|
|
|
|
|
|
void finsh_set_echo(rt_uint32_t echo);
|
|
|
|
rt_uint32_t finsh_get_echo(void);
|
|
|
|
|
2013-06-23 07:48:42 +08:00
|
|
|
int finsh_system_init(void);
|
2012-09-20 13:07:14 +08:00
|
|
|
void finsh_set_device(const char* device_name);
|
|
|
|
const char* finsh_get_device(void);
|
|
|
|
|
|
|
|
#endif
|