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/\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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/\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..a653f674614b40cae0c178747dc805ddbcfa34fe --- /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](图片/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](图片/image.png) +#### env更新 +``` +pkgs --upgrade +``` + + +## QEMU使用 +### 初步使用 +1. 打开文件夹`...\rt-thread\bsp\qemu-vexpress-a9` +2. 右键打开`ENV` +3. 输入`menuconfig`,按`q`退出,`y`确认,保存修改,下载相应软件包等 +4. 输入`scons -j4`,编译 +![编译成功图片](图片/image-8.png) +5. 运行QEMU +输入```qemu-nographic.bat``` +6. 可以在MSH中查看线程等 +![alt text](图片/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](图片/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](图片/image-6.png) +已经提交到云端的撤回 +例如 +![alt text](图片/image-4.png) +``` +git push origin branch_name --force +``` +### ssh使用 +![alt text](图片/image-2.png) +按上图操作可以用ssh方式克隆 +### 提交PR +1. Fork 仓库 +2. 新建分支,修改,提交PR +![alt text](图片/image-3.png) \ No newline at end of file