views:

105

answers:

1

Hello,

I am trying to port (or rather customize) a pure Linux application to OS X Snow Leopard (10.6.4). It is an application that sends a binary to a target hardware over the serial port. The app is almost running but i am hit with an interesting problem with the serial port writes.

With all the same settings as Linux (115.2k is the baudrate) OS X serial data send seems to be some 10 times or more slower compared to Linux. What takes 3 secs in Linux , takes 30-40 secs and by that time the target firmware at the receiving end times out :).

Digging in to the serial port write function, i see that it is using select() system call to find if the device (or rather the file descriptor) is ready to write data to. Each write system call writes 1024 bytes of data in OS X and 1087 bytes of data in Linux (Thats what the return value of write is). My data size is some 50KB for a first level binary (it is a small bootloader which can load a bigger binary in the next level).

Pseudo code

    select() configuration with 1s time out and observing the serial port file descriptor for write ready.
while(true)
{
rc=select(...)
if(rc>0){write(...) and other logic to get out of while if done}
if(rc==0){//try again}
if(rc<0){//error}
}

I observed that in linux, writes happen all the time one after another . A sequence of writes and it comes out of the function in a jiffy. But, in OS X, it is like 3 writes and then select returns zero twice (2 seconds gone) again a few writes and select time out etc etc making the function a lot slower.

Any clues?

Notes: The app is using termios lib API to control the serial port.

+1  A: 

I could fix this by changing the prolific chip device driver. By default it was using a non-standard open source driver, I downloaded the OS X driver from the prolific website and it works ok. Thanks to Nils and others for the support!

Deepak Narayan