distortos icon indicating copy to clipboard operation
distortos copied to clipboard

SerialPort::read and write functions

Open CezaryGapinski opened this issue 7 years ago • 1 comments

https://github.com/DISTORTEC/distortos/blob/f033d1eca25254db45f14e8cd4d26a52be94720c/include/distortos/devices/communication/SerialPort.hpp#L387

Hi! It is a must for read (or write) function to be canceled immediatelly when timeout from timePoint occurs? I mean situation where local buffer must be switched into SerialPort::readBuffer_ (or writeBuffer) for DMA (like for STM32F4, F7) where transfer cannot be stopped at once and after disable DMA can continue transfer till to flush the buffer. It is especially issue for reading function if after DMA disable data can still be written to the local buffer which can be out of the read function when we supposse that the read function will finish immediatelly.

CezaryGapinski avatar Feb 23 '18 17:02 CezaryGapinski

Well, probably it doesn't have to be immediate, but the low-level function which does the stopping should block/wait until the transfer is really stopped. Assuming that this wait is generally short (probably true, but I'm guessing here) I think a normal polling loop would be fine.

while (!(DMA->STATUS & ALREADY_STOPPED));

Maybe with a safety timeout ("don't loop more than X times") to be more robust.

FreddieChopin avatar Feb 23 '18 22:02 FreddieChopin