diff --git a/CMakeLists.txt b/CMakeLists.txt index 11c04da..160048c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,8 +113,8 @@ function(add_prebuilt_module MOD_NAME MOD_PATH DEFAULT_STATE HAS_TEST) set(GLOBAL_ENABLED_MACROS ${GLOBAL_ENABLED_MACROS} PARENT_SCOPE) endfunction() -add_module(common library/common ON OFF) add_module(log library/log OFF OFF) +add_module(common library/common ON OFF) add_module(list library/list OFF OFF) add_module(ringbuffer library/ringbuffer OFF OFF) add_module(peripheral peripheral OFF ON) diff --git a/library/common/common.c b/library/common/common.c index b8392f3..eacac22 100644 --- a/library/common/common.c +++ b/library/common/common.c @@ -6,11 +6,6 @@ static char g_sBuildTime[128] = {0}; -WEAK void Rd_ElogInit(void) -{ - return; -} - WEAK void elog_output(uint8_t level, const char *tag, const char *file, const char *func, long line, const char *format, ...) { #ifdef BUILD_COMMON diff --git a/library/common/include/common.h b/library/common/include/common.h index c94cd93..30ee40a 100644 --- a/library/common/include/common.h +++ b/library/common/include/common.h @@ -168,7 +168,11 @@ extern void Rd_ThreadEnableStrong(void); extern void Rd_Win32EnableStrong(void); #endif -#define INIT_LOG_PART() do { extern void Rd_ElogInit(void); Rd_ElogInit(); } while(0) +#ifdef BUILD_LOG + #define INIT_LOG_PART() do { extern void Rd_ElogInit(void); Rd_ElogInit(); } while(0) +#else + #define INIT_LOG_PART() do {} while(0) +#endif #ifdef BUILD_PLATFORM_LINUX #define INIT_LINUX_PART() do { Rd_LinuxEnableStrong(); Rd_ThreadEnableStrong();} while(0) diff --git a/library/common/include/elog_cfg.h b/library/common/include/elog_cfg.h index 95b12de..ee2e169 100644 --- a/library/common/include/elog_cfg.h +++ b/library/common/include/elog_cfg.h @@ -66,9 +66,9 @@ #define ELOG_FMT_USING_LINE /*---------------------------------------------------------------------------*/ /* enable asynchronous output mode */ -//#define ELOG_ASYNC_OUTPUT_ENABLE +#define ELOG_ASYNC_OUTPUT_ENABLE /* the highest output level for async mode, other level will sync output */ -#define ELOG_ASYNC_OUTPUT_LVL ELOG_LVL_ASSERT +#define ELOG_ASYNC_OUTPUT_LVL ELOG_LVL_VERBOSE /* buffer size for asynchronous output mode */ #define ELOG_ASYNC_OUTPUT_BUF_SIZE (ELOG_LINE_BUF_SIZE * 10) /* each asynchronous output's log which must end with newline sign */ diff --git a/library/log/CMakeLists.txt b/library/log/CMakeLists.txt index 9cd1a39..0ac2d5f 100644 --- a/library/log/CMakeLists.txt +++ b/library/log/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required(VERSION 3.10) -get_filename_component(TARGET_NAME "${CMAKE_CURRENT_SOURCE_DIR}" NAME) set(COMMON_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../CMakeLists.txt") if(EXISTS ${COMMON_CMAKE_PATH}) @@ -8,9 +7,3 @@ if(EXISTS ${COMMON_CMAKE_PATH}) else() message(FATAL_ERROR "Cannot find common build logic at ${COMMON_CMAKE_PATH}") endif() - -if(TARGET common) - target_link_libraries(${TARGET_NAME} PUBLIC common) -else() - message(FATAL_ERROR "[${TARGET_NAME}] Dependency 'common' not found.") -endif() \ No newline at end of file diff --git a/library/log/elog.c b/library/log/elog.c index b6cf590..2855ded 100644 --- a/library/log/elog.c +++ b/library/log/elog.c @@ -29,7 +29,7 @@ #define LOG_TAG "elog" -#include "elog.h" +#include "../common/include/elog.h" #include #include #include diff --git a/library/log/elog_async.c b/library/log/elog_async.c index fa97ec6..a9c4382 100644 --- a/library/log/elog_async.c +++ b/library/log/elog_async.c @@ -27,14 +27,14 @@ * Radkil fixed in 20260313 */ -#include "elog.h" +#include "../common/include/elog.h" #include #ifdef ELOG_ASYNC_OUTPUT_ENABLE #ifdef ELOG_ASYNC_OUTPUT_USING_PTHREAD -#include -#include +#include "../common/include/rd_thread.h" +#include "../../../Drivers/CMSIS/RTOS2/include/cmsis_os2.h" /* thread default stack size */ #ifndef ELOG_ASYNC_OUTPUT_PTHREAD_STACK_SIZE #if PTHREAD_STACK_MIN > 4*1024 @@ -61,7 +61,7 @@ /* asynchronous output log notice */ static Rd_sem_t output_notice; /* asynchronous output pthread thread */ -static pthread_t async_output_thread; +//static pthread_t async_output_thread; #endif /* ELOG_ASYNC_OUTPUT_USING_PTHREAD */ /* the highest output level for async mode, other level will sync output */ @@ -289,7 +289,7 @@ void elog_async_output_notice(void) { Rd_SemPost(&output_notice, __func__, NULL); } -static void *async_output(void *arg) { +static void async_output(void *arg) { size_t get_log_size = 0; static char poll_get_buf[ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE]; @@ -312,7 +312,7 @@ static void *async_output(void *arg) { } } } - return NULL; + return; } #endif @@ -339,21 +339,17 @@ ElogErrCode elog_async_init(void) { } #ifdef ELOG_ASYNC_OUTPUT_USING_PTHREAD - pthread_attr_t thread_attr; - struct sched_param thread_sched_param; Rd_SemInit(&output_notice, 0, 0); thread_running = true; - pthread_attr_init(&thread_attr); - //pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED); - pthread_attr_setstacksize(&thread_attr, ELOG_ASYNC_OUTPUT_PTHREAD_STACK_SIZE); - pthread_attr_setschedpolicy(&thread_attr, SCHED_RR); - thread_sched_param.sched_priority = ELOG_ASYNC_OUTPUT_PTHREAD_PRIORITY; - pthread_attr_setschedparam(&thread_attr, &thread_sched_param); - pthread_create(&async_output_thread, &thread_attr, async_output, NULL); - pthread_attr_destroy(&thread_attr); + const osThreadAttr_t log_output_attributes = { + .name = "log_output", + .stack_size = ELOG_ASYNC_OUTPUT_PTHREAD_STACK_SIZE, + .priority = 12, + }; + (void)osThreadNew(async_output, NULL, &log_output_attributes); #endif init_ok = true; @@ -375,9 +371,9 @@ void elog_async_deinit(void) { elog_async_output_notice(); - pthread_join(async_output_thread, NULL); + // pthread_join(async_output_thread, NULL); - sem_destroy(&output_notice); + // sem_destroy(&output_notice); #endif init_ok = false; diff --git a/library/log/elog_buf.c b/library/log/elog_buf.c index 61efb40..2bb6387 100644 --- a/library/log/elog_buf.c +++ b/library/log/elog_buf.c @@ -27,7 +27,7 @@ * Radkil fixed in 20260313 */ -#include "elog.h" +#include "../common/include/elog.h" #include #ifdef ELOG_BUF_OUTPUT_ENABLE diff --git a/library/log/elog_file.c b/library/log/elog_file.c index 9e380eb..b190cee 100644 --- a/library/log/elog_file.c +++ b/library/log/elog_file.c @@ -35,7 +35,7 @@ #include #include "elog_file.h" -#include "rd_stdio.h" +#include "../common/include/rd_stdio.h" #ifdef ELOG_FILE_ENABLE diff --git a/library/log/elog_port.c b/library/log/elog_port.c index 65f0308..a977406 100644 --- a/library/log/elog_port.c +++ b/library/log/elog_port.c @@ -27,13 +27,13 @@ * Radkil fixed in 20260313 */ -#include "elog.h" +#include "../common/include/elog.h" #include #include #include -#include "common.h" -#include "rd_time.h" -#include "rd_thread.h" +#include "../common/include/common.h" +#include "../common/include/rd_time.h" +#include "../common/include/rd_thread.h" #include "elog_file.h" diff --git a/library/log/elog_utils.c b/library/log/elog_utils.c index 4769c5e..69f5164 100644 --- a/library/log/elog_utils.c +++ b/library/log/elog_utils.c @@ -27,7 +27,7 @@ * Radkil fixed in 20260313 */ -#include "elog.h" +#include "../common/include/elog.h" #include /** diff --git a/library/log/include/elog_file.h b/library/log/include/elog_file.h index 1236bfc..7c914af 100644 --- a/library/log/include/elog_file.h +++ b/library/log/include/elog_file.h @@ -31,7 +31,7 @@ #define __ELOG_FILE__H__ #include -#include "elog.h" +#include "../../common/include/elog.h" #include "elog_file_cfg.h" #ifdef __cplusplus diff --git a/library/log/include/elog_file_cfg.h b/library/log/include/elog_file_cfg.h index 07c3192..53604b5 100644 --- a/library/log/include/elog_file_cfg.h +++ b/library/log/include/elog_file_cfg.h @@ -29,7 +29,7 @@ #ifndef _ELOG_FILE_CFG_H_ #define _ELOG_FILE_CFG_H_ - +#include "../common/include/common.h" /* EasyLogger file log plugin's using file name */ #define ELOG_FILE_NAME "C:rd.log" diff --git a/library/log/log.c b/library/log/log.c index 5445bfa..acdfec3 100644 --- a/library/log/log.c +++ b/library/log/log.c @@ -1,5 +1,5 @@ #include -#include "elog.h" +#include "../common/include/elog.h" void Rd_ElogInit(void) {