Hi,
I have some problem with io-char low level control fonction in RS485 serial
communication
I want to use a RS485 serial interface controlled by an 8250’s UART on QNX
6.2.
I use this script to control RTS signal and write data :
int fd;
int iReg;
char data[DATA_SIZE];
fd = open("/dev/ser2", O_RDWR); // Open device (speed 9600 Bds)
iReg = _CTL_RTS_CHG | _CTL_RTS; // Set RTS to 1
devctl (fd, DCMD_CHR_SERCTL, & iReg, sizeof(iReg), NULL);
write( fd, data, DATA_SIZE); // Send Data
// Wait until all output has been transmitted to device
devctl(__fildes, DCMD_CHR_TCDRAIN, NULL, 0, NULL);
iReg = _CTL_RTS_CHG; // Set RTS to 0
devctl (fd, DCMD_CHR_SERCTL, & iReg, sizeof(iReg), NULL);
close (fd); // Close device
I tested it and I observed two behaviors :
. if DATA_SIZE > 2 : It work !!!
. if DATA_SIZE <= 2 : There is some problem. All data aren’t
transmitted.
After having examined devc-ser820 source (DDK QNX 6.2) and io-char library
source (QNX 6.1A on cvs.qnx.com), I think I find a trouble on io-char
library. On file ‘io_devctl.c’, line 22 :
The test for beginning to test the 8250 LSR_TSRE bit on a drain request is
if(bup->cnt) {
// Start Waiting …
}
In the case of a small writing request (DATA_SIZE <= 2), when we call devctl
with TCDRAIN request, soft FIFO is empty, but hardware FIFO isn’t and all
data aren’t transmitted or serialized. Unfortunately, with this test, 8250
LSR_TSRE bit is never tested. So the drain function does not work properly.
This problem can be more serious if UART transmit FIFO is larger or if
interface speed is faster.
Do you think I do a mistake, or is it really a bug ?
Any information you can provide will be greatly appreciated. Thanks
KUBIT Stéphane