DISTORTEC / distortos

object-oriented C++ RTOS for microcontrollers
https://distortos.org/
Mozilla Public License 2.0
434 stars 67 forks source link

SerialPort::read and write functions #51

Closed CezaryGapinski closed 6 months ago

CezaryGapinski commented 6 years ago

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.

FreddieChopin commented 6 years ago

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.