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.

RTOS/TM4C1294NCPDT: UART read Timeout Problem

Part Number: TM4C1294NCPDT

Tool/software: TI-RTOS

TI-RTOS: v2.01.00.03

CCS: v6.0.1.0040

Hello,

I am working on project in which dont Know the Recived Data Length. I intialize Uart Parameter as Below.

Void com0TaskFxn(UArg arg0, UArg arg1)
{
        char rxBuffer[256], txBuffer[256];
	int ret, i;

  	UART_Handle      handle = NULL;
  	UART_Params      params;

	UART_Params_init(&params);
	params.baudRate  = usr_s.uart[STRUCT_INDEX_COM0].baud_rate;      // baud rate is configure By user.

	params.dataLength = UART_LEN_8;
	params.parityType = UART_PAR_NONE;
	params.stopBits = UART_STOP_ONE;

	params.writeDataMode = UART_DATA_BINARY;
	params.readDataMode = UART_DATA_BINARY;
	params.writeMode = UART_MODE_CALLBACK;
	params.writeCallback = (UART_Callback)(&com0WriteCompleteCallbackFunction);
	params.readReturnMode = UART_RETURN_FULL;
	params.readEcho = UART_ECHO_OFF;

	params.readTimeout = ? 

	  handle = UART_open(STRUCT_INDEX_COM0, &params);
	  if (!handle) {
	      System_printf("COM 0 UART did not open");
	  }
	  else
	  {
		  System_printf("COM 0 UART_initialised\n");
	  }

	  /* Clear store buffer */
	  rxBuffer[0] = 0;

	  while(1)
	  {
		  if(!GPIO_read(FACTORY_RESET_AND_UART_CONFIG_MODE_SWITCH))
		  {
			  uart0_mode = UART0_MODE_UIMANAGER;
			  goto com0_re_initialise_position;
		  }

		  ret = UART_read(handle, &rxBuffer, 250);

		  if(ret > 0)
		  {
			  /* Add null pointer to buffer for string sending */
			  rxBuffer[ret + 1] = 0;


			  if(sys_state.tcpServer1_is_active == true)
			  {
				  Mailbox_post(mboxCom0Rx4S1, rxBuffer, TCP_SERVER_TASK_MAIN_LOOP_DELAY_IN_MS + 5);//500);
			  }

		  }

		  if(Mailbox_pend(mboxCom0Tx, txBuffer, BIOS_NO_WAIT))
		  {
			  ret = UART_write(handle, &(txBuffer[1]), (int)txBuffer[0]);
		  }

	  }

  }

As per TI User Manual:

The receive timeout interrupt is asserted when the receive FIFO is not empty, and no further data is received over a 32-bit period when the HSE bit is clear or over a 64-bit period when the HSE bit is set.
The receive timeout interrupt is cleared either when the FIFO becomes empty through reading all the data (or by reading the holding register), or when a 1 is written to the corresponding bit in the UARTICR register.

My question is

<1>  read Timeout is the timeout is in "milliseconds" or in "seconds".

<2>  read Timeout is for 1 Byte or for whole 250 Bytes.

<3>  As In my code baud rate is not fix, In that case What should be read Timeout?

<4> In case of No data to read, After How much time UART_READ() return 0.

  • 1) The units for the readTimeout parameter are in SYS/BIOS Clock ticks. By default, the SYS/BIOS Clock tick period is 1ms, so the timeout is in milliseconds.

    2) The read Timeout is independent of the number of bytes requested in the UART_read() command. Whether you request 1 or 250 bytes, UART_read() will timeout after readTimeout Clock ticks if the number of bytes requested have not been received.

    3) If your application needs the readTimeout, then you'll have to calculate the timeout value that suits your needs based on the maximum number of bytes you want to read, and the slowest baudrate. Otherwise, set readTimeout to zero so that UART_read() will block indefinitely until all the characters requested have been received.

    4) UART_read() will return 0 after the number of readTimeout Clock ticks have passed. If readTimeout is set to zero, UART_read() will not return until the number of bytes requested have been received.

    Alan
  • Hi Alan,

    Thanks For Reply.

    In my code i dont know how many Bytes i have to read so i have to use readTimeout. And I use both UART_read() & UART_write In same while loop I cant set readTimeout to 0 and set UART_read() in Blocking Mode.But the problem is i dont know when readTimeout Clock is trigger?

    suppose In case i given 250 Bytes In UART_read() , And I am getting 240 Bytes only. so readTimeout Clock Trigger after 240 Bytes or when I call the UART_read() ?

    As per TI User Manual:

    The receive timeout interrupt is asserted when the receive FIFO is not empty, and no further data is received over a 32-bit period when the HSE bit is clear or over a 64-bit period when the HSE bit is set.

    The receive timeout interrupt is cleared either when the FIFO becomes empty through reading all the data (or by reading the holding register), or when a 1 is written to the corresponding bit in the UARTICR register.

    so, As i understand the readTimeout Clock is start only After i received 240 Bytes. so i have to calculate only the time required for reading 1 Byte only. For 9600 Baud Rate It requires  1 ms  Approx. so I have to set

      params.readTimeout = 1

    Is this Right?

     

  • No.

    The 'readTimeout' parameter that the UART driver uses IS NOT RELATED TO the receive timeout interrupt provided by the UART peripheral (the interrupt described in the TI User Manual you reference).

    The readTimeout is used to configure and start an internal one-shot SYS/BIOS Clock object when UART_read() is called. The one-shot IS NOT retriggered on each received character. UART_read() will return either when the number of bytes requested have been received, or after the one-shot times out, whichever is soonest.

    If you set the readTimeout to 1, then a 1 millisecond one-shot clock object is started when UART_read() is called. If after 1ms the number of characters asked for have not been received, UART_read() will return anyway.

    Alan
  • Hi Alan,

    As per your Last Reply:

    The 'readTimeout' parameter that the UART driver uses IS NOT RELATED TO the receive timeout interrupt provided by the UART peripheral (the interrupt described in the TI User Manual you reference).

    But As per TI User Manual:

    The receive timeout interrupt is asserted when the receive FIFO is not empty, and no further data is received over a 32-bit period when the HSE bit is clear or over a 64-bit period when the HSE bit is set.


    So, what its meaning?

  • The UART driver is not configuring the Tiva UART to generate the timeout interrupt you are referencing. As I mentioned before, the 'readTimeout' parameter is being used internally to set the timeout duration of a SYS/BIOS Clock object configured in one-shot mode. The 'readTimeout' units are in the 'tickPeriod' of the Clock module, which by default is 1ms.