mirror of
https://github.com/armink/EasyLogger.git
synced 2025-01-19 07:42:52 +08:00
解决此demo关闭异步输出功能(//#define ELOG_ASYNC_OUTPUT_ENABLE),输出日志不完整的问题。
1,初始化时无需对两个信号量做释放操作。 2,修改elog_port_output()函数。 3,修改异步输出线程 void elog_entry(void *para)。
This commit is contained in:
parent
8ea3ef9d3d
commit
aee6f5c743
@ -43,8 +43,6 @@ extern osSemaphoreId_t elog_dma_lockHandle;
|
||||
ElogErrCode elog_port_init(void) {
|
||||
ElogErrCode result = ELOG_NO_ERR;
|
||||
|
||||
osSemaphoreRelease(elog_dma_lockHandle);
|
||||
osSemaphoreRelease(elog_lockHandle);
|
||||
/* add your code here */
|
||||
|
||||
return result;
|
||||
@ -65,6 +63,7 @@ void elog_port_deinit(void) {
|
||||
*/
|
||||
void elog_port_output(const char *log, size_t size) {
|
||||
HAL_UART_Transmit_DMA(&huart2, (uint8_t *) log, size);
|
||||
osSemaphoreAcquire(elog_dma_lockHandle, osWaitForever);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -116,30 +115,28 @@ void elog_async_output_notice(void) {
|
||||
|
||||
void elog_entry(void *para) {
|
||||
size_t get_log_size = 0;
|
||||
#ifdef ELOG_ASYNC_LINE_OUTPUT
|
||||
static char poll_get_buf[ELOG_LINE_BUF_SIZE - 4];
|
||||
#else
|
||||
static char poll_get_buf[ELOG_ASYNC_OUTPUT_BUF_SIZE - 4];
|
||||
#endif
|
||||
|
||||
if (elog_port_init() != ELOG_NO_ERR) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
if (osOK ==
|
||||
osSemaphoreAcquire(elog_asyncHandle, osWaitForever)) {
|
||||
while (1) {
|
||||
if (osOK ==
|
||||
osSemaphoreAcquire(elog_dma_lockHandle, osWaitForever)) {
|
||||
get_log_size = elog_async_get_line_log(poll_get_buf, sizeof(poll_get_buf));
|
||||
if (get_log_size) {
|
||||
elog_port_output(poll_get_buf, get_log_size);
|
||||
} else {
|
||||
osSemaphoreRelease(elog_dma_lockHandle);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for(;;)
|
||||
{
|
||||
/* waiting log */
|
||||
osSemaphoreAcquire(elog_asyncHandle, osWaitForever);
|
||||
/* polling gets and outputs the log */
|
||||
while (1) {
|
||||
#ifdef ELOG_ASYNC_LINE_OUTPUT
|
||||
get_log_size = elog_async_get_line_log(poll_get_buf, sizeof(poll_get_buf));
|
||||
#else
|
||||
get_log_size = elog_async_get_log(poll_get_buf, sizeof(poll_get_buf));
|
||||
#endif
|
||||
if (get_log_size) {
|
||||
elog_port_output(poll_get_buf, get_log_size);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fail:
|
||||
osThreadExit();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user