Prevent background loop starvation by splitting long graphical tasks causing serial serial buffer underruns #2996
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prevent background loop starvation by splitting long graphical tasks causing serial buffer underruns.
Target is to split the graphical tasks into slices of max 1ms.
Description
This PR gives solves the issue of background loop starvation causing buffer underruns.
The TFT application is split into 2 parts, a the foreground and backend loop. The foreground loop handles graphical processes which are not very time critical. The backend loop handles critical processes like serial data receiving and sending. The processor is single threaded, there is not multitasking at all. The application uses interrupt, which helps to make sure serial data is received and send, but if the data is not processed rapidly then a buffer underrun can occur very fast. I did some benchmarks to illustrate this on my BTT TFT35 V3.01
GUI_ClearPrect(&terminalAreaRect[0]); Takes about 20ms
GUI_ClearPrect(&editorAreaRect[1]); Takes about 16ms
The following code takes about 90ms
And worse of all, in the terminal there are processes that can take over 1 second without giving attention to the background loop.
In Configuration.h I found this comment:
// NOTE: This may slow down graphics while switching menus while printing.
#define RAPID_SERIAL_COMM // Default: uncommented (enabled)
This option should definitely be enabled (is default). Bench marking shows that the background loop can be executed over 100.000 times a second. So I would not worry too much about giving more attention to it.
I bench marked the code changes I made in this PR and could not find any difference in the required time needed to execute the graphical processes.
Benefits
Improve overall data receive and send responsiveness.
Reduces or possibly even eliminates the chance of a serial buffer underruns.
No measurable negative affect on graphical performance.
Related Issues
#2994