Hello sparkee,
The best answer to the question "How does the ADC hardware averaging works" can be found in the Reference Manual from here https://www.nxp.com/webapp/Download?colCode=S32K1XXRM , the ADC chapter.

Now, all the toolbox does by enabling the HW ADC and samples to average checkboxes in the config block is to set the AVGE bit and the AVGS1 & AVGS0 bits. From what I've read, once you triggered a conversion, the hardware will perform as many conversions as selected [4, 8, 16, 32], and when it finishes the selected number, the averaging takes place. Once the average is computed, it will trigger the conversion complete interrupt. So, I don't think that the hw averaging takes the sample time into consideration at all.
To be honest with you, I don't know how does that delay block works in generated code, if it is performing busy waiting or not.
Reading your explanations, reminded me of another hardware functionality: the Automatic compare function, which we also support in the configuration block. And what is nice about it is that the ADC can be set to provide the conversion result only if some threshold conditions are fulfilled. Please have a look at the following screenshots from the Reference Manual.



So I recommend you read the ADC functional description (Chapter 44.5 from the Reference Manual) and maybe my idea of taking into consideration the usage of the ADC automatic compare function may do your task easier. The only question remains how to measure those 40ms of above threshold time, but I think we can figure it out :smileygrin:.
Hope this helps,
Marius