From c3c2126553f480ac9782d7c8e0c7bab3aa4c353a Mon Sep 17 00:00:00 2001 From: luyu121 <319931274@qq.com> Date: Mon, 21 Jul 2025 21:54:30 +0800 Subject: [PATCH 1/6] =?UTF-8?q?node=20=E6=96=87=E4=BB=B6=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lu_jing_han/node.md" | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 "2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/node.md" diff --git "a/2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/node.md" "b/2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/node.md" new file mode 100644 index 0000000..4290ac4 --- /dev/null +++ "b/2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/node.md" @@ -0,0 +1,11 @@ +# RT-Thread 学习笔记 + +## 1. RT-Thread 简介 +RT-Thread 是一个开源的嵌入式实时操作系统,适用于 ARM Cortex-M、Cortex-A、RISC-V 等多种架构。它具有内核小巧、组件丰富、易于移植等特点。 + +## 2. 基本概念 +- **线程(Thread)**:RT-Thread 的基本执行单元。 +- **调度器(Scheduler)**:负责线程的切换和管理。 +- **信号量、消息队列、邮箱**:用于线程间通信和同步。 +- **定时器**:用于定时任务处理。 + -- Gitee From 81b8727d4e53cba3268dad5f6f7d2d942eec73b1 Mon Sep 17 00:00:00 2001 From: luyu121 <319931274@qq.com> Date: Tue, 22 Jul 2025 21:03:37 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lu_jing_han/day_2/\347\254\224\350\256\260.txt" | 1 + 1 file changed, 1 insertion(+) create mode 100644 "2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/day_2/\347\254\224\350\256\260.txt" diff --git "a/2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/day_2/\347\254\224\350\256\260.txt" "b/2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/day_2/\347\254\224\350\256\260.txt" new file mode 100644 index 0000000..533805d --- /dev/null +++ "b/2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/day_2/\347\254\224\350\256\260.txt" @@ -0,0 +1 @@ +lala \ No newline at end of file -- Gitee From 428b4239058e76ecb29def90d6c838108030af05 Mon Sep 17 00:00:00 2001 From: luyu121 <319931274@qq.com> Date: Tue, 22 Jul 2025 21:13:15 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E6=8F=90=E4=BA=A4=20day=5F2=20=E9=87=8C?= =?UTF-8?q?=E7=9A=84=20min.c=20=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lu_jing_han/day_2/min.c" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/day_2/min.c" diff --git "a/2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/day_2/min.c" "b/2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/day_2/min.c" new file mode 100644 index 0000000..e69de29 -- Gitee From 7df010b8b1ce5db7d7e4363b8eed80a6820cf41e Mon Sep 17 00:00:00 2001 From: luyu121 <319931274@qq.com> Date: Tue, 22 Jul 2025 21:20:44 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lu_jing_han/day_1/node.md" | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 "2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/day_1/node.md" diff --git "a/2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/day_1/node.md" "b/2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/day_1/node.md" new file mode 100644 index 0000000..4290ac4 --- /dev/null +++ "b/2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/day_1/node.md" @@ -0,0 +1,11 @@ +# RT-Thread 学习笔记 + +## 1. RT-Thread 简介 +RT-Thread 是一个开源的嵌入式实时操作系统,适用于 ARM Cortex-M、Cortex-A、RISC-V 等多种架构。它具有内核小巧、组件丰富、易于移植等特点。 + +## 2. 基本概念 +- **线程(Thread)**:RT-Thread 的基本执行单元。 +- **调度器(Scheduler)**:负责线程的切换和管理。 +- **信号量、消息队列、邮箱**:用于线程间通信和同步。 +- **定时器**:用于定时任务处理。 + -- Gitee From c41edbb944a857dbde1f6ae6a7348859604e4f4e Mon Sep 17 00:00:00 2001 From: luyu121 <319931274@qq.com> Date: Tue, 22 Jul 2025 21:25:59 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E5=B0=86=20node.md=20=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E5=88=B0=20day=5F1=20=E6=96=87=E4=BB=B6=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lu_jing_han/node.md" | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 "2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/node.md" diff --git "a/2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/node.md" "b/2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/node.md" deleted file mode 100644 index 4290ac4..0000000 --- "a/2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/node.md" +++ /dev/null @@ -1,11 +0,0 @@ -# RT-Thread 学习笔记 - -## 1. RT-Thread 简介 -RT-Thread 是一个开源的嵌入式实时操作系统,适用于 ARM Cortex-M、Cortex-A、RISC-V 等多种架构。它具有内核小巧、组件丰富、易于移植等特点。 - -## 2. 基本概念 -- **线程(Thread)**:RT-Thread 的基本执行单元。 -- **调度器(Scheduler)**:负责线程的切换和管理。 -- **信号量、消息队列、邮箱**:用于线程间通信和同步。 -- **定时器**:用于定时任务处理。 - -- Gitee From e3081fac4a7e729fc931ce5df989db2aca358711 Mon Sep 17 00:00:00 2001 From: luyu121 <319931274@qq.com> Date: Wed, 23 Jul 2025 00:38:49 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E7=AC=AC=E4=BA=8C=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lu_jing_han/day_2/min.c" | 89 +++++++++++++++++++ .../day_2/\347\254\224\350\256\260.txt" | 55 +++++++++++- 2 files changed, 143 insertions(+), 1 deletion(-) diff --git "a/2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/day_2/min.c" "b/2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/day_2/min.c" index e69de29..713d50f 100644 --- "a/2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/day_2/min.c" +++ "b/2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/day_2/min.c" @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2018-11-06 SummerGift first version + * 2018-11-19 flybreak add stm32f407-atk-explorer bsp + */ + +#include +#include +#include + +/* 线程优先级定义(值越小优先级越高) */ +#define HIGH_PRIORITY 10 // 高优先级线程 +#define MID_PRIORITY 20 // 中优先级线程 +#define LOW_PRIORITY 30 // 低优先级线程 + +/* 线程栈大小 */ +#define THREAD_STACK_SIZE 512 + +/* 时间片 */ +#define THREAD_TIMESLICE 10 // 时间片大小(系统节拍数) + +// 线程计数变量 +static int h_cnt, m_cnt, l_cnt; + +/* 高优先级线程函数 */ +static void high_thread(void *p) +{ + while (1) + { + h_cnt++; + rt_kprintf("H%d\n", h_cnt); + rt_thread_mdelay(100); + } +} + +/* 中优先级线程函数 */ +static void mid_thread(void *p) +{ + while (1) + { + m_cnt++; + rt_kprintf("M%d\n", m_cnt); + rt_thread_mdelay(200); + } +} + +/* 低优先级线程函数 */ +static void low_thread(void *p) +{ + while (1) + { + l_cnt++; + rt_kprintf("L%d\n", l_cnt); + rt_thread_mdelay(500); + } +} + +int main(void) +{ + rt_thread_t tid; // 线程句柄 + + // 高优先级线程 + tid = rt_thread_create("high", high_thread, RT_NULL, 512, HIGH_PRIORITY, 10); + if (tid != RT_NULL) + rt_thread_startup(tid); + else + rt_kprintf("High thread create failed!\n"); + + // 中优先级线程 + tid = rt_thread_create("mid", mid_thread, RT_NULL, 512, MID_PRIORITY, 10); + if (tid != RT_NULL) + rt_thread_startup(tid); + else + rt_kprintf("Mid thread create failed!\n"); + + // 优先级线程 + tid = rt_thread_create("low", low_thread, RT_NULL, 512, LOW_PRIORITY , 10); + if (tid != RT_NULL) + rt_thread_startup(tid); + else + rt_kprintf("Low thread create failed!\n"); + + return RT_EOK; +} diff --git "a/2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/day_2/\347\254\224\350\256\260.txt" "b/2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/day_2/\347\254\224\350\256\260.txt" index 533805d..1632fe0 100644 --- "a/2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/day_2/\347\254\224\350\256\260.txt" +++ "b/2025/\347\254\2541\347\273\204(STM32H750-ART-PI)/lu_jing_han/day_2/\347\254\224\350\256\260.txt" @@ -1 +1,54 @@ -lala \ No newline at end of file +一、线程创建(动态 & 静态)​ +(一)动态创建​ +函数:rt_thread_create​ +特点:​ +从堆中分配线程控制块、栈空间,灵活但依赖堆内存。​ +示例:​ +rt_thread_t tid = rt_thread_create ("thread_name",​ +thread_entry,​ +RT_NULL,​ +STACK_SIZE,​ +PRIORITY,​ +TIMESLICE);​ +if (tid != RT_NULL) rt_thread_startup (tid);​ +适用场景:内存充足、需灵活创建 / 销毁线程的场景(如动态任务加载)。​ +(二)静态创建​ +函数:rt_thread_init + rt_thread_startup​ +特点:​ +需预先定义线程控制块、栈数组(用静态内存),不依赖堆。​ +示例:​ +struct rt_thread static_thread;​ +rt_uint8_t static_stack [STACK_SIZE];​ +rt_thread_init (&static_thread, "static_th",​ +thread_entry, RT_NULL,​ +static_stack, STACK_SIZE,​ +PRIORITY, TIMESLICE);​ +rt_thread_startup (&static_thread);​ +适用场景:内存紧张、对内存分配确定性要求高的场景(如裸机移植、关键任务)。​ +二、内核定时器(软 / 硬定时器)​ +(一)软件定时器​ +原理:由 RT-Thread 内核模拟,依赖系统时钟节拍(rt_tick)。​ + +特点:精度中等(受线程调度影响),灵活、资源占用小。​ +(二)硬件定时器​ +原理:基于芯片硬件定时器外设,由硬件触发中断。​ + +特点:精度极高(微秒级),但需占用硬件资源,适合高精度定时(如 PWM 输出、编码器计数)。​ +三、优先级与调度​ +(一)优先级​ +范围:RT-Thread 中优先级 0(最高)~ RT_THREAD_PRIORITY_MAX(默认 255,最低 )。​ +作用:高优先级线程可抢占低优先级线程(优先级翻转需用互斥锁解决)。​ +示例:​ +#define HIGH_PRIO 10​ +#define LOW_PRIO 30​ +// 高优先级线程可打断低优先级线程运行​ +(二)时间片​ +原理:同优先级线程轮流执行,时间片决定单次执行时长(单位:系统节拍 )。​ +设置:rt_thread_create 的 timeslice 参数(如 10 表示 10 个节拍时长 )。​ +效果:同优先级线程按时间片 “轮流执行”,避免单个线程长期占用 CPU。​ +四、总结​ +知识点 核心要点 适用场景​ +线程动态创建 堆分配、灵活创建,依赖 rt_thread_create 需动态管理线程(如任务加载)​ +线程静态创建 静态内存、确定性高,依赖 rt_thread_init + rt_thread_startup 内存紧张、关键任务​​ +优先级与时间片 优先级决定抢占,时间片决定同优先级线程轮流执行 所有多线程场景,需平衡实时性与公平性​ +通过理解线程创建方式、定时器类型、优先级调度,可高效构建 RT-Thread 多任务系统,适配不同场景需求(如实时控制、低功耗定时)。 \ No newline at end of file -- Gitee