Skip to content
Permalink
Browse files

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>
  • Loading branch information...
nordic-krch authored and carlescufi committed Jul 29, 2019
1 parent 5a39bca commit fce2692bcc4d17e0c7c4bc295fa1b947f1d822bd
@@ -7,7 +7,9 @@
#define ZEPHYR_INCLUDE_LOGGING_LOG_BACKEND_H_

#include <logging/log_msg.h>
#include <assert.h>
#include <stdarg.h>
#include <sys/__assert.h>

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

#ifdef __cplusplus
extern "C" {
@@ -7,6 +7,7 @@
#define ZEPHYR_INCLUDE_LOGGING_LOG_CTRL_H_

#include <logging/log_backend.h>
#include <kernel.h>

#ifdef __cplusplus
extern "C" {
@@ -6,9 +6,7 @@
#ifndef ZEPHYR_INCLUDE_LOGGING_LOG_MSG_H_
#define ZEPHYR_INCLUDE_LOGGING_LOG_MSG_H_

#include <kernel.h>
#include <sys/atomic.h>
#include <assert.h>
#include <string.h>

#ifdef __cplusplus
@@ -88,37 +86,25 @@ 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();
u16_t reserved : 10;
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.
*
@@ -7,6 +7,8 @@
#define ZEPHYR_INCLUDE_LOGGING_LOG_OUTPUT_H_

#include <logging/log_msg.h>
#include <sys/util.h>
#include <stdarg.h>

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

#define _STDOUT_BUF_SIZE 256
@@ -8,6 +8,7 @@

#include <logging/log_msg.h>
#include <logging/log_output.h>
#include <irq.h>

#ifdef __cplusplus
extern "C" {
@@ -8,6 +8,23 @@
#include <logging/log_ctrl.h>
#include <logging/log_core.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
#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);

0 comments on commit fce2692

Please sign in to comment.
You can’t perform that action at this time.