C 語(yǔ)言頭文件為了避免多次重復(fù)包含,需要定義一個(gè)符號(hào)。這個(gè)符號(hào)的定義形式請(qǐng)采用如下的風(fēng)格:
1????#ifndef?__FILE_H__
2????#define?__FILE_H__
3????/*?header?file?content?*/
4????#endif
即定義的符號(hào)兩側(cè)采用 “__” 以避免重名,另外也可以根據(jù)文件名中是否包含多個(gè)詞語(yǔ)而采用 “_” 連接起來(lái)。
在每個(gè)源文件文件頭上,應(yīng)該包括相應(yīng)的版權(quán)信息,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?*/結(jié)構(gòu)體名稱請(qǐng)使用小寫(xiě)英文名的形式,單詞與單詞之間采用 “_” 連接,例如:
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?????????????????????????11rt_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/*?你的英文注釋?*/注釋模版請(qǐng)參見(jiàn):rt-thread/src/ipc.c 源碼文件,英文注釋請(qǐng)參考使用 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?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將源文件編碼統(tǒng)一為 UTF-8
將 TAB 鍵替換為 4 空格
將每行末尾多余的空格刪除,并統(tǒng)一換行符為 ‘\n’
RT-Thread開(kāi)發(fā)者大會(huì)
我們將聯(lián)合重量級(jí)合作伙伴,圍繞AIoT的發(fā)展、產(chǎn)業(yè)技術(shù)趨勢(shì),聚焦控制、連接、行業(yè)應(yīng)用開(kāi)發(fā),通過(guò)主題演講、技術(shù)分享、應(yīng)用演示等環(huán)節(jié),助力開(kāi)發(fā)者探索萬(wàn)物智能的世界,期待與大家一起相聚線上直播間!

本次將在大會(huì)當(dāng)天在直播間宣布中獎(jiǎng)名單
更多獎(jiǎng)品即將來(lái)襲...
你可以添加微信17775982065為好友,注明:公司+姓名,拉進(jìn)RT-Thread官方微信交流群!

愛(ài)我就給我點(diǎn)在看
??點(diǎn)擊閱讀原文進(jìn)入報(bào)名