I am trying to implement a serial (UART) interface on a K60 under MQX. This seemed relatively straight forward, but am having no success.
I intend to have a task that that opens and receives characters on ittyx port.
I do not know how many characters will be received.
I want to read 4 characters when available (a header) and then read additional characters based on a length value included in the first 4 bytes read. It did not seem unreasonable to think the MQX serial drivers could support this kind of use case. Can someone point me to example code or offer insights as to how the driver works?
Should I be using read() or fread(), I am not clear on the difference?
If in a while(1) loop I make a call to fread() and no characters are available, does this task give up the cpu allowing other tasks to run.
If, as an example, the chip has received 8 bytes and I do an fread() to read the first 4 bytes, can I then do another fread() for the remaining bytes, will I get the next 4 bytes?