LibRTOSConsole-C-Library 1.0
Library Code documentation
Loading...
Searching...
No Matches
Console.c File Reference
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <math.h>
#include <sys/queue.h>
#include "main.h"
#include "Console.h"
#include "ConsoleConfig.h"
+ Include dependency graph for Console.c:

Data Structures

struct  cmdEntry
 
struct  cmdState
 
struct  cspState_t
 
struct  ConsoleHandle
 

Macros

#define CONSOLE_SAFETY_SPACE   4
 
#define CONSOLE_MAX_NUM_ARGS   ((CONSOLE_LINE_SIZE / 3) + 4)
 
#define CHECK_FOR_OVERFLOW(x)
 
#define xstr(a)
 
#define str(a)
 
#define ON_NULL_GOTO_ERROR(x)
 

Typedefs

typedef struct cmdEntry cmdEntry_t
 
typedef struct cmdState cmdState_t
 

Enumerations

enum  cspTYPE { csptNONE , csptCHARACTER , csptCONTROL }
 
enum  ctrlCodes_t {
  ctrlC0_NUL = 0x00 , ctrlC0_SOH = 0x01 , ctrlC0_STX = 0x02 , ctrlC0_ETX = 0x03 ,
  ctrlC0_EOT = 0x04 , ctrlC0_ENQ = 0x05 , ctrlC0_ACK = 0x06 , ctrlC0_BEL = 0x07 ,
  ctrlC0_BS = 0x08 , ctrlC0_TAB = 0x09 , ctrlC0_LF = 0x0A , ctrlC0_VT = 0x0B ,
  ctrlC0_FF = 0x0C , ctrlC0_CR = 0x0D , ctrlC0_SO = 0x0E , ctrlC0_SI = 0x0F ,
  ctrlC0_DLE = 0x10 , ctrlC0_DC1 = 0x11 , ctrlC0_DC2 = 0x12 , ctrlC0_DC3 = 0x13 ,
  ctrlC0_DC4 = 0x14 , ctrlC0_NAK = 0x15 , ctrlC0_SYN = 0x16 , ctrlC0_ETB = 0x17 ,
  ctrlC0_CAN = 0x18 , ctrlC0_EM = 0x19 , ctrlC0_SUB = 0x1A , ctrlC0_ESC = 0x1B ,
  ctrlC0_FS = 0x1C , ctrlC0_GS = 0x1D , ctrlC0_RS = 0x1E , ctrlC0_US = 0x1F ,
  ctrlC0_DEL = 0x7F , ctrlC1_MASK = 0x100 , ctrlC1_DCS = 0x101 , ctrlC1_CSI = 0x102 ,
  ctrlC1_SOS = 0x103 , ctrlC1_PM = 0x104 , ctrlC1_APC = 0x105 , ctrlC1_ST = 0x106 ,
  ctrlUNKNOWN = 0x1000 , ctrlOVERFLOW = 0x1001
}
 
enum  ctrlpStates_t {
  ctrlpsIDLE_DETECT = 0 , ctrlpsSTART_C1 = 1 , ctrlpsHANDLE_CSI = 2 , ctrlpsHANDLE_ST_1 = 3 ,
  ctrlpsHANDLE_ST_2 = 4
}
 

Functions

cspTYPE ControlSequenceParserConsume (char input, cspState_t *s)
 
static int ProcessCommand (char *command, int cmdLen, char **args, int numArgs, cmdState_t *c, int *isAlias, char *inputBuffer, int inbuffsz)
 
static int TransformAndProcessTheCommand (char *lineBuff, int line_size, cmdState_t *cState)
 
static void PrintConsoleControl (cspState_t *s)
 
static int ConsoleIsArrowLeft (cspState_t *s)
 
static int ConsoleIsArrowRight (cspState_t *s)
 
static int ConsoleIsArrowUp (cspState_t *s)
 
static int ConsoleIsArrowDown (cspState_t *s)
 
static int ConsoleIsEntf (cspState_t *s)
 
static void PrintConsoleArrowLeft (void)
 
int CONSOLE_RedirectStreams (ConsoleHandle_t h, ConsoleReadStream_t rdFunc, ConsoleWriteStream_t wrFunc, void *rdContext, void *wrContext)
 
static void ConsoleFunction (void *arg)
 
static int ConsolePrintHelp (int argc, char **argv, void *context)
 
static int ConsoleExecReset (int argc, char **argv, void *context)
 
static int ConsolePrintKernelTicks (int argc, char **argv, void *context)
 
static int ConsolePrintKernelVersion (int argc, char **argv, void *context)
 
static int ConsoleWhoAmI (int argc, char **argv, void *context)
 
static int ConsoleExit (int argc, char **argv, void *context)
 
static int ConsoleMallInfo (int argc, char **argv, void *context)
 
static int ConsoleGetEnv (int argc, char **argv, void *context)
 
static int ConsoleSetEnv (int argc, char **argv, void *context)
 
static int ConsoleAliasConfig (int argc, char **argv, void *context)
 
static void ConsoleRegisterBasicCommands (ConsoleHandle_t h)
 
ConsoleHandle_t CONSOLE_CreateInstance (unsigned int uxStackDepth, int xPrio)
 
int CONSOLE_RegisterCommand (ConsoleHandle_t h, char *cmd, char *help, CONSOLE_CommandFunc func, void *context)
 
int CONSOLE_RegisterAlias (ConsoleHandle_t h, char *cmd, char *aliasCmd)
 
int CONSOLE_RemoveAliasOrCommand (ConsoleHandle_t h, char *cmd)
 
void CONSOLE_DestroyInstance (ConsoleHandle_t h)
 

Macro Definition Documentation

◆ CHECK_FOR_OVERFLOW

#define CHECK_FOR_OVERFLOW ( x)
Value:
do { if ( ((x)+1) > s->maxLength ) \
{ s->type = ctrlOVERFLOW; s->length = 0; s->state = ctrlpsIDLE_DETECT; \
return csptCONTROL; } } while(0)

◆ ON_NULL_GOTO_ERROR

#define ON_NULL_GOTO_ERROR ( x)
Value:
do { if ((x) == NULL) goto error; } while(0);

◆ str

#define str ( a)
Value:
#a

◆ xstr

#define xstr ( a)
Value:
str(a)

Function Documentation

◆ CONSOLE_CreateInstance()

ConsoleHandle_t CONSOLE_CreateInstance ( unsigned int uxStackDepth,
int xPrio )

The CONSOLE_CreateInstance function is used to create the console processor. There is no singleton pattern implemented for the console but as there is no stream abstraction for the console processor, it only makes sense to have one instance at runtime!

The return value of a console function is a null pointer in case an error occured or a pointer of type ConsoleHandle_t.

Parameters
uxStackDepthis the stack depth of the console processor thread in words
xPriois the console processor priority. This should always be on a low level because the stdlib function may not block and so the processor always runs whenever it can. In case the reception of the newlib is blocking and interrupt based, the priority could be higher!

◆ CONSOLE_DestroyInstance()

void CONSOLE_DestroyInstance ( ConsoleHandle_t h)

The CONSOLE_DestroyInstance function is used to cleanup all used ressources which then stops the console processor. This leads to the case that no console functionallity is provided in the design anymore

◆ CONSOLE_RedirectStreams()

int CONSOLE_RedirectStreams ( ConsoleHandle_t h,
ConsoleReadStream_t rdFunc,
ConsoleWriteStream_t wrFunc,
void * rdContext,
void * wrContext )

The CONSOLE_RedirectStreams function is used to change stdin or stdout as default streams for the console functions. In case one or both stream function pointers are NULL, it will be set back to stdin respectively stdout. In case of an error, the last stream configuration is kept and -1 is returned, otherwise 0

Parameters
his of type ConsoleHandle_t which is created by a call of CONSOLE_CreateInstance
rdFuncis of type ConsoleReadStream_t which is the new stream read function for the command processor
wrFuncis of type ConsoleWriteStream_t which is the new stream write function for the command processor

NOTE it might be that not on all platforms it is possible to use this function, it then returns -2 if it is not implemented properly. So far only newlib stdlib is supported!

◆ CONSOLE_RegisterAlias()

int CONSOLE_RegisterAlias ( ConsoleHandle_t h,
char * cmd,
char * aliasCmd )

The CONSOLE_RegisterAlias function is used to register custom commands which can be mapped to other commands when the user enters the given alias command string. Arguments will not be passed from an alias command to the mapped command, so the alias should be specified with the required commands accordingly

Parameters
his of type ConsoleHandle_t which is created by a call of CONSOLE_CreateInstance
cmdis of type char* which is the case sensitive name of the alias command
aliasCmdis of type char* which is the mapped command and its args and is visible when the user types help

◆ CONSOLE_RegisterCommand()

int CONSOLE_RegisterCommand ( ConsoleHandle_t h,
char * cmd,
char * help,
CONSOLE_CommandFunc func,
void * context )

The CONSOLE_RegisterCommand function is used to register custom commands which can be called by the console processor when the user enters the given command string. The arguments and an additional context pointer are passed by the console processor to the function as well.

Parameters
his of type ConsoleHandle_t which is created by a call of CONSOLE_CreateInstance
cmdis of type char* which is the case sensitive name of the command
helpis of type char* which is the help text or description of the command when the user types help
funcis of type CONSOLE_CommandFunc which is the function pointer to the command
contextis of type void* which is an optional data pointer which is passed to the function when called

◆ CONSOLE_RemoveAliasOrCommand()

int CONSOLE_RemoveAliasOrCommand ( ConsoleHandle_t h,
char * cmd )

The CONSOLE_RemoveAliasOrCommand function is used to remove custom commands or alias entries which are mapped in the console processor.

Parameters
his of type ConsoleHandle_t which is created by a call of CONSOLE_CreateInstance
cmdis of type char* which is the case sensitive name of the alias or command