![]() |
LibRTOSConsole-C-Library 1.0
Library Code documentation
|
#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 |
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) |
| #define CHECK_FOR_OVERFLOW | ( | x | ) |
| #define ON_NULL_GOTO_ERROR | ( | x | ) |
| #define str | ( | a | ) |
| #define xstr | ( | a | ) |
| 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.
| uxStackDepth | is the stack depth of the console processor thread in words |
| xPrio | is 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! |
| 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
| 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
| h | is of type ConsoleHandle_t which is created by a call of CONSOLE_CreateInstance |
| rdFunc | is of type ConsoleReadStream_t which is the new stream read function for the command processor |
| wrFunc | is 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!
| 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
| h | is of type ConsoleHandle_t which is created by a call of CONSOLE_CreateInstance |
| cmd | is of type char* which is the case sensitive name of the alias command |
| aliasCmd | is of type char* which is the mapped command and its args and is visible when the user types help |
| 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.
| h | is of type ConsoleHandle_t which is created by a call of CONSOLE_CreateInstance |
| cmd | is of type char* which is the case sensitive name of the command |
| help | is of type char* which is the help text or description of the command when the user types help |
| func | is of type CONSOLE_CommandFunc which is the function pointer to the command |
| context | is of type void* which is an optional data pointer which is passed to the function when called |
| 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.
| h | is of type ConsoleHandle_t which is created by a call of CONSOLE_CreateInstance |
| cmd | is of type char* which is the case sensitive name of the alias or command |