Files
kunlun/common/io_lib/src/iot_printf.c
2024-09-28 14:24:04 +08:00

110 lines
2.4 KiB
C
Executable File

/****************************************************************************
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
be copied by any method or incorporated into another program without
the express written consent of Aerospace C.Power. This Information or any portion
thereof remains the property of Aerospace C.Power. The Information contained herein
is believed to be accurate and Aerospace C.Power assumes no responsibility or
liability for its use in any way and conveys no license or title under
any patent or copyright and makes no representation or warranty that this
Information is free from patent or copyright infringement.
****************************************************************************/
/* os shim includes */
#include "os_types.h"
#include "iot_config.h"
#include "strformat.h"
#include "os_lock.h"
uint8_t g_print_enable = 0;
uint8_t g_app_print_enable = 1;
os_mutex_h g_prt_log_mutex = NULL;
static StrFormatResult write_str(void *user_data,
const char *data, unsigned int len)
{
return STRFORMAT_OK;
}
str_format_context log_ctxt = {
write_str,
NULL,
NULL,
};
#if IOT_PRINTF_DEBUG
int32_t iot_printf(const char *fmt, ...)
{
int res;
va_list ap;
if(g_print_enable == 0)
return 0;
if (g_prt_log_mutex != NULL) {
os_acquire_mutex(g_prt_log_mutex);
}
va_start(ap, fmt);
res = format_str_v(&log_ctxt, fmt, ap);
va_end(ap);
if (g_prt_log_mutex != NULL) {
os_release_mutex(g_prt_log_mutex);
}
return res;
}
#endif
int32_t iot_cus_printf(const char *fmt, ...)
{
int res;
va_list ap;
if(g_app_print_enable == 0)
return 0;
if (g_prt_log_mutex != NULL) {
os_acquire_mutex(g_prt_log_mutex);
}
va_start(ap, fmt);
res = format_str_v(&log_ctxt, fmt, ap);
va_end(ap);
if (g_prt_log_mutex != NULL) {
os_release_mutex(g_prt_log_mutex);
}
return res;
}
int32_t __iot_printf(uint8_t dummy, ...)
{
(void)dummy;
return 0;
}
void iot_print_config(bool_t enable)
{
g_print_enable = enable;
}
void iot_cus_print_config(bool_t enable)
{
g_app_print_enable = enable;
/* enable cus print */
if (log_ctxt.enable_str != NULL) {
log_ctxt.enable_str(enable);
}
}