AnsweredAssumed Answered

select() on serial port

Question asked by Giuseppe Modugno on Feb 7, 2013
Latest reply on Mar 20, 2013 by Giuseppe Modugno

I'm using MQX 4.0 with Tower system (Kinetis K60).


I'm writing a task that communicates to another device through the serial port of TWR-SER board. I'm able to open the port and send/receive bytes on that port without problems.


Now I'd like to have a function similar to the classical select() function: I want to put the task in blocked state until a character on the serial port has arrived or a timeout expires. I noticed the select() function is implemented only in RTCS, but not for simple I/O serial port.


The serial protocol I'm implemented is master/slave, where the MQX application is the master. So it sends a packet and waits for the answer. The wait can't be indefinitely, because the other device couldn't be actually connected, so I have to do something if this condition occurs.


I can open the serial port in polling non-blocking mode and poll the serial port with fgetc() and make some ticks calculations to detect the timeout:


while(1) {


  end = start = _time_ticks();

  while(_time_diff(end, start) < TIMEOUT) {

    c = fgetc(serial_port);

    if (c >= 0) {


      if (rxpacket_complete()) {




  if (rxpacket_complete()) {

    /* Process the incoming packet */


  } else {

    /* No answer */



But I'd like to avoid this. The task is always running and never goes in blocked mode.