Answers to your questions:
Is there anyway to check how many bytes sitting in RX or TX buffers?
- not via current driver API - you would have to change internal implementation.
Is interrupts UART blocks other tasks until he is done sending bytes?
- Uart interrupts runs on background. It does not block task, it interrupts all tasks, reacting on IRQ TIE(Transmit Data Register Empty). In isr it sends next byte from OS buffer. After last byte it disables transmit interrupt.
Is flush() essentially blocks everything else until UART completed the send?
- flush() internal implementation is while(){} waiting till all OS device buffer is emptied.
Other task with higher priority can run.
Is IO_IOCTL_SERIAL_TRANSMIT_DONE sets when last byte of the OS buffer been send out to UART buffer or when hardware UART buffer been emptied?
- Current implementation of both - IO_IOCTL_SERIAL_TRANSMIT_DONE and flush() function are dependent only on OS buffer sending. Neither of them check UART HW buffer.
-------------------------
I think you would need to wait for Transmission Complete FLAG of the last send byte. In current driver implementation there is no way how to do it.
We will investigate this problem and change it in next MQX version.(probably modify IO_IOCTL_SERIAL_TRANSMIT_DONE ioctl to check TC flag.
Currently I would suggest you to modify driver to check TC flag. And in your application you should call flush() - waits till last byte is send, then check Transmit Complete flag.