Page 1 of 1

Enable programmatic termination of shell  Topic is solved

Posted: Thu Apr 19, 2018 2:11 pm
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_)

Re: Enable programmatic termination of shell

Posted: Tue Jun 19, 2018 12:32 pm
by FXCoder
Bump...

Re: Enable programmatic termination of shell

Posted: Sun Jul 08, 2018 6:58 am
by Giovanni
Hi,

Added to trunk and 18.2.

Giovanni

Re: Enable programmatic termination of shell

Posted: Thu Nov 22, 2018 12:30 am
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

Re: Enable programmatic termination of shell

Posted: Thu Nov 22, 2018 8:31 am
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.