2022-10-31 07:02 AM
Hello,
I am preparing a much larger code that handles a slew of tasks (gathers CAN data from up to 5 different nodes, reads ADCs, sends GPIO PWM signals and ON/OFF signals, LCD display screen via TouchGFX).
I have interrupts for specific tasks (when a CAN message is received, timer interrupt, etc.). Additionally, I will want to periodically send information to different CAN nodes. I understand that it is considered a good practice to minimize the amount of code in the interrupt functions, so I picture the code sequence being as follows (for the CAN receive portion, for example):
What I want to know is the best practice to do step 4. The arithmetic and/or logic could be a fair bit of code, so I know I shouldn't do it in the interrupt function, but the TouchGFX display portion will cause it to be in a specific task. Should I write the logic in the TouchGFX task function, or create a different task/function? If so, how will it be entered without another interrupt?
2022-10-31 10:15 PM
I tend to use circular buffers (or ring buffers as others have called them). The interrupt adds to the buffer and updates the "in index", the main program only alters the "out_index" and comparing the two indexes lets you know if new data is available (you probably know how this works...). Sometimes if the main processing is periodically sizeable (eg. an FFT), I even transfer the data from the interrupt buffer to another larger circular buffer. But if the processing is reasonable and predictable, I do it within the interrupt handler. eg. when I am reading data from my microphone (using the DFSDM), I do the dc-offset removal (assembly routine) and decimation low-pass filter (assembly routine) in the interrupt handler before adding it to the circular buffer - the main routine adds that to a larger buffer so I can do multiple FFTs to do spectograms etc.