serial: add txSpaceAvailable function
Solved Problem
Adds a txSpaceAvailable() function to the Serial abstraction
Changelog Entry
For release notes:
serial: add txSpaceAvailable function
Context
I will be using this in an upcoming GPS driver PR to ensure the TX buffer is not full before injecting RTCM data.
Just a quick comment: I think this functionality is good to have.
Just my 2 cent on the RTCM injection topic @dakejahl: I would propose one POLLIN fd and one POLLOUT fd on the uart instead. This way you would sleep until some work needs to be done (either reading from the UART as the buffer contains data, or writing to the UART as the buffer has space). Then there is no blocking logic at all: Wait until there is some work to do, do it, back to sleep.
I've made some changes. The bytesAvailable function now returns -1 when there's an error and sets errno = EBADF when the device is not open. The posix/qurt txSpaceAvailable sets errno to ENOSYS which means Function not implemented and returns -1.
We might want to consider errno = EBADF for all of the other if (!_open) { return -1; } cases, although I don't think any code makes use of the errno.