XFusion API v1.3.0
载入中...
搜索中...
未找到
xf_template_source_detail.c
浏览该文件的文档.
1
48/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 须知 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
49
120
121/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 须知 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
122
135/* ==================== [Includes] ========================================== */
136
138
139// #include <stdio.h>
140
142#include "xf_utils.h"
143
150/* ==================== [Defines] =========================================== */
151
152#define XF_TEMPLATE_HELP_STR "xf_template v0.1"
153#define XF_TEMPLATE_HELP_STR_SPLICING "test" XF_TEMPLATE_HELP_STR "abc123"
154#define XF_TEMPLATE_DEFINE (1)
155
161/* ==================== [Typedefs] ========================================== */
162
173typedef enum _xf_templ_enum_t {
177 /* 此处保留一行空行,以区分正常值和最大值 */
182
183typedef int xf_templ_int_t;
195typedef struct _xf_templ_struct_t {
197 char *p_str;
198 union {
199 uint8_t all;
200 struct {
201 uint8_t val_u4: 4;
202 uint8_t val_bit4: 1;
203 uint8_t reserved: 3;
207
215/* ==================== [Static Prototypes] ================================= */
216
231static xf_templ_int_t _xf_template_func(xf_templ_struct_t *p_struct, int32_t *p_out);
232
244 uint32_t a_parameter_with_a_very_long_name,
245 uint32_t another_parameter_with_a_very_long_name,
246 uint32_t a_parameter_with_a_very_long_name_too,
247 uint32_t a_parameter_with_a_very_long_name_that_is_really_long
248);
249
257/* ==================== [Static Variables] ================================== */
258
259static const char *const TAG = "xf_main";
262static void *p_a_pointer = NULL;
273/* ==================== [Global Variables] ================================== */
274
286/* ==================== [Macros] ============================================ */
287
291#define XF_TEMPLATE_MACROS_ADD(_a, _b) ((_a) + (_b))
292
299#define XF_TEMPLATE_MACROS_NO_RETURN(_a, _b) \
300 do { \
301 s_data = (_a) + (_b); \
302 } while (0)
303
310#define XF_TEMPLATE_MACROS_HAS_RETURN(_x) \
311 ({ \
312 typeof(_x) __ret = (_x); \
313 __ret = __ret + (_x); \
314 (__ret); \
315 })
316
325/* xf_template 输出接口 */
326#ifdef xf_log_printf
327# define XF_TEMPL_PRINTF(_fmt, ...) xf_log_printf(_fmt, ##__VA_ARGS__)
328#else /* !defined(xf_log_printf) */
329# define XF_TEMPL_PRINTF(_fmt, ...)
330#endif /* defined(xf_log_printf) */
331
332#ifndef UNUSED
333# define UNUSED(_x) ((void)(_x))
334#endif
335
341/* ==================== [Global Functions] ================================== */
342
346void xf_main(void)
347{
348 /* ↑函数定义首行换行 */
349 /* 不要以空行开始函数 */
350 xf_templ_int_t ret = 0;
351 int32_t val = 0;
355 XF_LOGI(TAG, "hello");
356
361 XF_TEMPL_PRINTF("error: version check failed\n");
362 } else {
363 XF_TEMPL_PRINTF("version check: ok\n");
364 }
366 XF_TEMPL_PRINTF("XF_TEMPLATE_VERSION: %d\n", (int)XF_TEMPLATE_VERSION);
367
376 /* 空语句 */
377 }
378
382
383 ret = _xf_template_func(&s_struct, &val);
388 if (XF_TEMPL_FAIL == ret) {
389 XF_TEMPL_PRINTF("error: ret is XF_TEMPL_FAIL\n");
390 return;
391 }
392
393 XF_TEMPL_PRINTF("ret: %d\n", ret);
394 XF_TEMPL_PRINTF("ok\n");
395
400 return;
401 /* 也不要以空行结束函数 */
402}
405{
406
407 /* **错误**示例 ↑,不要以空行开始函数 */
408 s_struct.num =
413 );
414 XF_TEMPL_PRINTF("xf_template_init: s_struct.num: %d\n", (int)s_struct.num);
415 return XF_TEMPL_OK;
416 /* **错误**示例 ↓,也不要以空行结束函数 */
417
418}
419
420/* ==================== [Static Functions] ================================== */
421
422static xf_templ_int_t _xf_template_func(xf_templ_struct_t *p_struct, int32_t *p_out)
423{
424 xf_templ_int_t ret = 0;
425 /* 参数检查 */
426 if ((NULL == p_struct) || (NULL == p_out) || (p_struct->num >= 100)) {
427 XF_TEMPL_PRINTF("参数错误\n");
428 goto _xf_template_func_err;
429 }
430
431 /* 具体操作 */
432 p_struct->p_str = XF_TEMPLATE_HELP_STR;
433 p_struct->data.all = 0;
434 p_struct->data.bits.val_u4 = 0x0a;
435 p_struct->data.bits.val_bit4 = true;
436 for (uint8_t i = 0; i < sizeof(XF_TEMPLATE_HELP_STR); i++) {
440 ret += p_struct->p_str[i];
441 }
442 ret += p_struct->data.all;
443
444 s_data = ret;
445 *p_out = ret;
446
447 /* 返回 */
448 return ret;
449
450_xf_template_func_err:
451 return XF_TEMPL_FAIL;
452}
453
455 uint32_t a_parameter_with_a_very_long_name,
456 uint32_t another_parameter_with_a_very_long_name,
457 uint32_t a_parameter_with_a_very_long_name_too,
458 uint32_t a_parameter_with_a_very_long_name_that_is_really_long
459)
460{
461 UNUSED(a_parameter_with_a_very_long_name);
462 UNUSED(another_parameter_with_a_very_long_name);
463 UNUSED(a_parameter_with_a_very_long_name_too);
464 UNUSED(a_parameter_with_a_very_long_name_that_is_really_long);
465}
466
467/* 为了消除警告,文件末尾(↓)通常带一个换行 */
struct _xf_templ_struct_t::@0::@1 bits
union _xf_templ_struct_t::@0 data
void xf_component_func(void)
extern "C" 的位置通常在 include 后面。
#define XF_LOGI(tag, format,...)
xf_err_t xf_templ_err_t
整形错误类型。
xf_templ_err_t xf_template_another_func(void)
一个函数,函数定义在 xf_template_another.c。
#define XF_TEMPLATE_VERSION
当前模板版本号整数。
#define XF_TEMPLATE_VERSION_CHECK(major, minor, patch)
将版本号转换为整数。与 XF_VERSION_VAL 不同。
xf_templ_err_t xf_template_init(void)
一个初始化函数。
static xf_templ_struct_t s_struct
void xf_main(void)
全局函数定义: [Global Functions].
#define XF_TEMPLATE_MACROS_ADD(_a, _b)
带参宏: [Macros].
struct _xf_templ_struct_t xf_templ_struct_t
结构体示例。
void a_function_of_very_many_parameters(uint32_t a_parameter_with_a_very_long_name, uint32_t another_parameter_with_a_very_long_name, uint32_t a_parameter_with_a_very_long_name_too, uint32_t a_parameter_with_a_very_long_name_that_is_really_long)
一个演示函数参数换行的示例。
static const char *const TAG
静态变量: [Static Variables].
#define XF_TEMPL_PRINTF(_fmt,...)
关于条件编译。
int g_xf_templ_global_data1_in_head
全局变量: [Global Variables].
static xf_templ_int_t s_data
enum _xf_templ_enum_t xf_templ_enum_t
类型定义: [Typedefs].
int g_xf_templ_global_data2_no_in_head
_xf_templ_enum_t
类型定义: [Typedefs].
#define UNUSED(_x)
#define XF_TEMPLATE_HELP_STR
关于格式化程序。
static void * p_a_pointer
static xf_templ_int_t _xf_template_func(xf_templ_struct_t *p_struct, int32_t *p_out)
静态函数原型: [Static Prototypes].