diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/readme.md" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/readme.md" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\344\270\211\345\244\251\344\275\234\344\270\232/my_event.c" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\344\270\211\345\244\251\344\275\234\344\270\232/my_event.c" new file mode 100644 index 0000000000000000000000000000000000000000..c37837b3f2b2e9690226ebc9e7772d86eb0c6a3d --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\344\270\211\345\244\251\344\275\234\344\270\232/my_event.c" @@ -0,0 +1,85 @@ +#include +#include +/* 事件控制块 */ +static struct rt_event event; +static rt_uint8_t player1_opt, player2_opt; +static char opt[3][10] = {"Rock", "Scissors", "Paper"}; // 石头、剪刀、布 +#define EVENT_PLAYER1 (1 << 3) +#define EVENT_PLAYER2 (1 << 5) +static rt_thread_t tid = RT_NULL; +static rt_thread_t tid2 = RT_NULL; +static rt_thread_t tid3 = RT_NULL; +static void player1_thread(void *parament) +{ + int i = 0; + while (i < 10) + { + ++i; + player1_opt = rand()%3; + rt_kprintf("player1 send (%d) %s\n", i, opt[player1_opt]); + rt_event_send(&event, EVENT_PLAYER1); + rt_thread_mdelay(300*(rand()%10)); + } +} +static void player2_thread(void *parament) +{ + int i = 0; + while (i < 10) + { + ++i; + player2_opt = rand()%3; + rt_kprintf("player2 send (%d) %s\n", i, opt[player2_opt]); + rt_event_send(&event, EVENT_PLAYER2); + rt_thread_mdelay(100*(rand()%10)); + } +} +static void judge_thread(void *parament) +{ + rt_uint32_t e; + while (rt_event_recv(&event, EVENT_PLAYER1 | EVENT_PLAYER2, RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER,&e) == RT_EOK) + { + rt_kprintf("judge: player1 : %s , player2 : %s\n", opt[player1_opt], opt[player2_opt]); + if (player1_opt == player2_opt) + { + rt_kprintf("judge: draw\n"); + } + else if ((player1_opt == 0 && player2_opt == 2) || (player1_opt == 1 && player2_opt == 0) || (player1_opt == 2 && player2_opt == 1)) { + rt_kprintf("judge: player2 win\n"); + } + else + { + rt_kprintf("judge: player1 win\n"); + } + } +} +int event_main(void) +{ + rt_err_t result; + + /* 初始化事件对象 */ + result = rt_event_init(&event, "event", RT_IPC_FLAG_PRIO); + if (result != RT_EOK) + { + rt_kprintf("init event failed.\n"); + return -1; + } + + tid = rt_thread_create("usr", player1_thread, RT_NULL, 1024, RT_MAIN_THREAD_PRIORITY + 1, 5); + tid2 = rt_thread_create("th2", player2_thread, RT_NULL, 1024, RT_MAIN_THREAD_PRIORITY + 1, 5); + tid3 = rt_thread_create("th3", judge_thread, RT_NULL, 1024, RT_MAIN_THREAD_PRIORITY + 1, 10); + + if (tid != RT_NULL) + { + rt_thread_startup(tid); + } + if (tid2 != RT_NULL) + { + rt_thread_startup(tid2); + } + if (tid3 != RT_NULL) + { + rt_thread_startup(tid3); + } +} +/* 导出到 msh 命令列表中 */ +MSH_CMD_EXPORT_ALIAS(event_main, my_event,my event sample); diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\344\270\211\345\244\251\344\275\234\344\270\232/my_mb.c" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\344\270\211\345\244\251\344\275\234\344\270\232/my_mb.c" new file mode 100644 index 0000000000000000000000000000000000000000..4798d5b19c8ddd53c777657de0207d9d5b1f9eee --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\344\270\211\345\244\251\344\275\234\344\270\232/my_mb.c" @@ -0,0 +1,104 @@ +#include +#include +static char opt[3][10] = {"Rock", "Scissors", "Paper"}; // 石头、剪刀、布 +rt_mailbox_t mb1, mb2; +static rt_thread_t tid = RT_NULL; +static rt_thread_t tid2 = RT_NULL; +static rt_thread_t tid3 = RT_NULL; +static void player1_thread(void *parament) +{ + int i = 0; + while (i < 10) + { + ++i; + rt_uint8_t player1_opt = rand() % 3; + rt_kprintf("player1 send (%d) %s\n", i, opt[player1_opt]); + rt_mb_send(mb1, (rt_uint32_t*)&opt[player1_opt]); + rt_thread_mdelay(300 * (rand() % 10)); + } +} +static void player2_thread(void *parament) +{ + int i = 0; + while (i < 10) + { + ++i; + rt_uint8_t player2_opt = rand() % 3; + rt_kprintf("player2 send (%d) %s\n", i, opt[player2_opt]); + rt_mb_send(mb2, (rt_uint32_t*)&opt[player2_opt]); + rt_thread_mdelay(100 * (rand() % 10)); + } +} +static void judge_thread(void *parament) +{ + int i = 0; + char *str1, *str2; + while (1) + { + /* 从邮箱中收取邮件 */ + if (rt_mb_recv(mb1, (rt_ubase_t *)&str1, RT_WAITING_FOREVER) == RT_EOK) + { + if (rt_mb_recv(mb2, (rt_ubase_t *)&str2, RT_WAITING_FOREVER) == RT_EOK) + { + rt_kprintf("Round(%d): player1 : %s , player2 : %s\n", ++i, str1, str2); + if (strcmp(str1, str2) == 0) + { + rt_kprintf("judge: draw\n"); + } + else if ((strcmp(str1, "Rock") == 0 && strcmp(str2, "Scissors") == 0) || + (strcmp(str1, "Scissors") == 0 && strcmp(str2, "Paper") == 0) || + (strcmp(str1, "Paper") == 0 && strcmp(str2, "Rock") == 0)) + { + rt_kprintf("judge: player1 win\n"); + } + else + { + rt_kprintf("judge: player2 win\n"); + } + } + else + { + rt_kprintf("mb2 recv failed\n"); + } + } + else + { + rt_kprintf("mb1 recv failed\n"); + } + } +} +int mb_main(void) +{ + mb1 = rt_mb_create("mb1", 10, RT_IPC_FLAG_FIFO); + if (mb1 == RT_NULL) + { + rt_kprintf("create mailbox1 failed\n"); + return -1; + } + mb2 = rt_mb_create("mb2", 10, RT_IPC_FLAG_FIFO); + if (mb2 == RT_NULL) + { + rt_kprintf("create mailbox2 failed\n"); + return -1; + } + + tid = rt_thread_create("usr", player1_thread, RT_NULL, 1024, RT_MAIN_THREAD_PRIORITY + 1, 5); + tid2 = rt_thread_create("th2", player2_thread, RT_NULL, 1024, RT_MAIN_THREAD_PRIORITY + 1, 5); + tid3 = rt_thread_create("th3", judge_thread, RT_NULL, 1024, RT_MAIN_THREAD_PRIORITY + 1, 10); + + if (tid != RT_NULL) + { + rt_thread_startup(tid); + } + if (tid2 != RT_NULL) + { + rt_thread_startup(tid2); + } + if (tid3 != RT_NULL) + { + rt_thread_startup(tid3); + } + return RT_EOK; +} +/* 导出到 msh 命令列表中 */ +MSH_CMD_EXPORT_ALIAS(mb_main, my_mb, my mb sample); diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\344\270\211\345\244\251\344\275\234\344\270\232/my_mq.c" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\344\270\211\345\244\251\344\275\234\344\270\232/my_mq.c" new file mode 100644 index 0000000000000000000000000000000000000000..a0bf1f3ffdc20c252d3b7edfd7d128296bc2ade7 --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\344\270\211\345\244\251\344\275\234\344\270\232/my_mq.c" @@ -0,0 +1,129 @@ +#include + +#define THREAD_PRIORITY 25 +#define THREAD_TIMESLICE 5 +#define RT_VERSION_CHECK(major, minor, revise) ((major * 10000) + (minor * 100) + revise) + +/* 消息队列控制块 */ +static struct rt_messagequeue mq; +/* 消息队列中用到的放置消息的内存池 */ +static rt_uint8_t msg_pool[2048]; + +ALIGN(RT_ALIGN_SIZE) +static rt_thread_t thread1; + +/* 线程1入口函数 */ +static void thread1_entry(void *parameter) +{ + char buf[15]; + 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:%s\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 rt_thread_t thread2; + +/* 线程2入口 */ +static void thread2_entry(void *parameter) +{ + int result; + char buf[11] = "abcdefghijk"; + rt_uint8_t cnt = 0; + + while (1) + { + if (cnt == 8) + { + /* 发送紧急消息到消息队列中 */ + result = rt_mq_urgent(&mq, buf, rt_strlen(buf)); + if (result != RT_EOK) + { + rt_kprintf("rt_mq_urgent ERR\n"); + } + else + { + rt_kprintf("thread2: send urgent message - %s\n", buf); + } + } + else if (cnt >= 20) /* 发送20次消息之后退出 */ + { + rt_kprintf("message queue stop send, thread2 quit\n"); + break; + } + else + { + /* 发送消息到消息队列中 */ + result = rt_mq_send(&mq, buf, rt_strlen(buf)); + if (result != RT_EOK) + { + rt_kprintf("rt_mq_send ERR\n"); + } + + rt_kprintf("thread2: send message - %s\n", buf); + } + buf[0]++; + cnt++; + /* 延时5ms */ + rt_thread_mdelay(5); + } +} + +/* 消息队列示例的初始化 */ +int msgq_main(void) +{ + rt_err_t result; + + /* 初始化消息队列 */ + result = rt_mq_init(&mq, + "mqt", + &msg_pool[0], /* 内存池指向msg_pool */ + 20, /* 每个消息的大小是 1 字节 */ + sizeof(msg_pool), /* 内存池的大小是msg_pool的大小 */ + RT_IPC_FLAG_PRIO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */ + + if (result != RT_EOK) + { + rt_kprintf("init message queue failed.\n"); + return -1; + } + + thread1 = rt_thread_create( + "thread1", + thread1_entry, + RT_NULL, 1024, + THREAD_PRIORITY, THREAD_TIMESLICE); + + rt_thread_startup(thread1); + + thread2 = rt_thread_create( + "thread2", + thread2_entry, + RT_NULL, + 1024, + THREAD_PRIORITY, THREAD_TIMESLICE); + + rt_thread_startup(thread2); + + return 0; +} + +/* 导出到 msh 命令列表中 */ +MSH_CMD_EXPORT_ALIAS(msgq_main, my_mq, my mq sample); diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\344\270\211\345\244\251\344\275\234\344\270\232/my_mutex.c" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\344\270\211\345\244\251\344\275\234\344\270\232/my_mutex.c" new file mode 100644 index 0000000000000000000000000000000000000000..ea2d90a45ec55cefabda946109de9c650fc75719 --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\344\270\211\345\244\251\344\275\234\344\270\232/my_mutex.c" @@ -0,0 +1,68 @@ +//保护串口打印,使其能够完整输出 +#include +static rt_mutex_t my_mutex = RT_NULL; + +static rt_thread_t tid = RT_NULL; +static rt_thread_t tid2 = RT_NULL; +static rt_thread_t tid3 = RT_NULL; +static void user_thread(void) +{ + int i = 0; + while (i < 10) + { + ++i; + rt_mutex_take(my_mutex, RT_WAITING_FOREVER); + rt_kprintf("111(%d)\n", i); + rt_mutex_release(my_mutex); + rt_thread_delay(20); + } +} +static void user2_thread(void) +{ + int i = 0; + while (i < 15) + { + ++i; + rt_mutex_take(my_mutex, RT_WAITING_FOREVER); + rt_kprintf("222(%d)\n", i); + rt_mutex_release(my_mutex); + } +} +static void user3_thread(void) +{ + int i = 0; + while (i < 30) + { + ++i; + rt_mutex_take(my_mutex, RT_WAITING_FOREVER); + rt_kprintf("3333(%d)\n", i); + rt_mutex_release(my_mutex); + } +} +int mutex_main(void) +{ + my_mutex = rt_mutex_create("mmutex", RT_IPC_FLAG_PRIO); + if (my_mutex == RT_NULL) + { + rt_kprintf("create my mutex failed.\n"); + return -1; + } + tid = rt_thread_create("usr", user_thread, RT_NULL, 1024, RT_MAIN_THREAD_PRIORITY - 1, 5); + tid2 = rt_thread_create("th2", user2_thread, RT_NULL, 1024, RT_MAIN_THREAD_PRIORITY + 1, 5); + tid3 = rt_thread_create("th3", user3_thread, RT_NULL, 1024, RT_MAIN_THREAD_PRIORITY + 1, 10); + + if (tid != RT_NULL) + { + rt_thread_startup(tid); + } + if (tid2 != RT_NULL) + { + rt_thread_startup(tid2); + } + if (tid3 != RT_NULL) + { + rt_thread_startup(tid3); + } +} +/* 导出到 msh 命令列表中 */ +MSH_CMD_EXPORT_ALIAS(mutex_main, my_mutex, my mutex sample); diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\344\270\211\345\244\251\344\275\234\344\270\232/my_sem.c" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\344\270\211\345\244\251\344\275\234\344\270\232/my_sem.c" new file mode 100644 index 0000000000000000000000000000000000000000..71c96451b85f052e71d6d99d4e194ecb0721cb7e --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\344\270\211\345\244\251\344\275\234\344\270\232/my_sem.c" @@ -0,0 +1,92 @@ +//保护串口打印,使其能够完整输出 +#include +static rt_sem_t my_sem = RT_NULL; +static rt_err_t result ; + +static rt_thread_t tid = RT_NULL; +static rt_thread_t tid2 = RT_NULL; +static rt_thread_t tid3 = RT_NULL; +static void user_thread(void) +{ + int i = 0; + while (i < 10) + { + ++i; + rt_kprintf("thread1 release my semaphore(%d).\n", i); + rt_sem_release(my_sem); + rt_thread_mdelay(500); + } +} +static void user2_thread(void) +{ + int num = 0; + while (1) + { + + result = rt_sem_take(my_sem, RT_WAITING_FOREVER); + if (result != RT_EOK) + { + rt_kprintf("thread2 take my semaphore, failed.\n"); + rt_sem_delete(my_sem); + return; + } + else + { + num++; + rt_kprintf("thread2 take my semaphore. number = %d\n", num); + } + rt_thread_mdelay(500); + } +} +static void user3_thread(void) +{ + int num = 0; + while (1) + { + + result = rt_sem_take(my_sem, RT_WAITING_FOREVER); + if (result != RT_EOK) + { + rt_kprintf("thread2 take my semaphore, failed.\n"); + rt_sem_delete(my_sem); + return; + } + else + { + num++; + rt_kprintf("thread3 take my semaphore. number = %d\n", num); + } + rt_thread_mdelay(1000); + } +} +int sem_main(void) +{ + my_sem = rt_sem_create("msem", 0, RT_IPC_FLAG_PRIO); + if (my_sem == RT_NULL) + { + rt_kprintf("create my semaphore failed.\n"); + return -1; + } + else + { + rt_kprintf("create done. my semaphore value = 0.\n"); + } + tid = rt_thread_create("usr", user_thread, RT_NULL, 1024, RT_MAIN_THREAD_PRIORITY + 1, 5); + tid2 = rt_thread_create("th2", user2_thread, RT_NULL, 1024, RT_MAIN_THREAD_PRIORITY + 1, 5); + tid3 = rt_thread_create("th3", user3_thread, RT_NULL, 1024, RT_MAIN_THREAD_PRIORITY + 1, 10); + + if (tid != RT_NULL) + { + rt_thread_startup(tid); + } + if (tid2 != RT_NULL) + { + rt_thread_startup(tid2); + } + if (tid3 != RT_NULL) + { + rt_thread_startup(tid3); + } +} +/* 导出到 msh 命令列表中 */ +MSH_CMD_EXPORT_ALIAS(sem_main, my_sem, my semaphore sample); diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\344\270\211\345\244\251\344\275\234\344\270\232/my_sig.c" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\344\270\211\345\244\251\344\275\234\344\270\232/my_sig.c" new file mode 100644 index 0000000000000000000000000000000000000000..be7f3536d2f76188699b91456331062d7ea60097 --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\344\270\211\345\244\251\344\275\234\344\270\232/my_sig.c" @@ -0,0 +1,55 @@ +#include + +#define THREAD_PRIORITY 25 +#define THREAD_STACK_SIZE 512 +#define THREAD_TIMESLICE 5 + +static rt_thread_t tid1 = RT_NULL; + +/* 线程1的信号处理函数 */ +void th1_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(SIGUSR2, th1_signal_handler); + rt_signal_unmask(SIGUSR2); + + /* 运行10次 */ + while (cnt < 10) + { + /* 线程1采用低优先级运行,一直打印计数值 */ + rt_kprintf("thread1 count : %d\n", cnt); + + cnt++; + rt_thread_mdelay(100); + } +} + +/* 信号示例的初始化 */ +int signal_main(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(500); + + /* 发送信号 SIGUSR2 给线程1 */ + rt_thread_kill(tid1, SIGUSR2); + + return 0; +} +/* 导出到 msh 命令列表中 */ +MSH_CMD_EXPORT_ALIAS(signal_main, my_sig, my sig sample); diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\344\272\214\345\244\251\344\275\234\344\270\232.md" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\344\272\214\345\244\251\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..2c74051a8c5c978f30ba95368d4839654be04386 --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\344\272\214\345\244\251\344\275\234\344\270\232.md" @@ -0,0 +1,73 @@ +main.c +线程1 优先级高,循环延时输出,抢占线程2、3; +线程2、3优先级低时间片轮转 +``` + +#include +#include +#include + +/* defined the LED0 pin: PF9 */ +#define LED0_PIN GET_PIN(F, 9) + +void user_thread(void) +{ + int i=0; + while(i<10) + {++i; + rt_kprintf("111(%d)\n",i); + rt_thread_delay(20); + } +} +void user2_thread(void) +{ + int i=0; + while(i<15) + {++i; + rt_kprintf("222(%d)\n",i); + } +} +void user3_thread(void) +{ + int i=0; + while(i<30) + {++i; + rt_kprintf("3333(%d)\n",i); + } +} +rt_thread_t tid=RT_NULL; +rt_thread_t tid2=RT_NULL; +rt_thread_t tid3=RT_NULL; +int main(void) +{ +// int count = 1; + /* set LED0 pin mode to output */ +// rt_pin_mode(LED0_PIN, PIN_MODE_OUTPUT); +// +// while (count++) +// { +// rt_pin_write(LED0_PIN, PIN_HIGH); +// rt_thread_mdelay(500); +// rt_pin_write(LED0_PIN, PIN_LOW); +// rt_thread_mdelay(500); +// } + tid=rt_thread_create("usr", user_thread, RT_NULL, 1024, RT_MAIN_THREAD_PRIORITY-1, 5); + tid2=rt_thread_create("th2", user2_thread, RT_NULL, 1024, RT_MAIN_THREAD_PRIORITY+1, 5); + tid3=rt_thread_create("th3", user3_thread, RT_NULL, 1024, RT_MAIN_THREAD_PRIORITY+1, 10); + + if(tid!=RT_NULL) + { + rt_thread_startup(tid); + } + if(tid2!=RT_NULL) + { + rt_thread_startup(tid2); + } + if(tid3!=RT_NULL) + { + rt_thread_startup(tid3); + } + return RT_EOK; +} + +``` \ No newline at end of file diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\345\233\233\345\244\251\344\275\234\344\270\232/dev_vir.c" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\345\233\233\345\244\251\344\275\234\344\270\232/dev_vir.c" new file mode 100644 index 0000000000000000000000000000000000000000..83603ec137d06350af3db06e8ac593a132d1c46c --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\345\233\233\345\244\251\344\275\234\344\270\232/dev_vir.c" @@ -0,0 +1,114 @@ +#include +#include +#include + +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_ssize_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_read) + { + *(rt_uint32_t *)buffer = device->ops->vir_read(dev); + return size; + } + return 0; +} + +static rt_ssize_t _vir_write(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_write) + { + device->ops->vir_write(dev, *(rt_uint32_t *)buffer); + return size; + } + return 0; +} + +static rt_err_t _vir_control(rt_device_t dev, int cmd, void *args) +{ + rt_vir_device_t vir = (rt_vir_device_t)dev; + + RT_ASSERT(vir != RT_NULL); + + if (vir->ops->vir_printinfo) + { + vir->ops->vir_printinfo(dev, args); + } + return RT_EOK; +} + +#ifdef RT_USING_DEVICE_OPS +const static struct rt_device_ops vir_ops = + { + _vir_init, + _vir_open, + _vir_close, + _vir_read, + _vir_write, + _vir_control}; +#endif + +rt_err_t rt_device_vir_register(rt_vir_device_t device, const char *name, const struct rt_vir_ops *ops, const void *user_data) +{ + rt_err_t result = RT_EOK; + RT_ASSERT(ops != RT_NULL); + + device->parent.type = RT_Device_Class_Miscellaneous; + device->parent.rx_indicate = RT_NULL; + device->parent.tx_complete = RT_NULL; + +#ifdef RT_USING_DEVICE_OPS + device->parent.ops = &vir_ops; +#else + device->parent.init = _vir_init; + device->parent.open = _vir_open; + device->parent.close = _vir_close; + device->parent.read = _vir_read; + device->parent.write = _vir_write; + device->parent.control = _vir_control; +#endif + device->ops = ops; + device->parent.user_data = user_data; + result = rt_device_register(&device->parent, name, RT_DEVICE_FLAG_RDWR); + return result; +} + +rt_uint32_t rt_vir_read(struct rt_device *dev) +{ + RT_ASSERT(dev != RT_NULL); + rt_vir_device_t device = (rt_vir_device_t)dev; + RT_ASSERT(device->ops != RT_NULL); + return device->ops->vir_read(dev); +} + +void rt_vir_write(struct rt_device *dev, rt_uint32_t val) +{ + RT_ASSERT(dev != RT_NULL); + rt_vir_device_t device = (rt_vir_device_t)dev; + RT_ASSERT(device->ops != RT_NULL); + device->ops->vir_write(dev, val); +} + +void rt_vir_printinfo(struct rt_device *dev, char *str) +{ + RT_ASSERT(dev != RT_NULL); + rt_vir_device_t device = (rt_vir_device_t)dev; + RT_ASSERT(device->ops != RT_NULL); + device->ops->vir_printinfo(dev, str); +} diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\345\233\233\345\244\251\344\275\234\344\270\232/dev_vir.h" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\345\233\233\345\244\251\344\275\234\344\270\232/dev_vir.h" new file mode 100644 index 0000000000000000000000000000000000000000..9e66390eb9cc82517ad8d5501e98d27c837ffd5a --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\345\233\233\345\244\251\344\275\234\344\270\232/dev_vir.h" @@ -0,0 +1,24 @@ +#ifndef __VIR_H__ +#define __VIR_H__ + +#include + +struct rt_vir_ops +{ + void (*vir_printinfo) (struct rt_device *device,char *str); + void (*vir_write) (struct rt_device *device,rt_uint32_t val); + rt_uint32_t (*vir_read) (struct rt_device *device); +}; +struct rt_vir_device +{ + struct rt_device parent; + struct rt_vir_ops *ops; +}; +typedef struct rt_vir_device *rt_vir_device_t; + +rt_err_t rt_device_vir_register(rt_vir_device_t device,const char *name, const struct rt_vir_ops *ops, const void *user_data); + +void rt_vir_printinfo(struct rt_device *device,char *str); +void rt_vir_write(struct rt_device *device,rt_uint32_t val); +rt_uint32_t rt_vir_read(struct rt_device *device); +#endif diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\345\233\233\345\244\251\344\275\234\344\270\232/drv_vir.c" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\345\233\233\345\244\251\344\275\234\344\270\232/drv_vir.c" new file mode 100644 index 0000000000000000000000000000000000000000..13410a1cbf4d8aadebb9548e734efb88f5b4e68e --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\345\233\233\345\244\251\344\275\234\344\270\232/drv_vir.c" @@ -0,0 +1,47 @@ +#include +#include "drv_vir.h" +// #include "cJSON.h" + +#ifdef RT_USING_VIR + +struct vir_test virhub; + +void xxc_vir_printinfo(struct rt_device *device,char *str) +{ + // cJSON* root = cJSON_CreateObject(); + // cJSON_AddStringToObject(root, "info", virhub.info); + // cJSON_AddNumberToObject(root, "val", virhub.val); + if(virhub.user!=RT_NULL) + { + virhub.user=str; + } + // cJSON_AddStringToObject(root, "user_data", virhub.user); + rt_kprintf("{\n\t%s:%s,\n\t%s:%d,\n\t%s:%s\n}\n", "info", virhub.info\ + , "val", virhub.val, "user_data", virhub.user); + // cJSON_Delete(root); +} +void xxc_vir_write(struct rt_device *device,rt_uint32_t val) +{ + virhub.val=val; +} +rt_uint32_t xxc_vir_read(struct rt_device *device) +{ + return (virhub.val); +} + + +const static struct rt_vir_ops _vir_ops = +{ + xxc_vir_printinfo, + xxc_vir_write, + xxc_vir_read +}; +int rt_hw_vir_init(void) +{ + virhub.val=0; + virhub.info="Hello world!"; + virhub.user=""; + return rt_device_vir_register(&(virhub.parent),"vir", &_vir_ops, RT_NULL); +} +INIT_BOARD_EXPORT(rt_hw_vir_init); +#endif diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\345\233\233\345\244\251\344\275\234\344\270\232/drv_vir.h" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\345\233\233\345\244\251\344\275\234\344\270\232/drv_vir.h" new file mode 100644 index 0000000000000000000000000000000000000000..ccdbaa36fb40185d53bbae60728d8be305b39f19 --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\345\233\233\345\244\251\344\275\234\344\270\232/drv_vir.h" @@ -0,0 +1,15 @@ +#ifndef __DRV_VIR_H__ +#define __DRV_VIR_H__ +#include +#include + +struct vir_test +{ + struct rt_vir_device parent; + rt_uint32_t val; + char *info,*user; +}; +int rt_hw_vir_init(void); + + +#endif \ No newline at end of file diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\345\233\233\345\244\251\344\275\234\344\270\232/main.c" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\345\233\233\345\244\251\344\275\234\344\270\232/main.c" new file mode 100644 index 0000000000000000000000000000000000000000..6f0cd764af938da01e8fedf6ee877a85e3b97042 --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\344\275\234\344\270\232/\347\254\254\345\233\233\345\244\251\344\275\234\344\270\232/main.c" @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2006-2020, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020/12/31 Bernard Add license info + */ + +#include +#include +#include +#include +#include + + +int main(void) +{ + rt_kprintf("Hello RT-Thread!\n"); + rt_device_t dev=rt_device_find("vir"); + if(dev==RT_NULL) + { + rt_kprintf("vir device not found!\n"); + } + rt_device_open(dev, RT_DEVICE_OFLAG_RDWR); + rt_uint32_t val2; + rt_device_read(dev, 0, &val2, 4); + rt_kprintf("read: %u\n", val2); + rt_uint32_t val=1314; + rt_device_write(dev, 0, &val, 4); + rt_device_control(dev,RT_NULL,"happy"); + LOG_I("read: %u", rt_vir_read(dev)); + rt_vir_write(dev, 100); + rt_vir_printinfo(dev,"It's always a good time"); + return 0; +} diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/IPC.md" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/IPC.md" new file mode 100644 index 0000000000000000000000000000000000000000..2ff9b6ee737b566dfeb8577a2b5d744965cbf823 --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/IPC.md" @@ -0,0 +1,154 @@ +# 线程间同步 +## 信号量 +线程与线程间,线程与中断间 +* 二值信号量 +* 计数信号量 +### API +具体可查看 +https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/ipc1/ipc1 +##### 创建 +当调用这个函数时,系统将先从对象管理器中分配一个 semaphore 对象,并初始化这个对象,然后初始化父类IPC对象以及与 semaphore 相关的部分。在创建信号量指定的参数中,信号量标志参数决定了当信号量不可用时,多个线程等待的排队方式。当选择RTIPC FLAG FIFO(先进先出)方式时,那么等待线程队列将按照先进先出的方式排队,先进入的线程将先获得等待的信号量;当选择 RTIPCFLAGPRI0(优先级等待)方式时,等待线程队列将按照优先级进行排队,优先级高的等待线程将先获得等待的信号量。 +#### 删除 +在删除前会唤醒所有挂起在……上的线程(线程的返回值是-RTERROR)然后释放对象占用的内存块。 +#### 初始化(静态) +#### 脱离 +#### 获取 +-1,根据time选择直接返回,挂起一段时间,或者一直等待 +#### 无等待获取 +#### 释放 +唤醒等待队列的第一个线程,否则加1 + +## 互斥量 +1. 互斥量所有权,只有加锁的线程能解锁 +2. 避免优先级反转 +3. +### 优先级反转 +A要等C,B抢占了C,使得A还要等B +![alt text](图片/DAY3/image.png) +### 优先级继承 +把C的优先级提升到提升到A的优先级 +![alt text](图片/DAY3/image-1.png) +### API +https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/ipc1/ipc1?id=%e4%ba%92%e6%96%a5%e9%87%8f +#### 创建 +按优先级的顺序处理 +#### 删除 +#### 初始化(静态) +句柄,名称,…… +#### 脱离(动态) +#### 获取 +#### 无等待获取 +#### 释放 + +## 事件集 +![alt text](图片/DAY3/image-2.png) +32 bit 每位代表一个事件 +### 发送 +中断或线程 +### 接收 +与触发、或触发 +&& 、 || +### API +https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/ipc1/ipc1?id=%e4%ba%8b%e4%bb%b6%e9%9b%86 +#### 创建 +#### 删除 +#### 初始化(静态) +#### 脱离 +#### 发送 +set 哪些事件要发 +遍历等待在 event 事件集对象上的等待线程链表,判断是否有线程的事件激活要求与当前 event 对象事件标志值匹配,如果有,则唤醒该线程 +#### 接收 + +## 邮箱 +线程间通信,数据量小 +### API +https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/ipc2/ipc2?id=%e9%82%ae%e7%ae%b1 +#### 创建 +``` +rt_mailbox_t rt_mb_create (const char* name, rt_size_t size, rt_uint8_t flag); +``` +|参数 | 说明 | +|--|--| +name | 邮箱名称 +size | 邮箱容量 这块内存的大小等于邮件大小(4 字节)与邮箱容量的乘积 +flag | 邮箱标志,它可以取如下数值: RT_IPC_FLAG_FIFO 或 RT_IPC_FLAG_PRIO + +#### 删除 +#### 初始化(静态) +#### 脱离 +#### 发送 +``` +rt_mb_send(&mb, (rt_uint32_t)&mb_str1); +``` +#### 等待方式发送 +#### 发送紧急邮件 +放到队首 +#### 接收 +``` +if (rt_mb_recv(&mb, (rt_ubase_t *)&str, RT_WAITING_FOREVER) == RT_EOK) +``` + +## 消息队列 +* eg 串口接收不定长数据 +* 异步处理机制(提供) +* 支持读消息超时机制 +* 支持等待方式发送消息 +* 允许不同长度(不超过队列节点最大值)任意类型消息 +* 支持发送紧急消息 +* 先进先出原则FIFO +### API +https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/ipc2/ipc2?id=%e6%b6%88%e6%81%af%e9%98%9f%e5%88%97 +![alt text](图片/DAY3/image-4.png) +#### 创建 +msg_size 消息队列中**一条消息**的最大长度,单位**字节** +max_msgs 消息队列的最大个数 +#### 初始化 +``` +/* 初始化消息队列 */ + result = rt_mq_init(&mq, + "mqt", + &msg_pool[0], /* 内存池指向msg_pool */ + 20, /* 每个消息的大小是 20 字节 */ + sizeof(msg_pool), /* 内存池的大小是msg_pool的大小 */ + RT_IPC_FLAG_PRIO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */ +``` +#### 发送 +复制到消息块,挂到队列尾部 +``` +char buf[11] = "abcdefghijk"; +result = rt_mq_urgent(&mq, buf, rt_strlen(buf)); +``` +#### 等待发送 +#### 发送紧急消息 +#### 接收 +大小? + +## 信号 +软中断信号 +什么时候用 +### 处理 +1. 不处理 +2. 指定函数处理 +3. 系统默认 + +### API +https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/ipc3/ipc3?id=%e4%bf%a1%e5%8f%b7 +#### 安装信号 +``` +/*在需要的线程中安装信号 */ +rt_signal_install(SIGUSR1, thread1_signal_handler); +rt_signal_unmask(SIGUSR1);//解除屏蔽 +``` + +#### 发送信号 +``` +rt_kill(tid1, SIGUSR1);//tid1为线程的句柄 +``` +#### 信号处理函数 +``` +/* 线程1的信号处理函数 */ +void thread1_signal_handler(int sig) +{ + rt_kprintf("thread1 received signal %d\n", sig); +} +``` \ No newline at end of file diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\206\205\346\240\270\345\237\272\347\241\200\344\270\216\347\272\277\347\250\213.md" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\206\205\346\240\270\345\237\272\347\241\200\344\270\216\347\272\277\347\250\213.md" new file mode 100644 index 0000000000000000000000000000000000000000..bd81514c399a2f87442eb0dcd33e06adb1ad288a --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\206\205\346\240\270\345\237\272\347\241\200\344\270\216\347\272\277\347\250\213.md" @@ -0,0 +1,177 @@ +## 裸机 vs RTOS +### 单一系统: +系统功能单一的情况下,此时系统整体功能没有细分为多个线程的必要此时采用裸机较为合适 +举例:电动牙刷 +### 复杂系统 +系统功能丰富的情况下,使用裸机编程需要用户编写复杂的逻辑去协调多个事件,同时代码的耦合度较高 +举例:机器人 + +### 裸机优势 +* 在单一功能的嵌入式系统使用裸机可以提高运行效率 +* 可以使用较少的存储实现单一功能的嵌入式系统 + +### 裸机缺点 +* 代码耦合度较高,复用性较差 +* 不适合复杂的嵌入式系统 +* 代码不合理时容易造成系统阻塞 + +### RTOS优点 +* 代码耦合度低,复用性较好 +* 可以使用任务划分的方式降低实现复杂嵌入式系统的代码逻辑 +* RTOS下的延时不会一直占用CPU,延时期间处理其他任务 +* 使用RTOS提供的线程同步与信息传递会提高系统的实时性 + +### RTOS缺点 +* 不适合小容量嵌入式系统,RTOS本身会占据部分存储 +* 不适合单一嵌入式系统,系统调度会引入额外的开销 + +### RTOS +* 并发,看起来同时运行,因为切换快 + +### 临界区 +只能被一个线程使用,一旦被占用,其他线程就不能使用,其他线程只能等待 +eg 多线程都要用串口打印,前一个打了一半,后一个就打出来了 + +### 阻塞式线程 +对于临界区只能等,期间不能做其他事 +### 非阻塞式线程 +对于临界区,等待期间可以做其他事 + + +## RT-Studio +https://www.rt-thread.org/download.html#download-rt-thread-studio + +## 内核 +### 启动流程 +![alt text](图片/DAY2/image.png) +``` + +int rtthread_startup(void) +{ + rt_hw_interrupt_disable(); + + /* board level initialization + * NOTE: please initialize heap inside board initialization. + */ + rt_hw_board_init();//板级初始化 + + /* show RT-Thread version */ + rt_show_version();//打印版本 + + /* timer system initialization */ + rt_system_timer_init();//定时器初始化 + + /* scheduler system initialization */ + rt_system_scheduler_init();//调度器初始化 + +#ifdef RT_USING_SIGNALS + /* signal system initialization */ + rt_system_signal_init(); +#endif /* RT_USING_SIGNALS */ + + /* create init_thread */ + rt_application_init();//创建main线程,启动main线程 + + /* timer thread initialization */ + rt_system_timer_thread_init();//创建定时器线程 + + /* idle thread initialization */ + rt_thread_idle_init();//创建空闲线程 + +#ifdef RT_USING_SMP + rt_hw_spin_lock(&_cpus_lock); +#endif /* RT_USING_SMP */ + + /* start scheduler */ + rt_system_scheduler_start(); + + /* never reach here */ + return 0; +} +``` + +### 线程名字作用 +1. 标识线程:线程名字是线程的唯一标识符,可以方便开发者识别和管理不同的线程。 + +2. 获取线程控制块(TCB):可以通过线程名字来查找和获取对应的线程控制块(TCB),例如使用rt_thread_find()函数。 + +3. 调试和日志:在线程出现问题时,可以通过线程名字快速定位问题线程,便于调试。 + +4. 线程间通信:在某些情况下,可以通过线程名字来指定通信的目标线程。 + +5. 系统监控:在系统运行时,可以通过线程名字来监控特定线程的状态和性能。 + + +### 线程 +#### sample +sdk管理器下载相应内容 +打开软件包 +![alt text](图片/DAY2/image-1.png) +![alt text](图片/DAY2/image-2.png) +要关闭之前的才能,重新烧录 +![alt text](图片/DAY2/image-4.png) +#### 静态vs动态 +静态:编译好,空间只能给那个线程使用,不管线程状态,对安全有要求,空间足够 +init +动态:内存有限,安全要求不高,要实现的功能多,一般使用 + +#### 接口 +``` + * thread interface + */ +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); +rt_err_t rt_thread_detach(rt_thread_t thread); +#ifdef RT_USING_HEAP +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); +rt_err_t rt_thread_delete(rt_thread_t thread); +#endif +rt_thread_t rt_thread_self(void); +rt_thread_t rt_thread_find(char *name); +rt_err_t rt_thread_startup(rt_thread_t thread);//要startup线程才会开始运行,进入就绪态,进入调度序列,如果优先级高会立刻切换 +rt_err_t rt_thread_yield(void);//放弃当前时间片 +rt_err_t rt_thread_delay(rt_tick_t tick);//延时,进入挂起状态 +rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick); +rt_err_t rt_thread_mdelay(rt_int32_t ms); +rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg);//对线程的参数调整 +rt_err_t rt_thread_suspend(rt_thread_t thread);//只能自己挂起自己 +rt_err_t rt_thread_resume(rt_thread_t thread);//恢复 +``` +#### 调试 +main 函数有个断点 + + +##### rt_thread_create +tick 线程的时间片大小。时间片(tick)的单位是操作系统的时钟节拍。当系统中存在相同优先级线程时,这个参数指定线程一次调度能够运行的最大时间长度。这个时间片运行结束时,调度器自动选择下一个就绪态的同优先级线程进行运行 + +#### 优先级 +数字越小,优先级越高 +main 线程10; +tshell 20 +可以`RT_MAIN_THREAD_PRIORITY-1` +#### 栈的大小给多大 +内部会自动对齐,尽量给大点(比如1024),否则可能会溢出 +查看使用率调整 + +#### 线程状态转化 +初始 ->就绪->运行->关闭(exit函数运行完了)/挂起(suspend,延时,等待IPC) +#### 线程调度 ms级 +抢占式,立马运行高优先级的 +![alt text](图片/DAY2/image-5.png) +相同优先级,时间片轮转 +![alt text](图片/DAY2/image-6.png) +特殊情况:中断 + + + diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image-1.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image-1.png" new file mode 100644 index 0000000000000000000000000000000000000000..885e2cef5fba2f8e0b29355e3f80a49445540247 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image-1.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image-2.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image-2.png" new file mode 100644 index 0000000000000000000000000000000000000000..c7600a5a613d5c71a89c56b8523acc37269a6306 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image-2.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image-3.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image-3.png" new file mode 100644 index 0000000000000000000000000000000000000000..4269d8529c552e63524be00f4607a667987e4d6c Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image-3.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image-4.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image-4.png" new file mode 100644 index 0000000000000000000000000000000000000000..2587b9716930e6c1c0d0c2d0b0fbd19d67ccf784 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image-4.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image-5.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image-5.png" new file mode 100644 index 0000000000000000000000000000000000000000..262fb78926734f77d772575db96a696c4f04bca4 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image-5.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image-6.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image-6.png" new file mode 100644 index 0000000000000000000000000000000000000000..5200d479b673141dab99b268529ddef91346439e Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image-6.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image-7.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image-7.png" new file mode 100644 index 0000000000000000000000000000000000000000..10ab7cef3804813b47e73b7156438644458e9d9f Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image-7.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image-8.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image-8.png" new file mode 100644 index 0000000000000000000000000000000000000000..591361f0274e0c42430f1c07c44dcce3590d870b Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image-8.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image.png" new file mode 100644 index 0000000000000000000000000000000000000000..c5da5e67ef0076448903ed6f2ac3af4eefe6d09c Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY1/image.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY2/image-1.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY2/image-1.png" new file mode 100644 index 0000000000000000000000000000000000000000..e005677a203218515a6270577dc063af97f74872 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY2/image-1.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY2/image-2.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY2/image-2.png" new file mode 100644 index 0000000000000000000000000000000000000000..b6c4c535ac9f1e4d0f293729f2c69cfeb6964108 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY2/image-2.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY2/image-3.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY2/image-3.png" new file mode 100644 index 0000000000000000000000000000000000000000..1de2fe6c13db56005605d2939df8ce918d1245b9 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY2/image-3.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY2/image-4.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY2/image-4.png" new file mode 100644 index 0000000000000000000000000000000000000000..9454520dc83c9223e8a86f61471460560aeccd8b Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY2/image-4.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY2/image-5.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY2/image-5.png" new file mode 100644 index 0000000000000000000000000000000000000000..d4b0fb1da9bca300d0951ec7d5e9e073f09dd38b Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY2/image-5.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY2/image-6.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY2/image-6.png" new file mode 100644 index 0000000000000000000000000000000000000000..5611da3938b0350544d0c2ac8c0513f36abc8440 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY2/image-6.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY2/image.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY2/image.png" new file mode 100644 index 0000000000000000000000000000000000000000..47d980d2c81436135c3a4d5fdeddeba68820fe16 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY2/image.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY3/image-1.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY3/image-1.png" new file mode 100644 index 0000000000000000000000000000000000000000..bd00a4be236d7a4918aca1a678a7f7ffaa181038 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY3/image-1.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY3/image-2.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY3/image-2.png" new file mode 100644 index 0000000000000000000000000000000000000000..11baafaaf493aa45e0432e33967bfcc1ed015ce1 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY3/image-2.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY3/image-3.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY3/image-3.png" new file mode 100644 index 0000000000000000000000000000000000000000..7d8c18f294620bd9d0a2d84ee1294626f690c7a8 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY3/image-3.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY3/image-4.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY3/image-4.png" new file mode 100644 index 0000000000000000000000000000000000000000..051b16154c6d24f3e3f11ba79e905f52cbb58de0 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY3/image-4.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY3/image.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY3/image.png" new file mode 100644 index 0000000000000000000000000000000000000000..065bc864dab571ccfd49698f03328408573425ff Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY3/image.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY4/image-1.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY4/image-1.png" new file mode 100644 index 0000000000000000000000000000000000000000..d459cfac39f4a67822265d71e45c7bbfe6c7e933 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY4/image-1.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY4/image-2.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY4/image-2.png" new file mode 100644 index 0000000000000000000000000000000000000000..2561caba9f168ffcaa9dbc7fbaa020d4a98c26b3 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY4/image-2.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY4/image-3.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY4/image-3.png" new file mode 100644 index 0000000000000000000000000000000000000000..89303c4543dd19e9905989405468ea29125b4c50 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY4/image-3.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY4/image-4.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY4/image-4.png" new file mode 100644 index 0000000000000000000000000000000000000000..d6da9b90a5fb4588686f115b2aa386eae8699df0 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY4/image-4.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY4/image-5.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY4/image-5.png" new file mode 100644 index 0000000000000000000000000000000000000000..b481794752bd2fb45c5203f3003a12911f002e86 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY4/image-5.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY4/image-6.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY4/image-6.png" new file mode 100644 index 0000000000000000000000000000000000000000..a887606305316a9569838accaa2c44ec66d5d7e7 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY4/image-6.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY4/image-7.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY4/image-7.png" new file mode 100644 index 0000000000000000000000000000000000000000..6f5b785388428f8fba44305089c873fcaec40f45 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY4/image-7.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY4/image.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY4/image.png" new file mode 100644 index 0000000000000000000000000000000000000000..62a431ff4c21ac65e8d5b5cf55ae900b2d6f7b99 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY4/image.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/2357af977a6810cecfe02d86abce7b60.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/2357af977a6810cecfe02d86abce7b60.png" new file mode 100644 index 0000000000000000000000000000000000000000..d0f1a6281aaf5565a007bf4f3814b18c807ac118 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/2357af977a6810cecfe02d86abce7b60.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/754b6c9f157fd957d6819334fc67dc2a.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/754b6c9f157fd957d6819334fc67dc2a.png" new file mode 100644 index 0000000000000000000000000000000000000000..0ac9f120bd637add863bedd9c3b5a44357a5ee40 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/754b6c9f157fd957d6819334fc67dc2a.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/a7a30c9a4836aae40603b0463b5853ae.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/a7a30c9a4836aae40603b0463b5853ae.png" new file mode 100644 index 0000000000000000000000000000000000000000..d32716bad224ac68f794fde314281b647ddca5c5 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/a7a30c9a4836aae40603b0463b5853ae.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/b64cd0a508036c31e2c34a5b8f0f10f1.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/b64cd0a508036c31e2c34a5b8f0f10f1.png" new file mode 100644 index 0000000000000000000000000000000000000000..8c0a1096c3d545b8568c5847b1cae1639ddc41ab Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/b64cd0a508036c31e2c34a5b8f0f10f1.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/ea71d230332015ce537ea1f57caef20b.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/ea71d230332015ce537ea1f57caef20b.png" new file mode 100644 index 0000000000000000000000000000000000000000..9b0db967fbc83392268165f4ba74e7878ba65781 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/ea71d230332015ce537ea1f57caef20b.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-1.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-1.png" new file mode 100644 index 0000000000000000000000000000000000000000..45eda3c63719faeadd423883241426e61bb8b091 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-1.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-10.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-10.png" new file mode 100644 index 0000000000000000000000000000000000000000..2d93698bd2a8300c7c42cc388a5b0b8a4d130714 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-10.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-11.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-11.png" new file mode 100644 index 0000000000000000000000000000000000000000..fedf988534f44b7547e8419d9bb645054dd6414e Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-11.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-12.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-12.png" new file mode 100644 index 0000000000000000000000000000000000000000..871b91268ead15e0076c3018ceb5c4fb5229483a Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-12.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-13.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-13.png" new file mode 100644 index 0000000000000000000000000000000000000000..91f2818acf3561f2947535ceb00bc9fce1ca940a Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-13.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-14.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-14.png" new file mode 100644 index 0000000000000000000000000000000000000000..fb4dac6a909cee82cb85476c647670c39ca3aa37 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-14.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-15.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-15.png" new file mode 100644 index 0000000000000000000000000000000000000000..13fe144ec283c8fec0854bebd23a77fa5d200302 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-15.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-2.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-2.png" new file mode 100644 index 0000000000000000000000000000000000000000..57ee29cb005031270f2b8e13872f38e427d7fcea Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-2.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-3.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-3.png" new file mode 100644 index 0000000000000000000000000000000000000000..a41978f36176aba7f41ba4eddfc6c8833b87aea6 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-3.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-4.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-4.png" new file mode 100644 index 0000000000000000000000000000000000000000..db961abc2d470ae4a9efd33f6082cbc9d8cbd4c3 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-4.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-5.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-5.png" new file mode 100644 index 0000000000000000000000000000000000000000..73c80eb33d464be6541aacccc457c49c0fcd2f5f Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-5.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-6.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-6.png" new file mode 100644 index 0000000000000000000000000000000000000000..25645748526b51b20e127159c6cfe04b9b545e88 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-6.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-7.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-7.png" new file mode 100644 index 0000000000000000000000000000000000000000..7e9e3f8e16d02de8b4f895075272b2a8d47b2335 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-7.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-8.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-8.png" new file mode 100644 index 0000000000000000000000000000000000000000..05fd4ad044c1b6e5f0d2b767bb76427de25ff38c Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-8.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-9.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-9.png" new file mode 100644 index 0000000000000000000000000000000000000000..7d242f3914e30515c81b4c10106b629424173f20 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\233\276\347\211\207/DAY5/image-9.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\274\200\345\217\221\346\235\277\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\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\274\200\345\217\221\346\235\277\347\216\257\345\242\203\346\220\255\345\273\272.md" new file mode 100644 index 0000000000000000000000000000000000000000..69dfb5e9a5ebaeb9823c5c60499ae97016299fb4 --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\345\274\200\345\217\221\346\235\277\347\216\257\345\242\203\346\220\255\345\273\272.md" @@ -0,0 +1,124 @@ +# infineon PSoC62 evaluation Kit在vscode的环境搭建(部分) +## openocd 烧录 +1. 下载infineon的openocd +https://github.com/Infineon/openocd +### cortex-debug F5运行方式 +2. 修改launch.json文件 +![alt text](图片/DAY5/image-10.png) +其中对于PSoC62 evaluation Kit,"configFiles"应该设置为 +``` +"configFiles": [ + "interface/kitprog3.cfg", + "target/psoc6_2m.cfg" +] +``` +可以在openocd的安装目录下找到这些文件 +![alt text](图片/DAY5/image-11.png) +完整launch.json文件如下 +``` +{ + "version": "0.2.0", + "configurations": [ + { + "name": "psoc6-openocd", + "executable": "${workspaceRoot}/rt-thread.elf", + "request": "launch", + "type": "cortex-debug", + "runToEntryPoint": "main", + "targetId": "CY8C624ABZI", + "servertype": "openocd", + "configFiles": [ + "interface/kitprog3.cfg", + "target/psoc6_2m.cfg" + ], + "armToolchainPath": "c:/devtools/env2/tools/gnu_gcc/arm_gcc/mingw/bin", // !!!需要修改为自己的GCC 工具链路径 !!! + "gdbPath": "C:/DevTools/env2/tools/gnu_gcc/arm_gcc/mingw/bin/arm-none-eabi-gdb.exe" // !!!需要修改为自己的GDB 路径 !!! + } + ] +} +``` +3. 按F5开始调试 + +### tasks.json F1运行任务下载 +1. 给openocd注册环境变量 +D:\DevTools\openocd-5.8.0.3960-windows\openocd\bin +2. 在env中用以下命令烧录与reset(不然要手动reset) +``` +openocd -f interface/kitprog3.cfg -f target/psoc6_2m.cfg -c "program rt-thread.elf verify reset exit" +``` + +| 命令 | 说明 | +| --- | --- | +| -f | 配置文件 | +| -c | 命令 | +| program | 下载 | +| reset | 复位 | + +3. 在工程的`.vscode/task.json`中添加烧录任务 + +``` +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "windows": { + "options": { + "shell": { + "executable": "cmd.exe", + "args": [ + "/d", + "/c", + "c:\\DevTools\\env2\\tools\\bin\\env-init.bat && " + ] + } + }, + }, + "tasks": [ + { + "label": "下载固件(openocd)", + "type": "shell", + "command": "openocd -f interface/kitprog3.cfg -f target/psoc6_2m.cfg -c \"program rt-thread.elf verify reset exit\"", + "args": [], + "problemMatcher": [] + }, + { + "label": "下载固件(pyocd)", + "type": "shell", + "command": "pyocd load -t cy8c64xa_cm4 ${workspaceFolder}/rt-thread.elf", + "args": [], + "problemMatcher": [] + }, + ] +} +``` +4. 按F1选择任务烧录 +![alt text](图片/DAY5/image-13.png) +## pyocd 烧录 +![alt text](图片/DAY5/image-12.png) +``` +pyocd list --targets +``` +可以看到有cy8c64xa_cm4是builtin的,也就是内置的,可以直接使用。 +同样的,我们可以用以下命令来烧录 +``` +pyocd load -t cy8c64xa_cm4 ${workspaceFolder}/rt-thread.elf +``` + +## vscode中使用env +![alt text](图片/DAY5/image-14.png) +![alt text](图片/DAY5/image-15.png) +找到"terminal.integrated.profiles.windows"加入以下内容 +``` +"terminal.integrated.profiles.windows": { + "RTT Env2": { + "path": [ + "${env:windir}\\Sysnative\\cmd.exe", + "${env:windir}\\System32\\cmd.exe" + ], + "args": [ + "/K", + "c:\\DevTools\\env2\\tools\\bin\\env-init.bat" + ], + } + }, +``` diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\347\216\257\345\242\203\346\220\255\345\273\272\345\222\214git.md" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\347\216\257\345\242\203\346\220\255\345\273\272\345\222\214git.md" new file mode 100644 index 0000000000000000000000000000000000000000..397395fdccac986bff4497a2f09b7ebbebf736db --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\347\216\257\345\242\203\346\220\255\345\273\272\345\222\214git.md" @@ -0,0 +1,96 @@ +# RTT环境搭建和git使用 +![alt text](图片/DAY1/image-5.png) +## 克隆RT-Thread源码 +### 下载git +https://git-scm.com/downloads/win +### 下载源码 +``` +git clone https://github.com/RT-Thread/rt-thread.git +``` +``` +git clone https://gitee.com/rtthread/rt-thread.git +``` +可以用gitee,国内镜像,会更稳定 +## env下载和使用 +### 下载 +https://github.com/RT-Thread/env-windows + +压缩包(离线)方式 (如果上面的不行) +https://download-redirect.rt-thread.org/download/env_release/env-windows-v2.0.0.7z + +### 使用 +#### 注册环境变量 +这样可以在任意目录右键打开env +打开`env.bat`,右上角`setting`。 +![Integration & Register](图片/DAY1/image.png) +#### env更新 +``` +pkgs --upgrade +``` + + +## QEMU使用 +### 初步使用 +1. 打开文件夹`...\rt-thread\bsp\qemu-vexpress-a9` +2. 右键打开`ENV` +3. 输入`menuconfig`,按`q`退出,`y`确认,保存修改,下载相应软件包等 +4. 输入`scons -j4`,编译 +![编译成功图片](图片/DAY1/image-8.png) +5. 运行QEMU +输入```qemu-nographic.bat``` +6. 可以在MSH中查看线程等 +![alt text](图片/DAY1/image-7.png) +7. 按CTRL+A,再按X退出,返回ENV +### SConscript 构建 +指定哪些文件参与项目的构建 +1. 新建文件夹 +2. 新建SConscript文件,内容复制项目最外面的就行,就是把所有文件加入构建 +### LVGL DEMO体验 +1. 打开文件夹`...\rt-thread\bsp\qemu-vexpress-a9` +2. 右键打开`ENV` +3. 输入`menuconfig`,勾选如图选项 +![alt text](图片/DAY1/image-1.png) +4. 输入`scons -j4`,编译 +5. 运行QEMU +输入```qemu.bat``` +6. 有DEMO窗口打开,关掉窗口就可以退出 +## git使用 +版本管理 +### git安装 +https://git-scm.com/downloads/win +### git基本内容 +初始化,添加所有文件暂存,提交,查看 +``` +git init +git add . +git commit -m "first commit" +git status +git log +``` +切换分支,新建分支 +``` +git checkout -b branch_name +git checkout master +git branch -a +git switch branch_name +``` +回退到上一个版本 +``` +git reset --hard HEAD^ +git reset --soft HEAD^ +``` +推送到云端 +![alt text](图片/DAY1/image-6.png) +已经提交到云端的撤回 +例如 +![alt text](图片/DAY1/image-4.png) +``` +git push origin branch_name --force +``` +### ssh使用 +![alt text](图片/DAY1/image-2.png) +按上图操作可以用ssh方式克隆 +### 提交PR +1. Fork 仓库 +2. 新建分支,修改,提交PR +![alt text](图片/DAY1/image-3.png) \ No newline at end of file diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\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\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\350\256\276\345\244\207\351\251\261\345\212\250.md" new file mode 100644 index 0000000000000000000000000000000000000000..87fffe5f81d506e9d7e60b03e41fcd0511d16599 --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\350\256\276\345\244\207\351\251\261\345\212\250.md" @@ -0,0 +1,390 @@ +## 1. IO设备框架 +![alt text](图片/DAY4/image-1.png) +![alt text](图片/DAY4/image-2.png) +![alt text](图片/DAY4/image-3.png) +图中各类里的c文件是各类对应的管理接口所在,比如设备基类rt_device的管理接口在device.c中。 +设备对象具体定义如下所示: +``` +struct rt_device +{ + struct rt_object parent; /* 内核对象基类 */ + enum rt_device_class_type type; /* 设备类型 */ + rt_uint16_t flag; /* 设备参数 */ + rt_uint16_t open_flag; /* 设备打开标志 */ + rt_uint8_t ref_count; /* 设备被引用次数 */ + rt_uint8_t device_id; /* 设备 ID,0 - 255 */ + + /* 数据收发回调函数 */ + rt_err_t (*rx_indicate)(rt_device_t dev, rt_size_t size); + rt_err_t (*tx_complete)(rt_device_t dev, void *buffer); + + const struct rt_device_ops *ops; /* 设备操作方法 */ + + /* 设备的私有数据 */ + void *user_data; +}; +typedef struct rt_device *rt_device_t; + +``` + +### 设备类型 +* 字符设备:提供连续的数据流,应用程序可以**顺序读取**,通常不支持随机存取。相反此类设备支持按**字节/字符**来读写数据。 +举例来说,键盘、串口、调制解调器都是典型的字符设备 +* 块设备:应用程序可以**随机访问**设备数据,程序可自行确定读取数据的位置。硬盘、软盘、CD-ROM驱动器和闪存都是典型的块设备,应用程序可以寻址磁盘上的任何位置,并由此读取数据。此外,数据的读写只能以**块(通常是512B)的倍数**进行。与字符设备不同,块设备并不支持基于字符的寻址。 +* 总结一下,这两种类型的设备的根本区别在于它们是否可以被随机访问。字符设备只能顺序读取,块设备可以随机读取。 +* 还有好多类型 +#### 为什么要对设备分类 +* MSH可以**重定向**到任意的字符设备上,例如将lcd模拟成字符设备,就可以将打印输出到LCD上,或者是实现一套空字符设备,将msh重定向到这里。 +* Fatfs 文件系统依赖块设备驱动,我们将SD卡读写实现成块设备,但是也可以用ram来模拟块设备驱动, +* 不同的组件和应用会依赖不同的设备,对设备进行分类,可以做到对一类设备同样的控制 +## 2. I/O API +* 创建设备 create +* 注册到*I/O 设备管理器* register +* flag 只读只写…… +* find 得到句柄 +* init 初始化 +* …… +* 如果上层应用要设置接收回调函数,那么打开设备的时候flag要设置为中断相关的 +![alt text](图片/DAY4/image-4.png) +## 3. GPIO 应用与驱动开发 +### pin 的设备管理接口 + +|函数|功能| +|--|--| +|rt_pin_get()|获取引脚编号| +|rt_pin_mode()|设置引脚模式| +|rt_pin_write()|设置引脚电平| +|rt_pin_read()|读取引脚电平| +|rt_pin_attach_irq()|绑定引脚中断回调函数| +|rt_pin_irq_enable()|使能引脚中断| +|rt_pin_detach_irq()|脱离引脚中断回调函数| + +另:ENABLE ISR log + +https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/pin/pin +## I2C 从机应用与驱动开发 +![alt text](图片/DAY4/image.png) +* 起始位:SCL为高电平,SDA从高电平切换到低电平 +* 停止位:SCL为高电平,SDA从低电平切换到高电平 +* ACK:SCL为高电平,SDA为低电平 +* NACK:SCL为高电平,SDA为高电平 +* I2C读写 +![alt text](图片/DAY4/image-5.png) +[图片来源:Jie_MSD【IIC通信】Chap.1(I2C)IIC通信原理、IIC读写时序详解 + ](https://blog.csdn.net/qq_43858116/article/details/126031721) +* i2c-tools 软件包方便调试 + i2c scan +* I2C 从机地址用包括读写位的 + +## 4. SPI从机应用与驱动开发 +![alt text](图片/DAY4/image-6.png) +spixy x:bus y:从机 eg spi10 +https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/spi/spi + +## PIN设备驱动框架分析 +PIN 设备管理接口 +``` +void rt_pin_write(rt_base_t pin, rt_base_t value) +``` +调用了 +``` +_hw_pin.ops->pin_write(&_hw_pin.parent, pin, value); +``` +其中`_hw_pin`在pin.c中定义 +``` +static struct rt_device_pin _hw_pin; +``` +pin设备类`rt_device_pin`的定义如下 +``` +struct rt_device_pin +{ + struct rt_device parent; + const struct rt_pin_ops *ops; +}; +``` +其中parent是设备基类`rt_device` +``` +struct rt_device +{ + struct rt_object parent; /**< inherit from rt_object */ + + enum rt_device_class_type type; /**< device type */ + rt_uint16_t flag; /**< device flag */ + rt_uint16_t open_flag; /**< device open flag */ + + rt_uint8_t ref_count; /**< reference count */ + rt_uint8_t device_id; /**< 0 - 255 */ + + /* device call back */ + rt_err_t (*rx_indicate)(rt_device_t dev, rt_size_t size); + rt_err_t (*tx_complete)(rt_device_t dev, void *buffer); + +#ifdef RT_USING_DEVICE_OPS + const struct rt_device_ops *ops; +#else + /* common device interface */ + rt_err_t (*init) (rt_device_t dev); + rt_err_t (*open) (rt_device_t dev, rt_uint16_t oflag); + rt_err_t (*close) (rt_device_t dev); + rt_size_t (*read) (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size); + rt_size_t (*write) (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size); + rt_err_t (*control)(rt_device_t dev, int cmd, void *args); +#endif + +#ifdef RT_USING_POSIX_DEVIO + const struct dfs_file_ops *fops; + struct rt_wqueue wait_queue; +#endif + + void *user_data; /**< device private data */ +}; +``` +其中还有parent为`rt_object`基类 +``` +struct rt_object +{ + char name[RT_NAME_MAX]; /**< name of kernel object */ + rt_uint8_t type; /**< type of kernel object */ + rt_uint8_t flag; /**< flag of kernel object */ + +#ifdef RT_USING_MODULE + void *module_id; /**< id of application module */ +#endif + rt_list_t list; /**< list node of kernel object */ +}; +``` +回到pin设备类`rt_device_pin`,中有`rt_pin_ops`类的ops,也就是operation操作方法,有如下几个函数指针 +``` +struct rt_pin_ops +{ + void (*pin_mode)(struct rt_device *device, rt_base_t pin, rt_base_t mode); + void (*pin_write)(struct rt_device *device, rt_base_t pin, rt_base_t value); + int (*pin_read)(struct rt_device *device, rt_base_t pin); + rt_err_t (*pin_attach_irq)(struct rt_device *device, rt_int32_t pin, + rt_uint32_t mode, void (*hdr)(void *args), void *args); + rt_err_t (*pin_detach_irq)(struct rt_device *device, rt_int32_t pin); + rt_err_t (*pin_irq_enable)(struct rt_device *device, rt_base_t pin, rt_uint32_t enabled); + rt_base_t (*pin_get)(const char *name); +}; +``` +而他们在`rt_device_pin`中被赋值 +``` +int rt_device_pin_register(const char *name, const struct rt_pin_ops *ops, void *user_data) +{ + _…… + _hw_pin.ops = ops; + _hw_pin.parent.user_data = user_data; + + /* register a character device */ + rt_device_register(&_hw_pin.parent, name, RT_DEVICE_FLAG_RDWR); + + return 0; +} +``` +在`rt_hw_pin_init`调用了`rt_device_pin_register`,并给ops赋值为`_stm32_pin_ops` +``` +int rt_hw_pin_init(void) +{ + return rt_device_pin_register("pin", &_stm32_pin_ops, RT_NULL); +} +``` +他们会在`rt_hw_board_init`中被调用,也就是在板子启动时就被相应初始化调用了 +``` +RT_WEAK void rt_hw_board_init() +{ + …… + + /* Pin driver initialization is open by default */ +#ifdef RT_USING_PIN + rt_hw_pin_init(); +#endif +} +``` +回到`_stm32_pin_ops`,可以看到有6个函数指针,分别对应`rt_pin_ops`中的6个函数 +``` +const static struct rt_pin_ops _stm32_pin_ops = +{ + stm32_pin_mode, + stm32_pin_write, + stm32_pin_read, + stm32_pin_attach_irq, + stm32_pin_dettach_irq, + stm32_pin_irq_enable, +}; +``` +这些函数在驱动层实现也就是`drv_gpio.c`中,是正常移植主要要改的地方 +``` +static void stm32_pin_write(rt_device_t dev, rt_base_t pin, rt_base_t value) +{ + const struct pin_index *index; + + index = get_pin(pin); + if (index == RT_NULL) + { + return; + } + + HAL_GPIO_WritePin(index->gpio, index->pin, (GPIO_PinState)value); +} +``` + +另 +`_pin_write`则服务于I/O设备管理接口,如`rt_device_write`,实际上,也是调用的上文所述的`pin->ops->pin_write`,~~有点困惑这样不是又调用回`_pin_write`自己了吗~~ +``` +static rt_size_t _pin_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size) +{ + struct rt_device_pin_status *status; + struct rt_device_pin *pin = (struct rt_device_pin *)dev; + + /* check parameters */ + RT_ASSERT(pin != RT_NULL); + + status = (struct rt_device_pin_status *) buffer; + if (status == RT_NULL || size != sizeof(*status)) return 0; + + pin->ops->pin_write(dev, (rt_base_t)status->pin, (rt_base_t)status->status); + + return size; +} +``` +### 疑惑: +1. 为什么`_pin_write`会调用`stm32_pin_write`? +1. `struct rt_device_pin *pin = (struct rt_device_pin *)dev;`之后ops怎么就变成_hw_pin的ops了呢 +### 回答 +1. 其实是同一个问题,因为`rt_pin_device`的第一个元素就是`rt_device`类型的`parent`,也就是说他们(rt_pin_device _hw_pin和_hw_pin.parent)的首地址是一样的,当强制转换为`rt_pin_device`时,也就可以用上地址紧接在后面的ops了。 +2. pin设备自始至终用的都是`pin.c`开头定义的_hw_pin设备 + + + +`_pin_write`也是在上文的`rt_device_pin_register`中被赋值的,这里的`pin_ops`也这几个函数 + +``` +int rt_device_pin_register(const char *name, const struct rt_pin_ops *ops, void *user_data) +{ + #ifdef RT_USING_DEVICE_OPS + _hw_pin.parent.ops = &pin_ops; + #else + _hw_pin.parent.init = RT_NULL; + _hw_pin.parent.open = RT_NULL; + _hw_pin.parent.close = RT_NULL; + _hw_pin.parent.read = _pin_read; + _hw_pin.parent.write = _pin_write; + _hw_pin.parent.control = _pin_control; + #endif + …… +} +``` +最终他们会在I/O设备管理接口,如`rt_device_write`中被调用,如下 +``` +#ifdef RT_USING_DEVICE_OPS +#define device_init (dev->ops->init) +#define device_open (dev->ops->open) +#define device_close (dev->ops->close) +#define device_read (dev->ops->read) +#define device_write (dev->ops->write) +#define device_control (dev->ops->control) +#else +#define device_init (dev->init) +#define device_open (dev->open) +#define device_close (dev->close) +#define device_read (dev->read) +#define device_write (dev->write) +#define device_control (dev->control) +#endif /* RT_USING_DEVICE_OPS */ + +rt_size_t rt_device_write(rt_device_t dev, + rt_off_t pos, + const void *buffer, + rt_size_t size) +{ + /* parameter check */ + RT_ASSERT(dev != RT_NULL); + RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device); + + if (dev->ref_count == 0) + { + rt_set_errno(-RT_ERROR); + return 0; + } + + /* call device_write interface */ + if (device_write != RT_NULL) + { + return device_write(dev, pos, buffer, size); + } + + /* set error code */ + rt_set_errno(-RT_ENOSYS); + + return 0; +} +RTM_EXPORT(rt_device_write); + +``` +## 动手实践:自己写一个设备框架 +编写完以下4个文件后`libraries\HAL_Drivers\`的`drv_vir.c`和`drv_vir.h`,`rt-thread\components\drivers\misc\vir.c`,`rt-thread\components\drivers\include\drivers\vir.h`,请注意: +1. 在rtdevice.h加入 +``` +#ifdef RT_USING_VIR +#include "drivers/vir.h" +#endif /* RT_USING_VIR */ +``` +2. 分别在Sconscript加入.c文件 +3. 在Kconfig中加入配置项`RT_USING_VIR` +### 初步效果 +![alt text](图片/DAY4/image-7.png) +``` main.c +#include +#include +#include + + +int main(void) +{ + rt_kprintf("Hello RT-Thread!\n"); + rt_device_t dev=rt_device_find("vir"); + if(dev==RT_NULL) + { + rt_kprintf("vir device not found!\n"); + } + rt_device_open(dev, RT_DEVICE_OFLAG_RDWR); + rt_uint32_t val2; + rt_device_read(dev, 0, &val2, 4); + rt_kprintf("read: %u\n", val2); + rt_uint32_t val=1314; + rt_device_write(dev, 0, &val, 4); + rt_device_control(dev,RT_NULL,"happy"); + LOG_I("read: %u", rt_vir_read(dev)); + rt_vir_write(dev, 100); + rt_vir_printinfo(dev,"It's always a good time"); + return 0; +} +``` + +### 总结 +#### 总而言之,以pin设备为例,主要有3种类型的变量 +1. pin设备类`rt_device_pin`: 有`rt_device`的parent和操作函数 `const struct rt_pin_ops *ops`;(驱动框架层) +2. 设备基类`rt_device`: 有`rt_object`的parent和操作函数`const struct rt_device_ops *ops;`(IO设备管理层) +3. 基类`rt_object`(IO设备管理层) + +#### 层次有 +1. 应用层 +2. I/O设备管理层 +3. 驱动框架层 +4. 驱动层(如上文的stm32_pin_write) +5. SDK(HAL库等) + + +#### I/O设备管理接口操作实现的流程 +1. 应用层调用I/O设备管理层的函数,如`rt_device_write`。其中使用`dev->ops->write`(在`rt_device_pin_register`被赋为`_pin_write`) +2. `_pin_write`。使用`pin->ops->pin_write`(在`rt_device_pin_register`被赋为`stm32_pin_write`) +3. 驱动框架层调用驱动层的函数,如`stm32_pin_write` +4. 驱动层调用SDK的函数,如`HAL_GPIO_WritePin` + +#### PIN设备接口操作实现的流程 +1. 应用层调用PIN设备接口函数,如`rt_pin_write` +2. pin设备管理层调用驱动框架层的函数,如`pin->ops->pin_write`(在`rt_device_pin_register`被赋为`stm32_pin_write`) +3. 驱动框架层函数调用驱动层的函数,如`stm32_pin_write` +4. 驱动层调用SDK的函数,如`HAL_GPIO_WritePin` + +(总结部分为个人理解,可能有误,还请多多指正) diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\350\275\257\344\273\266\345\214\205\347\273\204\344\273\266.md" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\350\275\257\344\273\266\345\214\205\347\273\204\344\273\266.md" new file mode 100644 index 0000000000000000000000000000000000000000..786cca32ca51f2bce42454446d9a79d0557366ad --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\346\242\201\346\265\232\350\266\205/\347\254\224\350\256\260/\350\275\257\344\273\266\345\214\205\347\273\204\344\273\266.md" @@ -0,0 +1,131 @@ +## 软件包机制 +### pkg --upgrade +从软件包索引仓库拉取到本地仓库,更新软件包索引 +解决找不到软件包的问题 +也可以去env package文件夹git 拉取 +![alt text](图片/DAY5/image-8.png) +### llm chat软件包 +通过api,在单片机在上使用大模型ai +#### 配置步骤 +* api key 获取 https://bailian.console.aliyun.com/?tab=model#/model-market +![alt text](图片/DAY5/image-1.png) +![alt text](图片/DAY5/2357af977a6810cecfe02d86abce7b60.png) +![alt text](图片/DAY5/754b6c9f157fd957d6819334fc67dc2a.png) +![alt text](图片/DAY5/ea71d230332015ce537ea1f57caef20b.png) +#### 效果 +![alt text](图片/DAY5/b64cd0a508036c31e2c34a5b8f0f10f1.png) +## Kconfig +配置文件 +![alt text](图片/DAY5/image-7.png) +* 在c语言 宏 + 条件编译 +* 可以分布在各个文件夹 +https://www.rt-thread.org/document/site/#/development-tools/build-config-system/Kconfig +* selete 使用要慎重,否则关不掉 +* shift+?可以查看该配置项情况 +![alt text](图片/DAY5/image-2.png) +上手尝试:对应Kconfig +``` +menu "Onboard Peripheral Drivers" + menuconfig BSP_MQTT_MESSAGE + bool "Enable MQTT default message" + default n + if BSP_MQTT_MESSAGE + config BSP_MQTT_MESSAGE_NAME + string "name" + default "abc" + config BSP_MQTT_MESSAGE_STUDY + string "study" + default "abd" + endif +# 省略…… +endmenu +``` +* 注意不要手动改rtconfig.h的配置,否则env更新会失效 +## env +上位机,环境变量、软件包 + +## scons +构建工具 +* SConstruct SCons 入口脚本 +* scons --dist 打包 +* scons -c 清理 +* scons --verbose 详细信息 +keil来开发要注意rtconfig.py的`EXEX_PATH`是否正确 +### 函数 +``` +import os +from building import * + +cwd = GetCurrentDir() # 获取当前地址 +objs = [] # 定义一个空列表,用于存储所有的对象文件 +list = os.listdir(cwd) # 获取目录 +src = Glob('*.c') # 所有.c文件 +CPPPATH = [cwd] # 包含路径 + +if not GetDepend('BSP_DRV_EMAC'): + SrcRemove(src, ['drv_smc911x.c']) + +if not GetDepend('BSP_DRV_CLCD'): + SrcRemove(src, ['drv_clcd.c']) + +if not GetDepend('RT_USING_SERIAL_V1'): + SrcRemove(src, ['drv_uart.c']) +if not GetDepend('RT_USING_SERIAL_V2'): + SrcRemove(src, ['drv_uart_v2.c']) + +group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH) # 名字,.c, 依赖的宏,.h + +# 有SConscript就追加 +for d in list: + path = os.path.join(cwd, d) + if os.path.isfile(os.path.join(path, 'SConscript')): + objs = objs + SConscript(os.path.join(d, 'SConscript')) +objs = objs + group + +Return('objs') +``` + +## 网络组件 +ntp 获取时间和 检查网络情况 +![alt text](图片/DAY5/image-3.png) + +## 软件包 +### kawaii mqtt +![alt text](图片/DAY5/a7a30c9a4836aae40603b0463b5853ae.png) +注意mqtt client id 随便起不要一样 +![alt text](图片/DAY5/image-5.png) +在MQTTX相应配置,还是注意mqtt client id 随便起不要一样的 + +## 动手实践 +* 在Kconfig加入上文的代码 +* 修改mqtt demo 实现发送json +``` + +char *tmp_json ; +char *message_json(void) +{ + cJSON* root = cJSON_CreateObject(); + cJSON_AddStringToObject(root, "name", BSP_MQTT_MESSAGE_NAME); + cJSON_AddStringToObject(root, "study", BSP_MQTT_MESSAGE_STUDY); + tmp_json = cJSON_Print(root); + rt_kprintf("json:%s\n",tmp_json); + cJSON_Delete(root); + return tmp_json; +} +MSH_CMD_EXPORT(message_json,print json message); + +static int my_mqtt_publish_handle(mqtt_client_t *client) +{ + mqtt_message_t msg; + memset(&msg, 0, sizeof(msg)); + + msg.qos = QOS0; + msg.payload = (void *)message_json(); + + return mqtt_publish(client, KAWAII_MQTT_PUBTOPIC, &msg); +} + +``` +![alt text](图片/DAY5/image-6.png) +![alt text](图片/DAY5/image-9.png) +