logging: Clean up log.h dependencies

Cleaning up log.h include dependencies to allow log.h including in base
headers (e.g. kernel.h).

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2019-07-29 12:24:04 +02:00 committed by Carles Cufí
commit fce2692bcc
8 changed files with 43 additions and 32 deletions

View file

@ -7,7 +7,9 @@
#define ZEPHYR_INCLUDE_LOGGING_LOG_BACKEND_H_ #define ZEPHYR_INCLUDE_LOGGING_LOG_BACKEND_H_
#include <logging/log_msg.h> #include <logging/log_msg.h>
#include <assert.h> #include <stdarg.h>
#include <sys/__assert.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

View file

@ -11,6 +11,7 @@
#include <sys/util.h> #include <sys/util.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdarg.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View file

@ -7,6 +7,7 @@
#define ZEPHYR_INCLUDE_LOGGING_LOG_CTRL_H_ #define ZEPHYR_INCLUDE_LOGGING_LOG_CTRL_H_
#include <logging/log_backend.h> #include <logging/log_backend.h>
#include <kernel.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View file

@ -6,9 +6,7 @@
#ifndef ZEPHYR_INCLUDE_LOGGING_LOG_MSG_H_ #ifndef ZEPHYR_INCLUDE_LOGGING_LOG_MSG_H_
#define ZEPHYR_INCLUDE_LOGGING_LOG_MSG_H_ #define ZEPHYR_INCLUDE_LOGGING_LOG_MSG_H_
#include <kernel.h>
#include <sys/atomic.h> #include <sys/atomic.h>
#include <assert.h>
#include <string.h> #include <string.h>
#ifdef __cplusplus #ifdef __cplusplus
@ -88,18 +86,12 @@ struct log_msg_ids {
u16_t source_id : 10; /*!< Source ID. */ u16_t source_id : 10; /*!< Source ID. */
}; };
BUILD_ASSERT_MSG((sizeof(struct log_msg_ids) == sizeof(u16_t)),
"Structure must fit in 2 bytes");
/** Part of log message header common to standard and hexdump log message. */ /** Part of log message header common to standard and hexdump log message. */
struct log_msg_generic_hdr { struct log_msg_generic_hdr {
COMMON_PARAM_HDR(); COMMON_PARAM_HDR();
u16_t reserved : 14; u16_t reserved : 14;
}; };
BUILD_ASSERT_MSG((sizeof(struct log_msg_generic_hdr) == sizeof(u16_t)),
"Structure must fit in 2 bytes");
/** Part of log message header specific to standard log message. */ /** Part of log message header specific to standard log message. */
struct log_msg_std_hdr { struct log_msg_std_hdr {
COMMON_PARAM_HDR(); COMMON_PARAM_HDR();
@ -107,18 +99,12 @@ struct log_msg_std_hdr {
u16_t nargs : 4; u16_t nargs : 4;
}; };
BUILD_ASSERT_MSG((sizeof(struct log_msg_std_hdr) == sizeof(u16_t)),
"Structure must fit in 2 bytes");
/** Part of log message header specific to hexdump log message. */ /** Part of log message header specific to hexdump log message. */
struct log_msg_hexdump_hdr { struct log_msg_hexdump_hdr {
COMMON_PARAM_HDR(); COMMON_PARAM_HDR();
u16_t length : LOG_MSG_HEXDUMP_LENGTH_BITS; u16_t length : LOG_MSG_HEXDUMP_LENGTH_BITS;
}; };
BUILD_ASSERT_MSG((sizeof(struct log_msg_hexdump_hdr) == sizeof(u16_t)),
"Structure must fit in 2 bytes");
/** Log message header structure */ /** Log message header structure */
struct log_msg_hdr { struct log_msg_hdr {
atomic_t ref_cnt; /*!< Reference counter for tracking message users. */ atomic_t ref_cnt; /*!< Reference counter for tracking message users. */
@ -158,10 +144,6 @@ struct log_msg {
} payload; /*!< Message data. */ } payload; /*!< Message data. */
}; };
BUILD_ASSERT_MSG((sizeof(union log_msg_head_data) ==
sizeof(struct log_msg_ext_head_data)),
"Structure must be same size");
/** @brief Chunks following message head when message is extended. */ /** @brief Chunks following message head when message is extended. */
struct log_msg_cont { struct log_msg_cont {
struct log_msg_cont *next; /*!< Pointer to the next chunk. */ struct log_msg_cont *next; /*!< Pointer to the next chunk. */
@ -177,8 +159,6 @@ union log_msg_chunk {
struct log_msg_cont cont; struct log_msg_cont cont;
}; };
extern struct k_mem_slab log_msg_pool;
/** @brief Function for initialization of the log message pool. */ /** @brief Function for initialization of the log message pool. */
void log_msg_pool_init(void); void log_msg_pool_init(void);
@ -327,17 +307,11 @@ void log_msg_hexdump_data_get(struct log_msg *msg,
union log_msg_chunk *log_msg_no_space_handle(void); union log_msg_chunk *log_msg_no_space_handle(void);
static inline union log_msg_chunk *log_msg_chunk_alloc(void) /** @brief Allocate single chunk from the pool.
{ *
union log_msg_chunk *msg = NULL; * @return Pointer to the allocated chunk or NULL if failed to allocate.
int err = k_mem_slab_alloc(&log_msg_pool, (void **)&msg, K_NO_WAIT); */
union log_msg_chunk *log_msg_chunk_alloc(void);
if (err != 0) {
msg = log_msg_no_space_handle();
}
return msg;
}
/** @brief Allocate chunk for standard log message. /** @brief Allocate chunk for standard log message.
* *

View file

@ -7,6 +7,8 @@
#define ZEPHYR_INCLUDE_LOGGING_LOG_OUTPUT_H_ #define ZEPHYR_INCLUDE_LOGGING_LOG_OUTPUT_H_
#include <logging/log_msg.h> #include <logging/log_msg.h>
#include <sys/util.h>
#include <stdarg.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View file

@ -11,6 +11,7 @@
#include <logging/log_core.h> #include <logging/log_core.h>
#include <logging/log_msg.h> #include <logging/log_msg.h>
#include <logging/log_output.h> #include <logging/log_output.h>
#include <irq.h>
#include "posix_trace.h" #include "posix_trace.h"
#define _STDOUT_BUF_SIZE 256 #define _STDOUT_BUF_SIZE 256

View file

@ -8,6 +8,7 @@
#include <logging/log_msg.h> #include <logging/log_msg.h>
#include <logging/log_output.h> #include <logging/log_output.h>
#include <irq.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View file

@ -8,6 +8,23 @@
#include <logging/log_ctrl.h> #include <logging/log_ctrl.h>
#include <logging/log_core.h> #include <logging/log_core.h>
#include <string.h> #include <string.h>
#include <assert.h>
BUILD_ASSERT_MSG((sizeof(struct log_msg_ids) == sizeof(u16_t)),
"Structure must fit in 2 bytes");
BUILD_ASSERT_MSG((sizeof(struct log_msg_generic_hdr) == sizeof(u16_t)),
"Structure must fit in 2 bytes");
BUILD_ASSERT_MSG((sizeof(struct log_msg_std_hdr) == sizeof(u16_t)),
"Structure must fit in 2 bytes");
BUILD_ASSERT_MSG((sizeof(struct log_msg_hexdump_hdr) == sizeof(u16_t)),
"Structure must fit in 2 bytes");
BUILD_ASSERT_MSG((sizeof(union log_msg_head_data) ==
sizeof(struct log_msg_ext_head_data)),
"Structure must be same size");
#ifndef CONFIG_LOG_BUFFER_SIZE #ifndef CONFIG_LOG_BUFFER_SIZE
#define CONFIG_LOG_BUFFER_SIZE 0 #define CONFIG_LOG_BUFFER_SIZE 0
@ -25,6 +42,18 @@ void log_msg_pool_init(void)
k_mem_slab_init(&log_msg_pool, log_msg_pool_buf, MSG_SIZE, NUM_OF_MSGS); k_mem_slab_init(&log_msg_pool, log_msg_pool_buf, MSG_SIZE, NUM_OF_MSGS);
} }
union log_msg_chunk *log_msg_chunk_alloc(void)
{
union log_msg_chunk *msg = NULL;
int err = k_mem_slab_alloc(&log_msg_pool, (void **)&msg, K_NO_WAIT);
if (err != 0) {
msg = log_msg_no_space_handle();
}
return msg;
}
void log_msg_get(struct log_msg *msg) void log_msg_get(struct log_msg *msg)
{ {
atomic_inc(&msg->hdr.ref_cnt); atomic_inc(&msg->hdr.ref_cnt);