Hello,
I am using the UART driver in the DSP/BIOS PSP (1.30.01) at 115.2 k baud. We have a UART packet protocol that I need to receive.
The packet length can vary, but the format it always the same. Each field is a byte, except for the data
| start | length | command | variable data | checksum |
In order to handle the variable length data I want to read the number of bytes corresponding to theminimum packet length (six) and then read the remaining bytes once I know the length.
Can I change the timeout for IOM reads after I initialize the driver ?
The code below works fine (as long as I don’t get a timeout). I can change the timeout and it always blocks until I get the start of the packet then I read the rest.
If I actually get a timeout the status of the IOCTL calls says they succeeded, but the UART driver never resumes reading packets.
As several other people have posted it is a very common problem to need to read variable length data from a UART.
If it is not possible to do what is shown below, do you have any other suggestions ?
Thanks
while ( readRxData )
{
// wait as long as necessary for the start of a packet
len = MIN_PKT_LEN;
hUart_IN->timeout = SYS_FOREVER;
// Read
the minimum packet length
status = GIO_submit(hUart_IN,IOM_READ, buf, &len, NULL);
// calculate how many more (if any) bytes we need to read to get the rest of the packet
len = CalculateRemainingBytes(buf);
// once we have started to receive the packet, the rest should show up in less than 100 mS
// set a timeout in case we have slipped synchronization
hUart_IN->timeout = 100; // mS
status = GIO_submit(hUart_IN,IOM_READ, buf, &len, NULL);
if (!((status == IOM_COMPLETED)||(status == IOM_PENDING)))
{
LOG_printf(&trace, "\r\n Error from GIO_read \n");
// Reset the FIFO and cancel the current read.
status = GIO_control(hUart_IN, Uart_IOCTL_CANCEL_CURRENT_IO, 0);
status = GIO_control(hUart_IN, Uart_IOCTL_RESET_RX_FIFO, 0);
}