Skip to content

Commit

Permalink
[features]: 实现中断上下文打印输出特性支持 v2
Browse files Browse the repository at this point in the history
  1. 添加宏定义控制是否启用中断输出支持
  • Loading branch information
ji.hb committed Nov 19, 2023
1 parent 5101be2 commit 4b4672e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
3 changes: 3 additions & 0 deletions easylogger/inc/elog_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,8 @@
#define ELOG_BUF_OUTPUT_ENABLE
/* buffer size for buffered output mode */
#define ELOG_BUF_OUTPUT_BUF_SIZE (ELOG_LINE_BUF_SIZE * 10)
/*---------------------------------------------------------------------------*/
/* enable use elog in isr context */
// #define ELOG_USING_ISR_LOG

#endif /* _ELOG_CFG_H_ */
4 changes: 4 additions & 0 deletions easylogger/port/elog_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ void elog_port_interrupt_get_nest(void) {

}

#ifdef ELOG_USING_ISR_LOG

/**
* output lock in isr context
*/
Expand All @@ -90,6 +92,8 @@ void elog_port_output_unlock_isr(void) {

}

#endif

/**
* output lock
*/
Expand Down
26 changes: 24 additions & 2 deletions easylogger/src/elog.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,26 @@ void (*elog_assert_hook)(const char* expr, const char* func, size_t line);

extern void elog_port_output(const char *log, size_t size);
extern int elog_port_interrupt_get_nest(void);

#ifdef ELOG_USING_ISR_LOG
extern void elog_port_output_lock_isr(void);
extern void elog_port_output_unlock_isr(void);
#endif

extern void elog_port_output_lock(void);
extern void elog_port_output_unlock(void);

static char *get_log_buf(void)
{
if (elog_port_interrupt_get_nest() == 0)
if (elog_port_interrupt_get_nest() == 0) {
return thread_log_buf;
else
} else {
#ifdef ELOG_USING_ISR_LOG
return isr_log_buf;
#else
return NULL;
#endif
}
}

/**
Expand Down Expand Up @@ -388,8 +397,10 @@ void elog_output_lock(void) {
elog.output_is_locked_before_enable = true;
}
} else {
#ifdef ELOG_USING_ISR_LOG
if (elog.output_lock_enabled)
elog_port_output_lock_isr();
#endif
}
}

Expand All @@ -405,8 +416,10 @@ void elog_output_unlock(void) {
elog.output_is_locked_before_enable = false;
}
} else {
#ifdef ELOG_USING_ISR_LOG
if (elog.output_lock_enabled)
elog_port_output_unlock_isr();
#endif
}
}

Expand Down Expand Up @@ -537,6 +550,9 @@ void elog_raw_output(const char *format, ...) {
}

log_buf = get_log_buf();
if (log_buf == NULL) {
return;
}

/* args point to the first variable parameter */
va_start(args, format);
Expand Down Expand Up @@ -609,6 +625,9 @@ void elog_output(uint8_t level, const char *tag, const char *file, const char *f
}

log_buf = get_log_buf();
if (log_buf == NULL) {
return;
}

/* args point to the first variable parameter */
va_start(args, format);
Expand Down Expand Up @@ -902,6 +921,9 @@ void elog_hexdump(const char *name, uint8_t width, const void *buf, uint16_t siz
}

log_buf = get_log_buf();
if (log_buf == NULL) {
return;
}

/* lock output */
elog_output_lock();
Expand Down

0 comments on commit 4b4672e

Please sign in to comment.