Skip to content

Commit 80d55df

Browse files
committed
feat: 🎉 V1.0定版
1. 配置头文件仅保留常见 2. 简化初始流程
1 parent 1e7c0b6 commit 80d55df

File tree

9 files changed

+189
-244
lines changed

9 files changed

+189
-244
lines changed

.gitignore

-9 Bytes
Binary file not shown.

core/fc_config_template.h

Lines changed: 94 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* @file fc_config.h
55
* @author fool_cat (2696652257@qq.com)
6-
* @brief fc_embed配置头文件 - 所有可配置项的集中管理
6+
* @brief fc_embed配置头文件 - 把一些关键宏配置放这里,具体的可以去相关的.h/.c文件中查看说明
77
* @version 1.0
88
* @date 2025-09-02
99
*
@@ -16,21 +16,35 @@
1616
#ifndef _FC_CONFIG_TEMPLATE_H_
1717
#define _FC_CONFIG_TEMPLATE_H_
1818

19-
/**
20-
* =====================================================================
21-
* Custom Header Files Section
22-
* =====================================================================
23-
* Add your custom #include statements here if needed.
24-
*
25-
* Examples:
26-
* #include "stm32f4xx_hal.h"
27-
* #include "FreeRTOS.h"
28-
* #include "cmsis_os.h"
29-
*
30-
* Note: Configuration Wizard does not support dynamic header inclusion.
31-
* Please manually edit this section to add your headers.
32-
* =====================================================================
33-
*/
19+
//+********************************* 配置项说明 **********************************/
20+
/**
21+
* Configuration Wizard 使用说明:
22+
*
23+
* 1. 本文件作为模版文件,移植时需定义一份fc_config.h文件,并保证文件的可包含性(#include 能找到)
24+
* 2. 可以旋转将本文件完整复制到fc_config.h中进行修改,也可以在fc_config.h中#include此文件
25+
* 3. 在 Keil MDK 中,点击 fc_config.h 文件底部的 "Configuration Wizard" 标签
26+
* 4. 点击编辑器底部的 "Configuration Wizard" 标签
27+
* 5. 通过图形界面配置所有选项 (复选框、下拉框、数值输入框)
28+
* 6. 保存文件后配置重新编译
29+
*/
30+
31+
/**
32+
* =====================================================================
33+
* Custom Header Files Section
34+
* =====================================================================
35+
* Add your custom #include statements here if needed.
36+
*
37+
* Examples:
38+
* #include "stm32f4xx_hal.h"
39+
* #include "FreeRTOS.h"
40+
* #include "cmsis_os.h"
41+
*
42+
* Note: Configuration Wizard does not support dynamic header inclusion.
43+
* Please manually edit this section to add your headers.
44+
* =====================================================================
45+
*/
46+
47+
//+********************************* auto_init **********************************/
3448

3549
// Add your custom includes below:
3650
// #include "your_header.h"
@@ -43,71 +57,13 @@
4357
// <i> Default: 1 (Enabled)
4458
#define USE_FC_AUTO_INIT 1
4559

46-
// </h>
47-
48-
// <h> Logger Configuration
49-
// <i> Logger component configuration
50-
51-
// <q> FC_LOG_ENABLE - Enable Logger
52-
// <i> Enable logging functionality
53-
// <i> Default: 1 (Enabled)
54-
#define FC_LOG_ENABLE 1
55-
56-
// <o> FC_LOG_LINE_SIZE - Log Line Buffer Size <32-512:8>
57-
// <i> Log line buffer size in bytes
58-
// <i> Default: 128
59-
#define FC_LOG_LINE_SIZE 128
60-
61-
// <o> FC_LOG_STACK_LINE_SIZE - Log Stack Line Size <32-512:8>
62-
// <i> Log buffer size on stack in bytes
63-
// <i> Default: FC_LOG_LINE_SIZE
64-
#define FC_LOG_STACK_LINE_SIZE (FC_LOG_LINE_SIZE)
65-
66-
// <q> FC_LOG_USING_COLOR - Enable Color Output
67-
// <i> Enable ANSI color codes for colored output
68-
// <i> Default: 1 (Enabled)
69-
#define FC_LOG_USING_COLOR 1
70-
71-
// <q> FC_LOG_NOPREFIX_API - Enable No-Prefix API
72-
// <i> Provide simplified log macros without fc_ prefix (log_debug, log_info, etc.)
73-
// <i> Default: 1 (Enabled)
74-
#define FC_LOG_NOPREFIX_API 1
75-
76-
// <o> FC_LOG_POOL_TOTAL_SIZE - Log Memory Pool Size <1024-16384:256>
77-
// <i> Total memory pool size for logger in bytes
78-
// <i> Default: 4096 (4KB)
79-
#define FC_LOG_POOL_TOTAL_SIZE (4 * 1024)
80-
81-
// <o> FC_LOG_ALLOC_BLOCK_SIZE - Log Allocation Block Size <64-512:64>
82-
// <i> Memory pool block size in bytes
83-
// <i> Default: 128
84-
#define FC_LOG_ALLOC_BLOCK_SIZE 128
85-
86-
// Note: The following string options are defined below but not configurable via Configuration Wizard
87-
// You can modify them directly in code if needed:
88-
// - FC_LOG_PREFIX_FMT: Log prefix format (default: "(%d)%s:")
89-
// - FC_LOG_END: Log end string (default: "" or "\r\n")
90-
// - FC_LOG_ERROR_HEAD/WARNING_HEAD/INFO_HEAD/DEBUG_HEAD/VERBOSE_HEAD: Log level prefixes
91-
92-
#define FC_LOG_PREFIX_FMT "(%d)%s:"
93-
#define FC_LOG_END ""
94-
#define FC_LOG_ERROR_HEAD "E"
95-
#define FC_LOG_WARNING_HEAD "W"
96-
#define FC_LOG_INFO_HEAD "I"
97-
#define FC_LOG_DEBUG_HEAD "D"
98-
#define FC_LOG_VERBOSE_HEAD "V"
99-
100-
// </h>
60+
// </h>
10161

102-
// <h> Memory Pool Configuration
103-
// <i> Memory pool configuration
62+
//+********************************* port **********************************/
10463

105-
// <q> FC_FOOL_ENABLE_DYNAMIC_POOL_ALLOC - Enable Dynamic Allocation
106-
// <i> Allow memory pool to use dynamic memory (malloc/free) when static memory is exhausted
107-
// <i> Default: 0 (Disabled)
108-
#define FC_FOOL_ENABLE_DYNAMIC_POOL_ALLOC 0
109-
110-
// </h>
64+
// fc_port的锁函数宏
65+
// #define FC_PORT_LOCK(port, rb_index, dir) ((void)0)
66+
// #define FC_PORT_UNLOCK(port, rb_index, dir) ((void)0)
11167

11268
// <h> Port Configuration
11369
// <i> Port and ring buffer configuration
@@ -147,8 +103,65 @@
147103
// <i> Default: 0 (Disabled)
148104
#define PHY_SERIAL_RX_ENABLE 0
149105

106+
// </h>
107+
108+
//+********************************* log **********************************/
109+
110+
// <h> Logger Configuration
111+
// <i> Logger component configuration
112+
113+
// <q> FC_LOG_ENABLE - Enable Logger
114+
// <i> Enable logging functionality
115+
// <i> Default: 1 (Enabled)
116+
#define FC_LOG_ENABLE 1
117+
118+
// <o> FC_LOG_LINE_SIZE - Log Line Buffer Size <32-512:8>
119+
// <i> Log line buffer size in bytes
120+
// <i> Default: 128
121+
#define FC_LOG_LINE_SIZE 128
122+
123+
// <q> FC_LOG_USING_COLOR - Enable Color Output
124+
// <i> Enable ANSI color codes for colored output
125+
// <i> Default: 1 (Enabled)
126+
#define FC_LOG_USING_COLOR 1
127+
128+
// <o> FC_LOG_POOL_TOTAL_SIZE - Log Memory Pool Size <1024-16384:256>
129+
// <i> Total memory pool size for logger in bytes
130+
// <i> Default: 4096 (4KB)
131+
#define FC_LOG_POOL_TOTAL_SIZE (4 * 1024)
132+
133+
// Note: The following string options are defined below but not configurable via Configuration Wizard
134+
// You can modify them directly in code if needed:
135+
// - FC_LOG_PREFIX_FMT: Log prefix format (default: "(%d)%s:")
136+
// - FC_LOG_END: Log end string (default: "" or "\r\n")
137+
// - FC_LOG_ERROR_HEAD/WARNING_HEAD/INFO_HEAD/DEBUG_HEAD/VERBOSE_HEAD: Log level prefixes
138+
139+
#define FC_LOG_PREFIX_FMT ":%s->%d:\t"
140+
#define FC_LOG_PREFIX_CONTENT __FC_LOG_MACRO_EXPANDING(__FUNCTION__, (uint32_t)__LINE__)
141+
142+
// #define FC_LOG_END ""
143+
// #define FC_LOG_ERROR_HEAD "E"
144+
// #define FC_LOG_WARNING_HEAD "W"
145+
// #define FC_LOG_INFO_HEAD "I"
146+
// #define FC_LOG_DEBUG_HEAD "D"
147+
// #define FC_LOG_VERBOSE_HEAD "V"
148+
150149
// </h>
151150

151+
//+********************************* pool **********************************/
152+
153+
// <h> Memory Pool Configuration
154+
// <i> Memory pool configuration
155+
156+
// <q> FC_FOOL_ENABLE_DYNAMIC_POOL_ALLOC - Enable Dynamic Allocation
157+
// <i> Allow memory pool to use dynamic memory (malloc/free) when static memory is exhausted
158+
// <i> Default: 0 (Disabled)
159+
#define FC_FOOL_ENABLE_DYNAMIC_POOL_ALLOC 0
160+
161+
// </h>
162+
163+
//+********************************* 基于日志的传输层 **********************************/
164+
152165
// <h> Transport Configuration
153166
// <i> Transport component configuration
154167

@@ -164,6 +177,8 @@
164177

165178
// </h>
166179

180+
//+********************************* stdio **********************************/
181+
167182
// <h> StdIO Configuration
168183
// <i> Standard I/O configuration
169184

@@ -177,81 +192,8 @@
177192
// <i> Default: 1 (Enabled)
178193
#define XF_USE_FP 1
179194

180-
// <o> SZB_OUTPUT - Output Buffer Size <16-128:8>
181-
// <i> Internal buffer size for printf/sprintf functions
182-
// <i> Default: 32
183-
#define SZB_OUTPUT 32
184-
185-
// <q> FC_FIFO_VPRINTF_LINEAR_WRITE - Enable Linear Write Mode
186-
// <i> Use linear write mode for better performance
187-
// <i> Default: 1 (Enabled)
188-
#define FC_FIFO_VPRINTF_LINEAR_WRITE 1
189-
190-
// Note: XF_DPC (Decimal Point Character) is defined below
191-
// Modify directly in code if you need a different decimal separator
192-
#define XF_DPC '.'
193-
194-
// </h>
195-
196-
// <h> FIFO Configuration
197-
// <i> FIFO (ring buffer) configuration
198-
199-
// <q> FC_USE_STD_MEMCPY - Use Standard memcpy
200-
// <i> Use standard library memcpy (0 = use byte-by-byte copy)
201-
// <i> Default: 1 (Enabled)
202-
#define FC_USE_STD_MEMCPY 1
203-
204195
// </h>
205196

206-
//+********************************* 高级配置 (通常不需要修改) **********************************/
207-
/**
208-
* Advanced Configuration - Normally no need to modify
209-
*
210-
* The following macros can be overridden in your project if needed:
211-
*
212-
* - fc_assert(x) - Runtime assertion
213-
* - FC_WAIT_MOMENT() - Wait/delay function
214-
* - FC_PORT_LOCK(port, rb, dir) - Port lock function
215-
* - FC_PORT_UNLOCK(port, rb, dir) - Port unlock function
216-
* - FC_PORT_LOSE_HOOK(...) - Data loss hook
217-
* - FC_LOG_OBJ - Log output object
218-
* - FC_LOG_LOSE_HOOK(...) - Log data loss hook
219-
* - FC_LOG_PREFIX_CONTENT - Log prefix content macro
220-
* - FC_STDOUT_OBJ - Standard output object
221-
* - FC_STDOUT_RB_INDEX - Standard output ring buffer index
222-
* - FC_STDIN_OBJ - Standard input object
223-
* - FC_STDIN_RB_INDEX - Standard input ring buffer index
224-
* - FC_POOL_ATOMIC_ENTER(obj) - Pool atomic section enter
225-
* - FC_POOL_ATOMIC_EXIT(obj) - Pool atomic section exit
226-
* - FC_POOL_MALLOC(size) - Pool malloc function
227-
* - FC_POOL_FREE(ptr) - Pool free function
228-
* - fc_fifo_assert(x) - FIFO assertion
229-
* - fc_fifo_memcpy(dst, src, size) - FIFO memory copy function
230-
*
231-
* Define these macros in your project before including fc_embed headers if you need
232-
* custom implementations.
233-
*/
234-
235-
//+********************************* 配置项说明 **********************************/
236-
/**
237-
* Configuration Wizard 使用说明:
238-
*
239-
* 1. 在 Keil MDK 中打开本文件
240-
* 2. 点击编辑器底部的 "Configuration Wizard" 标签
241-
* 3. 通过图形界面配置所有选项 (复选框、下拉框、数值输入框)
242-
* 4. 保存文件后配置立即生效
243-
*
244-
* 配置优先级:
245-
* 1. 工程中自定义的 fc_config.h (最高优先级)
246-
* 2. 本模板文件中的配置
247-
* 3. 源代码中的默认值 (最低优先级)
248-
*
249-
* 使用方法:
250-
* 1. 复制本文件并重命名为 fc_config.h
251-
* 2. 使用 Configuration Wizard 修改配置
252-
* 3. 将 fc_config.h 添加到工程的包含路径
253-
*/
254-
255197
#endif //\ _FC_CONFIG_TEMPLATE_H_
256198

257199
// <<< end of configuration section >>>

core/fc_log.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ fc_pool_t fc_log_pool; // log组件使用的内存池
416416
#define FC_LOG_ALLOC_BLOCK_SIZE FC_LOG_LINE_SIZE /* 128的话满足大多数情况下日志需求,减少内存分配次数 */
417417
#endif
418418

419-
void fc_log_pool_init(void)
419+
void fc_log_init(void)
420420
{
421421
default_log.file_user.log = &default_log; // 根对象初始化的时候必须将此指针指向自身!!!
422422

@@ -425,11 +425,6 @@ void fc_log_pool_init(void)
425425
fc_pool_init(&fc_log_pool, log_pool_mem, sizeof(log_pool_mem), FC_LOG_ALLOC_BLOCK_SIZE);
426426
}
427427

428-
#include "fc_auto_init.h"
429-
#if USE_FC_AUTO_INIT
430-
INIT_EXPORT_ENV(fc_log_pool_init, FC_LOG_INIT_ORDER - 1); // 确保在log_init之前初始化
431-
#endif
432-
433428
/**
434429
* @brief
435430
*
@@ -484,3 +479,7 @@ fc_weak size_t log_write_default(fc_log_file_user_t *file_user)
484479

485480
return file_user->total_write;
486481
}
482+
483+
//+********************************* 注册到ENV段中 **********************************/
484+
#include "fc_auto_init.h"
485+
INIT_EXPORT_ENV(fc_log_init, FC_LOG_INIT_ORDER);

core/fc_log.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ extern "C"
216216
// 提供一份默认的内存池获取函数,可以在外面重写
217217
extern bool log_alloc_default(fc_log_alloc_type_t alloc_type, fc_log_mem_t *mem, int advice_size);
218218

219+
// 使用log之前需要调用一次默认初始化,已注册到ENV中
220+
extern void fc_log_init(void);
221+
219222
#ifdef __cplusplus
220223
}
221224
#endif

core/fc_port.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -600,13 +600,7 @@ extern "C"
600600
}
601601
#endif //\ __cplusplus
602602

603-
//+********************************* 自动注册初始化 **********************************/
603+
//+********************************* 注册到ENV段中 **********************************/
604604
#include "fc_auto_init.h"
605-
#if USE_FC_AUTO_INIT
606-
static void _fc_port_auto_init(void)
607-
{
608-
fc_default_port_init(); // 纯内存结构初始化,可以放在constructor的时候就初始化
609-
}
610605
// 等级比默认的1000优先级更高,纯数据结构无外部依赖
611-
INIT_EXPORT_ENV(_fc_port_auto_init, FC_PORT_INIT_ORDER);
612-
#endif
606+
INIT_EXPORT_ENV(fc_default_port_init, FC_PORT_INIT_ORDER);

core/fc_trans.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void fc_receiver_monitor(fc_receiver_t *receiver)
126126
{
127127
len_total = fc_fifo_get_used(rb); // 更新现存数据量
128128
p_start = (char *)fc_fifo_linear_read_setup(rb, &len);
129-
p_end = (char*)memchr(p_start, head[0], len); // 查找是否可能存在分页信息
129+
p_end = (char *)memchr(p_start, head[0], len); // 查找是否可能存在分页信息
130130

131131
if (NULL == p_end) // 不存在分页信息
132132
{
@@ -458,14 +458,12 @@ extern "C"
458458
}
459459
#endif //\ __cplusplus
460460

461-
//+********************************* 自动注册初始化 **********************************/
461+
//+********************************* 注册到ENV段中 **********************************/
462462
#include "fc_auto_init.h"
463-
#if USE_FC_AUTO_INIT
464463
static void _fc_trans_auto_init(void)
465464
{
466465
fc_receiver_init(&fc_receiver, fc_stdin.rb[0]); // 初始化接收器
467466
fc_sender_init(&fc_sender, fc_stdout.rb[0]); // 初始化发送器
468467
}
469468
// 等级比默认的1000优先级更高,但是低于port层的默认初始化,纯数据结构无外部依赖
470469
INIT_EXPORT_ENV(_fc_trans_auto_init, FC_TRANS_INIT_ORDER);
471-
#endif

core/fc_trans.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* @author fool_cat (2696652257@qq.com)
44
* @brief 提供一种简单的分页机制实现单个通道聚合传输解析,接收器和发送器需要配合使用
55
* 通常用于传输日志等"可视化"字符,不完全适合二进制数据,存在极小概率与分页机制冲突,碰撞
6+
* !暂时建议不使用fc_trans
67
* @version 1.0
78
* @date 2025-04-05
89
*

0 commit comments

Comments
 (0)