Yes Greg, absolutely. It has no problem working without two threads. I can
write a HCI reset packet and I get correct response from the subsequent
read. I was wondering if at all I need look at the flip-buffer of tty layer
when debugging the issue with read when the read part is handled in a
different thread. Because once a seperate thread starts handling read, with
termios settings VMIN = 1 the read never returns at all and when VMIN=0
read returns, but with zero bytes read. I have again appended my original
mail with the code stub for easy reference below. What might be the problem,
any ideas ?

Thanks
amol

>2004-08-12 15:41, Greg KH wrote :

>I really don't know, sorry.  Odds are it's a syncronization issue.
> Does it work without 2 threads?
>
>thanks,

>greg k-h



>On Thu, Aug 12, 2004 at 06:30:04PM +0530, Amol Kailash wrote:

> Hi Greg,
>               I have a bluetooth stack as a shared object. While starting
> the stack I initiate a pthread to read from the tty driver in a loop. The
 main thread meanwhile sends a HCI reset packet to the tty driver using the
 write function as shown in the code stub below. Now my problem is when the
 dcb->c_cc[VMIN] = 1, the read function never returns at all, even after I
 added synchornization so that the first read executes only after the
 usb_write function writes a reset packet. So I set dcb->c_cc[VMIN] = 0, now
 read returns alright, but never returns a single byte. Will it have
 something to do with the bluetooth tty driver and some issues with the tty
 buffer that it uses or would it be some sort of a timing problem with the
 read thread syncronization ? And how can I go about solving this ?



 -----------------------------------------------------Code------------------
-
 --------------------------

 HANDLE cardHandle =NULL;

 main(){

     usb_connect(...);
     usb_write(...);

 }

 usb_connect(...){

 termios *dcb =NULL;

 if ((cardHandle = open("/dev/ttyUB0", O_RDWR | O_NOCTTY | O_NDELAY)) == -1)
    goto error;

           fcntl(g_btsInfo.cardHandle,F_SETFL,0);
           tcgetattr(g_btsInfo.cardHandle,dcb);
           cfsetispeed(dcb,B57600);
           cfsetospeed(dcb,B57600);

       dcb->c_cflag &=~PARENB;
       dcb->c_cflag &=~CSTOPB;
       dcb->c_cflag &=~CSIZE;
       dcb->c_cflag |=CS8;
       dcb->c_cflag |=CRTSCTS;
       dcb->c_cflag |=CLOCAL |CREAD;
       dcb->c_lflag = 0;  // enable non canonical input with no echo
       dcb->c_oflag=0;
       dcb->c_iflag&=~(IXON | IXOFF | IXANY);
       dcb->c_iflag |=IGNPAR;
       dcb->c_cc[VMIN] = 1;            // returns when there is 1 byte in
 buffer
        tcflush(cardHandle, TCIFLUSH);
        tcsetattr(cardHandle,TCSANOW,dcb);

       pthread_create( &thread_id, NULL, readThread, NULL);

 }

 readThread(){

     while(threadNotStopped){

             nbytes = read(cardHandle, readBuf, count);

     }

 }

 usb_write(....){



     nbytes = write(cardHandle, writeBuf, count);

 }



 Thanks
 regards
 amol






-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to