Adding "Reboot" command
based on BDH Shell
Last updated
based on BDH Shell
Last updated
Assoc. Prof. Wiroon Sriborrirux, Founder of Advance Innovation Center (AIC) and Bangsaen Design House (BDH), Electrical Engineering Department, Faculty of Engineering, Burapha University
Create New Application
Select Project
You can check the cmd functions in the `usrcmd.c` file.
The CLI (Command Line Interface) provides a way for users to interact with the system through text-based commands. Here is the detail of each function:
cmd_table_t
: This is a struct that includes a command name, a description, and a function that is executed when the command is entered. The CLI (Command Line Interface) provides a way for users to interact with the system through text-based commands. Here is the detail of each function:
cmd_table_t
: This is a struct that includes a command name, a description, and a function that is executed when the command is entered.
cmdlist[]
: This is a list of the custom commands available in the shell. Each command corresponds to a specific function that is executed when the command is entered.
usrcmd_execute()
: This function executes a given command by looking it up in the cmdlist and calling its corresponding function.
usrcmd_ntopt_callback()
: This is the callback function for the command parsing library. It is invoked when a command is entered, and it executes the appropriate function based on the entered command.
Command Functions
: Functions like usrcmd_help(), usrcmd_info(), usrcmd_clear(), etc. are the implementations of the custom commands. They are executed when the corresponding command is entered into the shell.
usrcmd_task()
: This function is where the command line interface starts. It initializes the shell, sets the prompt, and then starts executing commands.
The new commands that we added are usrcmd_history(), usrcmd_reboot(), and usrcmd_kill().
usrcmd_reboot
usrcmd_reboot
reboots the system by using the NVIC_SystemReset function which resets the processor and all peripheral devices to their default state.
Step-by-step guide on how to create the usrcmd_reboot
You have to declare the function prototype for usrcmd_reboot. The prototype of the function is as follows:
Now let's define the usrcmd_reboot function. Here, it will print a message and then call NVIC_SystemReset() to perform a system reboot.
In the cmdlist[]
structure, register the reboot
command to map it to the usrcmd_reboot
function. Add the following line in the cmdlist[]
structure:
usrcmd_kill
usrcmd_reboot
reboots the system by using the NVIC_SystemReset function which resets the processor and all peripheral devices to their default state.
Step-by-step guide on how to create the usrcmd_reboot
Declare the function prototype for usrcmd_kill
:
Define the usrcmd_kill
function. This function will typically take the process ID as a parameter from the command line arguments and terminate that process.
Add the kill
command to the cmdlist[]
structure to map it to the usrcmd_kill
function. Add the following line in the cmdlist[]
This registers the kill command such that it will call the usrcmd_kill function when invoked.