MCU-Common
Modules useful for embedded (MCU) programming
|
Universal logger module with deferred processing. More...
Data Structures | |
struct | logger |
Logger instance. More... | |
Macros | |
#define | LOGGER_MAX_ARGC 6 |
The maximum number of logger_put() arguments supported by the implementation. More... | |
#define | LOGGER_INIT(log, log_write_cb, log_capacity, str_capacity) |
Initializes the logger instance and allocates its string and FIFO buffers. More... | |
#define | LOGGER_PUT(log, ...) logger_put(log, VA_ARGC(__VA_ARGS__), __VA_ARGS__) |
Logs a message. More... | |
Functions | |
bool | logger_init (struct logger *log) |
Initializes logger. More... | |
bool | logger_put (const struct logger *log, int argc, const char *fmt,...) |
Logs a message (puts it into internal buffer for later processing). More... | |
bool | logger_process (const struct logger *log) |
Processes a single logged message from the buffer. More... | |
Universal logger module with deferred processing.
#define LOGGER_MAX_ARGC 6 |
The maximum number of logger_put() arguments supported by the implementation.
It is possible to reduce the number by providing a custom LOGGER_MAX_ARGC definition to save the space required by logger_entry.
#define LOGGER_INIT | ( | log, | |
log_write_cb, | |||
log_capacity, | |||
str_capacity | |||
) |
Initializes the logger instance and allocates its string and FIFO buffers.
log | Pointer to the logger structure |
log_write_cb | Pointer to write callback implemented by driver (see logger.write_cb for details) |
log_capacity | Capacity of the internal FIFO (maximum number of messages to be stored, see fifo.capacity) |
str_capacity | Capacity of the internal string buffer (should be large enough to store a message composed by snprintf , see logger.str and logger.str_size) |
#define LOGGER_PUT | ( | log, | |
... | |||
) | logger_put(log, VA_ARGC(__VA_ARGS__), __VA_ARGS__) |
Logs a message.
This is a macro which automatically determines the number of arguments and is replaced by the proper function logger_put0() to logger_put6().
log | Pointer to the logger structure |
... | Format string and up to LOGGER_MAX_ARGC optional arguments to be passed to sprintf (the format string is mandatory). |
bool logger_init | ( | struct logger * | log | ) |
Initializes logger.
log | Pointer to the logger structure |
true
if initialization succeeds, false
otherwise bool logger_put | ( | const struct logger * | log, |
int | argc, | ||
const char * | fmt, | ||
... | |||
) |
Logs a message (puts it into internal buffer for later processing).
The message consists of a format string and variable number of arguments which will be processed by sprintf
in logger_process(). To determine the number of arguments (argc
) automatically, use macro LOGGER_PUT() instead.
The access to internal fifo is protected by a critical section so logger_put() can be called from multiple threads or interrupt handlers.
log | Pointer to the logger structure | |
argc | Number of arguments (0 to LOGGER_MAX_ARGC) | |
[in] | fmt | Format string to be passed to sprintf |
... | Optional arguments to be passed to sprintf (only argc parameters will be processed) |
true
if initialization succeeds, false
otherwise (internal FIFO is full) bool logger_process | ( | const struct logger * | log | ) |
Processes a single logged message from the buffer.
This function calls logger.write_cb callback (implemented by the driver) to write the message to an actual output interface. It is meant to defer log processing from high priority contexts (such as interrupts) and should be therefore called in a low-priority context (e.g. a main loop).
It is assumed this function is called from multiple threads (the internal fifo is not protected by any locking mechanism).
log | Pointer to the logger structure |
true
if a message has been processed, false
otherwise (internal FIFO is empty)