2018-08-09 15:56:10 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Nordic Semiconductor ASA
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SHELL_FPRINTF_H__
|
|
|
|
#define SHELL_FPRINTF_H__
|
|
|
|
|
|
|
|
#include <zephyr.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef void (*shell_fprintf_fwrite)(const void *user_ctx,
|
2020-12-06 18:22:27 +08:00
|
|
|
const char *data,
|
|
|
|
size_t length);
|
2018-08-09 15:56:10 +08:00
|
|
|
|
|
|
|
struct shell_fprintf_control_block {
|
|
|
|
size_t buffer_cnt;
|
|
|
|
bool autoflush;
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* @brief fprintf context
|
|
|
|
*/
|
|
|
|
struct shell_fprintf {
|
2020-05-28 00:26:57 +08:00
|
|
|
uint8_t *buffer;
|
2018-08-09 15:56:10 +08:00
|
|
|
size_t buffer_size;
|
|
|
|
shell_fprintf_fwrite fwrite;
|
|
|
|
const void *user_ctx;
|
|
|
|
struct shell_fprintf_control_block *ctrl_blk;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Macro for defining shell_fprintf instance.
|
|
|
|
*
|
|
|
|
* @param _name Instance name.
|
|
|
|
* @param _user_ctx Pointer to user data.
|
|
|
|
* @param _buf Pointer to output buffer
|
|
|
|
* @param _size Size of output buffer.
|
|
|
|
* @param _autoflush Indicator if buffer shall be automatically flush.
|
|
|
|
* @param _fwrite Pointer to function sending data stream.
|
|
|
|
*/
|
2020-12-06 18:22:27 +08:00
|
|
|
#define Z_SHELL_FPRINTF_DEFINE(_name, _user_ctx, _buf, _size, \
|
2018-08-09 15:56:10 +08:00
|
|
|
_autoflush, _fwrite) \
|
|
|
|
static struct shell_fprintf_control_block \
|
|
|
|
_name##_shell_fprintf_ctx = { \
|
|
|
|
.autoflush = _autoflush, \
|
|
|
|
.buffer_cnt = 0 \
|
|
|
|
}; \
|
|
|
|
static const struct shell_fprintf _name = { \
|
|
|
|
.buffer = _buf, \
|
|
|
|
.buffer_size = _size, \
|
|
|
|
.fwrite = _fwrite, \
|
|
|
|
.user_ctx = _user_ctx, \
|
|
|
|
.ctrl_blk = &_name##_shell_fprintf_ctx \
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-09-27 07:29:24 +08:00
|
|
|
* @brief fprintf like function which send formatted data stream to output.
|
2018-08-09 15:56:10 +08:00
|
|
|
*
|
|
|
|
* @param sh_fprintf fprintf instance.
|
|
|
|
* @param fmt Format string.
|
|
|
|
* @param args List of parameters to print.
|
|
|
|
*/
|
2020-12-06 18:22:27 +08:00
|
|
|
void z_shell_fprintf_fmt(const struct shell_fprintf *sh_fprintf,
|
|
|
|
char const *fmt, va_list args);
|
2018-08-09 15:56:10 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief function flushing data stored in io_buffer.
|
|
|
|
*
|
|
|
|
* @param sh_fprintf fprintf instance
|
|
|
|
*/
|
2020-12-06 18:22:27 +08:00
|
|
|
void z_shell_fprintf_buffer_flush(const struct shell_fprintf *sh_fprintf);
|
2018-08-09 15:56:10 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* SHELL_FPRINTF_H__ */
|