Update repo

This commit is contained in:
hangpersonal committed 2026-10-19 23:09:38 -07:00
1 parent 42d54dc132
commit 6c33721f5e
19 files changed
+491 -1

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(my_workqueue)
target_sources(app PRIVATE src/main.c)
+16
View File
@@ -0,0 +1,16 @@
# Set to -Og
CONFIG_DEBUG_OPTIMIZATIONS=y
# Thread awareness support
CONFIG_DEBUG_THREAD_INFO=y
# Generate stack usage per-function
CONFIG_STACK_USAGE=y
# Other options in case not set by default
CONFIG_BUILD_OUTPUT_HEX=y
CONFIG_BUILD_OUTPUT_META=y
CONFIG_OUTPUT_SYMBOLS=y
CONFIG_OUTPUT_STAT=y
CONFIG_OUTPUT_DISASSEMBLY=y
CONFIG_OUTPUT_PRINT_MEMORY_USAGE=y
+49
View File
@@ -0,0 +1,49 @@
#include <zephyr/kernel.h>
// Define a work item with event data
struct my_operation {
int event_id;
int value;
struct k_work work; // Zephyr work item
};
// Work handler executed by the system workqueue thread
void my_work_handler(struct k_work *work) {
// Retrieve the parent structure from the work item pointer
struct my_operation *op =
CONTAINER_OF(work, struct my_operation, work);
// Process the event
printk("Workqueue: processing event_id=%d value=%d\n",
op->event_id, op->value);
}
// Define three work items with different event data
struct my_operation op1 = {.event_id = 1, .value = 10};
struct my_operation op2 = {.event_id = 2, .value = 20};
struct my_operation op3 = {.event_id = 3, .value = 30};
int main(void) {
// Initialize work items with the same work handler
printk("Main: initializing work items\n");
k_work_init(&op1.work, my_work_handler);
k_work_init(&op2.work, my_work_handler);
k_work_init(&op3.work, my_work_handler);
// Submit op1 to the system workqueue
printk("Main: submitting op1\n");
k_work_submit(&op1.work);
// Submit op2 to the system workqueue
printk("Main: submitting op2\n");
k_work_submit(&op2.work);
// Sleep for 500 ms, allowing other threads to execute
k_sleep(K_MSEC(500));
// Submit op3 after the delay
printk("Main: submitting op3\n");
k_work_submit(&op3.work);
return 0;
}