logging: printk: Fix LOG_PRINTK for v2

Fixed a dependency from printk.h to logging headers which in
certain configurations could lead to circular dependencies.
Cleaned up printk.c to call z_log_vprintk from vprintk.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2022-01-19 14:43:00 +01:00 committed by Carles Cufí
commit a40ca6fd1c
4 changed files with 56 additions and 66 deletions

View file

@ -256,18 +256,16 @@ extern "C" {
* @brief Writes an formatted string to the log.
*
* @details Conditionally compiled (see CONFIG_LOG_PRINTK). Function provides
* printk functionality. It is inefficient compared to standard logging
* because string formatting is performed in the call context and not deferred
* to the log processing context (@ref log_process).
* printk functionality.
*
* It is less efficient compared to standard logging because static packaging
* cannot be used. When CONFIG_LOG1 is used string formatting is performed in the
* call context and not deferred to the log processing context (@ref log_process).
*
* @param fmt Formatted string to output.
* @param ap Variable parameters.
*/
void z_log_printk(const char *fmt, va_list ap);
static inline void log_printk(const char *fmt, va_list ap)
{
z_log_printk(fmt, ap);
}
void z_log_vprintk(const char *fmt, va_list ap);
/** @brief Copy transient string to a buffer from internal, logger pool.
*

View file

@ -12,9 +12,6 @@
#include <stddef.h>
#include <stdarg.h>
#include <inttypes.h>
#if defined(CONFIG_LOG_PRINTK) && defined(CONFIG_LOG2)
#include <logging/log.h>
#endif
#ifdef __cplusplus
extern "C" {
@ -47,18 +44,8 @@ extern "C" {
*/
#ifdef CONFIG_PRINTK
#if defined(CONFIG_LOG_PRINTK) && defined(CONFIG_LOG2)
#define printk(...) Z_LOG_PRINTK(__VA_ARGS__)
static inline __printf_like(1, 0) void vprintk(const char *fmt, va_list ap)
{
z_log_msg2_runtime_vcreate(CONFIG_LOG_DOMAIN_ID, NULL,
LOG_LEVEL_INTERNAL_RAW_STRING, NULL, 0,
fmt, ap);
}
#else
extern __printf_like(1, 2) void printk(const char *fmt, ...);
extern __printf_like(1, 0) void vprintk(const char *fmt, va_list ap);
#endif /* defined(CONFIG_LOG_PRINTK) && defined(CONFIG_LOG) */
#else
static inline __printf_like(1, 2) void printk(const char *fmt, ...)

View file

@ -27,8 +27,7 @@
#define CONFIG_PRINTK_BUFFER_SIZE 0
#endif
#if defined(CONFIG_PRINTK_SYNC) && \
!(defined(CONFIG_LOG_PRINTK) && defined(CONFIG_LOG2))
#if defined(CONFIG_PRINTK_SYNC)
static struct k_spinlock lock;
#endif
@ -78,10 +77,7 @@ void *__printk_get_hook(void)
{
return _char_out;
}
#endif /* CONFIG_PRINTK */
#if defined(CONFIG_PRINTK) && \
!(defined(CONFIG_LOG_PRINTK) && defined(CONFIG_LOG2))
struct buf_out_context {
int count;
unsigned int buf_count;
@ -121,6 +117,11 @@ static int char_out(int c, void *ctx_p)
void vprintk(const char *fmt, va_list ap)
{
if (IS_ENABLED(CONFIG_LOG_PRINTK)) {
z_log_vprintk(fmt, ap);
return;
}
if (k_is_user_context()) {
struct buf_out_context ctx = { 0 };
@ -195,16 +196,11 @@ void printk(const char *fmt, ...)
va_start(ap, fmt);
if (IS_ENABLED(CONFIG_LOG_PRINTK)) {
log_printk(fmt, ap);
} else {
vprintk(fmt, ap);
}
va_end(ap);
}
#endif /* defined(CONFIG_PRINTK) && \
* !(defined(CONFIG_LOG_PRINTK) && defined(CONFIG_LOG2))
*/
#endif /* defined(CONFIG_PRINTK) */
struct str_context {
char *str;

View file

@ -370,9 +370,19 @@ void log_hexdump(const char *str, const void *data, uint32_t length,
}
}
void z_log_printk(const char *fmt, va_list ap)
void z_log_vprintk(const char *fmt, va_list ap)
{
if (IS_ENABLED(CONFIG_LOG_PRINTK)) {
if (!IS_ENABLED(CONFIG_LOG_PRINTK)) {
return;
}
if (!IS_ENABLED(CONFIG_LOG1)) {
z_log_msg2_runtime_vcreate(CONFIG_LOG_DOMAIN_ID, NULL,
LOG_LEVEL_INTERNAL_RAW_STRING, NULL, 0,
fmt, ap);
return;
}
union {
struct log_msg_ids structure;
uint32_t value;
@ -407,7 +417,6 @@ void z_log_printk(const char *fmt, va_list ap)
msg_finalize(msg, src_level_union.structure);
}
}
}
/** @brief Count number of arguments in formatted string.
*