Enable programmatic termination of shell Topic is solved

Use this forum for requesting small changes in ChibiOS. Large changes should be discussed in the development forum. This forum is NOT for support.
Post Reply
User avatar
FXCoder
Posts: 403
Joined: Sun Jun 12, 2016 4:10 am
Has thanked: 188 times
Been thanked: 134 times

Enable programmatic termination of shell

Post by FXCoder »

Small change to enable a software shell terminate request to be issued.
I've implemented this change to shell.c for an SDU use case where status output is directed to SDU.
Output to SDU is paused when a shell session is requested (by hitting a key on terminal).
After shell commands, etc. are finished the shell is normally terminated by 'exit' or ^D by the user.
However, when an SDU disconnect event happens due to USB SUSPEND then the shell can be programmatically terminated.

Code: Select all

Index: shell.c
===================================================================
--- shell.c   (revision 11940)
+++ shell.c   (working copy)
@@ -354,7 +354,7 @@
 
   chprintf(chp, SHELL_NEWLINE_STR);
   chprintf(chp, "ChibiOS/RT Shell" SHELL_NEWLINE_STR);
-  while (true) {
+ while (!chThdShouldTerminateX()) {
     chprintf(chp, SHELL_PROMPT_STR);
     if (shellGetLine(scfg, line, sizeof(line), shp)) {
 #if (SHELL_CMD_EXIT_ENABLED == TRUE) && !defined(_CHIBIOS_NIL_)
User avatar
FXCoder
Posts: 403
Joined: Sun Jun 12, 2016 4:10 am
Has thanked: 188 times
Been thanked: 134 times

Re: Enable programmatic termination of shell

Post by FXCoder »

Bump...
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Enable programmatic termination of shell

Post by Giovanni »

Hi,

Added to trunk and 18.2.

Giovanni
User avatar
sabdulqadir
Posts: 49
Joined: Fri Mar 23, 2018 7:29 pm
Has thanked: 13 times
Been thanked: 4 times

Re: Enable programmatic termination of shell

Post by sabdulqadir »

Just to make sure, this means the shell would terminate when the USB device is detached?
Would you guys be able to tell who is requesting the termination?
Thanks,
AQ
User avatar
FXCoder
Posts: 403
Joined: Sun Jun 12, 2016 4:10 am
Has thanked: 188 times
Been thanked: 134 times

Re: Enable programmatic termination of shell

Post by FXCoder »

Hi,
In RT shell can be terminated by:
1. A channel reset or input of ^D to the shell
2. Entering the "exit" command (if enabled) to shell.
3. By another thread signaling for shell to terminate at next loop with chThdTerminate(...)

In all cases the exit is via shellExit(MSG_OK) which broadcasts a non-specific event and returns MSG_OK as its termination status.

So bottom line is, as currently implemented, you won't know which of the above triggered the termination.
Post Reply