@@ -121,30 +121,59 @@ int rt_hw_spi_init(void)
121121
122122** 函数注释** :
123123
124- - 以 ` /** ` 开头,以 ` */ ` 结尾,中间写入函数注释
125- - 第一部分:一个段落介绍函数的作用
126- - 第二部分:参数采用 @param + 参数 + 介绍参数 的方式
127- - 第三部分:返回采用 @return + 返回值 + 介绍返回值 的方式
128- - 以上每个部分之间空一行
124+ 注释以 ` /** ` 开头,以 ` */ ` 结尾,中间写入函数注释,组成元素如下,每个元素描述之间空一行,且首列对齐:
125+
126+ - @brief + 简述函数作用。在描述中,着重说明该函数的作用,每句话首字母大写,句尾加英文句号。
127+ - @note + 函数说明。在上述简述中未能体现到的函数功能或作用的一些点,可以做解释说明,每句话首字母大写,句尾加英文句号。
128+ - @see + 相关 API 罗列。若有与当前函数相关度较高的 API,可以进行列举。
129+ - @param + 以参数为主语 + be 动词 + 描述,说明参数的意义或来源。
130+ - @return + 枚举返回值 + 返回值的意思,若返回值为数据,则直接介绍数据的功能。
131+ - @warning + 函数使用注意要点。在函数使用时,描述需要注意的事项,如使用环境、使用方式等。每句话首字母大写,句尾加英文句号。
132+
133+ 注释模版请参见:rt-thread/src/ipc.c 源码文件,英文注释请参考使用 grammarly 以及谷歌翻译。
129134
130135``` C
131136/* *
132- * This function will initialize a semaphore and put it under control of
133- * resource management.
137+ * @brief The function will initialize a static event object.
138+ *
139+ * @note For the static event object, its memory space is allocated by the compiler during compiling,
140+ * and shall placed on the read-write data segment or on the uninitialized data segment.
141+ * By contrast, the rt_event_create() function will allocate memory space automatically
142+ * and initialize the event.
143+ *
144+ * @see rt_event_create()
145+ *
146+ * @param event is a pointer to the event to initialize. It is assumed that storage for the event
147+ * will be allocated in your application.
148+ *
149+ * @param name is a pointer to the name that given to the event.
150+ *
151+ * @param value is the initial value for the event.
152+ * If want to share resources, you should initialize the value as the number of available resources.
153+ * If want to signal the occurrence of an event, you should initialize the value as 0.
154+ *
155+ * @param flag is the event flag, which determines the queuing way of how multiple threads wait
156+ * when the event is not available.
157+ * The event flag can be ONE of the following values:
158+ *
159+ * RT_IPC_FLAG_PRIO The pending threads will queue in order of priority.
134160 *
135- * @param sem the semaphore object
136- * @param name the name of semaphore
137- * @param value the initial value of semaphore
138- * @param flag the flag of semaphore
161+ * RT_IPC_FLAG_FIFO The pending threads will queue in the first-in-first-out method
162+ * (also known as first-come-first-served (FCFS) scheduling strategy).
139163 *
140- * @return the operation status, RT_EOK on successful
164+ * NOTE: RT_IPC_FLAG_FIFO is a non-real-time scheduling mode. It is strongly recommended to
165+ * use RT_IPC_FLAG_PRIO to ensure the thread is real-time UNLESS your applications concern about
166+ * the first-in-first-out principle, and you clearly understand that all threads involved in
167+ * this event will become non-real-time threads.
168+ *
169+ * @return Return the operation status. When the return value is RT_EOK, the initialization is successful.
170+ * If the return value is any other values, it represents the initialization failed.
171+ *
172+ * @warning This function can ONLY be called from threads.
141173 */
142- rt_err_t rt_sem_init (rt_sem_t sem,
143- const char * name,
144- rt_uint32_t value,
145- rt_uint8_t flag)
174+ rt_err_t rt_event_init (rt_event_t event, const char * name, rt_uint8_t flag)
146175{
147- ....
176+ ...
148177}
149178```
150179
@@ -159,8 +188,7 @@ rt_err_t rt_sem_init(rt_sem_t sem,
159188 }
160189```
161190
162- 唯一的例外是 switch 语句,switch-case 语句采用 case 语句与 switch 对齐的方式,
163- 例如:
191+ 唯一的例外是 switch 语句,switch-case 语句采用 case 语句与 switch 对齐的方式,例如:
164192
165193``` c
166194 switch (value)
@@ -249,9 +277,15 @@ rt_timer + 动词短语的形式表示能够应用于 timer 对象的方法。
249277
250278在创建一个新的对象时,应该思考好,对象的内存操作处理:是否允许一个静态对象存在,或仅仅支持从堆中动态分配的对象。
251279
252- ## 14.用 astyle 自动格式化代码
280+ ## 14.格式化代码
281+
282+ 格式化代码是指通过脚本自动整理你的代码,并使其符合 RT-Thread 的编码规范。本文提供以下两种自动格式化代码方法,可以自行选择或配合使用。
283+
284+ ### 使用 astyle 格式化
285+
286+ 用 astyle 自动格式化代码,参数如下:
253287
254- 参数: --style=allman
288+ --style=allman
255289 --indent=spaces=4
256290 --indent-preproc-block
257291 --pad-oper
@@ -262,3 +296,13 @@ rt_timer + 动词短语的形式表示能够应用于 timer 对象的方法。
262296 --lineend=linux
263297 --convert-tabs
264298 --verbose
299+
300+ 能满足函数空格、缩进、函数语句等的规范。
301+
302+ ### 使用 formatting 格式化
303+
304+ 使用 [ formatting] ( https://github.com/mysterywolf/formatting ) 扫描文件来格式化代码:formatting 可以满足编码规则的基本要求,如:
305+
306+ - 将源文件编码统一为 UTF-8
307+ - 将 TAB 键替换为 4 空格
308+ - 将每行末尾多余的空格删除,并统一换行符为 '\n'
0 commit comments