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.

UART Buffering Concepts in TI-RTOS

MCU: TM4C1294NCPDT

TI-RTOS: v2.01.00.03

CCS: v6.0.1.0040

Hello,

    I am going to add UART functionality in my project. I have gone through the UART documentation(s) but am not understanding HOW THE UART BUFFER ALLOCATION IS DONE!! What I mean is that when we call the function UART_read [in blocking mode, no call backs & timeout set to BIOS_WAIT_FOREVER] it will block execution of the task until the desired number of bytes (size of the buffer passed to this function) have been received.

    Imagine a situation where due to some reason, the function UART_read is not called for a long time & a very huge number of bytes arrived on the UART port. What will happen?

1.    The RTOS is going to allocate RAM to these UART data and the system will start starving for RAM

2.    The UART driver will stop accepting any new byte (may be because the RTOS's UART buffer is full) coming in through the UART & will ignore all new data

3.    The UART driver will keep on accepting new data & will keep on deleting old ones (FIFO type)

4.    Even if situation 2 and/or 3 happens, how is the size of the RTOS's UART buffer determined or decided? I mean what function to use to set the value?

    Somewhere, I feel I am missing something or having some misconception!!

Thanks

Regards

Soumyajit

  • Hi Soumyajit,

    The TI-RTOS UART is pretty simple, it only reads/writes data when the application calls the UART_read/write APIs.  It does not allocate memory, so it will not take any more resources than what is needed to open the driver.  Additionally, the UART driver does not create/maintain any internal buffers for data (not copy based).  UART_read/write APIs require that a pointer to a buffer (for the data sent/received) to be passed in as a parameter.  It is the 

    /*!
     *  @brief  Function that read data from a UART
     *
     *  This function initiates an operation to read data from a UART controller.
     *
     *  In UART_MODE_BLOCKING, UART_read will block task execution until all
     *  the data in buffer has been read.
     *
     *  In UART_MODE_CALLBACK, UART_read does not block task execution an calls a
     *  callback function specified by readCallback.
     *
     *  @param  handle      A UART_Handle
     *
     *  @param  buffer      A pointer to an empty buffer in which data should be
     *                      written to
     *
     *  @param  size        The number of bytes to be written into buffer
     *
     *  @return Returns the number of bytes that have been read from the UART,
     *          UART_ERROR on an error.
     */
    extern int UART_read(UART_Handle handle, void *buffer, size_t size);

    Soumyajit Das said:

        Imagine a situation where due to some reason, the function UART_read is not called for a long time & a very huge number of bytes arrived on the UART port. What will happen?

    In this situation, the data will be ignored by the UART driver.

    We are currently reviewing different approaches to allow for some buffering to occur in the driver (which will address your concern with what happens to data received if UART_read is not called); but we currently do not have a fixed date when this will be added.  

    Hope this helps,

    -- Emmanuel