shmsg.c 18.1 KB
Newer Older
1
/*
2 3
 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this list of
 *    conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
 *    of conditions and the following disclaimer in the documentation and/or other materials
 *    provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
 *    to endorse or promote products derived from this software without specific prior written
 *    permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "shmsg.h"
#include "shell_pri.h"
#include "shcmd.h"
#include "stdlib.h"
#include "stdio.h"
#include "unistd.h"
#include "securec.h"
#include "los_base.h"
#include "los_task.h"
#include "los_event.h"
#include "los_list.h"
#include "los_printf.h"

#ifdef LOSCFG_FS_VFS
#include "console.h"
#endif

49
//获取输入命令buf
50 51
CHAR *ShellGetInputBuf(ShellCB *shellCB)
{
52
    CmdKeyLink *cmdkey = shellCB->cmdKeyLink;//待处理的shell命令链表
53 54 55
    CmdKeyLink *cmdNode = NULL;

    (VOID)pthread_mutex_lock(&shellCB->keyMutex);
56
    if ((cmdkey == NULL) || LOS_ListEmpty(&cmdkey->list)) {//链表为空的处理
57 58 59 60
        (VOID)pthread_mutex_unlock(&shellCB->keyMutex);
        return NULL;
    }

61 62
    cmdNode = LOS_DL_LIST_ENTRY(cmdkey->list.pstNext, CmdKeyLink, list);//获取当前命令项
    LOS_ListDelete(&(cmdNode->list)); /* 'cmdNode' freed in history save process *///将自己摘出去,但在历史记录中还存在
63 64
    (VOID)pthread_mutex_unlock(&shellCB->keyMutex);

65
    return cmdNode->cmdString;//返回命令内容
66
}
67
///保存命令历史记录,这个函数写的不太好
68 69
STATIC VOID ShellSaveHistoryCmd(const CHAR *string, ShellCB *shellCB)
{
70 71
    CmdKeyLink *cmdHistory = shellCB->cmdHistoryKeyLink;//获取历史记录的源头
    CmdKeyLink *cmdkey = LOS_DL_LIST_ENTRY(string, CmdKeyLink, cmdString);// @note_good ,获取CmdKeyLink,这里挺秒的,通过局部字符串找到整体
72 73 74 75 76 77
    CmdKeyLink *cmdNxt = NULL;

    if ((string == NULL) || (strlen(string) == 0)) {
        return;
    }

78 79 80 81
    (VOID)pthread_mutex_lock(&shellCB->historyMutex);//对链表的操作都要拿互斥锁
    if (cmdHistory->count != 0) { //有历史记录的情况
        cmdNxt = LOS_DL_LIST_ENTRY(cmdHistory->list.pstPrev, CmdKeyLink, list);//获取最老的历史记录
        if (strcmp(string, cmdNxt->cmdString) == 0) {//比较是否一样,这个地方感觉很怪,只比较一个吗?
82 83 84 85 86 87
            (VOID)LOS_MemFree(m_aucSysMem0, (VOID *)cmdkey);
            (VOID)pthread_mutex_unlock(&shellCB->historyMutex);
            return;
        }
    }

88 89 90 91 92 93
    if (cmdHistory->count == CMD_HISTORY_LEN) {//历史记录已满,一删一添导致历史记录永远是满的,所以一旦跑进来了
        cmdNxt = LOS_DL_LIST_ENTRY(cmdHistory->list.pstNext, CmdKeyLink, list);//后续 ShellSaveHistoryCmd都会跑进来执行
        LOS_ListDelete(&(cmdNxt->list));//先删除一个最早插入的
        LOS_ListTailInsert(&(cmdHistory->list), &(cmdkey->list));//再从尾部挂入新的节点,变成最新的记录
        (VOID)LOS_MemFree(m_aucSysMem0, (VOID *)cmdNxt);//释放已经删除的节点, @note_thinking     , 建议和上一句换个位置,保证逻辑上的完整性
        (VOID)pthread_mutex_unlock(&shellCB->historyMutex);//释放互斥锁
94 95
        return;
    }
96 97 98
	//未满的情况下执行到此处
    LOS_ListTailInsert(&(cmdHistory->list), &(cmdkey->list));//从尾部插入
    cmdHistory->count++;//历史记录增加
99

100
    (VOID)pthread_mutex_unlock(&shellCB->historyMutex);//释放互斥锁
101 102
    return;
}
103
///发送解析事件
104 105 106 107 108 109
STATIC VOID ShellNotify(ShellCB *shellCB)
{
    (VOID)LOS_EventWrite(&shellCB->shellEvent, SHELL_CMD_PARSE_EVENT);
}

enum {
110
    STAT_NORMAL_KEY,	///< 普通的按键
111 112
    STAT_ESC_KEY,	//<ESC>键在VT控制规范中时控制的起始键
    STAT_MULTI_KEY	//组合键
113
};
114
//解析上下左右键
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
/* https://www.cnblogs.com/Spiro-K/p/6592518.html
#!/bin/bash
#字符颜色显示
#-e:允许echo使用转义
#\033[:开始位
#\033[0m:结束位
#\033等同于\e
echo -e "\033[30m黑色字\033[0m"  
echo -e "\033[31m红色字\033[0m"  
echo -e "\033[32m绿色字\033[0m"  
echo -e "\033[33m黄色字\033[0m"  
echo -e "\033[34m蓝色字\033[0m"  
echo -e "\033[35m紫色字\033[0m"  
echo -e "\033[36m天蓝字\033[0m"  
echo -e "\033[37m白色字\033[0m" 
*/
131 132 133
STATIC INT32 ShellCmdLineCheckUDRL(const CHAR ch, ShellCB *shellCB)
{
    INT32 ret = LOS_OK;
134 135
    if (ch == 0x1b) { /* 0x1b: ESC *///按下<ESC>键(逃逸键)
        shellCB->shellKeyType = STAT_ESC_KEY;//代表控制开始
136
        return ret;
137
    } else if (ch == 0x5b) { /* 0x5b: first Key combination */ //为[键 ,遵循 vt100 规则
138 139 140 141
        if (shellCB->shellKeyType == STAT_ESC_KEY) {
            shellCB->shellKeyType = STAT_MULTI_KEY;
            return ret;
        }
142
    } else if (ch == 0x41) { /* up */	//上方向键
143 144
        if (shellCB->shellKeyType == STAT_MULTI_KEY) {
            OsShellHistoryShow(CMD_KEY_UP, shellCB);
145
            shellCB->shellKeyType = STAT_NORMAL_KEY;
146 147
            return ret;
        }
148
    } else if (ch == 0x42) { /* down *///下方向键
149
        if (shellCB->shellKeyType == STAT_MULTI_KEY) {
150
            shellCB->shellKeyType = STAT_NORMAL_KEY;
151 152 153
            OsShellHistoryShow(CMD_KEY_DOWN, shellCB);
            return ret;
        }
154
    } else if (ch == 0x43) { /* right *///右方向键
155
        if (shellCB->shellKeyType == STAT_MULTI_KEY) {
156
            shellCB->shellKeyType = STAT_NORMAL_KEY;
157 158
            return ret;
        }
159
    } else if (ch == 0x44) { /* left *///左方向键
160
        if (shellCB->shellKeyType == STAT_MULTI_KEY) {
161
            shellCB->shellKeyType = STAT_NORMAL_KEY;
162 163 164 165 166
            return ret;
        }
    }
    return LOS_NOK;
}
167
///对命令行内容解析
168 169 170 171
LITE_OS_SEC_TEXT_MINOR VOID ShellCmdLineParse(CHAR c, pf_OUTPUT outputFunc, ShellCB *shellCB)
{
    const CHAR ch = c;
    INT32 ret;
172
	//不是回车键和字符串结束,且偏移量为0
173
    if ((shellCB->shellBufOffset == 0) && (ch != '\n') && (ch != '\0')) {
174
        (VOID)memset_s(shellCB->shellBuf, SHOW_MAX_LEN, 0, SHOW_MAX_LEN);//重置buf
175
    }
176
	//遇到回车或换行
177 178
    if ((ch == '\r') || (ch == '\n')) {
        if (shellCB->shellBufOffset < (SHOW_MAX_LEN - 1)) {
179
            shellCB->shellBuf[shellCB->shellBufOffset] = '\0';//字符串结束
180 181 182
        }
        shellCB->shellBufOffset = 0;
        (VOID)pthread_mutex_lock(&shellCB->keyMutex);
183
        OsShellCmdPush(shellCB->shellBuf, shellCB->cmdKeyLink);//解析回车或换行
184
        (VOID)pthread_mutex_unlock(&shellCB->keyMutex);
185
        ShellNotify(shellCB);//通知任务解析shell命令
186
        return;
187
    } else if ((ch == '\b') || (ch == 0x7F)) { /* backspace or delete(0x7F) */ //遇到删除键
188
        if ((shellCB->shellBufOffset > 0) && (shellCB->shellBufOffset < (SHOW_MAX_LEN - 1))) {
189 190 191
            shellCB->shellBuf[shellCB->shellBufOffset - 1] = '\0';//填充`\0`
            shellCB->shellBufOffset--;//buf减少
            outputFunc("\b \b");//回调入参函数
192 193
        }
        return;
194
    } else if (ch == 0x09) { /* 0x09: tab *///遇到tab键
195
        if ((shellCB->shellBufOffset > 0) && (shellCB->shellBufOffset < (SHOW_MAX_LEN - 1))) {
196
            ret = OsTabCompletion(shellCB->shellBuf, &shellCB->shellBufOffset);//解析tab键
197
            if (ret > 1) {
198
                outputFunc("OHOS # %s", shellCB->shellBuf);//回调入参函数
199 200 201 202 203
            }
        }
        return;
    }
    /* parse the up/down/right/left key */
204
    ret = ShellCmdLineCheckUDRL(ch, shellCB);//解析上下左右键
205 206 207
    if (ret == LOS_OK) {
        return;
    }
208 209 210 211
	
    if ((ch != '\n') && (ch != '\0')) {//普通的字符的处理
        if (shellCB->shellBufOffset < (SHOW_MAX_LEN - 1)) {//buf范围
            shellCB->shellBuf[shellCB->shellBufOffset] = ch;//直接加入
212
        } else {
213
            shellCB->shellBuf[SHOW_MAX_LEN - 1] = '\0';//加入字符串结束符
214
        }
215 216
        shellCB->shellBufOffset++;//偏移量增加
        outputFunc("%c", ch);//向终端输出字符
217 218
    }

219
    shellCB->shellKeyType = STAT_NORMAL_KEY;//普通字符
220
}
221
///获取shell消息类型
222 223 224 225 226
LITE_OS_SEC_TEXT_MINOR UINT32 ShellMsgTypeGet(CmdParsed *cmdParsed, const CHAR *cmdType)
{
    CmdItemNode *curCmdItem = (CmdItemNode *)NULL;
    UINT32 len;
    UINT32 minLen;
227
    CmdModInfo *cmdInfo = OsCmdInfoGet();//获取全局变量
228 229 230 231 232 233 234 235

    if ((cmdParsed == NULL) || (cmdType == NULL)) {
        return OS_INVALID;
    }

    len = strlen(cmdType);
    LOS_DL_LIST_FOR_EACH_ENTRY(curCmdItem, &(cmdInfo->cmdList.list), CmdItemNode, list) {
        if ((len == strlen(curCmdItem->cmd->cmdKey)) &&
236
            (strncmp((CHAR *)(curCmdItem->cmd->cmdKey), cmdType, len) == 0)) {
237 238 239 240 241 242 243 244 245
            minLen = (len < CMD_KEY_LEN) ? len : CMD_KEY_LEN;
            (VOID)memcpy_s((CHAR *)(cmdParsed->cmdKeyword), CMD_KEY_LEN, cmdType, minLen);
            cmdParsed->cmdType = curCmdItem->cmd->cmdType;
            return LOS_OK;
        }
    }

    return OS_INVALID;
}
246
///获取命令名称和参数,并执行
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
STATIC UINT32 ShellMsgNameGetAndExec(CmdParsed *cmdParsed, const CHAR *output, UINT32 len)
{
    UINT32 loop;
    UINT32 ret;
    const CHAR *tmpStr = NULL;
    BOOL quotes = FALSE;
    CHAR *msgName = (CHAR *)LOS_MemAlloc(m_aucSysMem0, len + 1);
    if (msgName == NULL) {
        PRINTK("malloc failure in %s[%d]\n", __FUNCTION__, __LINE__);
        return OS_INVALID;
    }
    /* Scan the 'output' string for command */
    /* Notice: Command string must not have any special name */
    for (tmpStr = output, loop = 0; (*tmpStr != '\0') && (loop < len);) {
        /* If reach a double quotes, switch the quotes matching status */
        if (*tmpStr == '\"') {
            SWITCH_QUOTES_STATUS(quotes);
            /* Ignore the double quote CHARactor itself */
            tmpStr++;
            continue;
        }
        /* If detected a space which the quotes matching status is false */
        /* which said has detected the first space for seperator, finish this scan operation */
        if ((*tmpStr == ' ') && (QUOTES_STATUS_CLOSE(quotes))) {
            break;
        }
        msgName[loop] = *tmpStr++;
        loop++;
    }
    msgName[loop] = '\0';
    /* Scan the command list to check whether the command can be found */
    ret = ShellMsgTypeGet(cmdParsed, msgName);
    PRINTK("\n");
    if (ret != LOS_OK) {
        PRINTK("%s:command not found", msgName);
    } else {
283
        (VOID)OsCmdExec(cmdParsed, (CHAR *)output);//真正的执行命令 output为输出设备
284 285 286 287
    }
    (VOID)LOS_MemFree(m_aucSysMem0, msgName);
    return ret;
}
288
///命令内容解析
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
LITE_OS_SEC_TEXT_MINOR UINT32 ShellMsgParse(const VOID *msg)
{
    CHAR *output = NULL;
    UINT32 len, cmdLen, newLen;
    CmdParsed cmdParsed;
    UINT32 ret = OS_INVALID;
    CHAR *buf = (CHAR *)msg;
    CHAR *newMsg = NULL;
    CHAR *cmd = "exec";

    if (msg == NULL) {
        goto END;
    }

    len = strlen(msg);
    /* 2: strlen("./") */
    if ((len > 2) && (buf[0] == '.') && (buf[1] == '/')) {
        cmdLen = strlen(cmd);
        newLen = len + 1 + cmdLen + 1;
        newMsg = (CHAR *)LOS_MemAlloc(m_aucSysMem0, newLen);
        if (newMsg == NULL) {
            PRINTK("malloc failure in %s[%d]\n", __FUNCTION__, __LINE__);
            goto END;
        }
        (VOID)memcpy_s(newMsg, newLen, cmd, cmdLen);
        newMsg[cmdLen] = ' ';
        (VOID)memcpy_s(newMsg + cmdLen + 1, newLen - cmdLen - 1,  (CHAR *)msg + 1, len);
        msg = newMsg;
        len = newLen - 1;
    }
    output = (CHAR *)LOS_MemAlloc(m_aucSysMem0, len + 1);
    if (output == NULL) {
        PRINTK("malloc failure in %s[%d]\n", __FUNCTION__, __LINE__);
        goto END;
323
    }//对字符串缓冲区,调用函数“OsCmdKeyShift”来挤压和清除无用或过多的空间
324 325 326 327 328 329 330 331 332
    /* Call function 'OsCmdKeyShift' to squeeze and clear useless or overmuch space if string buffer */
    ret = OsCmdKeyShift((CHAR *)msg, output, len + 1);
    if ((ret != LOS_OK) || (strlen(output) == 0)) {
        ret = OS_INVALID;
        goto END_FREE_OUTPUT;
    }

    (VOID)memset_s(&cmdParsed, sizeof(CmdParsed), 0, sizeof(CmdParsed));

333
    ret = ShellMsgNameGetAndExec(&cmdParsed, output, len);////获取命令名称和参数,并执行
334 335 336 337 338 339 340 341 342

END_FREE_OUTPUT:
    (VOID)LOS_MemFree(m_aucSysMem0, output);
END:
    if (newMsg != NULL) {
        (VOID)LOS_MemFree(m_aucSysMem0, newMsg);
    }
    return ret;
}
343
///读取命令行内容
344 345 346 347 348 349 350
#ifdef LOSCFG_FS_VFS
LITE_OS_SEC_TEXT_MINOR UINT32 ShellEntry(UINTPTR param)
{
    CHAR ch;
    INT32 n = 0;
    ShellCB *shellCB = (ShellCB *)param;

351
    CONSOLE_CB *consoleCB = OsGetConsoleByID((INT32)shellCB->consoleID);//获取控制台
352 353 354 355 356
    if (consoleCB == NULL) {
        PRINT_ERR("Shell task init error!\n");
        return 1;
    }

357
    (VOID)memset_s(shellCB->shellBuf, SHOW_MAX_LEN, 0, SHOW_MAX_LEN);//重置shell命令buf
358 359 360

    while (1) {
#ifdef LOSCFG_PLATFORM_CONSOLE
361
        if (!IsConsoleOccupied(consoleCB)) {//控制台是否被占用
362 363
#endif
            /* is console ready for shell ? */
364
            n = read(consoleCB->fd, &ch, 1);//从控制台读取一个字符内容,字符一个个处理
365
            if (n == 1) {//如果能读到一个字符
366 367
                ShellCmdLineParse(ch, (pf_OUTPUT)dprintf, shellCB);
            }
368
            if (is_nonblock(consoleCB)) {//在非阻塞模式下暂停 50ms
369 370 371 372 373 374 375 376
                LOS_Msleep(50); /* 50: 50MS for sleep */
            }
#ifdef LOSCFG_PLATFORM_CONSOLE
        }
#endif
    }
}
#endif
377
//处理shell 命令
378 379 380 381
STATIC VOID ShellCmdProcess(ShellCB *shellCB)
{
    CHAR *buf = NULL;
    while (1) {
382
        buf = ShellGetInputBuf(shellCB);//获取命令buf
383 384 385
        if (buf == NULL) {
            break;
        }
386 387
        (VOID)ShellMsgParse(buf);//解析buf
        ShellSaveHistoryCmd(buf, shellCB);//保存到历史记录中
388 389 390
        shellCB->cmdMaskKeyLink = shellCB->cmdHistoryKeyLink;
    }
}
391
///shell 任务,处理解析,执行命令
392 393 394 395 396 397 398 399 400 401 402
LITE_OS_SEC_TEXT_MINOR UINT32 ShellTask(UINTPTR param1,
                                        UINTPTR param2,
                                        UINTPTR param3,
                                        UINTPTR param4)
{
    UINT32 ret;
    ShellCB *shellCB = (ShellCB *)param1;
    (VOID)param2;
    (VOID)param3;
    (VOID)param4;

403
    while (1) {
404 405
        PRINTK("\nOHOS # ");//读取shell 输入事件 例如: cat weharmony.net 命令
        ret = LOS_EventRead(&shellCB->shellEvent,
406
                            0xFFF, LOS_WAITMODE_OR | LOS_WAITMODE_CLR, LOS_WAIT_FOREVER);
407 408
        if (ret == SHELL_CMD_PARSE_EVENT) {//获得解析命令事件
            ShellCmdProcess(shellCB);//处理命令 
409
        } else if (ret == CONSOLE_SHELL_KEY_EVENT) {//退出shell事件
410 411 412
            break;
        }
    }
413
    OsShellKeyDeInit((CmdKeyLink *)shellCB->cmdKeyLink);//
414
    OsShellKeyDeInit((CmdKeyLink *)shellCB->cmdHistoryKeyLink);
415 416
    (VOID)LOS_EventDestroy(&shellCB->shellEvent);//注销事件
    (VOID)LOS_MemFree((VOID *)m_aucSysMem0, shellCB);//释放shell控制块
417 418 419 420 421 422 423
    return 0;
}

#define SERIAL_SHELL_TASK_NAME "SerialShellTask"
#define SERIAL_ENTRY_TASK_NAME "SerialEntryTask"
#define TELNET_SHELL_TASK_NAME "TelnetShellTask"
#define TELNET_ENTRY_TASK_NAME "TelnetEntryTask"
424
//shell 服务端任务初始化,这个任务负责解析和执行命令
425 426 427 428
LITE_OS_SEC_TEXT_MINOR UINT32 ShellTaskInit(ShellCB *shellCB)
{
    CHAR *name = NULL;
    TSK_INIT_PARAM_S initParam = {0};
429 430
	//输入Shell命令的两种方式
    if (shellCB->consoleID == CONSOLE_SERIAL) {	//通过串口工具
431
        name = SERIAL_SHELL_TASK_NAME;
432
    } else if (shellCB->consoleID == CONSOLE_TELNET) {//通过远程工具
433 434 435 436 437
        name = TELNET_SHELL_TASK_NAME;
    } else {
        return LOS_NOK;
    }

438
    initParam.pfnTaskEntry = (TSK_ENTRY_FUNC)ShellTask;//任务入口函数,主要是解析shell命令
439
    initParam.usTaskPrio   = 9; /* 9:shell task priority */
440 441
    initParam.auwArgs[0]   = (UINTPTR)shellCB;
    initParam.uwStackSize  = 0x3000;
442
    initParam.pcName       = name;
443
    initParam.uwResved     = LOS_TASK_STATUS_DETACHED;
444

445
    (VOID)LOS_EventInit(&shellCB->shellEvent);//初始化事件,以事件方式通知任务解析命令
446

447
    return LOS_TaskCreate(&shellCB->shellTaskHandle, &initParam);//创建任务
448
}
449
///进入shell客户端任务初始化,这个任务负责编辑命令,处理命令产生的过程,例如如何处理方向键,退格键,回车键等
450 451 452 453 454 455 456 457 458 459 460 461 462 463
LITE_OS_SEC_TEXT_MINOR UINT32 ShellEntryInit(ShellCB *shellCB)
{
    UINT32 ret;
    CHAR *name = NULL;
    TSK_INIT_PARAM_S initParam = {0};

    if (shellCB->consoleID == CONSOLE_SERIAL) {
        name = SERIAL_ENTRY_TASK_NAME;
    } else if (shellCB->consoleID == CONSOLE_TELNET) {
        name = TELNET_ENTRY_TASK_NAME;
    } else {
        return LOS_NOK;
    }

464
    initParam.pfnTaskEntry = (TSK_ENTRY_FUNC)ShellEntry;//任务入口函数
465 466 467
    initParam.usTaskPrio   = 9; /* 9:shell task priority */
    initParam.auwArgs[0]   = (UINTPTR)shellCB;
    initParam.uwStackSize  = 0x1000;
468
    initParam.pcName       = name;	//任务名称
469 470
    initParam.uwResved     = LOS_TASK_STATUS_DETACHED;

471
    ret = LOS_TaskCreate(&shellCB->shellEntryHandle, &initParam);//创建shell任务
472
#ifdef LOSCFG_PLATFORM_CONSOLE
473
    (VOID)ConsoleTaskReg((INT32)shellCB->consoleID, shellCB->shellEntryHandle);//将shell注册到控制台
474 475 476 477 478
#endif

    return ret;
}