This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to detect UART chars available in TI RTOS



I have a program using "tirtos_tivac_2_00_01_23" and one function of it is to provide a UART console to accept and respond to commands. I understand the RTOS provide thread safe functions for accessing the UART. Typically this is working well for me except for one case and need some help.

I'm using the following setup;

UART_Params_init(&uartParams);
uartParams.writeMode = UART_MODE_BLOCKING;
uartParams.readMode = UART_MODE_BLOCKING;
uartParams.writeDataMode = UART_DATA_BINARY;
uartParams.readDataMode = UART_DATA_BINARY;
uartParams.readReturnMode = UART_RETURN_FULL;
uartParams.readEcho = UART_ECHO_OFF;
uartParams.baudRate = 115200;
uart = UART_open(Board_UART0, &uartParams);

I have a task that reads one character at a time using "UART_read(uart, &readChar, 1)" then process it as needed. No problem here. I like the way this works because it will block forever until a character is received, keeping the system free for other tasks. This works great for single character ASCII from a terminal.

I now want to process a few multi-character ESC codes such as "up arrow" and "down arrow". What I had in mind was that if I receive an ESC character, enter a special processing thread that waits a couple milliseconds for the rest of the characters to be sent, then read the UART. If it was just an escape char with no other characters I don't want to wait forever. I'd like to have the read return immediately with any characters read, or none if nothing is there.

There are two option I can think of but don't know if either will work. Also if there is a better way, please let me know.

1. Somehow temporarily change the UART readTimeout value from wait forever to some small amount. Can this be done while the UART port is open and in use?

2. Use the TIVA driver function "UARTCharsAvail" to check for available characters before using the RTOS read function. Is it safe to use this function in the RTOS?

Thanks in advance for your help!

  • Hi James,

    James Ball said:

    1. Somehow temporarily change the UART readTimeout value from wait forever to some small amount. Can this be done while the UART port is open and in use?

    In order to change the read timeout, you would have to close and re-open the UART with a different timeour param.

    James Ball said:

    2. Use the TIVA driver function "UARTCharsAvail" to check for available characters before using the RTOS read function. Is it safe to use this function in the RTOS?

    The UARTCharsAvail function only does a register read so it should be safe to call. However, it only tells you if characters are available or not. It does not return a count of how many characters are available to read.

    Best,

    Ashish

  • Hi,

    Thanks for the response. UARTCharsAvail seems to work OK.

     

    There does seem to be a gap in documentation with using the TIVA drivers in RTOS. The RTOS drivers don't seem to have an extensive enough API for anything other than the most basic programs. I hope TI can integrate these drivers better in future releases.

     

    Thanks, 

    James