I have a simple theoretical question. The DMAs I know usually have half full or full interrupts. If I want to use a DMA for data transfer from a peripheral, how can I ensure I got all the data since data may not be at the dma transfer boundary.

For example, serial port might send 5 bytes, I would get and interrupt for the first 4 combined together (assuming dma size is 4), but nothing for the 5th one. What is the method people usually use to solve such a problem.

有帮助吗?

解决方案

My best approach is this:

  • Setup a DMA memory region. lets say it's address 0x2 to 0x1000
  • The serial device writes bytes in this region, as a circular buffer
  • Each time the serial device writes, it updates it's "write pointer" and saves in bytes 0x0 and 0x1
  • The PC Host can dma the write pointer, and compare with it's own read pointer. The read pointer can be kept on the pc host and not deal with DMA at all. Then the PC knows how much memory to read, and it also knows if there has been an underflow or overflow.

This should be a good starting point for what you want.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top