shell.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*----------------------------------------------------------------------------
  2. * Copyright (c) <2018>, <Huawei Technologies Co., Ltd>
  3. * All rights reserved.
  4. * Redistribution and use in source and binary forms, with or without modification,
  5. * are permitted provided that the following conditions are met:
  6. * 1. Redistributions of source code must retain the above copyright notice, this list of
  7. * conditions and the following disclaimer.
  8. * 2. Redistributions in binary form must reproduce the above copyright notice, this list
  9. * of conditions and the following disclaimer in the documentation and/or other materials
  10. * provided with the distribution.
  11. * 3. Neither the name of the copyright holder nor the names of its contributors may be used
  12. * to endorse or promote products derived from this software without specific prior written
  13. * permission.
  14. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  15. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  16. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  18. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  21. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  22. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  23. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  24. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. *---------------------------------------------------------------------------*/
  26. /*----------------------------------------------------------------------------
  27. * Notice of Export Control Law
  28. * ===============================================
  29. * Huawei LiteOS may be subject to applicable export control laws and regulations, which might
  30. * include those applicable to Huawei LiteOS of U.S. and the country in which you are located.
  31. * Import, export and usage of Huawei LiteOS in any manner by you shall be in compliance with such
  32. * applicable export control laws and regulations.
  33. *---------------------------------------------------------------------------*/
  34. /**
  35. * DATE AUTHOR INSTRUCTION
  36. * 2019-05-14 17:22 zhangqianfu The first version
  37. *
  38. */
  39. #ifndef __OSSHELL_H
  40. #define __OSSHELL_H
  41. #include <stdint.h>
  42. #include <stddef.h>
  43. #include <link_log.h>
  44. #if CONFIG_SHELL_ENABLE
  45. //this is a shell module designed for the os
  46. //this is a shell type,maybe a command or the data variables
  47. enum en_os_shell_type
  48. {
  49. EN_OSSHELL_CMD = 0,
  50. EN_OSSHELL_VAR, //up till now, we only support 4 bytes
  51. EN_OSSHELL_LAST,
  52. };
  53. #define BUILD_VAR_NAME(A,B) A##B
  54. #define MAX_TAB_MATCHES 16
  55. struct shell_tab_matches
  56. {
  57. const char *matches[MAX_TAB_MATCHES];
  58. unsigned short len;
  59. };
  60. //this is the shell function module.the register function must have the same type
  61. //uptils now, we don't care the return value
  62. struct shell_item_t
  63. {
  64. const char *name; //point to the shell name string
  65. const char *help; //point to the shell description string
  66. void *addr; //point to the shell function or the shell data
  67. unsigned short type; //used to point the shell type:command or a data
  68. unsigned short len; //used to point the shell command or data length
  69. };
  70. //this define will create a shell command with the specified cmdname
  71. #define OSSHELL_EXPORT_CMD(cmdentry,cmdname,cmdhelp) \
  72. static const struct shell_item_t BUILD_VAR_NAME(__oshell_,cmdentry) __attribute__((used,section("oshell")))= \
  73. { \
  74. .name=cmdname, \
  75. .help=cmdhelp, \
  76. .addr=(void *)&cmdentry, \
  77. .type=EN_OSSHELL_CMD, \
  78. .len = sizeof(void *), \
  79. }
  80. //this define will create a create a shell data with the specified name
  81. #define OSSHELL_EXPORT_VAR(var,varname,varhelp) \
  82. static const struct shell_item_t BUILD_VAR_NAME(__oshell_,var) __attribute__((used,section("oshell")))= \
  83. { \
  84. .name=varname, \
  85. .help=varhelp, \
  86. .addr=(void *)&var, \
  87. .type=EN_OSSHELL_VAR, \
  88. .len =sizeof(var), \
  89. }
  90. void shell_init(void);
  91. #else
  92. #define OSSHELL_EXPORT_CMD(cmdentry,cmdname,cmdhelp)
  93. #define OSSHELL_EXPORT_VAR(var,varname,varhelp)
  94. #define shell_init()
  95. #endif //end for the shell_config
  96. #endif /* __OSSHELL_H */