Add 07_multithread_rr and 08_thread_control_apis

This commit is contained in:
hangpersonal committed 2026-10-12 22:24:42 -07:00
1 parent c8fe95e63b
commit f7ae8d226b
6 files changed
+297

No files matched your search

+66
View File
@@ -0,0 +1,66 @@
#include <zephyr/kernel.h>
#include <zephyr/sys/printk.h>
// Define stack size in bytes
#define THREAD_1_STACK_SZ 1024
#define THREAD_2_STACK_SZ 1024
// Define priority, lower number = higher prio
#define THREAD_1_PRIORITY 5
#define THREAD_2_PRIORITY 5
static void thread_1_function(void *p1, void *p2, void *p3) {
ARG_UNUSED(p1);
ARG_UNUSED(p1);
ARG_UNUSED(p1);
printk("\r\n---------------[RTOS THREAD] Project----------------\r\n");
while(1) {
printk("Hello from Thread 1 \r\n");
k_msleep(50);
}
}
static void thread_2_function(void *p1, void *p2, void *p3) {
ARG_UNUSED(p1);
ARG_UNUSED(p1);
ARG_UNUSED(p1);
printk("\r\n---------------[RTOS THREAD] Project----------------\r\n");
while(1) {
printk("Hello from Thread 2 \r\n");
k_msleep(50);
}
}
// Statically create the thread and auto-start
K_THREAD_DEFINE(
thread_1_tid, // Symbolic thread identifier
THREAD_1_STACK_SZ,
thread_1_function,
NULL,
NULL,
NULL,
THREAD_1_PRIORITY,
0,
0 // Start immediately at boot
);
// Statically create the thread and auto-start
K_THREAD_DEFINE(
thread_2_tid, // Symbolic thread identifier
THREAD_2_STACK_SZ,
thread_2_function,
NULL,
NULL,
NULL,
THREAD_2_PRIORITY,
0,
0 // Start immediately at boot
);
int main(void) {
printk("\r\n----- Main Function -----\r\n");
while(1){
k_sleep(K_FOREVER);
}
return 0;
}