Browse Source

【支线待合】异步输出调通;freeRTOS要把初始化放到内核初始化后

paint_robot_new-v1.5
Lizongdi 2 weeks ago
parent
commit
b3f8eec668
  1. 2
      CMakeLists.txt
  2. 5
      library/common/common.c
  3. 4
      library/common/include/common.h
  4. 4
      library/common/include/elog_cfg.h
  5. 7
      library/log/CMakeLists.txt
  6. 2
      library/log/elog.c
  7. 32
      library/log/elog_async.c
  8. 2
      library/log/elog_buf.c
  9. 2
      library/log/elog_file.c
  10. 8
      library/log/elog_port.c
  11. 2
      library/log/elog_utils.c
  12. 2
      library/log/include/elog_file.h
  13. 2
      library/log/include/elog_file_cfg.h
  14. 2
      library/log/log.c

2
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)

5
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

4
library/common/include/common.h

@ -168,7 +168,11 @@ extern void Rd_ThreadEnableStrong(void);
extern void Rd_Win32EnableStrong(void);
#endif
#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)

4
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 */

7
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()

2
library/log/elog.c

@ -29,7 +29,7 @@
#define LOG_TAG "elog"
#include "elog.h"
#include "../common/include/elog.h"
#include <string.h>
#include <stdarg.h>
#include <stdio.h>

32
library/log/elog_async.c

@ -27,14 +27,14 @@
* Radkil fixed in 20260313
*/
#include "elog.h"
#include "../common/include/elog.h"
#include <string.h>
#ifdef ELOG_ASYNC_OUTPUT_ENABLE
#ifdef ELOG_ASYNC_OUTPUT_USING_PTHREAD
#include <sched.h>
#include <semaphore.h>
#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;

2
library/log/elog_buf.c

@ -27,7 +27,7 @@
* Radkil fixed in 20260313
*/
#include "elog.h"
#include "../common/include/elog.h"
#include <string.h>
#ifdef ELOG_BUF_OUTPUT_ENABLE

2
library/log/elog_file.c

@ -35,7 +35,7 @@
#include <string.h>
#include "elog_file.h"
#include "rd_stdio.h"
#include "../common/include/rd_stdio.h"
#ifdef ELOG_FILE_ENABLE

8
library/log/elog_port.c

@ -27,13 +27,13 @@
* Radkil fixed in 20260313
*/
#include "elog.h"
#include "../common/include/elog.h"
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#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"

2
library/log/elog_utils.c

@ -27,7 +27,7 @@
* Radkil fixed in 20260313
*/
#include "elog.h"
#include "../common/include/elog.h"
#include <string.h>
/**

2
library/log/include/elog_file.h

@ -31,7 +31,7 @@
#define __ELOG_FILE__H__
#include <stdio.h>
#include "elog.h"
#include "../../common/include/elog.h"
#include "elog_file_cfg.h"
#ifdef __cplusplus

2
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"

2
library/log/log.c

@ -1,5 +1,5 @@
#include <stdio.h>
#include "elog.h"
#include "../common/include/elog.h"
void Rd_ElogInit(void)
{

Loading…
Cancel
Save