FreeRTOS-Plus-IO Integration
FreeRTOS-Plus-CLI is an extensible framework that allows the application writer
to define and register their own command line input commands. Separate
documentation pages are provided that describe
how to write a function
that implements the behaviour of a user defined command, and
how to
register user defined commands with FreeRTOS-Plus-CLI.
This page describes
how to port FreeRTOS-Plus-CLI onto real hardware by providing input output (IO)
routines, and a FreeRTOS-Plus-CLI task.
Input and output
A command line interface receives characters from an input, and writes
characters to an output. The low level details of how this is achieved
is dependent on the microcontroller being used, and the interfaces the
microcontroller provides.
There is a FreeRTOS-Plus-CLI featured demo that uses the FreeRTOS-Plus-IO
FreeRTOS_read()
and
FreeRTOS_write()
API functions to provide the necessary
input and output to a UART. The command line interface it creates is accessed using
a standard dumb terminal program, such as HyperTerminal.
There is another FreeRTOS-Plus-CLI featured demo that uses a TCP/IP sockets
interface to provide the necessary input and output. The command line interface
it creates is accessed using a telnet client. The structure of the FreeRTOS
task that runs the FreeRTOS-Plus-CLI code is similar in both cases, and is
provided below.
An example FreeRTOS-Plus-CLI task
The source code below implements a task that manages a FreeRTOS-Plus-CLI
command interpreter interface. The FreeRTOS-Plus-IO FreeRTOS_read() and
FreeRTOS_write() API functions are use to provide the IO interface. It
is assumed that the FreeRTOS-Plus-IO descriptor has already been
opened
and configured to use the interrupt driven
character queue transfer mode.
The task uses the FreeRTOS-Plus-CLI FreeRTOS_CLIProcessCommand() API function.
The comments in the source code provide more information. Note this
function is not re-entrant.
#define MAX_INPUT_LENGTH 50
#define MAX_OUTPUT_LENGTH 100
static const int8_t * const pcWelcomeMessage =
"FreeRTOS command server.rnType Help to view a list of registered commands.rn";
void vCommandConsoleTask( void *pvParameters )
{
Peripheral_Descriptor_t xConsole;
int8_t cRxedChar, cInputIndex = 0;
BaseType_t xMoreDataToFollow;
static int8_t pcOutputString[ MAX_OUTPUT_LENGTH ], pcInputString[ MAX_INPUT_LENGTH ];
xConsole = ( Peripheral_Descriptor_t ) pvParameters;
FreeRTOS_write( xConsole, pcWelcomeMessage, strlen( pcWelcomeMessage ) );
for( ;; )
{
FreeRTOS_read( xConsole, &cRxedChar, sizeof( cRxedChar ) );
if( cRxedChar == '\n' )
{
FreeRTOS_write( xConsole, "\r\n", strlen( "\r\n" );
do
{
xMoreDataToFollow = FreeRTOS_CLIProcessCommand
(
pcInputString,
pcOutputString,
MAX_OUTPUT_LENGTH
);
FreeRTOS_write( xConsole, pcOutputString, strlen( pcOutputString ) );
} while( xMoreDataToFollow != pdFALSE );
cInputIndex = 0;
memset( pcInputString, 0x00, MAX_INPUT_LENGTH );
}
else
{
if( cRxedChar == '\r' )
{
}
else if( cRxedChar == '\b' )
{
if( cInputIndex > 0 )
{
cInputIndex--;
pcInputString[ cInputIndex ] = '';
}
}
else
{
if( cInputIndex < MAX_INPUT_LENGTH )
{
pcInputString[ cInputIndex ] = cRxedChar;
cInputIndex++;
}
}
}
}
}
An example of a task that implements a FreeRTOS-Plus-CLI command console
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.