U2CR test-case:
test.sh
: test running P1 and P2 interleaved until the error is detected.p1.sh
: process P1 which creates problems.p2.sh
: process P2 which detect the problem.
Process 1 p1.sh
:
-
- Send a status request, like "\xff\x01\x03"
-
- Do not read the answer.
Process 2 p2.sh
:
-
- Send another status request, like "\xFF\x02\x03"
-
- Read the answer
-
- Check the answer is the good one : \xFF\x02\xXX"
The problem can happen at point 2 of process 2 where in fact you can receive the status requested by process 1.
root@nuclab:~/u2cr-unsync# ./test.sh /dev/ttyUSB0
answer received:
01ff0a
data received then:
020a
answer expected: FF02XX
the expected answer is out-of-sync - offsetted by P1 request
the answer can be truncated because linux ftdi driver reset the device which flushes the RX/TX FIFOS
root@nuclab:~/u2cr-unsync# ./test.sh /dev/ttyUSB0
answer received:
ff010a
data received then:
ff020a
answer expected: FF02XX
the expected answer is out-of-sync - offsetted by P1 request
the answer can be truncated because linux ftdi driver reset the device which flushes the RX/TX FIFOS
Given the facts that:
- The linux driver
ftdi_sio
resets the ftdi chipset which flushes the RX and TX FIFOs. - The USB data is read by polling the ftdi device (debugged using wireshark on usbmon). There are no interrupts.
- Flushing the kernel TTY FIFOs using
tcflush()
after flushing the USB FIFOs does not solve the issue.
It means the KMTronic device behing the FTDI device is processing the request during the USB or TTY flush operations. Which explains why all or part of the previous unterminated answer of P1 is received by P2.
Linux nuclab 4.5.0-2-amd64 #1 SMP Debian 4.5.4-1 (2016-05-16) x86_64 GNU/Linux
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 1
On-line CPU(s) list: 0
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 55
Model name: Intel(R) Atom(TM) CPU E3815 @ 1.46GHz
Stepping: 3
CPU MHz: 533.194
CPU max MHz: 1466.3000
CPU min MHz: 533.2000
BogoMIPS: 2930.40
Virtualization: VT-x
L1d cache: 24K
L1i cache: 32K
L2 cache: 512K
NUMA node0 CPU(s): 0
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm sse4_1 sse4_2 movbe popcnt tsc_deadline_timer aes rdrand lahf_lm 3dnowprefetch epb tpr_shadow vnmi flexpriority ept vpid tsc_adjust smep erms dtherm arat