Tool/software:
Hello,
I'm developing an application and using the LP-AM243 to do my initial development work. I'm using a UART in polled mode but I'm setting the timeout = 0, and the count = 94 which is the typical packet size sent to the LP-AM243 from the host PC. From the documentation it states that if a timeout happens then the count variable of the trans structure will be modified with the actual number of bytes read. Since the underlying FIFO is only 64 bytes I don't want any unnecessarily large timeout to wait for the full packet to come in, i manage building up the packet to the full size at my top layer of code, in addition there are times when the packet size changes for me and it always has a special character sequence at the end of packet so that the application knows what the packet is regardless of size.
I'm pretty sure this worked for me when I had originally used SDK Version 8 but when I use the latest version 11 I don't get the same behavior.
The trans.count value is always = 94 and never gets modified, as I debugged down into the layers of code I could see that in this function UART_readPolling(), for the case when the full trans.count number of bytes is not read that it changes the actual bytes read back to 0 during the UART_lld_Transaction_deInit() call. However, that doesn't even matter because the trans structure doesn't get passed down through the layers of code anyway.
At some point in the stack this function gets called UART_lld_read(), and the size and timeout variables are just passed by value, there is no way for the trans.count to be modified anymore.
As I dug through the layers I discovered that I could still access the actual number of bytes read by creating the line of code in green below, i just wanted to make the team aware of this issue, perhaps most people don't have variable size packets coming in so this wouldn't be an issue in those applications.
transferOK = UART_read(com, &trans);
// count=trans.count; //This doesn't work unless the full amount expected is read, if only a partial number of bytes is read it still is set to the full value
count = ((UART_Config *)com)->object->uartLld_handle->readCount; //This allows me to access the actual number of bytes read up at the top level of my code and solved my issue
//At this point in the stack the trans structure is not passed down any more and the hUART handle needs to be used recover readCount
int32_t UART_lld_read(UARTLLD_Handle hUart, void * rxBuf, uint32_t size, uint32_t timeout, const UART_ExtendedParams *extendedParams)
static int32_t UART_readPolling(UARTLLD_Handle hUart, UART_Transaction *trans)
...
else
{
/* Return UART_TRANSFER_TIMEOUT so that application gets whatever bytes are
* transmitted. Set the trans status to timeout so that
* application can handle the timeout. */
retVal = UART_TRANSFER_TIMEOUT;
trans->status = UART_TRANSFER_STATUS_TIMEOUT;
trans->count = hUart->readCount;
UART_lld_Transaction_deInit(&hUart->readTrans);
}
return (retVal);
}