I have a project where I use my board's UART4 with the stdio and I can "printf" just fine. Additionally, I need that very same port for another part of my project so in my code I open it with:
port = fopen("ttye:", IO_SERIAL_RAW_IO);
That works wonderfully because I can send data through the port using:
write(port, data, size);
But I'm having some problems when reading bytes from the port. I found a post where someone has a similar case scenario than me and wants to find out when four bytes have arrived into the port. Nevertheless, the post is 5 years old and inconclusive since it does not have a satisfactory answer and it doesn't help my situation.
It is suggested in the post to use "IO_IOCTL_CHAR_AVAIL" to detect bytes available. I'm doing it like this:
ioctl(port, IO_IOCTL_CHAR_AVAIL, &result);
But the problem is that I only get TRUE if the reception is 1 byte only and I need to detect when more than 1 byte has arrived.
Why is this happening? Or is there any other way of detecting when more than one bytes have been received?
By the way, I can't use interrupts and it's ok to poll as I'm doing it right now. And I can't use "fread" because that blocks execution even if I open the port with "IO_SERIAL_NON_BLOCKING".
I don't know if I'm facing these problems because of the fact that I'm trying to use the same port as the stdio, but I can write just fine to the port using printf and write. Isn't it the same for the reception?