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.

  • Resolved

CCS/TI-RTOS-MCU: Number of bytes available on UART

Intellectual 320 points

Replies: 4

Views: 164

Part Number: TI-RTOS-MCU

Tool/software: Code Composer Studio

Hi,

I'm developing an application for TM4C1294NCDPT using TI-RTOS. I'm facing a problem that I know how to solve using TivaWare drivers, but using TI-RTOS drivers for such is being a bit of challenge.

I'm using several UART interfaces and routing my packages to a single task responsible for make any processing required. I decided to make a single reception buffer and when any UART receives any package, I lock such buffer using a semaphore. It's working as described.

The problem I'm facing is when receiving any noise bytes, I fall in a deadlock condition. They way to solve this using TivaWare would be checking if there is any bytes available at UART before entering the UART_read blocking function and implementing a timeout to free the semaphore after a little while.

My question is: is there a fuction inside TI-RTOS to know beforehand if there is any bytes on given UART_Handle? Can I use the UART_Handle in conjunction with UartCharsAvail from Tivaware? How so?

The simplified version of my code is just below:

        if(UART_read(uart, &input, 1) == 1)   // wait for a single byte
        {

            if(Semaphore_pend(semHandle2, 100 / Clock_tickPeriod) == true) // try to aquire the semaphore
            {
                syscom->receiveChar(input);               // put the received byte inside reception buffer
                timeout = 3;                              // set a timeout, which is decremented in another context
                while((input != EOT)  && timeout > 0)     // wait for my end of transmission byte or timeout to expire
                {
                    UART_read(uart, &input, 1);           // my routine get stucks here if i dont have any bytes
                    syscom->receiveChar(input);           // save my byte on reception buffer
                }
                if(input == EOT)
                {
                    // signaling for another task to process what is in inside the buffer
                }
                else
                {
                    // timeout occorred
                }
                syscom->resetRxBuffer();
                Semaphore_post(semHandle2);
            }
            else    // semaphore was already acquired by another uart interface (sit and cry)
            {
                System_printf("COM Blocked uart2!\n"); System_flush();
            }

        }

  • Hi Daniolip,

    What version of TI-RTOS are you using? Depending on which version you are using, there may be a control function you can call to see if the rx buffer has data. For example, UARTMSP432E4.c has UART_CMD_GETRXCOUNT that can be passed as an argument to the UART_control fxn.

    Thanks,

    Sean
  • In reply to Sean Oliver28:

    Hi,

    I'm using TI-RTOS 2.16.01.14.

    Isn't UARTMSP432E4 a specific library for MSP432? I'm using TM4C1294NCDPT.
  • In reply to daniolip:

    Ah yes, the MSP432E4 is one successor to the TM4C129 and so many of the peripherals/drivers are the same. But the naming is different.

    The TivaC UART driver seems to have the same control function code UART_CMD_GETRXCOUNT as can be seen here in the doxygen page for TI DRIVERS in 2.16.01.14.

    Let me know if you have further questions!

    Thanks,

    Sean

  • In reply to Sean Oliver28:

    Hi Sean,

    That solved my problem. Now I can implement a timeout for incomplete messages and get rid of my deadlock condition.

    Thanks.

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.