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 behaviour after recovering from timeout error

Other Parts Discussed in Thread: OMAP-L138

Hello,

I am using UART from PSP 1.30.01 to communicate with a computer with packets very similar to those described in this post : http://e2e.ti.com/support/embedded/bios/f/355/t/111541.aspx and I have problems making Uart work after a timeout error (IOM_ETIMEOUTUNREC).

Here is a test function I have written to understand how UART works :

GIO_Handle hInput;
size_t size;
unsigned char buffer[50];
int i =0;
int status;
memset(buffer, 0, sizeof(buffer));

... // Create hInput : interrupt mode, 19200 bps

hInput->timeout = SYS_FOREVER;
size = 1;
status = GIO_read(hInput, buffer+0, &size);
// 1) DSP waits for me. I send 'A' on serial link using Tera Term

// Here, status==IOM_COMPLETED
// and buffer = ['A', 0, 0, 0, 0 ...]
hInput->timeout = 1000;
size = 1;
status = GIO_read(hInput, buffer+1, &size);
// 2) I wait for timeout to expire (~1s)

// Here, status==IOM_ETIMEOUTUNREC
// and buffer = ['A', 0, 0, 0, 0 ...]
GIO_control(hInput, Uart_IOCTL_RESET_RX_FIFO, 0);
GIO_control(hInput, Uart_IOCTL_CANCEL_CURRENT_IO, 0);

hInput->timeout = SYS_FOREVER;
size = 1;
status = GIO_read(hInput, buffer+2, &size);
// 3) I don't send any character, but DSP does not wait for me and goes on without error !!!

// Here, status==IOM_COMPLETED
// and buffer = ['A', 0, 0, 0, 0 ...]

hInput->timeout = SYS_FOREVER;
size = 1;
status = GIO_read(hInput, buffer+3, &size);
// 4) DSP waits for me. I send 'B' on serial link using Tera Term

// Here, status==IOM_COMPLETED
// and buffer = ['A', 0, 'B', 0, 0, ....]     instead of  ['A', 0, 0, 'B', 0, ....]

I don't understand why program goes on in 3) although timeout is FOREVER and why 'B' is written at index=2 instead of index=3.

Thanks in advance if someone has an explanation,

Romain

PS : CCS 3.3  -   DSP/BIOS 5.41.13.42    -    CGT 6.1.21   -  LogicPD's OMAP-L138 SOM-M1

  • Romain,

    I am moving this thread over to the device forum in hopes that it will get a faster response there.

  • Hi Romain,

    Thanks for your post.

    In my understanding, the issue could be a delay in the synchronization in receiving packets through UART. I would recommend you to set a character timeout delay of less than 200ms by checking the staus == IOM_COMPLETED, wait for a time out period and if it fails within the timeout, may be, you shall print error message to investigate for better clarity.

    Once we receive the start of a packet and for the remaining packets to show up, you can choose a typical timeout period to avoid synchronization gap across the Rx. packets.

    Thanks & regards,

    Sivaraj K

    ---------------------------------------------------------------------------------
    Please click the
    Verify Answer button on this post if it answers your question.
    ---------------------------------------------------------------------------------

     

  • Hello Sivaraj,

    Thank you for your help.

    What you advise is something like that, right ?

    while(1)
    {
     hInput->timeout = 100; // ms
     size = 1;
     // Wait for 1st character of packet
     do
     {
      status = GIO_read(hInput, buffer+0, &size);
     }
     while(status != IOM_COMPLETED);
     // Wait for the rest of the packet
     // for example, let's say that packets are always 5 characters long
     hInput->timeout = 400;
     size = 4;
     status = GIO_read(hInput, buffer+1, &size);
     if (status == IOM_COMPLETED)
     {
      // Reception ok, process the packet
      ...
     }
     else
     {
      GIO_control(hInput, Uart_IOCTL_RESET_RX_FIFO, 0);
      GIO_control(hInput, Uart_IOCTL_CANCEL_CURRENT_IO, 0);
     }
    }

    What I find difficult to understand is that, after a timeout error and a call to GIO_control(hInput, Uart_IOCTL_CANCEL_CURRENT_IO, 0), the first call to GIO_read is non blocking and the second one is queued and blocking.

    Regards,

    Romain

  • Romain,

    You are exactly fine with my understanding.

    Try adjusting your time out period (high/low) to avoid block on the second call. Please try to choose an optimum timeout which would help out to stay always with in IF loop, sothat, you are forcefully providing an adjustable timeout for successful reception of UART packets.

    Thanks for your update.

    Thanks & regards,

    Sivaraj K

    ---------------------------------------------------------------------------------
    Please click the
    Verify Answer button on this post if it answers your question.
    ---------------------------------------------------------------------------------
  • I finally made the program read the UART one byte by one byte and don't use the "GIO_control(hInput, Uart_IOCTL_CANCEL_CURRENT_IO, 0)" command.

    Not perfect but that works.

    Thanks !