Stop a command from running

cheesechief wrote on Thursday, October 17, 2019:

Hey all,

In the event that i am running my own command and it happens to be taking a long time, is there a something available to stop a running command?

rtel wrote on Thursday, October 17, 2019:

Sorry but you are going to have to give a lot more information about what you are doing before I could make any suggestions. What is the command? How is the code structured? etc. The first answer would be you can just delete the task that is running the command but I doubt that is what you want.

https://www.freertos.org/FAQ-how-to-use-the-FreeRTOS-support-forum.html

cheesechief wrote on Thursday, October 17, 2019:

trying to run some simple walking ones memory test on a SmartFusion2 dev kit. via a custom CLI command.

at present i have (some pseudo-ish code)
`
static portBASE_TYPE prvTestCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
const char *pcParameter;
portBASE_TYPE lParameterStringLength;

( void ) pcCommandString;
( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer );

SomeFunc();

return pdFALSE;
}
`

In the event this command ‘hangs’ at SomeFunc() where SomeFunc is an unintentional infinite loop, I wanted to know if there was guidance anywhere in regards to forcing this command to stop that didnt involve the aformentioned deletion of the task thats running the command.

Thanks again for taking the time to read this.

rtel wrote on Thursday, October 17, 2019:

Executing a command is basically just executing a function that runs in
the context of whichever task is running the CLI - hence deleting the
task would delete the CLI as you note - so not a good solution. You
could do something like have the command spawn another task to run the
command, then monitor how long it takes, and if it takes too long delete
the second task - that way you don’t delete the task that is running the
command interpreter. The problem you will then have is how to pass any
text generated by the command back to the command console. Other than
that you would probably have to do something like use an event group (or
semaphore, or direct to task notification - basically some kind of
synchronisation primitive) and have the function that is running the
command check the event group on each n iterations of any loop that
could potentially become infinite. If another task sees the command is
taking too long it can set a bit in the event group, then when the task
that is executing the command sees that bit is set, it exits the
function. A bit clumsy…