Characteristics of ChibiOS' main thread
Posted: Tue Jun 29, 2021 2:32 pm
Dear ChibiOS team, I am a newbie to ChibiOS and microcontroller programming. I have got a question regarding ChibiOS's main thread on an Arduino mega. As of my understanding, after having initialized all threads, ChibiOS's main thread ends up in the "loop()" function (similar to Arduino's super-loop). Now I wonder where I am being wrong: I am using a NextionDisplay connected via serial port to an Ardunio mega. The NextionDisplay is controlled by the Arduino over a serial port and signals the Arduino upon any touch events triggered on the NextionDisplay over the serial port. When polling the NextionDisplay touch events in a dedicated ChibiOS thread, no signals coming from the NextionDisplay are caught by the code in the thread, though when I poll for NextionDisplay touch events in the "loop()" function (as of my best & humble knowledge it is the main thread) I get the touch signals correctly while the other threads still being processed. For my use case this is a feasible approach, though I would like to know if it is good practice to place legacy serial communication processing (as of the NextionDisplay library) in the main thread ("loop()") or are there configuration means to use a dedicated thread when doing such communication (what have I missed)?
(NextionDisplay: https://www.exp-tech.de/displays/tft/76 ... lay?c=1074)
(NextionLibrary: https://github.com/itead/ITEADLIB_Arduino_Nextion)
Below a snippet on how I created the threads:
Thank you beforehand & best regards,
Siegfried
(NextionDisplay: https://www.exp-tech.de/displays/tft/76 ... lay?c=1074)
(NextionLibrary: https://github.com/itead/ITEADLIB_Arduino_Nextion)
Below a snippet on how I created the threads:
Code: Select all
#include "NextionChibiOS.h"
#include <Arduino.h>
#include ...
#include <ChRt.h>
#define THREAD_MEMORY 512
...
void displayThread() {
while( true ) {
// nexLoop(touchListeners); // NextionDisplay query touch events does not function here
}
}
THD_WORKING_AREA(displayArea, THREAD_MEMORY);
THD_FUNCTION(displayStart, arg) {
displayThread();
}
void startThreads() {
ch_thread *displayThread = chThdCreateStatic(displayArea, sizeof(displayArea), HIGHPRIO, displayStart, NULL);
}
void setup() {
chBegin(startThreads);
}
void loop() {
nexLoop(touchListeners); // NextionDisplay query touch events does function here
}
Thank you beforehand & best regards,
Siegfried