diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\344\275\234\344\270\232/2f867f096ace9a549d0cd063f741e78.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\344\275\234\344\270\232/2f867f096ace9a549d0cd063f741e78.png" new file mode 100644 index 0000000000000000000000000000000000000000..003b6ea2d5ba27fd1017cc5d332bfbb517c6d5f3 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\344\275\234\344\270\232/2f867f096ace9a549d0cd063f741e78.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\344\275\234\344\270\232/main.c" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\344\275\234\344\270\232/main.c" new file mode 100644 index 0000000000000000000000000000000000000000..e4502519cda68052151b508f5164649465dd08d2 --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\344\275\234\344\270\232/main.c" @@ -0,0 +1,59 @@ +/* + * 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 + +void usr_thread1(void){ + while(1){ + rt_kprintf("run in usr1 thread\r\n"); + rt_thread_delay(5); + + } +} +void usr_thread2(void){ + while(1){ + rt_kprintf("run in usr2 thread\r\n"); + rt_thread_delay(5); + + } +} +void usr_thread3(void){ + while(1){ + rt_kprintf("run in usr3 thread\r\n"); + rt_thread_delay(5); + + } +} +rt_thread_t tid1 = RT_NULL; +rt_thread_t tid2 = RT_NULL; +rt_thread_t tid3 = RT_NULL; +int main(void) +{ + tid1 = rt_thread_create("usr1", usr_thread1, RT_NULL, 1024, 11, 5); + + if (tid1 != RT_NULL){ + rt_thread_startup(tid1); + } + + tid2 = rt_thread_create("usr2", usr_thread2, RT_NULL, 1024, 11, 5); + + if (tid2 != RT_NULL){ + rt_thread_startup(tid2); + } + tid2 = rt_thread_create("usr3", usr_thread3, RT_NULL, 1024, 11, 5); + + if (tid3 != RT_NULL){ + rt_thread_startup(tid3); + } + return RT_EOK; +} diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\344\275\234\344\270\232/\347\254\2541\345\244\251\344\275\234\344\270\232.md" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\344\275\234\344\270\232/\347\254\2541\345\244\251\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..711dd7b0b9b7f33dcfa7996053aef6916b761b50 --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\344\275\234\344\270\232/\347\254\2541\345\244\251\344\275\234\344\270\232.md" @@ -0,0 +1,2 @@ +66666 +![输入图片说明](2f867f096ace9a549d0cd063f741e78.png) \ No newline at end of file diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/23c856df9580baf9897db12d91bf2fd.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/23c856df9580baf9897db12d91bf2fd.png" new file mode 100644 index 0000000000000000000000000000000000000000..d2986e965679ec7879dd5b0222fa4dafb9db8a94 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/23c856df9580baf9897db12d91bf2fd.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/2ddecf4c80910807a8e5abd5a9fe4c0.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/2ddecf4c80910807a8e5abd5a9fe4c0.png" new file mode 100644 index 0000000000000000000000000000000000000000..d8e7cdee9b762df9d2d4ffe328c5ad8ce53811b9 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/2ddecf4c80910807a8e5abd5a9fe4c0.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/7c7168d559975f42044aff38e717dad.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/7c7168d559975f42044aff38e717dad.png" new file mode 100644 index 0000000000000000000000000000000000000000..7ea63bfd9cd0c8bedee0c70db8ea64945d5004af Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/7c7168d559975f42044aff38e717dad.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/7f21eb171dc885a5fc14e9b14c8998d.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/7f21eb171dc885a5fc14e9b14c8998d.png" new file mode 100644 index 0000000000000000000000000000000000000000..1be90b858897c73635e7a2b7cf3f991dfc6f62ab Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/7f21eb171dc885a5fc14e9b14c8998d.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/82d61c35200855f0fb4bd19d079399f.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/82d61c35200855f0fb4bd19d079399f.png" new file mode 100644 index 0000000000000000000000000000000000000000..414fc619f08280de8af354a3150e95f6d937bace Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/82d61c35200855f0fb4bd19d079399f.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/b030b219db593e4e964400f776f3ece.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/b030b219db593e4e964400f776f3ece.png" new file mode 100644 index 0000000000000000000000000000000000000000..a479eca11d2ec434c802981420e2f58ad6c73d7a Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/b030b219db593e4e964400f776f3ece.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/c78ac23d4aebb68565812ca5e72d8c3.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/c78ac23d4aebb68565812ca5e72d8c3.png" new file mode 100644 index 0000000000000000000000000000000000000000..9bb5363e7619177d5888a859fe9b68ed2cda99a0 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/c78ac23d4aebb68565812ca5e72d8c3.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/d2e8596385d067470f2a2becf1f0e24.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/d2e8596385d067470f2a2becf1f0e24.png" new file mode 100644 index 0000000000000000000000000000000000000000..0f9567f23df05b8fb3dcfa3224e6c43b7de21019 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/d2e8596385d067470f2a2becf1f0e24.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/image.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/image.png" new file mode 100644 index 0000000000000000000000000000000000000000..d17e62e451ef8e1492b6b7eebf019d307f2795aa Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/image.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/image2.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/image2.png" new file mode 100644 index 0000000000000000000000000000000000000000..d17e62e451ef8e1492b6b7eebf019d307f2795aa Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/image2.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/\347\254\254\344\270\200\346\254\241\347\254\224\350\256\260.md" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/\347\254\254\344\270\200\346\254\241\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..b377c8509c881a6458db3ba8817b489cdb962266 --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/\347\254\254\344\270\200\346\254\241\347\254\224\350\256\260.md" @@ -0,0 +1,63 @@ +# 笔记 +## 前提环境,仓库和软件安装 +gitcmd 下载地址:https://git-scm.com/downloads + +clone RT-Thread仓库代码 + +env工具 下载,项目配置:https://github.com/RT-Thread/rt-thread + +clone后点击env.exe,等待软件自动配置 + +![输入图片说明](image.png) + +![输入图片说明](image2.png) + +配置完成后,在\rt-thread\bsp\qemu-vexpress-a9里面打开env后,scons -j4编译 + +vscode网上自行下载 + +在qemu-vexpress-a9里面打开vscode + +## + +简单的打印功能c语言测试文件,与编译文件的讲解 + +## qemu虚拟机(?)启动 + +qemu.bat + +## git仓库的学习 + +## 命令 + +命令初始化一个空的 Git 仓库: + +git init + +git add . 命令一次性将所有变更添加到暂存区: + +git status:查看当前工作区和暂存区的状态。 + +git log:查看提交记录。 + +git branch:管理分支。 + +git remote:管理远程仓库。 + +## 版本回退 + +git reset HEAD~1 + +## 完全返回到以前的提交并放弃所有更改 + +git reset --hard HEAD~1 + +## 在分支上开发并提交 +git checkout master + + +## +git checkout -b first_yhh + +## 添加或修改文件后,提交到仓库 +git push origin first_yhh \ No newline at end of file diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/\347\254\254\344\272\214\346\254\241\347\254\224\350\256\260.md" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/\347\254\254\344\272\214\346\254\241\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..f5a53e2ba571f208c2f53353369c3e81c12f41d6 --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\350\242\201\346\265\251\345\215\216/\347\254\224\350\256\260/\347\254\254\344\272\214\346\254\241\347\254\224\350\256\260.md" @@ -0,0 +1,267 @@ +# 笔记 + +### 全是图片 + +第1步:关中断(保护初始化原子性) +## +rt_hw_interrupt_disable(); // 关键一步! +## +防止硬件中断打断内核初始化(如调度器/定时器初始化),导致数据不一致。 + +何时恢复中断? +在 rt_system_scheduler_start() 启动调度器时自动恢复! + +第2步:硬件初始化 +(rt_hw_board_init()) + +// 必须在此函数内完成: + + +``` +void rt_hw_board_init() { + + 1. 初始化系统时钟、内存 + + 2. 初始化调试串口(如UART1) + + 3. 注册控制台设备:rt_console_set_device("uart1"); + + +} +``` + + + +重点:串口初始化必须在这里完成! + +第3步:双定时器系统初始化 + +定时器类型 初始化函数 运行位置 精度 用途 + +系统时钟 rt_system_timer_init() 硬件中断 微秒级 线程延时/时间片轮转 + + +软件定时器 rt_system_timer_thread_init() 线程 毫秒级 应用层定时任务 + + +硬件定时器中断示例: + + + +``` +void SysTick_Handler() { + rt_tick_increase(); // 每1ms触发一次(驱动OS心跳) +} + +``` + +第4步:调度器初始化(核心!) + + +``` + +rt_system_scheduler_init(); // 初始化就绪列表 +``` + +调度规则: +永远从就绪列表中选择优先级最高的线程运行! + +优先级数字越小越高(pri=0 最高) + +同优先级才用时间片轮转(需开启 RT_USING_RR) + +第5步:创建系统线程 + + +``` +// 1. 主线程(运行用户main函数) +rt_application_init() --> 创建 main_thread_entry + +// 2. 定时器线程(管理软件定时器) +rt_thread_init(rt_thread_timer_entry) + +// 3. 空闲线程(系统最低优先级) +rt_thread_idle_init() // 优先级31,永不休眠! +``` + +空闲线程特殊作用: + +执行低功耗睡眠(通过钩子函数) + +回收已删除线程的资源 + + + +``` +// 低功耗示例 +void idle_hook() { __WFI(); } // CPU睡眠 +rt_thread_idle_sethook(idle_hook); +``` + + + 第6步:启动调度器(引爆点!) + +``` + +rt_system_scheduler_start(); // 从此进入多线程世界! +``` + +此时: + +中断恢复 + +系统开始按优先级调度线程 + +CPU控制权交给最高优先级就绪线程(通常是 main 线程) + + +## 图片 +![输入图片说明](82d61c35200855f0fb4bd19d079399f.png) + +![输入图片说明](b030b219db593e4e964400f776f3ece.png) + + +![输入图片说明](7f21eb171dc885a5fc14e9b14c8998d.png) + +![输入图片说明](7c7168d559975f42044aff38e717dad.png) + +![输入图片说明](23c856df9580baf9897db12d91bf2fd.png) + + +![输入图片说明](2ddecf4c80910807a8e5abd5a9fe4c0.png) + + +![输入图片说明](c78ac23d4aebb68565812ca5e72d8c3.png) + +![输入图片说明](d2e8596385d067470f2a2becf1f0e24.png) + +## 课上测试代码 + + +``` +/* + * 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 + +void usr_thread1(void){ + while(1){ + rt_kprintf("run in usr1 thread\r\n"); + rt_thread_delay(5); + + } +} +void usr_thread2(void){ + while(1){ + rt_kprintf("run in usr2 thread\r\n"); + rt_thread_delay(5); + + } +} +rt_thread_t tid1 = RT_NULL; +rt_thread_t tid2 = RT_NULL; +int main(void) +{ + tid1 = rt_thread_create("usr1", usr_thread1, RT_NULL, 1024, 2, 5); + + if (tid1 != RT_NULL){ + rt_thread_startup(tid1); + } + + tid2 = rt_thread_create("usr2", usr_thread2, RT_NULL, 1024, 2, 5); + + if (tid2 != RT_NULL){ + rt_thread_startup(tid2); + } + rt_kprintf("run in main thread\r\n"); + return RT_EOK; +} + +``` + +## ai解释 + +1. **初始状态** _(Initial State)_ +比喻:你刚入职一家公司,填完入职表,但还没被分配到具体的部门或工作。 + +说明:线程被创建但尚未激活,就像你还没开始正式工作。 + +2. **就绪状态** _(Ready State)_ + +比喻:你被分配到了部门,坐在工位上,随时等待领导给你安排任务。 + +说明:线程已经准备好执行,等待 CPU 调度,就像你在工位上等活儿干。 + +3. **运行状态** _(Running State)_ + +比喻:领导给你安排了任务,你正在执行任务(比如写报告、开会)。 + +说明:线程正在占用 CPU 执行代码,就像你正在干活。 + +4. **挂起状态** _(Suspended State)_ + +比喻: + +你在写报告时,突然被领导叫去开会(被迫暂停)。 + +或者你主动休息一下(比如喝咖啡、回邮件)。 + +说明:线程暂时停止执行,等待被唤醒,就像你暂时停下手中的活。 + +5. **关闭状态** _(Closed State)_ + +比喻:你完成了所有任务,或者被公司解雇,离开了公司。 + +说明:线程执行完毕或被删除,资源被释放,就像你不再为公司工作。 + +状态转换的比喻 + + **初始 → 就绪** : + +你入职后被分配到部门(rt_thread_startup())。 + + **就绪 → 运行** : + +领导给你安排任务(调度器调度)。 + +**运行 → 挂起** : + +你被临时叫走(rt_thread_delay()、rt_sem_take() 等)。 + +你主动休息(rt_thread_suspend())。 + + **挂起 → 就绪** : + +会议结束,你回到工位(rt_thread_resume()、rt_sem_release() 等)。 + + **运行 → 关闭** : + +你完成任务离职(rt_thread_exit())。 + + **挂起 → 关闭** : + +你被解雇(rt_thread_delete() 或 rt_thread_detach())。 + + **就绪 → 挂起** + +比喻:你坐在工位上(就绪状态),突然收到一封紧急邮件需要处理,你放下手头的工作去处理邮件(挂起状态)。 + +说明:线程在就绪状态时,被外部事件(如信号量、消息队列等)触发,主动进入挂起状态,等待事件处理完毕后再恢复。 + + + ** + 运行 → 就绪** + +比喻:你正在写报告(运行状态),突然领导说 “先停一下,等会儿再继续”,你停下手中的工作,回到工位等待下一步指示(就绪状态)。 + +说明:线程在运行状态时,时间片用完或被更高优先级的线程抢占,回到就绪状态等待下一次调度。