Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLambdasOnASingleLine: None
AllowShortLoopsOnASingleLine: false
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
Expand All @@ -76,7 +76,7 @@ BraceWrapping:
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: true
BeforeWhile: true
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/format_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Install clang-format
shell: bash
run: |
python -m pip install clang-format
python -m pip install -r tools/ci/requirements-format.txt
clang-format --version

- name: Check clang-format
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/pr_clang_format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
lfs: false

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.8'

- name: Install clang-format
run: sudo apt-get update && sudo apt-get install -y clang-format
run: python -m pip install -r tools/ci/requirements-format.txt

- name: Check clang-format version
run: |
Expand Down
9 changes: 9 additions & 0 deletions documentation/7.contribution/coding_style_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,15 @@ rt_timer + 动词短语的形式表示能够应用于 timer 对象的方法。

RT-Thread 现在使用 clang-format 作为统一的代码格式化工具。提交 C/C++、头文件及相关源文件前,请优先使用仓库根目录的 `.clang-format` 配置进行格式化,不要再使用与该配置不一致的手工排版或旧的 astyle 参数。

统一使用 clang-format **22.1.8**,版本固定在 `tools/ci/requirements-format.txt`。本地开发、格式检查 CI 和手动格式化工作流使用同一版本,避免不同版本产生格式差异。在仓库根目录安装并确认版本:

```shell
python -m pip install -r tools/ci/requirements-format.txt
clang-format --version
```

编辑器也应使用上述安装的 clang-format 可执行文件。

常用命令如下:

```shell
Expand Down
10 changes: 10 additions & 0 deletions documentation/7.contribution/coding_style_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ submitting C/C++ source files, header files, and related source files, format
them with the `.clang-format` configuration in the repository root. Do not use
manual formatting or old astyle parameters that conflict with this configuration.

Use clang-format **22.1.8**, pinned in `tools/ci/requirements-format.txt`.
Local development, format checks, and the manual formatting workflow use the
same version to avoid formatting differences. Install it from the repository
root and verify the version:

python -m pip install -r tools/ci/requirements-format.txt
clang-format --version

Configure your editor to use the same installed clang-format executable.

Common commands:

clang-format -style=file -i path/to/file.c
Expand Down
2 changes: 2 additions & 0 deletions src/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ rt_tick_t rt_tick_get_delta(rt_tick_t base)
{
rt_tick_t tnow = rt_tick_get();
if (tnow >= base)
{
return tnow - base;
}
return RT_TICK_MAX - base + tnow + 1;
}
RTM_EXPORT(rt_tick_get_delta);
Expand Down
13 changes: 6 additions & 7 deletions src/components.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

#ifdef RT_USING_USER_MAIN
#ifndef RT_MAIN_THREAD_STACK_SIZE
#define RT_MAIN_THREAD_STACK_SIZE 2048
#define RT_MAIN_THREAD_STACK_SIZE 2048
#endif /* RT_MAIN_THREAD_STACK_SIZE */
#ifndef RT_MAIN_THREAD_PRIORITY
#define RT_MAIN_THREAD_PRIORITY (RT_THREAD_PRIORITY_MAX / 3)
#define RT_MAIN_THREAD_PRIORITY (RT_THREAD_PRIORITY_MAX / 3)
#endif /* RT_MAIN_THREAD_PRIORITY */
#if (RT_MAIN_THREAD_PRIORITY >= RT_THREAD_PRIORITY_MAX)
#error "RT_MAIN_THREAD_PRIORITY must be < RT_THREAD_PRIORITY_MAX"
Expand Down Expand Up @@ -93,7 +93,7 @@ void rt_components_board_init(void)
#ifdef RT_DEBUGING_AUTO_INIT
int result;
const struct rt_init_desc *desc;
for (desc = &__rt_init_desc_rti_board_start; desc < &__rt_init_desc_rti_board_end; desc ++)
for (desc = &__rt_init_desc_rti_board_start; desc < &__rt_init_desc_rti_board_end; desc++)
{
rt_kprintf("initialize %s\n", desc->fn_name);
result = desc->fn();
Expand All @@ -119,7 +119,7 @@ void rt_components_init(void)
const struct rt_init_desc *desc;

rt_kprintf("do components initialization.\n");
for (desc = &__rt_init_desc_rti_board_end; desc < &__rt_init_desc_rti_end; desc ++)
for (desc = &__rt_init_desc_rti_board_end; desc < &__rt_init_desc_rti_end; desc++)
{
rt_kprintf("initialize %s\n", desc->fn_name);
result = desc->fn();
Expand All @@ -128,7 +128,7 @@ void rt_components_init(void)
#else
volatile const init_fn_t *fn_ptr;

for (fn_ptr = &__rt_init_rti_board_end; fn_ptr < &__rt_init_rti_end; fn_ptr ++)
for (fn_ptr = &__rt_init_rti_board_end; fn_ptr < &__rt_init_rti_end; fn_ptr++)
{
(*fn_ptr)();
}
Expand Down Expand Up @@ -171,8 +171,7 @@ int entry(void)

#ifndef RT_USING_HEAP
/* if there is not enable heap, we should use static thread and stack. */
rt_align(RT_ALIGN_SIZE)
static rt_uint8_t main_thread_stack[RT_MAIN_THREAD_STACK_SIZE];
rt_align(RT_ALIGN_SIZE) static rt_uint8_t main_thread_stack[RT_MAIN_THREAD_STACK_SIZE];
struct rt_thread main_thread;
#endif /* RT_USING_HEAP */

Expand Down
5 changes: 2 additions & 3 deletions src/cpu_mp.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ struct rt_cpu *rt_cpu_index(int index)
rt_base_t rt_cpus_lock(void)
{
rt_base_t level;
struct rt_cpu* pcpu;
struct rt_cpu *pcpu;

level = rt_hw_local_irq_disable();
pcpu = rt_cpu_self();
Expand Down Expand Up @@ -205,7 +205,7 @@ RTM_EXPORT(rt_cpus_lock);
*/
void rt_cpus_unlock(rt_base_t level)
{
struct rt_cpu* pcpu = rt_cpu_self();
struct rt_cpu *pcpu = rt_cpu_self();

if (pcpu->current_thread != RT_NULL)
{
Expand Down Expand Up @@ -261,7 +261,6 @@ RTM_EXPORT(rt_cpus_lock_status_restore);
*/
rt_base_t rt_cpu_get_id(void)
{

RT_ASSERT(rt_sched_thread_is_binding(RT_NULL) ||
rt_hw_interrupt_is_disabled() ||
!rt_scheduler_is_available());
Expand Down
8 changes: 4 additions & 4 deletions src/defunct.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef SYSTEM_THREAD_STACK_SIZE
#define SYSTEM_THREAD_STACK_SIZE IDLE_THREAD_STACK_SIZE
#endif
static rt_list_t _rt_thread_defunct = RT_LIST_OBJECT_INIT(_rt_thread_defunct);
static rt_list_t _rt_thread_defunct = RT_LIST_OBJECT_INIT(_rt_thread_defunct);
static struct rt_spinlock _defunct_spinlock;
#if defined(RT_USING_SMP) || defined(RT_USING_SMART)
static struct rt_thread rt_system_thread;
Expand Down Expand Up @@ -46,9 +46,9 @@ void rt_thread_defunct_enqueue(rt_thread_t thread)
*/
rt_thread_t rt_thread_defunct_dequeue(void)
{
rt_base_t level;
rt_base_t level;
rt_thread_t thread = RT_NULL;
rt_list_t *l = &_rt_thread_defunct;
rt_list_t *l = &_rt_thread_defunct;

level = rt_spin_lock_irqsave(&_defunct_spinlock);
if (!rt_list_isempty(l))
Expand All @@ -71,7 +71,7 @@ void rt_defunct_execute(void)
while (1)
{
rt_thread_t thread;
rt_bool_t object_is_systemobject;
rt_bool_t object_is_systemobject;
void (*cleanup)(struct rt_thread *tid);

#ifdef RT_USING_MODULE
Expand Down
35 changes: 18 additions & 17 deletions src/idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,21 @@
#endif /* RT_USING_HOOK */

#ifndef IDLE_THREAD_STACK_SIZE
#if defined (RT_USING_IDLE_HOOK) || defined(RT_USING_HEAP)
#define IDLE_THREAD_STACK_SIZE 256
#if defined(RT_USING_IDLE_HOOK) || defined(RT_USING_HEAP)
#define IDLE_THREAD_STACK_SIZE 256
#else
#define IDLE_THREAD_STACK_SIZE 128
#define IDLE_THREAD_STACK_SIZE 128
#endif /* (RT_USING_IDLE_HOOK) || defined(RT_USING_HEAP) */
#endif /* IDLE_THREAD_STACK_SIZE */

#define _CPUS_NR RT_CPUS_NR
#define _CPUS_NR RT_CPUS_NR

static struct rt_thread idle_thread[_CPUS_NR];
rt_align(RT_ALIGN_SIZE)
static rt_uint8_t idle_thread_stack[_CPUS_NR][IDLE_THREAD_STACK_SIZE];
rt_align(RT_ALIGN_SIZE) static rt_uint8_t idle_thread_stack[_CPUS_NR][IDLE_THREAD_STACK_SIZE];

#ifdef RT_USING_IDLE_HOOK
#ifndef RT_IDLE_HOOK_LIST_SIZE
#define RT_IDLE_HOOK_LIST_SIZE 4
#define RT_IDLE_HOOK_LIST_SIZE 4
#endif /* RT_IDLE_HOOK_LIST_SIZE */

static void (*idle_hook_list[RT_IDLE_HOOK_LIST_SIZE])(void);
Expand Down Expand Up @@ -147,7 +146,7 @@ static void idle_thread_entry(void *parameter)
#endif /* RT_USING_IDLE_HOOK */

#if !defined(RT_USING_SMP) && !defined(RT_USING_SMART)
rt_defunct_execute();
rt_defunct_execute();
#endif

#ifdef RT_USING_PM
Expand Down Expand Up @@ -180,18 +179,18 @@ void rt_thread_idle_init(void)
#endif /* RT_NAME_MAX > 0 */
rt_thread_init(&idle_thread[i],
#if RT_NAME_MAX > 0
idle_thread_name,
idle_thread_name,
#else
"tidle",
"tidle",
#endif /* RT_NAME_MAX > 0 */
idle_thread_entry,
RT_NULL,
&idle_thread_stack[i][0],
sizeof(idle_thread_stack[i]),
RT_THREAD_PRIORITY_MAX - 1,
32);
idle_thread_entry,
RT_NULL,
&idle_thread_stack[i][0],
sizeof(idle_thread_stack[i]),
RT_THREAD_PRIORITY_MAX - 1,
32);
#ifdef RT_USING_SMP
rt_thread_control(&idle_thread[i], RT_THREAD_CTRL_BIND_CPU, (void*)i);
rt_thread_control(&idle_thread[i], RT_THREAD_CTRL_BIND_CPU, (void *)i);
#endif /* RT_USING_SMP */

/* update */
Expand Down Expand Up @@ -243,7 +242,9 @@ rt_bool_t rt_thread_is_idle_thread(rt_thread_t thread)
for (i = 0; i < _CPUS_NR; i++)
{
if (thread == &idle_thread[i])
{
return RT_TRUE;
}
}
}

Expand Down
Loading
Loading