Abstract: Shell, as Huawei Liteos online debugging tool, can input and output through serial port tool, supporting common basic debugging functions. At the same time, you can add customized commands, which can be executed only after recompiling and burning

This article is shared by Huawei Cloud community LIteOS—- Shell Application (1) System Shell, author: O0 Long Long 0o.

preface

Many times we too can set breakpoints when debugging applications or inability to observation program real process, which have statement execution, there is a manual open a write their own application and so on, then you need a shell command line operation, he can command line way to access the operating system’s functions and services, receive user input commands, Prints the output of the operating system.

1. Shell of Huawei Liteos

As a Huawei Liteos online debugging tool, Shell can input and output through the serial port tool and support common basic debugging functions. At the same time, you can add customized commands, which can be executed only after recompiling and burning

2. Opening method of shell function

To configure the Shell, run the make menuconfig command: Debug –> Enable a Debug Version –> Enable Shell.

3, LiteOS built-in Shell command

After burning a new system image, restart the system. If the shell function is enabled, you can use the shell function of the system from the serial port.

  • help* * * *,date,uname,task,free,memcheck, memused,hwi,queue,sem,mutex,dlock,swtmr,systeminfo,stack, cpup,watchEtc.

Through these commands I can complete some basic operations on the system, such as query task execution, memory allocation and the help function of various commands.

For example, enter help on the cli

System who outputs all current shell commands:

Huawei LiteOS # help *******************shell commands:************************* cpup date dlock dmesg free help hwi log  memcheck mutex queue sem stack swtmr systeminfo task uname watchCopy the code

The task command is used to query system task information

If task [ID] is entered, information about the task whose ID is ID is displayed

For example, when task 0x01 is entered, the system prints:

Huawei LiteOS # task 0x01 TaskName = SerialEntryTask TaskId = 0x01 *******backtrace begin******* traceback 0 -- lr = 0x1d804 fp = 0xa86bc traceback 1 -- lr = 0x1da40 fp = 0xa86e4 traceback 2 -- lr = 0x20154 fp = 0xa86fc traceback 3 -- lr  = 0x258e4 fp = 0xa8714 traceback 4 -- lr = 0x242f4 fp = 0xa872c traceback 5 -- lr = 0x123e4 fp = 0xa8754 traceback 6 --  lr = 0x2a9d8 fp = 0xb0b0b0bCopy the code

You can try and find out for yourself what the functions of these systems are, and actually find better applications.

4. Define command functions

The first thing to do is to have a function that also handles commands. You need to declare the function prototype in a header file.

So let’s say I define it here

int osShellCmdLs(int argc, const char **argv);
Copy the code

Normally, the function needs to wrap two arguments, argc and argv string Pointers. Argc: number of arguments in a Shell command. Whether the command keyword is included depends on the command type used when registering the command. Argv: is an array of Pointers, each element pointing to a string that is the argument passed to the command processing function when executing shell commands. Whether the command keyword is included in the parameter depends on the command type when the command is registered.

5. Register the command name

LiteOS shell has two registration modes: static register command and dynamic register command at system runtime. Static registration requires that support be turned on in the compiler and Settings to take effect. It is generally recommended to use dynamic shell registration, which is easy to operate.

6, use cases

1. Define a shell function named pf_Best. The function is to print “We r Best”

#include "shell.h" #include "shcmd.h" int cmd_pfbest(void) { printf("We r best! \n"); return 0; }Copy the code

Since no entry or exit arguments are required, the function is void.

2. Register commands

Follow dynamic registration requirements.

#include "shell.h"
void cmd_init(void)
{
osCmdReg(CMD_TYPE_EX, "pf_best", XARGS, (CMD_CBK_FUNC)cmd_pfbest);
}
Copy the code

Once compiled and downloaded, you can use this command to interact.

After shell, everyone is not feeling very simple, let’s try it

Learn more about the IoT community

Add huawei Cloud IoT Small Assistant wechat account (HWC-iot) and reply “Read” for more information

Click to follow, the first time to learn about Huawei cloud fresh technology ~