1/* 2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this list of 9 * conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 * of conditions and the following disclaimer in the documentation and/or other materials 13 * provided with the distribution. 14 * 15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 16 * to endorse or promote products derived from this software without specific prior written 17 * permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#ifndef _HWLITEOS_SHELL_H 33#define _HWLITEOS_SHELL_H 34 35#include "pthread.h" 36#include "limits.h" 37#include "los_compiler.h" 38 39#ifdef __cplusplus 40#if __cplusplus 41extern "C" { 42#endif /* __cplusplus */ 43#endif /* __cplusplus */ 44 45#define OS_ERRNO_SHELL_NO_HOOK LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x00) 46#define OS_ERRNO_SHELL_CMDREG_PARA_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x01) 47#define OS_ERRNO_SHELL_CMDREG_CMD_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x02) 48#define OS_ERRNO_SHELL_CMDREG_CMD_EXIST LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x03) 49#define OS_ERRNO_SHELL_CMDREG_MEMALLOC_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x04) 50#define OS_ERRNO_SHELL_SHOW_HOOK_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x05) 51#define OS_ERRNO_SHELL_SHOW_HOOK_EXIST LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x06) 52#define OS_ERRNO_SHELL_SHOW_HOOK_TOO_MUCH LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x07) 53#define OS_ERRNO_SHELL_NOT_INIT LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x08) 54#define OS_ERRNO_SHELL_CMD_HOOK_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x09) 55#define OS_ERRNO_SHELL_FIFO_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x10) 56 57/* Max len of show str */ 58#define SHOW_MAX_LEN CMD_MAX_LEN 59 60#define XARGS 0xFFFFFFFF /* default args */ 61 62#define CMD_MAX_PARAS 32 63#define CMD_KEY_LEN 16U 64#define CMD_MAX_LEN (256U + CMD_KEY_LEN) 65#define CMD_KEY_NUM 32 66#define CMD_HISTORY_LEN 10 67#define CMD_MAX_PATH 256 68#define DEFAULT_SCREEN_WIDTH 80 69#define DEFAULT_SCREEN_HEIGNT 24 70 71#define SHELL_MODE 0 72#define OTHER_MODE 1 73 74#define SWITCH_QUOTES_STATUS(qu) do { \ 75 if ((qu) == TRUE) { \ 76 (qu) = FALSE; \ 77 } else { \ 78 (qu) = TRUE; \ 79 } \ 80} while (0) 81 82#define QUOTES_STATUS_CLOSE(qu) ((qu) == FALSE) 83#define QUOTES_STATUS_OPEN(qu) ((qu) == TRUE) 84 85typedef struct { 86 UINT32 consoleID; 87 UINT32 shellTaskHandle; 88 UINT32 shellEntryHandle; 89 VOID *cmdKeyLink; 90 VOID *cmdHistoryKeyLink; 91 VOID *cmdMaskKeyLink; 92 UINT32 shellBufOffset; 93 UINT32 shellKeyType; 94 pthread_mutex_t keyMutex; 95 pthread_mutex_t historyMutex; 96 CHAR shellBuf[SHOW_MAX_LEN]; 97 CHAR shellWorkingDirectory[PATH_MAX]; 98} ShellCB; 99 100/* All support cmd types */ 101typedef enum { 102 CMD_TYPE_SHOW = 0, 103 CMD_TYPE_STD = 1, 104 CMD_TYPE_EX = 2, 105 CMD_TYPE_BUTT 106} CmdType; 107 108typedef enum { 109 CMD_KEY_UP = 0, 110 CMD_KEY_DOWN = 1, 111 CMD_KEY_RIGHT = 2, 112 CMD_KEY_LEFT = 4, 113 CMD_KEY_BUTT 114} CmdKeyDirection; 115 116/* 117 * Hook for user-defined debug function 118 * Unify different module's func for registration 119 */ 120typedef UINT32 (*CmdCallBackFunc)(UINT32 argc, const CHAR **argv); 121 122/* External interface, need reserved */ 123typedef CmdCallBackFunc CMD_CBK_FUNC; 124typedef CmdType CMD_TYPE_E; 125 126extern UINT32 osCmdReg(CmdType cmdType, const CHAR *cmdKey, UINT32 paraNum, CmdCallBackFunc cmdProc); 127 128#ifdef __cplusplus 129#if __cplusplus 130} 131#endif /* __cplusplus */ 132#endif /* __cplusplus */ 133 134#endif /* _HWLITEOS_SHELL_H */ 135