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