diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/Snipaste_2025-07-21_20-54-10.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/Snipaste_2025-07-21_20-54-10.png" new file mode 100644 index 0000000000000000000000000000000000000000..736ad8428365e93115b39f804bf37d3a133bf9da Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/Snipaste_2025-07-21_20-54-10.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day1 \344\275\234\344\270\232.md" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day1 \344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..4f006cf9402578e37ede964659eeb86d5aa47cee --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day1 \344\275\234\344\270\232.md" @@ -0,0 +1,10 @@ +# Day1 + +运行LVGL例程 + +`qemu.bat` + + + + + diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day2\344\275\234\344\270\232.md" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day2\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..34075bc5d9e99f3c125dac30621c4c9262432c00 --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day2\344\275\234\344\270\232.md" @@ -0,0 +1,77 @@ +# Day2作业 + +今日作业: 1.在论坛发文章描述对今天内容的总结与收获 2.编写代码上传至git仓库,创建至少3个线程,能体现抢占与时间片轮转,在今天的工程的mian.c中实现,其他同学拿到该文件可以直接运行。 自行研究: 1.ARM函数调用规范 课程回放链接:#小程序://腾讯会议/ZFa6PsCDJPy15pH(密码:RTT1) + + + +``` +/* + + * 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 + +rt_thread_t thread1 = RT_NULL; +rt_thread_t thread2 = RT_NULL; +rt_thread_t thread3 = RT_NULL; + +void thread1_entry() +{ + while (1) + { + rt_kprintf("this is thread1\n"); + rt_thread_mdelay(1000); + + } + +} + +void thread2_entry() +{ + while (1) + { + rt_kprintf("this is thread2\n"); + } +} + +void thread3_entry() +{ + while (1) + { + rt_kprintf("this is thread3\n"); + } +} +int main(void) +{ + + thread1 = rt_thread_create("thread1", thread1_entry, RT_NULL, 1024, 11, 10); + thread2 = rt_thread_create("thread2", thread2_entry, RT_NULL, 1024, 12, 10); + thread3 = rt_thread_create("thread3", thread3_entry, RT_NULL, 1024, 12, 10); + + if (thread1 != RT_NULL) + rt_thread_startup(thread1); + if (thread2 != RT_NULL) + rt_thread_startup(thread2); + if (thread3 != RT_NULL) + rt_thread_startup(thread3); + while (1) + { + rt_kprintf("main thread\n"); + rt_thread_mdelay(500); + } + return RT_EOK; + +} + + +``` + diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day3 \344\275\234\344\270\232/event_sample.c" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day3 \344\275\234\344\270\232/event_sample.c" new file mode 100644 index 0000000000000000000000000000000000000000..3635810b86789aadf45413744c995ae6040b2554 --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day3 \344\275\234\344\270\232/event_sample.c" @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2018-08-24 yangjie the first version + */ + +/* + * 程序清单:事件例程 + * + * 程序会初始化2个线程及初始化一个静态事件对象 + * 一个线程等待于事件对象上,以接收事件; + * 一个线程发送事件 (事件3/事件5) +*/ +#include + +#define THREAD_PRIORITY 9 +#define THREAD_TIMESLICE 5 + +#define EVENT_FLAG3 (1 << 3) +#define EVENT_FLAG5 (1 << 5) + +/* 事件控制块 */ +static struct rt_event event; + +ALIGN(RT_ALIGN_SIZE) +static char thread1_stack[1024]; +static struct rt_thread thread1; + +/* 线程1入口函数 */ +static void thread1_recv_event(void *param) +{ + rt_uint32_t e; + + /* 第一次接收事件,事件3或事件5任意一个可以触发线程1,接收完后清除事件标志 */ + if (rt_event_recv(&event, (EVENT_FLAG3 | EVENT_FLAG5), + RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, + RT_WAITING_FOREVER, &e) == RT_EOK) + { + rt_kprintf("thread1: OR recv event 0x%x\n", e); + } + + rt_kprintf("thread1: delay 1s to prepare the second event\n"); + rt_thread_mdelay(1000); + + /* 第二次接收事件,事件3和事件5均发生时才可以触发线程1,接收完后清除事件标志 */ + if (rt_event_recv(&event, (EVENT_FLAG3 | EVENT_FLAG5), + RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, + RT_WAITING_FOREVER, &e) == RT_EOK) + { + rt_kprintf("thread1: AND recv event 0x%x\n", e); + } + rt_kprintf("thread1 leave.\n"); +} + +ALIGN(RT_ALIGN_SIZE) +static char thread2_stack[1024]; +static struct rt_thread thread2; + +/* 线程2入口 */ +static void thread2_send_event(void *param) +{ + rt_kprintf("thread2: send event3\n"); + rt_event_send(&event, EVENT_FLAG3); + rt_thread_mdelay(200); + + rt_kprintf("thread2: send event5\n"); + rt_event_send(&event, EVENT_FLAG5); + rt_thread_mdelay(200); + + rt_kprintf("thread2: send event3\n"); + rt_event_send(&event, EVENT_FLAG3); + rt_kprintf("thread2 leave.\n"); +} + +int event_sample(void) +{ + rt_err_t result; + + /* 初始化事件对象 */ + result = rt_event_init(&event, "event", RT_IPC_FLAG_FIFO); + if (result != RT_EOK) + { + rt_kprintf("init event failed.\n"); + return -1; + } + + rt_thread_init(&thread1, + "thread1", + thread1_recv_event, + RT_NULL, + &thread1_stack[0], + sizeof(thread1_stack), + THREAD_PRIORITY - 1, THREAD_TIMESLICE); + rt_thread_startup(&thread1); + + rt_thread_init(&thread2, + "thread2", + thread2_send_event, + RT_NULL, + &thread2_stack[0], + sizeof(thread2_stack), + THREAD_PRIORITY, THREAD_TIMESLICE); + rt_thread_startup(&thread2); + + return 0; +} + +/* 导出到 msh 命令列表中 */ +MSH_CMD_EXPORT(event_sample, event sample); diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day3 \344\275\234\344\270\232/mailbox_sample.c" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day3 \344\275\234\344\270\232/mailbox_sample.c" new file mode 100644 index 0000000000000000000000000000000000000000..6f1530536acb9d3203cfde685b17473662894b65 --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day3 \344\275\234\344\270\232/mailbox_sample.c" @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2018-08-24 yangjie the first version + */ + +/* + * 程序清单:邮箱例程 + * + * 这个程序会创建2个动态线程,一个静态的邮箱对象,其中一个线程往邮箱中发送邮件, + * 一个线程往邮箱中收取邮件。 + */ +#include + +#define THREAD_PRIORITY 10 +#define THREAD_TIMESLICE 5 + +/* 邮箱控制块 */ +static struct rt_mailbox mb; +/* 用于放邮件的内存池 */ +static char mb_pool[128]; + +static char mb_str1[] = "I'm a mail!"; +static char mb_str2[] = "this is another mail!"; +static char mb_str3[] = "over"; + +ALIGN(RT_ALIGN_SIZE) +static char thread1_stack[1024]; +static struct rt_thread thread1; + +/* 线程1入口 */ +static void thread1_entry(void *parameter) +{ + char *str; + + while (1) + { + rt_kprintf("thread1: try to recv a mail\n"); + + /* 从邮箱中收取邮件 */ + if (rt_mb_recv(&mb, (rt_ubase_t *)&str, RT_WAITING_FOREVER) == RT_EOK) + { + rt_kprintf("thread1: get a mail from mailbox, the content:%s\n", str); + if (str == mb_str3) + break; + + /* 延时100ms */ + rt_thread_mdelay(100); + } + } + /* 执行邮箱对象脱离 */ + rt_mb_detach(&mb); +} + +ALIGN(RT_ALIGN_SIZE) +static char thread2_stack[1024]; +static struct rt_thread thread2; + +/* 线程2入口 */ +static void thread2_entry(void *parameter) +{ + rt_uint8_t count; + + count = 0; + while (count < 10) + { + count ++; + if (count & 0x1) + { + /* 发送mb_str1地址到邮箱中 */ + rt_mb_send(&mb, (rt_uint32_t)&mb_str1); + } + else + { + /* 发送mb_str2地址到邮箱中 */ + rt_mb_send(&mb, (rt_uint32_t)&mb_str2); + } + + /* 延时200ms */ + rt_thread_mdelay(200); + } + + /* 发送邮件告诉线程1,线程2已经运行结束 */ + rt_mb_send(&mb, (rt_uint32_t)&mb_str3); +} + +int mailbox_sample(void) +{ + rt_err_t result; + + /* 初始化一个mailbox */ + result = rt_mb_init(&mb, + "mbt", /* 名称是mbt */ + &mb_pool[0], /* 邮箱用到的内存池是mb_pool */ + sizeof(mb_pool) / sizeof(rt_ubase_t), /* 邮箱中的邮件数目,sizeof(rt_ubase_t)表示指针大小 */ + RT_IPC_FLAG_FIFO); /* 采用FIFO方式进行线程等待 */ + if (result != RT_EOK) + { + rt_kprintf("init mailbox failed.\n"); + return -1; + } + + rt_thread_init(&thread1, + "thread1", + thread1_entry, + RT_NULL, + &thread1_stack[0], + sizeof(thread1_stack), + THREAD_PRIORITY, THREAD_TIMESLICE); + rt_thread_startup(&thread1); + + rt_thread_init(&thread2, + "thread2", + thread2_entry, + RT_NULL, + &thread2_stack[0], + sizeof(thread2_stack), + THREAD_PRIORITY, THREAD_TIMESLICE); + rt_thread_startup(&thread2); + return 0; +} + +/* 导出到 msh 命令列表中 */ +MSH_CMD_EXPORT(mailbox_sample, mailbox sample); diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day3 \344\275\234\344\270\232/msgq_sample.c" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day3 \344\275\234\344\270\232/msgq_sample.c" new file mode 100644 index 0000000000000000000000000000000000000000..4df8ffcf53bdf99ce176c7fccc2a168768eefbfd --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day3 \344\275\234\344\270\232/msgq_sample.c" @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2018-08-24 yangjie the first version + */ + +/* + * 程序清单:消息队列例程 + * + * 这个程序会创建2个动态线程,一个线程会从消息队列中收取消息;一个线程会定时给消 + * 息队列发送 普通消息和紧急消息。 + */ +#include + +#define THREAD_PRIORITY 25 +#define THREAD_TIMESLICE 5 + +/* 消息队列控制块 */ +static struct rt_messagequeue mq; +/* 消息队列中用到的放置消息的内存池 */ +static rt_uint8_t msg_pool[2048]; + +ALIGN(RT_ALIGN_SIZE) +static char thread1_stack[1024]; +static struct rt_thread thread1; + +/* 线程1入口函数 */ +static void thread1_entry(void *parameter) +{ + char buf = 0; + rt_uint8_t cnt = 0; + + while (1) + { + /* 从消息队列中接收消息 */ + if (rt_mq_recv(&mq, &buf, sizeof(buf), RT_WAITING_FOREVER) == RT_EOK) + { + rt_kprintf("thread1: recv msg from msg queue, the content:%c\n", buf); + if (cnt == 19) + { + break; + } + } + /* 延时50ms */ + cnt++; + rt_thread_mdelay(50); + } + rt_kprintf("thread1: detach mq \n"); + rt_mq_detach(&mq); +} + +ALIGN(RT_ALIGN_SIZE) +static char thread2_stack[1024]; +static struct rt_thread thread2; + +/* 线程2入口 */ +static void thread2_entry(void *parameter) +{ + int result; + char buf = 'A'; + rt_uint8_t cnt = 0; + + while (1) + { + if (cnt == 8) + { + /* 发送紧急消息到消息队列中 */ + result = rt_mq_urgent(&mq, &buf, 1); + if (result != RT_EOK) + { + rt_kprintf("rt_mq_urgent ERR\n"); + } + else + { + rt_kprintf("thread2: send urgent message - %c\n", buf); + } + } + else if (cnt >= 20)/* 发送20次消息之后退出 */ + { + rt_kprintf("message queue stop send, thread2 quit\n"); + break; + } + else + { + /* 发送消息到消息队列中 */ + result = rt_mq_send(&mq, &buf, 1); + if (result != RT_EOK) + { + rt_kprintf("rt_mq_send ERR\n"); + } + + rt_kprintf("thread2: send message - %c\n", buf); + } + buf++; + cnt++; + /* 延时5ms */ + rt_thread_mdelay(5); + } +} + +/* 消息队列示例的初始化 */ +int msgq_sample(void) +{ + rt_err_t result; + + /* 初始化消息队列 */ + result = rt_mq_init(&mq, + "mqt", + &msg_pool[0], /* 内存池指向msg_pool */ + 1, /* 每个消息的大小是 1 字节 */ + sizeof(msg_pool), /* 内存池的大小是msg_pool的大小 */ + RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */ + + if (result != RT_EOK) + { + rt_kprintf("init message queue failed.\n"); + return -1; + } + + rt_thread_init(&thread1, + "thread1", + thread1_entry, + RT_NULL, + &thread1_stack[0], + sizeof(thread1_stack), + THREAD_PRIORITY, THREAD_TIMESLICE); + rt_thread_startup(&thread1); + + rt_thread_init(&thread2, + "thread2", + thread2_entry, + RT_NULL, + &thread2_stack[0], + sizeof(thread2_stack), + THREAD_PRIORITY, THREAD_TIMESLICE); + rt_thread_startup(&thread2); + + return 0; +} + +/* 导出到 msh 命令列表中 */ +MSH_CMD_EXPORT(msgq_sample, msgq sample); diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day3 \344\275\234\344\270\232/mutex_sample.c" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day3 \344\275\234\344\270\232/mutex_sample.c" new file mode 100644 index 0000000000000000000000000000000000000000..2ec362200fcc3267014d6d80c877e45f3ffbae6c --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day3 \344\275\234\344\270\232/mutex_sample.c" @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2018-08-24 yangjie the first version + */ + +/* + * 程序清单:互斥锁例程 + * + * 互斥锁是一种保护共享资源的方法。当一个线程拥有互斥锁的时候, + * 可以保护共享资源不被其他线程破坏。线程1对2个number分别进行加1操作 + * 线程2也会对2个number分别进行加1操作。使用互斥量保证2个number值保持一致 + */ +#include + +#define THREAD_PRIORITY 8 +#define THREAD_TIMESLICE 5 + +/* 指向互斥量的指针 */ +static rt_mutex_t dynamic_mutex = RT_NULL; +static rt_uint8_t number1, number2 = 0; + +ALIGN(RT_ALIGN_SIZE) +static char thread1_stack[1024]; +static struct rt_thread thread1; +static void rt_thread_entry1(void *parameter) +{ + while (1) + { + /* 线程1获取到互斥量后,先后对number1、number2进行加1操作,然后释放互斥量 */ + rt_mutex_take(dynamic_mutex, RT_WAITING_FOREVER); +// number1++; + rt_thread_mdelay(10); +// number2++; + rt_kprintf("aaaaaaaaaaaaa ,number1 = mumber2 is %d\n", number1); + + rt_mutex_release(dynamic_mutex); + } +} + +ALIGN(RT_ALIGN_SIZE) +static char thread2_stack[1024]; +static struct rt_thread thread2; +static void rt_thread_entry2(void *parameter) +{ + while (1) + { + /* 线程2获取到互斥量后,检查number1、number2的值是否相同,相同则表示mutex起到了锁的作用 */ + rt_mutex_take(dynamic_mutex, RT_WAITING_FOREVER); + if (number1 != number2) + { + rt_kprintf("not protect.number1 = %d, mumber2 = %d \n", number1, number2); + } + else + { + rt_kprintf("mutex protect ,number1 = mumber2 is %d\n", number1); + } + + number1++; + number2++; + rt_mutex_release(dynamic_mutex); + + if (number1 >= 50) + return; + } +} + +/* 互斥量示例的初始化 */ +int mutex_sample(void) +{ + /* 创建一个动态互斥量 */ + dynamic_mutex = rt_mutex_create("dmutex", RT_IPC_FLAG_FIFO); + if (dynamic_mutex == RT_NULL) + { + rt_kprintf("create dynamic mutex failed.\n"); + return -1; + } + + rt_thread_init(&thread1, + "thread1", + rt_thread_entry1, + RT_NULL, + &thread1_stack[0], + sizeof(thread1_stack), + THREAD_PRIORITY, THREAD_TIMESLICE); + rt_thread_startup(&thread1); + + rt_thread_init(&thread2, + "thread2", + rt_thread_entry2, + RT_NULL, + &thread2_stack[0], + sizeof(thread2_stack), + THREAD_PRIORITY - 1, THREAD_TIMESLICE); + rt_thread_startup(&thread2); + return 0; +} + +/* 导出到 msh 命令列表中 */ +MSH_CMD_EXPORT(mutex_sample, mutex sample); diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day3 \344\275\234\344\270\232/semaphore_sample.c" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day3 \344\275\234\344\270\232/semaphore_sample.c" new file mode 100644 index 0000000000000000000000000000000000000000..a8f75bb64e718e3c1305b34fa1bca9aac189bd01 --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day3 \344\275\234\344\270\232/semaphore_sample.c" @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2006-2022, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2018-08-24 yangjie the first version + */ + +/* + * 程序清单:信号量例程 + * + * 该例程创建了一个动态信号量,初始化两个线程,线程1在count每计数10次时, + * 发送一个信号量,线程2在接收信号量后,对number进行加1操作 + */ +#include + +#define THREAD_PRIORITY 25 +#define THREAD_TIMESLICE 5 + +/* 指向信号量的指针 */ +static rt_sem_t dynamic_sem = RT_NULL; + +#ifdef rt_align +rt_align(RT_ALIGN_SIZE) +#else +ALIGN(RT_ALIGN_SIZE) +#endif +static char thread1_stack[1024]; +static struct rt_thread thread1; +static void rt_thread1_entry(void *parameter) +{ + static rt_uint8_t count = 0; + + while (1) + { + if (count <= 100) + { + count++; + } + else + return; + + /* count每计数10次,就释放一次信号量 */ + if (0 == (count % 10)) + { + rt_kprintf("thread1 release a dynamic semaphore.\n"); + rt_sem_release(dynamic_sem); + } + } +} + +#ifdef rt_align +rt_align(RT_ALIGN_SIZE) +#else +ALIGN(RT_ALIGN_SIZE) +#endif +static char thread2_stack[1024]; +static struct rt_thread thread2; +static void rt_thread2_entry(void *parameter) +{ + static rt_err_t result; + static rt_uint8_t number = 0; + while (1) + { + /* 永久方式等待信号量,获取到信号量,则执行number自加的操作 */ + result = rt_sem_take(dynamic_sem, RT_WAITING_FOREVER); + if (result != RT_EOK) + { + rt_kprintf("thread2 take a dynamic semaphore, failed.\n"); + rt_sem_delete(dynamic_sem); + return; + } + else + { + number++; + rt_kprintf("thread2 take a dynamic semaphore. number = %d\n", number); + } + } +} + +/* 信号量示例的初始化 */ +int semaphore_sample() +{ + /* 创建一个动态信号量,初始值是0 */ + dynamic_sem = rt_sem_create("dsem", 0, RT_IPC_FLAG_PRIO); + if (dynamic_sem == RT_NULL) + { + rt_kprintf("create dynamic semaphore failed.\n"); + return -1; + } + else + { + rt_kprintf("create done. dynamic semaphore value = 0.\n"); + } + + rt_thread_init(&thread1, + "thread1", + rt_thread1_entry, + RT_NULL, + &thread1_stack[0], + sizeof(thread1_stack), + THREAD_PRIORITY, THREAD_TIMESLICE); + + rt_thread_startup(&thread1); + + rt_thread_init(&thread2, + "thread2", + rt_thread2_entry, + RT_NULL, + &thread2_stack[0], + sizeof(thread2_stack), + THREAD_PRIORITY - 1, THREAD_TIMESLICE); + + rt_thread_startup(&thread2); + + return 0; +} + +/* 导出到 msh 命令列表中 */ +MSH_CMD_EXPORT(semaphore_sample, semaphore sample); + diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day3 \344\275\234\344\270\232/signal_sample.c" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day3 \344\275\234\344\270\232/signal_sample.c" new file mode 100644 index 0000000000000000000000000000000000000000..fe6e98ffd1d44218f8170db36c0d802de4c75cd6 --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day3 \344\275\234\344\270\232/signal_sample.c" @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2018-08-24 yangjie the first version + */ + +/* + * 程序清单:信号例程 + * + * 这个例子会创建一个线程,线程安装信号,然后给这个线程发送信号。 + * + */ +#include + +#define THREAD_PRIORITY 25 +#define THREAD_STACK_SIZE 512 +#define THREAD_TIMESLICE 5 + +static rt_thread_t tid1 = RT_NULL; + +/* 线程1的信号处理函数 */ +void thread1_signal_handler(int sig) +{ + rt_kprintf("thread1 received signal %d\n", sig); +} + +/* 线程1的入口函数 */ +static void thread1_entry(void *parameter) +{ + int cnt = 0; + + /* 安装信号 */ + rt_signal_install(SIGUSR1, thread1_signal_handler); + rt_signal_unmask(SIGUSR1); + + /* 运行10次 */ + while (cnt < 10) + { + /* 线程1采用低优先级运行,一直打印计数值 */ + rt_kprintf("thread1 count : %d\n", cnt); + + cnt++; + rt_thread_mdelay(100); + } +} + +/* 信号示例的初始化 */ +int signal_sample(void) +{ + /* 创建线程1 */ + tid1 = rt_thread_create("thread1", + thread1_entry, RT_NULL, + THREAD_STACK_SIZE, + THREAD_PRIORITY, THREAD_TIMESLICE); + + if (tid1 != RT_NULL) + rt_thread_startup(tid1); + + rt_thread_mdelay(300); + + /* 发送信号 SIGUSR1 给线程1 */ + rt_thread_kill(tid1, SIGUSR1); + + return 0; +} + +/* 导出到 msh 命令列表中 */ +MSH_CMD_EXPORT(signal_sample, signal sample); diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day4 \344\275\234\344\270\232/drv_vir.c" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day4 \344\275\234\344\270\232/drv_vir.c" new file mode 100644 index 0000000000000000000000000000000000000000..e10ead919e7d72f5973e3fe5a38b8d8d50ddc16d --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day4 \344\275\234\344\270\232/drv_vir.c" @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2025-07-26 Y8314 the first version + */ +#include + +#if defined(RT_USING_VIR) + +struct vir_test vir; +void printfinfo(struct rt_device * device,rt_uint8_t * str) +{ + rt_kprintf("vir info :%s\n",str); +} +void vir_set_val(struct rt_device * device,rt_uint32_t val) +{ + vir.val = val; +} +void vir_get_val(struct rt_device * device,rt_uint32_t *val) +{ + *val = vir.val; +} +struct rt_vir_ops ops = +{ + printfinfo, + vir_set_val, + vir_get_val, +}; + +static int vir_init(void) +{ + vir.val = 0; + vir.info = "test_vir"; + rt_hw_vir_register(&vir.parent,"vir",&ops,(void*)vir.info); +} +INIT_APP_EXPORT(vir_init); + +#endif + + + + + diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day4 \344\275\234\344\270\232/drv_vir.h" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day4 \344\275\234\344\270\232/drv_vir.h" new file mode 100644 index 0000000000000000000000000000000000000000..8616e90d0d13f98745208a0822073eed4568d74e --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day4 \344\275\234\344\270\232/drv_vir.h" @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2025-07-26 Y8314 the first version + */ +#ifndef LIBRARIES_HAL_DRIVERS_DRV_VIR_H_ +#define LIBRARIES_HAL_DRIVERS_DRV_VIR_H_ + +#include +#include + +struct vir_test +{ + + struct rt_vir_device parent; + rt_uint32_t val; + char * info; +}; + + +#endif /* LIBRARIES_HAL_DRIVERS_DRV_VIR_H_ */ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day4 \344\275\234\344\270\232/vir.c" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day4 \344\275\234\344\270\232/vir.c" new file mode 100644 index 0000000000000000000000000000000000000000..6f8cddc0f8535baa1d848c2528a4dbaa02cc49a9 --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day4 \344\275\234\344\270\232/vir.c" @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2025-07-26 Y8314 the first version + */ +#include +#include + +#if defined(RT_USING_VIR) + +rt_err_t _vir_init(rt_device_t dev) +{ + rt_kprintf("vir init \n"); + return RT_EOK; +} +rt_err_t _vir_open(rt_device_t dev, rt_uint16_t oflag) +{ + rt_kprintf("vir open\n"); + return RT_EOK; +} +rt_err_t _vir_close (rt_device_t dev) +{ + rt_kprintf("vir close\n"); + return RT_EOK; +} +rt_size_t _vir_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size) +{ + rt_vir_device_t device = (rt_vir_device_t)dev; + if(device->ops->vir_get_val) + { + device->ops->vir_get_val(dev,(rt_uint32_t*)buffer); + return RT_EOK; + } + return -RT_ERROR; +} + +rt_size_t _vir_wirte(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size) +{ + rt_vir_device_t device = (rt_vir_device_t)dev; + if(device->ops->vir_set_val) + { + device->ops->vir_set_val(dev,*(rt_uint32_t*)buffer); + return RT_EOK; + } + return -RT_ERROR; +} +rt_err_t _vir_control(rt_device_t dev, int cmd, void *args) +{ + rt_kprintf("vir control %d\n",cmd); + return RT_EOK; +} + +rt_err_t rt_hw_vir_register(rt_vir_device_t device, const char *name, const struct rt_vir_ops *ops, const void *user_data) +{ + RT_ASSERT(ops != RT_NULL); + rt_err_t result; + device->ops = ops; + device->parent.init = _vir_init; + device->parent.open = _vir_open; + device->parent.close = _vir_close; + device->parent.read = _vir_read; + device->parent.write = _vir_wirte; + device->parent.control = _vir_control; + result = rt_device_register(&device->parent, name, RT_DEVICE_FLAG_RDWR); + return result; +} + +rt_err_t rt_vir_read(rt_vir_device_t device,rt_uint32_t * val) +{ + RT_ASSERT(device != RT_NULL && device->ops != RT_NULL); + rt_device_t dev = (rt_device_t)device; + + if(device->ops->vir_get_val) + { + device->ops->vir_get_val(dev,val); + return RT_EOK; + } + return -RT_ERROR; + +} + +rt_err_t rt_vir_wirte(rt_vir_device_t device,rt_uint32_t val) +{ + RT_ASSERT(device != RT_NULL && device->ops != RT_NULL); + rt_device_t dev = (rt_device_t)device; + if(device->ops->vir_set_val) + { + device->ops->vir_set_val(dev,val); + return RT_EOK; + } + return -RT_ERROR; +} + + +#endif diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day4 \344\275\234\344\270\232/vir.h" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day4 \344\275\234\344\270\232/vir.h" new file mode 100644 index 0000000000000000000000000000000000000000..26eae07c3876972931604ca82501455baf153b0f --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day4 \344\275\234\344\270\232/vir.h" @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2025-07-26 Y8314 the first version + */ +#ifndef RT_THREAD_COMPONENTS_DRIVERS_INCLUDE_DRIVERS_VIR_H_ +#define APPLICATIONS_VIR_H_ + +#include +#include + +struct rt_vir_ops +{ + void (*printfinfo)(struct rt_device * device,rt_uint8_t * str); + void (*vir_set_val)(struct rt_device * device,rt_uint32_t val); + void (*vir_get_val)(struct rt_device * device,rt_uint32_t *val); +}; + +struct rt_vir_device +{ + struct rt_device parent; + const struct rt_vir_ops *ops; +}; +typedef struct rt_vir_device *rt_vir_device_t; + +rt_err_t rt_hw_vir_register(rt_vir_device_t device, const char *name, const struct rt_vir_ops *ops, const void *user_data); +rt_err_t rt_vir_read(rt_vir_device_t device,rt_uint32_t * val); +rt_err_t rt_vir_wirte(rt_vir_device_t device,rt_uint32_t val); + + + +#endif /* RT_THREAD_COMPONENTS_DRIVERS_INCLUDE_DRIVERS_VIR_H_ */ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day5 \344\275\234\344\270\232/Snipaste_2025-07-29_12-30-41.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day5 \344\275\234\344\270\232/Snipaste_2025-07-29_12-30-41.png" new file mode 100644 index 0000000000000000000000000000000000000000..98ac355cb2f2541c191da1a6fd4c766a722ebd50 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\344\275\234\344\270\232/\343\200\220RSOC25\343\200\221Day5 \344\275\234\344\270\232/Snipaste_2025-07-29_12-30-41.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\347\205\247\347\211\207/04main_thread.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\347\205\247\347\211\207/04main_thread.png" new file mode 100644 index 0000000000000000000000000000000000000000..7e86b22aa676c0ff2ba3bf8498cb6034eb26d878 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\347\205\247\347\211\207/04main_thread.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\347\205\247\347\211\207/04thread_sta.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\347\205\247\347\211\207/04thread_sta.png" new file mode 100644 index 0000000000000000000000000000000000000000..fe2cc8141fd5c220db0fca600c75bd9b8ea66a92 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\347\205\247\347\211\207/04thread_sta.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\347\205\247\347\211\207/rtt_startup.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\347\205\247\347\211\207/rtt_startup.png" new file mode 100644 index 0000000000000000000000000000000000000000..04dbb79fed05b7463c5ceea179f5dd75c6553724 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\347\205\247\347\211\207/rtt_startup.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\347\254\224\350\256\260/\343\200\220RSOC25\343\200\221Day1 \350\257\276\347\250\213\347\254\224\350\256\260\357\274\232\347\216\257\345\242\203\346\220\255\345\273\272.md" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\347\254\224\350\256\260/\343\200\220RSOC25\343\200\221Day1 \350\257\276\347\250\213\347\254\224\350\256\260\357\274\232\347\216\257\345\242\203\346\220\255\345\273\272.md" new file mode 100644 index 0000000000000000000000000000000000000000..ba3e6a4a60de8d835d2de01c593c7dc6572b02ca --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\347\254\224\350\256\260/\343\200\220RSOC25\343\200\221Day1 \350\257\276\347\250\213\347\254\224\350\256\260\357\274\232\347\216\257\345\242\203\346\220\255\345\273\272.md" @@ -0,0 +1,152 @@ +# Day1 + +#### 1. RT-Thread 操作系统介绍 +- **发展历程**: + - 2017年推出3.0版本物联网操作系统。 + - 2020年发布IT Smart混合微内核操作系统,支持实时性。 + - 2021-2025年完成功能安全认证,覆盖车规和工业领域。 +- **版本分类**: + - **Nano版**:精简内核,支持基础交互(如串口终端)。 + - **标准版**:完整功能,包含网络协议栈、USB协议栈、低功耗日志等组件。 + - **Smart版**:面向高性能设备(如MPU),支持进程隔离和MMU。 +- **技术亮点**: + - 简单易用,兼容主流工具链(32/64位)。 + - 内置超800个软件包,支持跨芯片平台(ARM、x86、龙芯等)。 + - 高度可裁剪,适应不同产品需求。 + +#### 2. 开源生态与影响力 +- **装机量**:国内超25亿,GitHub Star超1万(全球排名第二)。 +- **开发者社区**:超30万人,海外超2万人。 +- **软硬件合作**: + - 官方开发板:Hi-MyBoard、星火一号、Vision Board等。 + - 芯片支持:超300家,合作厂商包括英飞凌、瑞萨、ST等。 +- **高校合作**:覆盖210所高校,提供开发板、书籍及技术支持。 + +#### 3. 2025年暑期夏令营安排 +- **学习周(第一周)**: + - 环境搭建与内核培训(官方工程师指导)。 + - 驱动框架与上层应用开发(文件系统、网络协议栈等)。 + - 开发板硬件上手(分赛道导师指导)。 +- **实验周(后两周)**: + - 分6个赛题独立完成项目(如水杯电子琴、声纹识别等)。 + - 两周开发时间,最终答辩评选优秀作品。 +- **奖励机制**: + - 优秀学员:企业内推、现金奖励、维护者培养机会。 + - 优秀成果:官方渠道推广,个人影响力提升。 + +#### 4. 开发工具与环境搭建 +- **工具链**: + - Git:代码版本管理。 + - ENV:RT-Thread构建与配置工具。 + - VS Code:代码编辑与图形化Git操作。 +- **环境配置步骤**: + 1. 拉取RT-Thread代码仓库(GitHub或镜像源)。 + 2. 安装ENV工具并注册系统路径。 + 3. 使用`menuconfig`配置功能模块(如LVGL图形库)。 + 4. 编译生成固件并通过QEMU或开发板运行。 + +#### 5. Git与代码提交规范 +- **基础操作**: + - 本地仓库管理:`git add`(暂存)、`git commit`(提交)、`git log`(历史记录)。 + - 分支管理:`git branch`(创建/切换分支)、`git merge`(合并分支)。 + +- **远程协作流程**: + 1. Fork仓库到个人账号。 + 2. 克隆本地后修改代码,提交到新分支。 + 3. 推送分支至远程,发起Pull Request(PR)。 + 4. 审核通过后合并至主分支。 + +- **注意事项**: + - 强制推送(`git push -f`)需谨慎,可能覆盖历史记录。 + + - PR标题需清晰描述修改内容。 + + + +#### **6.sconscript语法** + +创建新文件夹需要添加sconscript文件,scons构建是基于sconstruct和sconscript的,后者每个文件夹都有一个,python通过该文件递归遍历每一个文件夹以控制编译内容。没有sconscript的话编译器是找不到文件的。 + +`#导入库 +import os +from building import * +#获取当前路径 +cwd = GetCurrentDir() +objs = [] +#列举当前路径下的内容 +list = os.listdir(cwd) +#遍历寻找子文件夹的文件,如果没有子文件夹可以去掉这个for循环 +for d in list: + path = os.path.join(cwd, d) + #如果子文件夹有sconscript就把对应文件添加到obj + if os.path.isfile(os.path.join(path, 'SConscript')): + objs = objs + SConscript(os.path.join(d, 'SConscript')) +#把obj返回给上一级 +Return('objs')` + +#### **7.ENV常用指令** + +升级软件包 + +`pkgs --upgrade` + +**更新软件包** + +`pkgs --update` + +**编译** + +`scons -j4` + +**打开qemu** + +`qemu-nographic.bat` + +**打开UI屏幕** + +`qemu.bat` + +**msh 退出** + +`先按ctrl+a然后再按下x` + + + +#### 8.Git常用指令 + +初始化 + +`git init` + +查看文件状态 + +`git status` + +添加所有修改的文件到暂存区 + +`git add .` + +提交 + +`git commit -m "说明"` + +查看历史 + +`git log` + +查看分支 + +`git branch -a` + +切换分支 + +`git switch master` + +创建分支 + +`git checkout -b sec` + +硬重置 +`git reset --hard HEAD~` +软重置 +`git reset--soft HEAD~` \ No newline at end of file diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\347\254\224\350\256\260/\343\200\220RSOC25\343\200\221Day2 \350\257\276\347\250\213\347\254\224\350\256\260\357\274\232\345\206\205\346\240\270\347\272\277\347\250\213.md" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\347\254\224\350\256\260/\343\200\220RSOC25\343\200\221Day2 \350\257\276\347\250\213\347\254\224\350\256\260\357\274\232\345\206\205\346\240\270\347\272\277\347\250\213.md" new file mode 100644 index 0000000000000000000000000000000000000000..f40317cd61c6f519a583d6f14750816aed828643 --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\347\254\224\350\256\260/\343\200\220RSOC25\343\200\221Day2 \350\257\276\347\250\213\347\254\224\350\256\260\357\274\232\345\206\205\346\240\270\347\272\277\347\250\213.md" @@ -0,0 +1,68 @@ +# Day2 + +### 内核 + +#### [RT-Thread 启动流程](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/basic/basic?id=rt-thread-启动流程) + +一般了解一份代码大多从启动部分开始,同样这里也采用这种方式,先寻找启动的源头。RT-Thread 支持多种平台和多种编译器,而 rtthread_startup() 函数是 RT-Thread 规定的统一启动入口。一般执行顺序是:系统先从启动文件开始运行,然后进入 RT-Thread 的启动函数 rtthread_startup() ,最后进入用户入口函数 main(),如下图所示: + +![启动流程](E:\Project\rtt\2025RTT\rsoc-rtt\2025\第3组(PSoC62 evaluation Kit)\杨锦\照片\rtt_startup.png) + +### 线程 + +### [主线程](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/thread/thread?id=主线程) + +在系统启动时,系统会创建 main 线程,它的入口函数为 main_thread_entry(),用户的应用入口函数 main() 就是从这里真正开始的,系统调度器启动后,main 线程就开始运行,过程如下图,用户可以在 main() 函数里添加自己的应用程序初始化代码。 + +![主线程调用过程](E:\Project\rtt\2025RTT\rsoc-rtt\2025\第3组(PSoC62 evaluation Kit)\杨锦\照片\04main_thread.png) + +### [线程状态切换](https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/thread/thread?id=线程状态切换) + +RT-Thread 提供一系列的操作系统调用接口,使得线程的状态在这五个状态之间来回切换。几种状态间的转换关系如下图所示: + +**** + +![线程状态转换图](E:\Project\rtt\2025RTT\rsoc-rtt\2025\第3组(PSoC62 evaluation Kit)\杨锦\照片\04thread_sta.png) + + + +动态创建线程接口: + +```c +rt_thread_t rt_thread_create(const char* name, + void (*entry)(void* parameter), + void* parameter, + rt_uint32_t stack_size, + rt_uint8_t priority, + rt_uint32_t tick); +``` + +删除线程: + +```c +rt_err_t rt_thread_delete(rt_thread_t thread); +``` + + + +静态创建线程接口: + +```c +rt_err_t rt_thread_init(struct rt_thread* thread, + const char* name, + void (*entry)(void* parameter), void* parameter, + void* stack_start, rt_uint32_t stack_size, + rt_uint8_t priority, rt_uint32_t tick); +``` + +脱离: + +```c +rt_err_t rt_thread_detach (rt_thread_t thread); +``` + +启动线程: + +```c +rt_err_t rt_thread_startup(rt_thread_t thread); +``` \ No newline at end of file diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\347\254\224\350\256\260/\343\200\220RSOC25\343\200\221Day3 \350\257\276\347\250\213\347\254\224\350\256\260\357\274\232\347\272\277\347\250\213.md" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\347\254\224\350\256\260/\343\200\220RSOC25\343\200\221Day3 \350\257\276\347\250\213\347\254\224\350\256\260\357\274\232\347\272\277\347\250\213.md" new file mode 100644 index 0000000000000000000000000000000000000000..c66d686dbd568f1da43709c85abc57c28927aedb --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\347\254\224\350\256\260/\343\200\220RSOC25\343\200\221Day3 \350\257\276\347\250\213\347\254\224\350\256\260\357\274\232\347\272\277\347\250\213.md" @@ -0,0 +1,226 @@ +# Day3 + +## 一、信号量(Semaphore) + +### 1.1 二值信号量 + +- **应用场景**:线程与线程、线程与中断之间的同步 +- **初始值**:0(表示事件未发生) +- **机制**: + - 线程等待:`rt_sem_take()` 阻塞等待 + - 事件触发:`rt_sem_release()` 唤醒等待线程 + +------ + +### 1.2 计数信号量 + +- **作用**:控制多个资源实例的访问 +- **初始值**:资源数量 `n` +- **机制**: + - 获取资源:`value--` + - 释放资源:`value++` + - `value = 0` 表示资源不可用 + +------ + +### 1.3 信号量 API + +| 功能 | 函数原型 | +| :----------- | :------------------------------------ | +| 创建信号量 | `rt_sem_create(name, value, flag)` | +| 删除信号量 | `rt_sem_delete(sem)` | +| 初始化信号量 | `rt_sem_init(sem, name, value, flag)` | +| 脱离信号量 | `rt_sem_detach(sem)` | +| 获取信号量 | `rt_sem_take(sem, time)` | +| 释放信号量 | `rt_sem_release(sem)` | + +- `flag` 选项: + - `RT_IPC_FLAG_FIFO`:按顺序排队 + - `RT_IPC_FLAG_PRIO`:按优先级排队 + +------ + +## 二、互斥量(Mutex) + +### 2.1 特性 + +- 是特殊的二值信号量 +- **所有权机制**:只有持有者才能释放 +- **递归访问**:同一线程可多次获取 +- **优先级继承**:防止优先级反转 + +------ + +### 2.2 优先级反转问题 + +- **场景**: + - 高优先级线程 A 被低优先级线程 C 阻塞 + - 中优先级线程 B 抢占 C,导致 A 长时间等待 +- **解决方案**: + - 优先级继承:C 临时提升到 A 的优先级 + +------ + +### 2.3 互斥量 API + +| 功能 | 函数原型 | +| :--- | :---------------------------- | +| 创建 | `rt_mutex_create(name, flag)` | +| 删除 | `rt_mutex_delete(mutex)` | +| 获取 | `rt_mutex_take(mutex, time)` | +| 释放 | `rt_mutex_release(mutex)` | + +- `flag` 已废弃,默认使用优先级排队 + +------ + +## 三、事件集(Event Set) + +### 3.1 结构 + +- 32 位无符号整数,每 bit 表示一个事件 +- **触发方式**: + - 逻辑与(AND) + - 逻辑或(OR) + +------ + +### 3.2 事件集 API + +| 功能 | 函数原型 | +| :------- | :--------------------------------------------------- | +| 创建 | `rt_event_create(name, flag)` | +| 删除 | `rt_event_delete(event)` | +| 初始化 | `rt_event_init(event, name, flag)` | +| 脱离 | `rt_event_detach(event)` | +| 发送事件 | `rt_event_send(event, set)` | +| 接收事件 | `rt_event_recv(event, set, option, timeout, recved)` | + +- `option`: + - `RT_EVENT_FLAG_OR` + - `RT_EVENT_FLAG_AND` + - `RT_EVENT_FLAG_CLEAR`:接收后清除标志位 + +------ + + + +## 四、邮箱(Mailbox) + +### 关键数据结构 +```c +struct rt_mailbox { + struct rt_ipc_object parent; /* IPC 基类 */ + rt_ubase_t *msg_pool; /* 邮箱缓冲区起始地址 */ + rt_uint16_t size; /* 邮箱容量(邮件数) */ + rt_uint16_t entry; /* 当前邮件数 */ + rt_uint16_t in_offset; /* 写指针 */ + rt_uint16_t out_offset; /* 读指针 */ + /* ... 其他成员 */ +}; +``` + +### 典型使用流程 + +1. 定义邮箱控制块与缓冲区 + + ```c + static rt_mailbox_t mb; + static rt_uint8_t mb_pool[4 * 10]; /* 10 封邮件 */ + ``` + + + +2. 初始化/创建 + + ```c + rt_mb_init(&mb, "mbt", &mb_pool, 10, RT_IPC_FLAG_PRIO); + ``` + + 线程 A(接收) + + ```c + rt_mb_recv(&mb, (rt_ubase_t *)&msg, RT_WAITING_FOREVER); + ``` + + 线程 B(发送) + + ```c + rt_mb_send(&mb, (rt_uint32_t)&str); + ``` + + + +------ + +## 五、消息队列(Message Queue) + +### 关键数据结构 + +```c +struct rt_messagequeue { + struct rt_ipc_object parent; + void *msg_pool; /* 消息池首地址 */ + rt_uint16_t msg_size; /* 单条消息最大长度 */ + rt_uint16_t max_msgs; /* 队列容量 */ + rt_uint16_t entry; /* 当前消息数 */ + /* ... 其他成员 */ +}; +``` + +### 典型使用流程 + +定义缓冲区 + +```c +static rt_uint8_t msg_pool[ (1+sizeof(struct rt_mq_message)) * 10 ]; +``` + +创建/初始化 + +```c +rt_mq_init(&mq, "mq", &msg_pool, 1, 10, RT_IPC_FLAG_PRIO); +``` + +线程 A(接收) + +```c +rt_mq_recv(&mq, buf, sizeof(buf), RT_WAITING_FOREVER); +``` + +线程 B(发送) + +```c +rt_mq_send(&mq, "A", 1); +rt_mq_urgent(&mq, "I", 1); /* 紧急插队 */ +``` + + + +------ + +## 六、信号(Signal) + +### 典型使用流程 + +线程内安装信号处理函数 + +```c +rt_signal_install(SIGUSR1, thread1_signal_handler); +rt_signal_unmask(SIGUSR1); +``` + +任意线程发送信号 + +```c +rt_thread_kill(tid1, SIGUSR1); +``` + +处理函数 + +```c +void thread1_signal_handler(int sig) { + rt_kprintf("recv signal %d\n", sig); +} +``` + diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\347\254\224\350\256\260/\343\200\220RSOC25\343\200\221Day4 \350\257\276\347\250\213\347\254\224\350\256\260\357\274\232\350\256\276\345\244\207\351\251\261\345\212\250.md" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\347\254\224\350\256\260/\343\200\220RSOC25\343\200\221Day4 \350\257\276\347\250\213\347\254\224\350\256\260\357\274\232\350\256\276\345\244\207\351\251\261\345\212\250.md" new file mode 100644 index 0000000000000000000000000000000000000000..6fa04b643c9b8214ad27d52ce5e7350e9dc44041 --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\347\254\224\350\256\260/\343\200\220RSOC25\343\200\221Day4 \350\257\276\347\250\213\347\254\224\350\256\260\357\274\232\350\256\276\345\244\207\351\251\261\345\212\250.md" @@ -0,0 +1,68 @@ +# Day4 + +## 一、驱动开发 + +- **框架设计**: + - 分层架构:应用层→统一API层→厂商驱动层 + - 效果:设备开发基于统一接口,底层驱动通过标准接口对接不同厂家SDK + +## 二、RT-Thread设备框架 + +- **分层架构**: + - 应用程序层 + - I/O设备管理层 + - 设备驱动框架层 + - 设备驱动层(对接具体厂商SDK) +- **面向对象设计**: + - 继承体系:rt_object→rt_device→具体设备类 + - 通过ops结构体实现多态调用 + +## 三、设备类型与操作 + +- **设备分类**: + - 字符设备:顺序访问数据流(如串口) + - 块设备:支持随机访问(如Flash/SD卡) + - 网络设备、MTD设备等 +- **核心API**: + - 创建设备:`rt_device_create()` + - 注册设备:`rt_device_register()` + - 查找设备:`rt_device_find()` + - 打开/关闭:`rt_device_open()/close()` + - 读写操作:`rt_device_read()/write()` + +## 四、GPIO开发 + +- **引脚分类**: + - 电源、时钟、控制、I/O引脚 + - I/O模式:GPIO和功能复用模式(SPI/I2C/UART等) +- **中断触发模式**: + - 上升沿、下降沿、高电平、低电平、双边沿触发 +- **API接口**: + - `rt_pin_mode()`:设置引脚模式 + - `rt_pin_write()`:设置引脚电平 + - `rt_pin_read()`:读取引脚电平 + - `rt_pin_attach_irq()`:绑定中断回调 + +## 五、I2C总线开发 + +- **协议特点**: + - 主从架构,支持多主多从 + - 四种速率模式:低速(100Kbit/s)、标准(400Kbit/s)等 +- **核心操作**: + - 设备探测:`i2c scan`命令 + - 数据传输:`rt_i2c_transfer()` + - 消息结构:包含从机地址、读写标志、数据缓冲区等 + +## 六、SPI总线开发 + +- **特点**: + - 全双工同步通信,4线制(SCLK,MOSI,MISO,CS) + - 四种工作模式(CPOL和CPHA组合) +- **开发流程**: + 1. 查找设备:`rt_device_find("spi10")` + 2. 配置参数:设置data_width、mode、max_hz + 3. 执行传输:`rt_spi_transfer()` +- **API**: + - `rt_spi_send()`:单独发送 + - `rt_spi_recv()`:单独接收 + - `rt_spi_send_then_recv()`:先发送后接收 diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\347\254\224\350\256\260/\343\200\220RSOC25\343\200\221Day5 \350\257\276\347\250\213\347\254\224\350\256\260\357\274\232\350\275\257\344\273\266\345\214\205.md" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\347\254\224\350\256\260/\343\200\220RSOC25\343\200\221Day5 \350\257\276\347\250\213\347\254\224\350\256\260\357\274\232\350\275\257\344\273\266\345\214\205.md" new file mode 100644 index 0000000000000000000000000000000000000000..958b19120e1efd5635e784d8000827fdb71e832f --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\235\250\351\224\246/\347\254\224\350\256\260/\343\200\220RSOC25\343\200\221Day5 \350\257\276\347\250\213\347\254\224\350\256\260\357\274\232\350\275\257\344\273\266\345\214\205.md" @@ -0,0 +1,69 @@ +# Day5 + +## 一、软件包 +### 1) LLM-Chat(通义千问) + +| 配置项 | 示例值 | +| :---------------------- | :----------------------------------- | +| `llm_qwen_user_api_key` | 阿里云百炼平台申请 | +| `mbedtls` fragment | 6144 | +| 依赖 | webclient + mbedtls(≥2.28.1) + cjson | + +### 2) NTP 校时 + +```bash +menuconfig → online packages → IoT → netutils → Enable NTP +# 运行后 +ntp_sync # 立即同步 +``` + +### 3) kawaiiMQTT + +| 配置项 | 值 | +| :------------- | :------------- | +| `mqtt_host` | broker.emqx.io | +| mqtt_port | 1883 | +| mqtt_client_id | 随机 | + +- + +## 二、Kconfig 语法 + +```kconfig +# 基本模板 +config BSP_USING_GPIO + bool "Enable GPIO" + default y + select RT_USING_PIN + help + Enable GPIO driver ... + +# 类型 +bool / string / int / hex / tristate +range 64 65535 # int 范围 + +# 依赖 +depends on BSP_USING_UART1 && RT_SERIAL_USING_DMA +# 或 +depends on BSP_USING_UART1 || RT_SERIAL_USING_DMA + +# 菜单 +menu "Hardware Drivers Config" + ... +endmenu + +# 单选 +choice + ... +endchoice +``` + +------ + +## 三、SCons 构建系统 + +| 文件 | 作用 | +| :------------ | :---------------- | +| `rtconfig.py` | 编译/链接所有参数 | +| `SConscript` | 各目录构建脚本 | +