C 语言头文件为了避免多次重复包含,需要定义一个符号。这个符号的定义形式请采用如下的风格:
1 #ifndef __FILE_H__
2 #define __FILE_H__
3 /* header file content */
4 #endif
即定义的符号两侧采用 “__” 以避免重名,另外也可以根据文件名中是否包含多个词语而采用 “_” 连接起来。
在每个源文件文件头上,应该包括相应的版权信息,Change Log 记录:
1/*
2 * Copyright (c) 2006-2020, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2006-03-18 Bernard the first version
9 * 2006-04-26 Bernard add semaphore APIs
10 */
结构体名称请使用小写英文名的形式,单词与单词之间采用 “_” 连接,例如:
1 struct rt_list_node
2 {
3 struct rt_list_node *next;
4 struct rt_list_node *prev;
5 };
1 typedef struct rt_list_node rt_list_t;
1 typedef struct rt_timer* rt_timer_t;
1 #define RT_TRUE 1
1rt_thread_t rt_thread_self(void);
1/* IPC object init */
2static rt_err_t _ipc_object_init()
3
4/* UART driver ops */
5static rt_err_t _uart_configure()
6static rt_err_t _uart_control()
1int rt_hw_uart_init(void)
2int rt_hw_spi_init(void)
1/* 你的英文注释 */
注释模版请参见:rt-thread/src/ipc.c 源码文件,英文注释请参考使用 grammarly 以及谷歌翻译。
1/**
2 * @brief The function will initialize a static event object.
3 *
4 * @note For the static event object, its memory space is allocated by the compiler during compiling,
5 * and shall placed on the read-write data segment or on the uninitialized data segment.
6 * By contrast, the rt_event_create() function will allocate memory space automatically
7 * and initialize the event.
8 *
9 * @see rt_event_create()
10 *
11 * @param event is a pointer to the event to initialize. It is assumed that storage for the event
12 * will be allocated in your application.
13 *
14 * @param name is a pointer to the name that given to the event.
15 *
16 * @param value is the initial value for the event.
17 * If want to share resources, you should initialize the value as the number of available resources.
18 * If want to signal the occurrence of an event, you should initialize the value as 0.
19 *
20 * @param flag is the event flag, which determines the queuing way of how multiple threads wait
21 * when the event is not available.
22 * The event flag can be ONE of the following values:
23 *
24 * RT_IPC_FLAG_PRIO The pending threads will queue in order of priority.
25 *
26 * RT_IPC_FLAG_FIFO The pending threads will queue in the first-in-first-out method
27 * (also known as first-come-first-served (FCFS) scheduling strategy).
28 *
29 * NOTE: RT_IPC_FLAG_FIFO is a non-real-time scheduling mode. It is strongly recommended to
30 * use RT_IPC_FLAG_PRIO to ensure the thread is real-time UNLESS your applications concern about
31 * the first-in-first-out principle, and you clearly understand that all threads involved in
32 * this event will become non-real-time threads.
33 *
34 * @return Return the operation status. When the return value is RT_EOK, the initialization is successful.
35 * If the return value is any other values, it represents the initialization failed.
36 *
37 * @warning This function can ONLY be called from threads.
38 */
39rt_err_t rt_event_init(rt_event_t event, const char *name, rt_uint8_t flag)
40{
41 ...
42}
1 if (condition)
2 {
3 /* others */
4 }
1 switch (value)
2 {
3 case value1:
4 break;
5 }
1 if (condition)
2 {
3 /* others */
4 }
1 if (x <= y)
2 {
3 /* others */
4 }
5
6 for (index = 0; index < MAX_NUMBER; index ++)
7 {
8 /* others */
9 }
1 if ( x <= y )
2 {
3 /* other */
4 }
1 struct rt_timer
2 {
3 struct rt_object parent;
4 /* other fields */
5 };
6 typedef struct rt_timer* rt_timer_t;
1rt_timer_t rt_timer_create(const char* name,
2 void (*timeout)(void* parameter),
3 void* parameter,
4 rt_tick_t time, rt_uint8_t flag);
5rt_err_t rt_timer_delete(rt_timer_t timer);
6rt_err_t rt_timer_start(rt_timer_t timer);
7rt_err_t rt_timer_stop(rt_timer_t timer);
1 --style=allman
2 --indent=spaces=4
3 --indent-preproc-block
4 --pad-oper
5 --pad-header
6 --unpad-paren
7 --suffix=none
8 --align-pointer=name
9 --lineend=linux
10 --convert-tabs
11 --verbose
将源文件编码统一为 UTF-8
将 TAB 键替换为 4 空格
将每行末尾多余的空格删除,并统一换行符为 ‘\n’
RT-Thread开发者大会
我们将联合重量级合作伙伴,围绕AIoT的发展、产业技术趋势,聚焦控制、连接、行业应用开发,通过主题演讲、技术分享、应用演示等环节,助力开发者探索万物智能的世界,期待与大家一起相聚线上直播间!
本次将在大会当天在直播间宣布中奖名单
更多奖品即将来袭...
你可以添加微信17775982065为好友,注明:公司+姓名,拉进RT-Thread官方微信交流群!
爱我就给我点在看
👇点击阅读原文进入报名