From aee6f5c7430e2d400b2fc05d1da62cb6ed8513d3 Mon Sep 17 00:00:00 2001 From: Riggin Date: Wed, 28 Jun 2023 18:15:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=AD=A4demo=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E5=BC=82=E6=AD=A5=E8=BE=93=E5=87=BA=E5=8A=9F=E8=83=BD?= =?UTF-8?q?(//#define=20ELOG=5FASYNC=5FOUTPUT=5FENABLE)=EF=BC=8C=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E6=97=A5=E5=BF=97=E4=B8=8D=E5=AE=8C=E6=95=B4=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1,初始化时无需对两个信号量做释放操作。 2,修改elog_port_output()函数。 3,修改异步输出线程 void elog_entry(void *para)。 --- .../Components/EasyLogger_Port/elog_port.c | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/demo/os/cube-freertos/nucleo-g070rb/Components/EasyLogger_Port/elog_port.c b/demo/os/cube-freertos/nucleo-g070rb/Components/EasyLogger_Port/elog_port.c index f85d99e..1512a72 100644 --- a/demo/os/cube-freertos/nucleo-g070rb/Components/EasyLogger_Port/elog_port.c +++ b/demo/os/cube-freertos/nucleo-g070rb/Components/EasyLogger_Port/elog_port.c @@ -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(); }