embedded-software
reusable software modules for embedded systems
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Subsystem Module

Macros

#define SUBSYSTEM_IO_NONE   0
 
#define SUBSYSTEM_IO_UART   1
 
#define SUBSYSTEM_IO_PRINTF   2
 
#define SUBSYSTEM_IO_CUSTOM   255
 
#define SUBSYSTEM_IO   SUBSYSTEM_IO_NONE
 
#define LogError(sys_id, str,...)
 
#define LogWarning(sys_id, str,...)
 
#define LogMsg(sys_id, str,...)
 
#define LogDebug(sys_id, str,...)
 
#define Subsystem_printf(str,...)
 
#define Subsystem_vprintf(str, arg)
 
#define Subsystem_PrintChar(c)
 
#define Subsystem_RegisterReceiver(r)
 
#define SYSTEM_VERSION   0x04000000u
 subsystem module version number More...
 
#define RECEIVE_MAX_LENGTH   64
 default length of receive line for commands More...
 
#define RECEIVE_START_CHAR   '$'
 start character for command lines More...
 
#define RECEIVE_STOP_CHAR   '\r'
 stop character for command lines More...
 
#define RECEIVE_MAX_ARGC   8
 max number of arguments after the command name More...
 
#define GetLogTimestamp()   TimeNow()
 

Enumerations

enum  log_level {
  LOG_OFF = 0, LOG_ERROR, LOG_WARNING, LOG_MESSAGE,
  LOG_DEBUG
}
 

Functions

void LogStr (char *str,...)
 
void Subsystem_Write (uint8_t subsystem_id, enum log_level level, char *str,...)
 
uint8_t Subsystem_Init (char *name, version_t version, void(*callback)(int argc, char *argv[]))
 
void Subsystem_RegisterCallback (uint8_t subsystem_id, void(*callback)(int argc, char *argv[]))
 
char * Subsystem_GetName (uint8_t subsystem_id)
 
void Log_EchoOn (void)
 
void Log_EchoOff (void)
 
uint8_t Log_GetEcho (void)
 
void Log_Version (uint8_t subys_id)
 
void Log_Header (uint8_t subsystem_id, enum log_level level)
 
void Log_MuteAll (void)
 
void Log_UnmuteAll (void)
 
void Log_MuteSys (uint8_t sys_id)
 
void Log_UnmuteSys (uint8_t sys_id)
 
void Log_SetLevel (uint8_t sys_id, enum log_level level)
 
uint16_t ArgToU16 (char *arg)
 
uint8_t ArgToU8 (char *arg)
 
uint32_t ArgToU32 (char *arg)
 
void Subsystem_SystemDisable (void)
 
void Subsystem_SystemEnable (void)
 

Detailed Description

This module is intended to assist in logging and or management of modules via a command line. The user should define one of the following IO methods in project_settings.h:

SubSystem module command interface

If bi-directional communication is available (e.g. UART) then the user can interface with the SubSystem module in real time using the module's command interface.A command can be sent to the module in the following format:

$name arg1 arg2 arg3 arg4

Where the $ indicates the start of the command, name is the name of the subsystem the command is sent to and it is followed by argument stringsThe Subsytem Module registers itself as "SYS" and the commands available are:

  • "$sys list" list the handles and names of all present subsystems
  • "$sys mute" global mute of log messages
  • "$sys unmute" global unmute of log messages
  • "$sys unmute all" global unmute of log messages plus enable logging of every subsystem
  • "$sys echo" echo back received characters
  • "$sys echo off" disable echoing
  • "$sys name mute" turn off logging for the subsystem called "name"
  • "$sys name unmute" turn on logging for the subsystem called "name"
If your module wishes to receive commands from the command line simply register with the subsystem module and the arguments following a command that starts with the name of your module will be passed to your callback.
static uint8_t sys_id; // handle for the subsystem
void MyCallback(int argc, char *argv[]) {
// do something based on the arguments
}
...
sys_id = Subsystem_Init("example", (version_t)0x01020003u, MyCallback);
// now you can use the handle to log messages with a header and to enable
// your messages to be muted or unmuted
LogMsG(sys_id, "printf style formatted %s", "message");
// MyCallback will be called after any command that starts with "$example "

Subsystem module initialization

Below are three example of how a subsystem could initialize itself.
// define the version
#define TASK_VERSION (version_t)0x01010014u
static uint8_t sys_id; // global to the file only
// initialize module use "task" to refer to this subsystem in output messages
// and don't register a callback for receiving commands
sys_id = Subsystem_Init("task", TASK_VERSION, 0);
// or another way to do the same thing
static uint8_t sys_id; // global to the file only
#define TASK_VERSION_MAJOR 1
#define TASK_VERSION_MINOR 1
#define TASK_VERSION_BUILD 20
version_t task_version;
task_version.major = TASK_VERSION_MAJOR;
task_version.minor = TASK_VERSION_MINOR;
task_version.build = TASK_VERSION_BUILD;
task_id = Subsystem_Init("task", task_version, 0);
static uint8_t sys_id; // global to the file only
// or to do it all in one line
sys_id = Subsystem_Init("task", (version_t)0x01010014u, 0);
LogMsg(sys_id, "Crap hit the fan");

Macro Definition Documentation

#define GetLogTimestamp ( )    TimeNow()

GetLogTimestamp must be defined so that it returns a integer (up to 32 bits) timestamp

#define LogDebug (   sys_id,
  str,
  ... 
)
#define LogError (   sys_id,
  str,
  ... 
)
#define LogMsg (   sys_id,
  str,
  ... 
)
#define LogWarning (   sys_id,
  str,
  ... 
)
#define RECEIVE_MAX_ARGC   8

max number of arguments after the command name

#define RECEIVE_MAX_LENGTH   64

default length of receive line for commands

#define RECEIVE_START_CHAR   '$'

start character for command lines

#define RECEIVE_STOP_CHAR   '\r'

stop character for command lines

#define SUBSYSTEM_IO   SUBSYSTEM_IO_NONE
#define SUBSYSTEM_IO_CUSTOM   255
#define SUBSYSTEM_IO_NONE   0
#define SUBSYSTEM_IO_PRINTF   2
#define SUBSYSTEM_IO_UART   1
#define Subsystem_PrintChar (   c)
#define Subsystem_printf (   str,
  ... 
)
#define Subsystem_RegisterReceiver (   r)
#define Subsystem_vprintf (   str,
  arg 
)
#define SYSTEM_VERSION   0x04000000u

subsystem module version number

Enumeration Type Documentation

enum log_level
Enumerator
LOG_OFF 
LOG_ERROR 
LOG_WARNING 
LOG_MESSAGE 
LOG_DEBUG 

Function Documentation

uint16_t ArgToU16 ( char *  arg)
uint32_t ArgToU32 ( char *  arg)
uint8_t ArgToU8 ( char *  arg)

Here is the caller graph for this function:

void Log_EchoOff ( void  )

Turn echo feature off

void Log_EchoOn ( void  )

Turn echo featuren on (default is off)

Here is the caller graph for this function:

uint8_t Log_GetEcho ( void  )

Get status of echo setting

Returns
echo setting, 1 if echo is on
void Log_Header ( uint8_t  subsystem_id,
enum log_level  level 
)

Here is the call graph for this function:

Here is the caller graph for this function:

void Log_MuteAll ( void  )

Mute all log messages

void Log_MuteSys ( uint8_t  sys_id)

Mute messages from certain sys_id

void Log_SetLevel ( uint8_t  sys_id,
enum log_level  level 
)
void Log_UnmuteAll ( void  )

Global unmute

void Log_UnmuteSys ( uint8_t  sys_id)

Unmute messages from certain sys_id

void Log_Version ( uint8_t  subys_id)
void LogStr ( char *  str,
  ... 
)

Logs the null terminated string at the pointer (str)

Same as LogMsg() without the header in the beginning and without the CRLF at the end.

This function is implemented using Push_vprintf. See Push_printf() for supported flags/features.

Will log the string to the buffer defined by LOG_BUF (typically tx0)

Parameters
strpointer to string to log
...variable number of replacement parameters for the str string

Example usage:

LogStr("oops I crapped my pants %d times", num_craps);

Here is the caller graph for this function:

char* Subsystem_GetName ( uint8_t  subsystem_id)

Return a pointer to a string corresponding to the name of the subsystem

The name returned is the one set by Subsystem_Init()

Parameters
subsystem_id
Returns
- pointer to a null terminated string corresponding to the name of the subsystem

Here is the caller graph for this function:

uint8_t Subsystem_Init ( char *  name,
version_t  version,
void(*)(int argc, char *argv[])  callback 
)

Initialize settings for a subsystem - critical for proper logging and command interface

If a module/subsystem uses logging it should call this function with the appropriate inputs when the subsystem is initializing.

Returns
subsystem index
Parameters
namepointer to name of the subsystem (recommended to make the name 8 characters or less)
versionsoftware version of subsystem, see version_t for more info
callbackcallback function to be called when the user inputs a command in the form of "$name var1 var2 var3...". Where name is the name passed to this function. The callback will be passed the number of arguments, argc , and a array of pointers to the argument strings, argv.

Here is the caller graph for this function:

void Subsystem_RegisterCallback ( uint8_t  subsystem_id,
void(*)(int argc, char *argv[])  callback 
)

Register a callback function for a subsystem

When a command is received by the logging module for the subsystem sys the callback function will be executed and passed the number of arguments argc and a array (vector) of pointer to the argument strungs argv.

The callback is set by Subsystem_Init(), this function can be used to update the callback.

Parameters
subsystem_id- subsystem to register the callback for
callback- function pointer to the function to run when a command is received for the subsystem.
void Subsystem_SystemDisable ( void  )

Used to disable the Subsystem Module's UART receiver so data can be transmitted without being intercepted by the Subsystem Module

Here is the call graph for this function:

void Subsystem_SystemEnable ( void  )

Used to re-register the Subsystem Module's UART after it has been disabled by Subsystem_SystemDisable().

Only call this function after Subsystem_SystemDisable()

Here is the call graph for this function:

void Subsystem_Write ( uint8_t  subsystem_id,
enum log_level  level,
char *  str,
  ... 
)

Logs the message at the pointer (str) with a timestamp and subsystem name

Before logging the message the function will check the current log setting of the subsystem and to determine if the message should be logged

This function is implemented using Push_vprintf. See Push_printf() for supported flags/features.

Will log the string to the buffer defined by SUSSYS_UART

Parameters
subsystem_idsubsystem id
strpointer to message to log
...variable number of replacement parameters for the str string

Example usage:

LogMsg(sys.id, "oops I crapped my pants");
LogMsg(sys.id, "System Index %d, System Name %s.", sys.id, GetSubsystemName(SYSTEM));

Here is the call graph for this function: