shell.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #define FINSH_USING_HISTORY
  34. #ifndef FINSH_THREAD_PRIORITY
  35. #define FINSH_THREAD_PRIORITY 20
  36. #endif
  37. #ifndef FINSH_THREAD_STACK_SIZE
  38. #define FINSH_THREAD_STACK_SIZE 2048
  39. #endif
  40. #define FINSH_CMD_SIZE 80
  41. #define FINSH_OPTION_ECHO 0x01
  42. #if defined(FINSH_USING_MSH) || (defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR))
  43. #define FINSH_PROMPT finsh_get_prompt()
  44. const char* finsh_get_prompt(void);
  45. #else
  46. #define FINSH_PROMPT "finsh>>"
  47. #endif
  48. #ifdef FINSH_USING_HISTORY
  49. #ifndef FINSH_HISTORY_LINES
  50. #define FINSH_HISTORY_LINES 5
  51. #endif
  52. #endif
  53. enum input_stat
  54. {
  55. WAIT_NORMAL,
  56. WAIT_SPEC_KEY,
  57. WAIT_FUNC_KEY,
  58. };
  59. struct finsh_shell
  60. {
  61. struct rt_semaphore rx_sem;
  62. enum input_stat stat;
  63. rt_uint8_t echo_mode:1;
  64. #ifdef FINSH_USING_HISTORY
  65. rt_uint16_t current_history;
  66. rt_uint16_t history_count;
  67. char cmd_history[FINSH_HISTORY_LINES][FINSH_CMD_SIZE];
  68. #endif
  69. #ifndef FINSH_USING_MSH_ONLY
  70. struct finsh_parser parser;
  71. #endif
  72. char line[FINSH_CMD_SIZE];
  73. rt_uint8_t line_position;
  74. rt_uint8_t line_curpos;
  75. rt_device_t device;
  76. };
  77. void finsh_set_echo(rt_uint32_t echo);
  78. rt_uint32_t finsh_get_echo(void);
  79. int finsh_system_init(void);
  80. void finsh_set_device(const char* device_name);
  81. const char* finsh_get_device(void);
  82. #endif