diff --git a/include/logging/log_backend.h b/include/logging/log_backend.h index 68ec651ea81..3a918f47009 100644 --- a/include/logging/log_backend.h +++ b/include/logging/log_backend.h @@ -7,7 +7,9 @@ #define ZEPHYR_INCLUDE_LOGGING_LOG_BACKEND_H_ #include -#include +#include +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/include/logging/log_core.h b/include/logging/log_core.h index 1665c67a7a2..b08aad40224 100644 --- a/include/logging/log_core.h +++ b/include/logging/log_core.h @@ -11,6 +11,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { diff --git a/include/logging/log_ctrl.h b/include/logging/log_ctrl.h index f3b2d59ae5c..11ce67ebfd5 100644 --- a/include/logging/log_ctrl.h +++ b/include/logging/log_ctrl.h @@ -7,6 +7,7 @@ #define ZEPHYR_INCLUDE_LOGGING_LOG_CTRL_H_ #include +#include #ifdef __cplusplus extern "C" { diff --git a/include/logging/log_msg.h b/include/logging/log_msg.h index eceb809a242..f0187140e99 100644 --- a/include/logging/log_msg.h +++ b/include/logging/log_msg.h @@ -6,9 +6,7 @@ #ifndef ZEPHYR_INCLUDE_LOGGING_LOG_MSG_H_ #define ZEPHYR_INCLUDE_LOGGING_LOG_MSG_H_ -#include #include -#include #include #ifdef __cplusplus @@ -88,18 +86,12 @@ struct log_msg_ids { 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. */ struct log_msg_generic_hdr { COMMON_PARAM_HDR(); 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. */ struct log_msg_std_hdr { COMMON_PARAM_HDR(); @@ -107,18 +99,12 @@ struct log_msg_std_hdr { 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. */ struct log_msg_hexdump_hdr { COMMON_PARAM_HDR(); 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 */ struct log_msg_hdr { atomic_t ref_cnt; /*!< Reference counter for tracking message users. */ @@ -158,10 +144,6 @@ struct log_msg { } 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. */ struct log_msg_cont { struct log_msg_cont *next; /*!< Pointer to the next chunk. */ @@ -177,8 +159,6 @@ union log_msg_chunk { struct log_msg_cont cont; }; -extern struct k_mem_slab log_msg_pool; - /** @brief Function for initialization of the log message pool. */ 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); -static inline 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; -} +/** @brief Allocate single chunk from the pool. + * + * @return Pointer to the allocated chunk or NULL if failed to allocate. + */ +union log_msg_chunk *log_msg_chunk_alloc(void); /** @brief Allocate chunk for standard log message. * diff --git a/include/logging/log_output.h b/include/logging/log_output.h index 066f0785248..b15c8c90518 100644 --- a/include/logging/log_output.h +++ b/include/logging/log_output.h @@ -7,6 +7,8 @@ #define ZEPHYR_INCLUDE_LOGGING_LOG_OUTPUT_H_ #include +#include +#include #ifdef __cplusplus extern "C" { diff --git a/subsys/logging/log_backend_native_posix.c b/subsys/logging/log_backend_native_posix.c index 152b97d4aa7..b26457eeee5 100644 --- a/subsys/logging/log_backend_native_posix.c +++ b/subsys/logging/log_backend_native_posix.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "posix_trace.h" #define _STDOUT_BUF_SIZE 256 diff --git a/subsys/logging/log_backend_std.h b/subsys/logging/log_backend_std.h index 332408e6c86..219679a63cb 100644 --- a/subsys/logging/log_backend_std.h +++ b/subsys/logging/log_backend_std.h @@ -8,6 +8,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { diff --git a/subsys/logging/log_msg.c b/subsys/logging/log_msg.c index 155d736f8de..cab68a6ecda 100644 --- a/subsys/logging/log_msg.c +++ b/subsys/logging/log_msg.c @@ -8,6 +8,23 @@ #include #include #include +#include + +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 #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); } +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) { atomic_inc(&msg->hdr.ref_cnt);