[Ftdi-usb-sio-devel] Using status bytes from FTDI devices
Brought to you by:
bryder
From: Craig V. D. <cr...@yo...> - 2007-02-09 22:59:44
|
I am using ftdi_sio with a DLP-2232PB-G protoboard that uses an FT2232C chip. The protoboard includes a PIC16F877A processor with which I am communicating. When I first tried using ftdi_sio, the responses from the device never reached my application code. read() just hung. I traced the problem down to the fact that the protoboard responses did not terminate with newline characters and therefore the buffer transfer from kernel to application was not made. All responses are preceded by a pair of status bytes, the second of which is identified in ftdi_sio.h as: * Byte 1: Line Status * * Offset Description * B0 Data Ready (DR) * B1 Overrun Error (OE) * B2 Parity Error (PE) * B3 Framing Error (FE) * B4 Break Interrupt (BI) * B5 Transmitter Holding Register (THRE) * B6 Transmitter Empty (TEMT) * B7 Error in RCVR FIFO * */ #define FTDI_RS0_CTS (1 << 4) #define FTDI_RS0_DSR (1 << 5) #define FTDI_RS0_RI (1 << 6) #define FTDI_RS0_RLSD (1 << 7) #define FTDI_RS_DR 1 #define FTDI_RS_OE (1<<1) #define FTDI_RS_PE (1<<2) #define FTDI_RS_FE (1<<3) #define FTDI_RS_BI (1<<4) #define FTDI_RS_THRE (1<<5) #define FTDI_RS_TEMT (1<<6) #define FTDI_RS_FIFO (1<<7) I solved my problem by using the FTDI_RS_TEMT bit to tell me if the received data was complete. If it was complete and did not already end in a 0x0A, I added a 0x0A to the data stream as it was processed by ftdi_process_read() in ftdi_sio.c. (Are there some devices that end with just a 0x0D?) The fix is shown here: http://yosemitefoothills.com/Electronics/ftdi_sio.c_fix.html Obviously, one can insist that all devices end their messages with a newline character, but that seems to be completely redundant to the status bytes that already precede the line. The newline character therefore would reduce throughput without adding anything new. With all that background, I am asking: Is my fix is reasonable to apply to the ftdi_sio code? Will any other devices benefit from it? Will it cause trouble for any FTDI-based devices? This may be related to the parity error problem mentioned in the lines following my fix. Maybe that can also be solved now. Craig |