From owner-freebsd-usb@FreeBSD.ORG Mon Sep 28 04:48:37 2009 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id F231D1065670; Mon, 28 Sep 2009 04:48:37 +0000 (UTC) (envelope-from pldrouin@pldrouin.net) Received: from smtp.cyberfingers.net (smtp.cyberfingers.net [198.177.254.227]) by mx1.freebsd.org (Postfix) with ESMTP id CEBD28FC1A; Mon, 28 Sep 2009 04:48:37 +0000 (UTC) Received: from mdaemon.pldrouin.net (CPE0023695b905f-CM001a666aca96.cpe.net.cable.rogers.com [99.246.67.95]) by smtp.cyberfingers.net (Postfix) with ESMTP id D4359AB6C14; Mon, 28 Sep 2009 00:45:46 -0400 (EDT) Message-ID: <4AC04026.9090202@pldrouin.net> Date: Mon, 28 Sep 2009 00:48:38 -0400 From: Pierre-Luc Drouin User-Agent: Thunderbird 2.0.0.23 (X11/20090824) MIME-Version: 1.0 To: freebsd-usb@freebsd.org, ed@freebsd.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Subject: Asynchronous Communications with uftdi/ucom (Is there a bug?) X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Sep 2009 04:48:38 -0000 Hi, I am trying to communicate with a fan controller that uses a FTDI FT232BL chip with uftdi/ucom and I am having troubles with asynchronous communications on FreeBSD (7.2 amd64 and 8.0-RC1 amd64, although what I present here has been obtained with 8.0-RC1 amd64). The exact same code works perfectly on Linux (amd64 on the same machine). I got synchronous communications working, but it seems that in asynchronous communications, SIGIO is generated randomly and read statements produce either junk or return the EINT, "Interrupted system call" error. What I did is to write simplified code where I only request the device to provide its status. I have a source file that performs this in synchronous mode (bigngtest.c) and another one that does this in asynchronous mode (bigngtestasync.c). I ran both codes while enabling debug mode for uftdi and ucom and I put the output to stdout and the output to dmesg in some files. I also created files where I put the output when running the same codes on Linux. These files can be found in a bzipped2 tar file here: http://download.yousendit.com/Y1Ryc0wwdGpVbTlFQlE9PQ To summarize, here is how I set asynchronous mode compared to synchronous mode, in a "diff" format > struct sigaction saio; < fd=open(DEV, O_RDWR | O_NOCTTY); > fd=open(DEV, O_RDWR | O_NOCTTY | O_NONBLOCK); ... > /* Install the signal handler before making the device asynchronous */ > saio.sa_handler = signal_handler_IO; > result = sigemptyset(&saio.sa_mask); > if(result<0) { > perror("sigemptyset"); > return 1; > } > saio.sa_flags = 0; > sigaction(SIGIO,&saio,NULL); > > /* Allow the process to receive SIGIO */ > fcntl(fd, F_SETOWN, getpid()); > /* Make the file descriptor asynchronous */ > fcntl(fd, F_SETFL, FASYNC); Please let me know if there are additional commands that are required to set asynchronous mode correctly on FreeBSD. Otherwise, it looks like there might be a bug somewhere in a kernel driver... Thank you! Pierre-Luc Drouin