AVRly - AVR Development Resources
log_system.c File Reference

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

#include <stdbool.h>
#include "usart.h"
#include "log_system.h"

Go to the source code of this file.

Functions

void print_tag_and_log_level (const char *p_tag, enum eLogLevel level)
 
void init_log_system (void)
 Initialisation routine - call this function once at startup before using other functions. More...
 
void log_message (const char *p_tag, enum eLogLevel level, const char *msg)
 
void log_message_with_dec_val (const char *p_tag, enum eLogLevel level, const char *msg, uint8_t val)
 
void log_message_with_16bit_dec_val (const char *p_tag, enum eLogLevel level, const char *msg, uint16_t val)
 
void log_message_with_bin_val (const char *p_tag, enum eLogLevel level, const char *msg, uint8_t val)
 
void log_message_with_16bit_bin_val (const char *p_tag, enum eLogLevel level, const char *msg, uint16_t val)
 
void log_message_with_hex_val (const char *p_tag, enum eLogLevel level, const char *msg, uint8_t val)
 
void log_set_output_level (const char *p_tag, enum eLogLevel level)
 
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.c.

Function Documentation

◆ print_tag_and_log_level()

void print_tag_and_log_level ( const char *  p_tag,
enum eLogLevel  level 
)

Definition at line 151 of file log_system.c.

152{
153 if (level == NONE)
154 {
155 break;
156 }
157 print_string("\n");
158 print_string(p_tag);
159
160 if (level == INFO)
161 {
162 print_string(", INFO: ");
163 }
164
165 else if (level == DEBUG)
166 {
167 print_string(", DEBUG: ");
168 }
169
170 else if (level == VERBOSE_DEBUG)
171 {
172 print_string(", VERBOSE_DEBUG: ");
173 }
174
175 else if (level == WARNING)
176 {
177 print_string(", WARNING: ");
178 }
179
180 else if (level == ERROR)
181 {
182 print_string(", ERROR: ");
183 }
184
185 // TODO: Throw exception here to be caught at compile time
186 else
187 {
188 print_string(", INVALID_LOG_LEVEL: ");
189 }
190}
void print_string(const char myString[])
Utility function to transmit an entire string from RAM.
Definition: usart.c:67

◆ 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 ( const char *  p_tag,
enum eLogLevel  level,
const char *  msg 
)

Definition at line 54 of file log_system.c.

55{
56 print_tag_and_log_level(p_tag, level);
57 print_string(msg);
58}
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_dec_val()

void log_message_with_dec_val ( const char *  p_tag,
enum eLogLevel  level,
const char *  msg,
uint8_t  val 
)

Definition at line 61 of file log_system.c.

65{
66 print_tag_and_log_level(p_tag, level);
67 print_string(msg);
68 print_string(" ");
69 print_byte(val);
70}
void print_byte(uint8_t byte)
Prints a byte out as its 3-digit ascii equivalent.
Definition: usart.c:106

◆ log_message_with_16bit_dec_val()

void log_message_with_16bit_dec_val ( const char *  p_tag,
enum eLogLevel  level,
const char *  msg,
uint16_t  val 
)

Definition at line 74 of file log_system.c.

78{
79 print_tag_and_log_level(p_tag, level);
80 print_string(msg);
81 print_string(" ");
82 print_word(val);
83}
void print_word(uint16_t word)
Prints a word (16-bits) out as its 5-digit ascii equivalent.
Definition: usart.c:115

◆ log_message_with_bin_val()

void log_message_with_bin_val ( const char *  p_tag,
enum eLogLevel  level,
const char *  msg,
uint8_t  val 
)

Definition at line 87 of file log_system.c.

91{
92 print_tag_and_log_level(p_tag, level);
93 print_string(msg);
94 print_string(" ");
96}
void print_binary_byte(uint8_t byte)
Prints a byte out in 1s and 0s.
Definition: usart.c:125

◆ log_message_with_16bit_bin_val()

void log_message_with_16bit_bin_val ( const char *  p_tag,
enum eLogLevel  level,
const char *  msg,
uint16_t  val 
)

Definition at line 99 of file log_system.c.

103{
104 print_tag_and_log_level(p_tag, level);
105 print_string(msg);
106 print_string(" ");
107
108 uint8_t msb = (val >> 8);
109 uint8_t lsb = val;
112}

◆ log_message_with_hex_val()

void log_message_with_hex_val ( const char *  p_tag,
enum eLogLevel  level,
const char *  msg,
uint8_t  val 
)

Definition at line 115 of file log_system.c.

119{
120 print_tag_and_log_level(p_tag, level);
121 print_string(msg);
122 print_string(" ");
123 print_hex_byte(val);
124}
void print_hex_byte(uint8_t byte)
Prints a byte out in hexadecimal.
Definition: usart.c:155

◆ log_set_output_level()

void log_set_output_level ( const char *  p_tag,
enum eLogLevel  level 
)

Definition at line 127 of file log_system.c.

128{
129
130}

◆ 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}