ebiguy / RespeQt

RespeQt Atari serial peripheral emulator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RespeQt SIO timing is not correct when used with FTDI usb to serial device on linux (possibly other serial devices as well)

jzatarski opened this issue · comments

RespeQt does not delay between command acknowledge response and operation complete response when used with FTDI usb to serial device. The issue is caused by tcdrain which does not wait for the FTDI chips buffer to be empty, only the OS buffer. As a result, the transmit buffer is not empty when when the operation complete response is sent 300 microseconds later. This byte is added to the transmit buffer of the FTDI device. It is sent immediately after the Acknowledge Command response even though the minimum time between the two needs to be at least 250 microseconds or the Atari computer might miss the response and retry the operation after a long delay.

A temporary fix is to increase the delay between the Acknowledge Command response and the Operation Complete response by approximately the time it requires to send one byte (about 500 microseconds at 19200 baud). The same modification should be performed to the Operation Error response delay as well.

It is not clear whether tcdrain should wait for the hardware device's transmit buffer to be empty before returning, or not. The FTDI USB to serial device reportedly does return empty/not-empty status for the transmit buffer. I will attempt to work with the FTDI driver maintainer(s) to have tcdrain wait until the hardware buffer is empty as well within the FTDI device driver.

Further testing has revealed that tcdrain waits for the FTDI chip to empty it's buffer, but does not wait for the chip to finish sending the byte it is in the process of sending. It is likely a fact of the hardware that this does not work ideally. Furthermore, the timing of tcdrain returning when using an FTDI device does not seem to be consistent in all cases. When sending one byte, such as the Operation Complete or Operation Error byte, the timing of tcdrain appears to be sufficiently consistent for the purposes of an atari SIO emulator. The quick fix for now is an increase in the delay of these two responses to ensure they occur with the minimum delay required by the atari. The long term fix is to use this longer value as a default, and allow configuration of this delay in the configuration menu.