Add 07_multithread_rr and 08_thread_control_apis
This commit is contained in:
1 parent
c8fe95e63b
commit
f7ae8d226b
6 files changed
+297
No files matched your search
@@ -0,0 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
|
||||
project(07_multithread_rr)
|
||||
|
||||
target_sources(app PRIVATE src/main.c)
|
||||
@@ -0,0 +1,12 @@
|
||||
CONFIG_SERIAL=y
|
||||
CONFIG_CONSOLE=y
|
||||
CONFIG_PRINTK=y
|
||||
|
||||
# Enable zephyr timeslicing
|
||||
CONFIG_TIMESLICING=y
|
||||
|
||||
# Set the timeslice lenght in milliseconds
|
||||
CONFIG_TIMESLICE_SIZE=10
|
||||
|
||||
# Timeslicing only applies to threads whose priority is numerically >= this value(e.g. 0)
|
||||
CONFIG_TIMESLICE_PRIORITY=0
|
||||
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user