shell.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * shell implementation for finsh shell.
  3. *
  4. * COPYRIGHT (C) 2006 - 2013, RT-Thread Development Team
  5. *
  6. * This file is part of RT-Thread (http://www.rt-thread.org)
  7. * Maintainer: bernard.xiong <bernard.xiong at gmail.com>
  8. *
  9. * All rights reserved.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License along
  22. * with this program; if not, write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  24. *
  25. * Change Logs:
  26. * Date Author Notes
  27. * 2011-06-02 Bernard Add finsh_get_prompt function declaration
  28. */
  29. #ifndef __SHELL_H__
  30. #define __SHELL_H__
  31. #include <rtthread.h>
  32. #include "finsh.h"
  33. /* For historical reasons, users don't define FINSH_USING_HISTORY in rtconfig.h
  34. * but expect the history feature. So you sould define FINSH_USING_HISTORY to 0
  35. * to disable it from the rtconfig.h. */
  36. #ifdef FINSH_USING_HISTORY
  37. # if FINSH_USING_HISTORY == 0
  38. # undef FINSH_USING_HISTORY
  39. # endif
  40. #else
  41. # define FINSH_USING_HISTORY
  42. #endif
  43. #ifndef FINSH_THREAD_PRIORITY
  44. #define FINSH_THREAD_PRIORITY 20
  45. #endif
  46. #ifndef FINSH_THREAD_STACK_SIZE
  47. #define FINSH_THREAD_STACK_SIZE 2048
  48. #endif
  49. #ifndef FINSH_CMD_SIZE
  50. #define FINSH_CMD_SIZE 80
  51. #endif
  52. #define FINSH_OPTION_ECHO 0x01
  53. #if defined(FINSH_USING_MSH) || (defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR))
  54. #define FINSH_PROMPT finsh_get_prompt()
  55. const char* finsh_get_prompt(void);
  56. #else
  57. #define FINSH_PROMPT "finsh>>"
  58. #endif
  59. #ifdef FINSH_USING_HISTORY
  60. #ifndef FINSH_HISTORY_LINES
  61. #define FINSH_HISTORY_LINES 5
  62. #endif
  63. #endif
  64. enum input_stat
  65. {
  66. WAIT_NORMAL,
  67. WAIT_SPEC_KEY,
  68. WAIT_FUNC_KEY,
  69. };
  70. struct finsh_shell
  71. {
  72. struct rt_semaphore rx_sem;
  73. enum input_stat stat;
  74. rt_uint8_t echo_mode:1;
  75. #ifdef FINSH_USING_HISTORY
  76. rt_uint16_t current_history;
  77. rt_uint16_t history_count;
  78. char cmd_history[FINSH_HISTORY_LINES][FINSH_CMD_SIZE];
  79. #endif
  80. #ifndef FINSH_USING_MSH_ONLY
  81. struct finsh_parser parser;
  82. #endif
  83. char line[FINSH_CMD_SIZE];
  84. rt_uint8_t line_position;
  85. rt_uint8_t line_curpos;
  86. rt_device_t device;
  87. };
  88. void finsh_set_echo(rt_uint32_t echo);
  89. rt_uint32_t finsh_get_echo(void);
  90. int finsh_system_init(void);
  91. void finsh_set_device(const char* device_name);
  92. const char* finsh_get_device(void);
  93. #endif