From 4924a705be8cab479472e11cd3bb73b6f9309da4 Mon Sep 17 00:00:00 2001 From: Klagarge Date: Tue, 26 May 2026 13:58:08 +0000 Subject: [PATCH] feat(lab03): add note about thread and timer design --- doc/lab03-silly_led/main.typ | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/lab03-silly_led/main.typ b/doc/lab03-silly_led/main.typ index f9c0864..fa414dd 100644 --- a/doc/lab03-silly_led/main.typ +++ b/doc/lab03-silly_led/main.typ @@ -8,8 +8,17 @@ This laboratory implements a user-space application for the NanoPi NEO Plus2 tha == Design The application is based on multithreading: one thread handles the LED timing, while another handles button events. GPIOs are accessed through sysfs, which allows the LED and buttons to be managed as file descriptors. A key design choice was to centralize all events with a single epoll instance, so both timer events and button events can be processed efficiently. +The timer thread use only 1 timer and set the initial time on every cycle. That allow to allocate only once the timer and avoid memory fragmentation. The button thread write write the next time to sleep on a shared variable, and the timer thread read this variable to set the next time to sleep. Since we have only one provider of this variable, we don't need to use a mutex to protect it. + + All logs are done using the syslog at info level: ```c +// First, we open the syslog with a specific name and facility +// LOG_PID to include the PID (process ID) in the logs +// LOG_USER to specify the log facility (what type of programme) +openlog("CSEL Logs", LOG_PID, LOG_USER); + +// Then log what you want: syslog(LOG_INFO, "Start logging silly led-controller"); // INFO level ``` @@ -25,13 +34,13 @@ We can demonstracte that the application works in an efficient than the silly le stroke: none, [ #figure( - image("test-silly.png"), + image("test-silly.png", height: 10em), caption:[Run silly led controller on nanopi] ) ],[ #figure( - image("test-epoll.png"), + image("test-epoll.png", height: 10em), caption:[Run epoll led controller on nanopi] ) ]