Jetson control ADC using SPI

Hi everyone,
I have a ADC device with SPI port. The sample rate of the ADC up to 16kHz. When the ADC get data, it will send a data ready signal to the master.
I want to use jetson to get data from the ADC. The ideal way is when Jetson get data ready signal, it use spi related API to read data.
I make the first plan:
I use spi_sync_transfer API, this API can not be place in irq handler, so I use request_threaded_irq API, it will put spi_sync_transfer to bottom half of interrupt.
When I finish the codes, I find they can’t meet my requirements, because when the interrupt is fast, SPI communication cannot be completed in the interrupt interval, I have a test, when the sample rate is 4kHz, it will lose 1 or 2 sample data in 1 seconds.

To deal with it, I try the second plan:
I use the spi_async API, this API can be put in irq handler, and when spi communication finish, it will call a completion function. I hope it will solve the data lose question, but in fact, it get a worse results. I make a timer to calculate the time cost in the spi_async API, I find the time cost is stable in most of the time, around 100us, but in some cases, the time cost is up to 500us, even >1ms, and if the ADS’s sample rate is 4kHz, the interrupt interval is 250us, if the SPI transfer cost greater than 250us, I got a data lose.

I conclusion the question:

1.Why the spi transfer API cost is not stable, is this due to the linux system? Can I give higher priority to SPI related interfaces to reduce the time cost(less than 250us of 4kHz sample rate)?
2.My third plan is about DMA, data ready triggers the SPI controller’s DMA channel directly, The DMA transfers one sample set into RAM, and waits for the next trigger, after(say) 100 samples, the DMA triggers a callback to let CPU deal with the data.
I think this DMA plan may helpful, but When I check the forum at How SPI can use DMA on Xavier!, the expert of NVIDIA says if I use the spi API, I use the DMA. So I am confused about it, Which documents I can learn about SPI use DMA, maybe you can help me with this plan.
Thanks
Yan

1 Like

Looks like duplicate with topic SPI transfer API time cost issue ?

Yes, Shane, you are right, I will try your method and close this topic.