Tool/software: TI-RTOS
Hi
I have a problem with using the UART driver, it seems during each callback I am loosing one byte.
1. If I take a look at c:\ti\pdk_am437x_1_0_8\packages\ti\drv\uart\src\v1\UART_v1.c, it does a byte read at the end of the while loop, but if size is 0, this byte gets discarded!
2. In the uart driver layer (csl) UARTCharGetNonBlocking(hwAttrs->baseAddr) returns -1 on no data. This is returned in a int8_t thus it will not be possible to receive any binary data that are 0xFF ???
It seems though that in starterware UARTCharGetNonBlocking() is returning an int (32 bit). So which function is used by the uart driver?
The same problem applies to int8_t UARTCharGet(uint32_t baseAddr).
This IS a bug in csl an should be fixed.
/*
* ======== UART_v1_readData ========
* Read and process data from the UART.
*/
static inline int32_t UART_v1_readData(UART_Handle handle, int32_t size); /* for misra warnings*/
static inline int32_t UART_v1_readData(UART_Handle handle, int32_t size)
{
int32_t readIn;
UART_V1_Object *object;
UART_HwAttrs const *hwAttrs;
object = (UART_V1_Object*)handle->object;
hwAttrs = (UART_HwAttrs*)handle->hwAttrs;
readIn = (int32_t)UARTCharGetNonBlocking(hwAttrs->baseAddr);
/* Receive chars until empty or done. */
while ((size != 0) && (readIn != (int32_t)(-1)))
{
/* If data mode is set to TEXT replace return with a newline. */
if (object->params.readDataMode == UART_DATA_TEXT)
{
if ((uint8_t)readIn == ((uint8_t)('\r')))
{
/* Echo character if enabled. */
if (object->params.readEcho)
{
UARTCharPut(hwAttrs->baseAddr, ((uint8_t)('\r')));
}
readIn = (int32_t)'\n';
}
}
UART_drv_log2("UART:(0x%x) Read character 0x%x",
hwAttrs->baseAddr, (uint8_t)readIn);
*(uint8_t *)object->readBuf = (uint8_t)readIn;
object->readBuf = (uint8_t *)object->readBuf + 1;
object->readCount++;
size--;
/* Echo character if enabled. */
if (object->params.readEcho)
{
UARTCharPut(hwAttrs->baseAddr, (uint8_t)readIn);
}
/* If read return mode is newline, finish if a newline was received. */
if ((object->params.readReturnMode == UART_RETURN_NEWLINE) &&
((uint8_t)readIn == ((uint8_t)('\n'))))
{
UART_drv_log1("UART:(0x%x) Newline character received, ",
hwAttrs->baseAddr);
size = 0;
break;
}
readIn = (int32_t)UARTCharGetNonBlocking(hwAttrs->baseAddr); // THIS WILL READ EXTRA CHARACTER FROM RX FIFO - IF ONE IS PRESENT! Must skip this if size is 0!
}
return (size);
}