SPI/DMA Filtering frames on the fly
Posted: Tue Jan 19, 2021 6:19 pm
Hi,
for my app, I need to discard some SPI frames. As I understand SPI+DMA, all frames have to be the same size, the buffer size depending on the frames size. I have some variable length frames that have to be discarded (they are useless). They are easily recognizable with their first byte, and thay are smaller than legit ones.
I solved the problem this way (it works fine) :
- an interrupt on the falling edge of the /CS pin
- an interrupt vector that tests for the buffer's first byte :
- if the first byte is not "legit" -> reset SPI : the whole sequence from setModule() to
spi_rx_dma_enable(), dettaching and reattaching the DMA interrupt. I tried to remove some
functions with no success
- if the first byte is legit, fine, return !
It could take too long (who knows...), so I could miss the next frame from time to time.
Sounds a bit like crap. Doesn't it ? Or as Dave Jones would say : if it looks like..., if it smells like..., it is !
Searching the headers, I didn't find anything that looks like reset or restart. dma_clear_isr_bits() has not the expected effect (it has no effect, but it's only DMA...). It's not enough. Looking for something more brutal, but smarter than what I did.
Is there somethingthat just resets the SPI transfer (and DMA), keeping all the parameters alone ?
(Community Core)
(obviously)
for my app, I need to discard some SPI frames. As I understand SPI+DMA, all frames have to be the same size, the buffer size depending on the frames size. I have some variable length frames that have to be discarded (they are useless). They are easily recognizable with their first byte, and thay are smaller than legit ones.
I solved the problem this way (it works fine) :
- an interrupt on the falling edge of the /CS pin
- an interrupt vector that tests for the buffer's first byte :
- if the first byte is not "legit" -> reset SPI : the whole sequence from setModule() to
spi_rx_dma_enable(), dettaching and reattaching the DMA interrupt. I tried to remove some
functions with no success
- if the first byte is legit, fine, return !
It could take too long (who knows...), so I could miss the next frame from time to time.
Sounds a bit like crap. Doesn't it ? Or as Dave Jones would say : if it looks like..., if it smells like..., it is !
Searching the headers, I didn't find anything that looks like reset or restart. dma_clear_isr_bits() has not the expected effect (it has no effect, but it's only DMA...). It's not enough. Looking for something more brutal, but smarter than what I did.
Is there somethingthat just resets the SPI transfer (and DMA), keeping all the parameters alone ?
(Community Core)
(obviously)