Skip to content

Commit 4b4672e

Browse files
author
ji.hb
committed
[features]: 实现中断上下文打印输出特性支持 v2
1. 添加宏定义控制是否启用中断输出支持
1 parent 5101be2 commit 4b4672e

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

easylogger/inc/elog_cfg.h

+3
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,8 @@
7373
#define ELOG_BUF_OUTPUT_ENABLE
7474
/* buffer size for buffered output mode */
7575
#define ELOG_BUF_OUTPUT_BUF_SIZE (ELOG_LINE_BUF_SIZE * 10)
76+
/*---------------------------------------------------------------------------*/
77+
/* enable use elog in isr context */
78+
// #define ELOG_USING_ISR_LOG
7679

7780
#endif /* _ELOG_CFG_H_ */

easylogger/port/elog_port.c

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ void elog_port_interrupt_get_nest(void) {
7272

7373
}
7474

75+
#ifdef ELOG_USING_ISR_LOG
76+
7577
/**
7678
* output lock in isr context
7779
*/
@@ -90,6 +92,8 @@ void elog_port_output_unlock_isr(void) {
9092

9193
}
9294

95+
#endif
96+
9397
/**
9498
* output lock
9599
*/

easylogger/src/elog.c

+24-2
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,26 @@ void (*elog_assert_hook)(const char* expr, const char* func, size_t line);
149149

150150
extern void elog_port_output(const char *log, size_t size);
151151
extern int elog_port_interrupt_get_nest(void);
152+
153+
#ifdef ELOG_USING_ISR_LOG
152154
extern void elog_port_output_lock_isr(void);
153155
extern void elog_port_output_unlock_isr(void);
156+
#endif
157+
154158
extern void elog_port_output_lock(void);
155159
extern void elog_port_output_unlock(void);
156160

157161
static char *get_log_buf(void)
158162
{
159-
if (elog_port_interrupt_get_nest() == 0)
163+
if (elog_port_interrupt_get_nest() == 0) {
160164
return thread_log_buf;
161-
else
165+
} else {
166+
#ifdef ELOG_USING_ISR_LOG
162167
return isr_log_buf;
168+
#else
169+
return NULL;
170+
#endif
171+
}
163172
}
164173

165174
/**
@@ -388,8 +397,10 @@ void elog_output_lock(void) {
388397
elog.output_is_locked_before_enable = true;
389398
}
390399
} else {
400+
#ifdef ELOG_USING_ISR_LOG
391401
if (elog.output_lock_enabled)
392402
elog_port_output_lock_isr();
403+
#endif
393404
}
394405
}
395406

@@ -405,8 +416,10 @@ void elog_output_unlock(void) {
405416
elog.output_is_locked_before_enable = false;
406417
}
407418
} else {
419+
#ifdef ELOG_USING_ISR_LOG
408420
if (elog.output_lock_enabled)
409421
elog_port_output_unlock_isr();
422+
#endif
410423
}
411424
}
412425

@@ -537,6 +550,9 @@ void elog_raw_output(const char *format, ...) {
537550
}
538551

539552
log_buf = get_log_buf();
553+
if (log_buf == NULL) {
554+
return;
555+
}
540556

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

611627
log_buf = get_log_buf();
628+
if (log_buf == NULL) {
629+
return;
630+
}
612631

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

904923
log_buf = get_log_buf();
924+
if (log_buf == NULL) {
925+
return;
926+
}
905927

906928
/* lock output */
907929
elog_output_lock();

0 commit comments

Comments
 (0)