AVRly - AVR Development Resources

Driver file providing logging functionality over USART, to print debug messages and values to a teminal program on your PC. More...

Go to the source code of this file.

Classes

struct  log_system_config_t
 Config object, to be instantiated in each file the log system is to be used, then pass it's address into the functions with names beginning with "log". More...
 

Typedefs

typedef enum name format_type_t
 Enumerated constants to specify the output format of numerical values.
 

Enumerations

enum  log_type_t {
  NONE , ERROR , WARNING , INFO ,
  DEBUG , VERBOSE_DEBUG , NONE , ERROR ,
  WARNING , INFO , DEBUG , VERBOSE_DEBUG
}
 Enumerated constants for the type of message to be logged. More...
 
enum  name { DECIMAL , HEXADECIMAL , BINARY }
 Enumerated constants to specify the output format of numerical values. More...
 

Functions

void init_log_system (void)
 Initialisation routine - call this function once at startup before using other functions. More...
 
void log_message (log_system_config_t *p_config, log_type_t level, const char *msg)
 Sends only the system tag, log level and message string. More...
 
void log_message_with_8bit_unsigned_val (log_system_config_t *p_config, log_type_t level, const char *msg, uint8_t val, format_type_t format)
 Sends a string, followed by an 8 bit unsigned value. More...
 
void log_message_with_8bit_signed_val (log_system_config_t *p_config, log_type_t level, const char *msg, int8_t val, format_type_t format)
 Sends a string, followed by an 8 bit value. More...
 
void log_message_with_16bit_unsigned_val (log_system_config_t *p_config, log_type_t level, const char *msg, uint16_t val, format_type_t format)
 Sends a string, followed by a 16 bit value. More...
 
void log_message_with_16bit_signed_val (log_system_config_t *p_config, log_type_t level, const char *msg, int16_t val, format_type_t format)
 Sends a string, followed by a 16 bit value. More...
 
void log_message_with_16bit_unsigned_dec_val (log_system_config_t *p_config, log_type_t level, const char *msg, uint16_t val)
 
void log_message_with_32bit_unsigned_val (log_system_config_t *p_config, log_type_t level, const char *msg, uint32_t val, format_type_t format)
 Sends a string, followed by a 32 bit value. More...
 
void log_message_with_32bit_signed_val (log_system_config_t *p_config, log_type_t level, const char *msg, int32_t val, format_type_t format)
 Sends a string, followed by a 32 bit value. More...
 
void log_message_with_64bit_unsigned_dec_val (log_system_config_t *p_config, log_type_t level, const char *msg, uint64_t val, format_type_t format)
 Sends a string, followed by a 64 bit value. More...
 
void log_set_file_max_output_level (log_system_config_t *p_config, log_type_t level)
 Sets maximum output level of logging required, to be used at file scope. More...
 
void log_set_global_max_output_level (log_type_t level)
 Sets maximum output level of logging required, has global effect. More...
 
void log_global_on (void)
 Turns logging system on globally. More...
 
void log_global_off (void)
 Turns logging system off globally. More...
 

Detailed Description

Driver file providing logging functionality over USART, to print debug messages and values to a teminal program on your PC.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Author
Jason Duffy
Date
1st March 2022

Definition in file log_system.h.

Enumeration Type Documentation

◆ log_type_t

enum log_type_t

Enumerated constants for the type of message to be logged.

Definition at line 39 of file log_system.h.

40{
41 NONE,
42 ERROR,
43 WARNING,
44 INFO,
45 DEBUG,
46 VERBOSE_DEBUG
log_type_t
Enumerated constants for the type of message to be logged.
Definition: log_system.h:40

◆ name

enum name

Enumerated constants to specify the output format of numerical values.

Definition at line 53 of file log_system.h.

54{
55 DECIMAL,
56 HEXADECIMAL,
57 BINARY
enum name format_type_t
Enumerated constants to specify the output format of numerical values.

Function Documentation

◆ init_log_system()

void init_log_system ( void  )

Initialisation routine - call this function once at startup before using other functions.

Log system will then be turned on by default - call log_global_off() if you do not wish it to be.

Definition at line 46 of file log_system.c.

47{
48 init_usart();
50 log_message(p_system_tag, INFO, "Log system initialised");
51};
void init_usart(void)
Takes the defined BAUD and F_CPU, calculates the bit-clock multiplier, configures the hardware USART ...
Definition: usart.c:50
void log_global_on(void)
Turns logging system on globally.
Definition: log_system.c:133
void log_message(log_system_config_t *p_config, log_type_t level, const char *msg)
Sends only the system tag, log level and message string.
Definition: log_system.c:93

◆ log_message()

void log_message ( log_system_config_t p_config,
log_type_t  level,
const char *  msg 
)

Sends only the system tag, log level and message string.

Parameters
p_configis a pointer to the log_system config object. Instantiate the config object at the head of each file where logging is required and pass it's address into this function.
levelis the level status of the log message - see log_type_t for available options.
msgis the message to be logged, enclose it in "" quotation marks.

Definition at line 93 of file log_system.c.

96{
97 // If all test expressions evaluate true, log message.
98 if (log_message_preference_check(p_config, level))
99 {
100 print_tag_and_log_level(p_config->p_system_tag, level);
102 }
103}
void usart_print_string(const char myString[])
Utility function to transmit a string.
Definition: usart.c:74
bool log_message_preference_check(log_system_config_t *p_config, log_type_t level)
Utility function to test if the log message level meets the preferences set.
Definition: log_system.c:304
void print_tag_and_log_level(const char *p_tag, log_type_t level)
Utility function to print labels over serial.
Definition: log_system.c:260

◆ log_message_with_8bit_unsigned_val()

void log_message_with_8bit_unsigned_val ( log_system_config_t p_config,
log_type_t  level,
const char *  msg,
uint8_t  val,
format_type_t  format 
)

Sends a string, followed by an 8 bit unsigned value.

Parameters
p_configis a pointer to the log_system config object. Instantiate the config object at the head of each file where logging is required and pass it's address into this function.
levelis the level status of the log message - see log_type_t for available options.
msgis the message to be logged, enclose it in "" quotation marks.
valis the numerical value to be logged - Acceptable values 0 to 255.
formatis the desired output format of val - see format_type_t for avilable options.

◆ log_message_with_8bit_signed_val()

void log_message_with_8bit_signed_val ( log_system_config_t p_config,
log_type_t  level,
const char *  msg,
int8_t  val,
format_type_t  format 
)

Sends a string, followed by an 8 bit value.

Parameters
p_configis a pointer to the log_system config object. Instantiate the config object at the head of each file where logging is required and pass it's address into this function.
levelis the level status of the log message - see log_type_t for available options.
msgis the message to be logged, enclose it in "" quotation marks.
valis the numerical value to be logged - Acceptable values -128 to 127.
formatis the desired output format of val - see format_type_t for avilable options.

Definition at line 118 of file log_system.c.

123{
124 // If all test expressions evaluate true, log message.
125 if (log_message_preference_check(p_config, level))
126 {
127 print_tag_and_log_level(p_config->p_system_tag, level);
130 if (val < 0)
131 {
133 val *= -1; // Convert to positive integer
134 }
135 usart_print_byte(val);
136 }
137}
void usart_print_byte(uint8_t byte)
Prints a byte out as its 3-digit ascii equivalent.
Definition: usart.c:121

◆ log_message_with_16bit_unsigned_val()

void log_message_with_16bit_unsigned_val ( log_system_config_t p_config,
log_type_t  level,
const char *  msg,
uint16_t  val,
format_type_t  format 
)

Sends a string, followed by a 16 bit value.

Parameters
p_configis a pointer to the log_system config object. Instantiate the config object at the head of each file where logging is required and pass it's address into this function.
levelis the level status of the log message - see log_type_t for available options.
msgis the message to be logged, enclose it in "" quotation marks.
valis the numerical value to be logged - Acceptable values 0 - 65,535.
formatis the desired output format of val - see format_type_t for avilable options.

◆ log_message_with_16bit_signed_val()

void log_message_with_16bit_signed_val ( log_system_config_t p_config,
log_type_t  level,
const char *  msg,
int16_t  val,
format_type_t  format 
)

Sends a string, followed by a 16 bit value.

Parameters
p_configis a pointer to the log_system config object. Instantiate the config object at the head of each file where logging is required and pass it's address into this function.
levelis the level status of the log message - see log_type_t for available options.
msgis the message to be logged, enclose it in "" quotation marks.
valis the numerical value to be logged - Acceptable values -32,768 to 32,767.
formatis the desired output format of val - see format_type_t for avilable options.

◆ log_message_with_16bit_unsigned_dec_val()

void log_message_with_16bit_unsigned_dec_val ( log_system_config_t p_config,
log_type_t  level,
const char *  msg,
uint16_t  val 
)

Definition at line 140 of file log_system.c.

144{
145 // If all test expressions evaluate true, log message.
146 if (log_message_preference_check(p_config, level))
147 {
148 print_tag_and_log_level(p_config->p_system_tag, level);
151 usart_print_word(val);
152 }
153}
void usart_print_word(uint16_t word)
Prints a word (16-bits) out as its 5-digit ascii equivalent.
Definition: usart.c:155

◆ log_message_with_32bit_unsigned_val()

void log_message_with_32bit_unsigned_val ( log_system_config_t p_config,
log_type_t  level,
const char *  msg,
uint32_t  val,
format_type_t  format 
)

Sends a string, followed by a 32 bit value.

Parameters
p_configis a pointer to the log_system config object. Instantiate the config object at the head of each file where logging is required and pass it's address into this function.
levelis the level status of the log message - see log_type_t for available options.
msgis the message to be logged, enclose it in "" quotation marks.
valis the numerical value to be logged - Acceptable values 0 - 4,294,967,295.
formatis the desired output format of val - see format_type_t for avilable options.

◆ log_message_with_32bit_signed_val()

void log_message_with_32bit_signed_val ( log_system_config_t p_config,
log_type_t  level,
const char *  msg,
int32_t  val,
format_type_t  format 
)

Sends a string, followed by a 32 bit value.

Parameters
p_configis a pointer to the log_system config object. Instantiate the config object at the head of each file where logging is required and pass it's address into this function.
levelis the level status of the log message - see log_type_t for available options.
msgis the message to be logged, enclose it in "" quotation marks.
valis the numerical value to be logged - Acceptable values 0 - 4,294,967,295.
formatis the desired output format of val - see format_type_t for avilable options.

◆ log_message_with_64bit_unsigned_dec_val()

void log_message_with_64bit_unsigned_dec_val ( log_system_config_t p_config,
log_type_t  level,
const char *  msg,
uint64_t  val,
format_type_t  format 
)

Sends a string, followed by a 64 bit value.

Parameters
p_configis a pointer to the log_system config object. Instantiate the config object at the head of each file where logging is required and pass it's address into this function.
levelis the level status of the log message - see log_type_t for available options.
msgis the message to be logged, enclose it in "" quotation marks.
valis the numerical value to be logged - Acceptable values 0 - (1.8446744e+19 - 1).
formatis the desired output format of val - see format_type_t for avilable options.

◆ log_set_file_max_output_level()

void log_set_file_max_output_level ( log_system_config_t p_config,
log_type_t  level 
)

Sets maximum output level of logging required, to be used at file scope.

Parameters
p_configis a pointer to the log_system config object. Instantiate the config object at the head of each file where logging is required and pass it's address into this function.
levelis the maximum level required - see log_type_t for available options.

Definition at line 217 of file log_system.c.

219{
220 p_config->file_log_level = level;
221}

◆ log_set_global_max_output_level()

void log_set_global_max_output_level ( log_type_t  level)

Sets maximum output level of logging required, has global effect.

Parameters
levelis the maximum level required - see log_type_t for available options.

Definition at line 229 of file log_system.c.

230{
231 global_max_output_level = level;
232}

◆ log_global_on()

void log_global_on ( void  )

Turns logging system on globally.

Definition at line 133 of file log_system.c.

134{
135 log_system_enabled = true;
136}

◆ log_global_off()

void log_global_off ( void  )

Turns logging system off globally.

Definition at line 139 of file log_system.c.

140{
141 log_system_enabled = false;
142}