Hi,
 
I have used usb.c ( as posted on Wavinci Wiki page for USB to PCI loopback). I 
modified this by removing some of PCI waitforInterrupt calls and was testing 
with two sink and source threads with pthread_cond_wait and 
pthread_cond_broadcast. Essentially 
 
-  The source thread blocks with a call to pthread_cond_wait
- The sink thread receives data from USB bus and after reading in a buffer 
broadcast to source thread
- The source thread should wake up and write back this data
 
The issue is I do see the call for broadcast to test_cond ( my conditional 
variable) but never see the source thread being woken up by this. Is there 
anything I am doing wrong in this code snippet:
 
WRITE (source thread) 
 
do {
      /* original LinuxThreads cancelation didn't work right
* so test for it explicitly.
*/
pthread_testcancel ();
pthread_mutex_lock(&test_mutex);

if (data_received == 0) {
printf("blocked on cond\n");
ret = pthread_cond_wait(&test_cond, &test_mutex);
printf("write ret = %d\n", ret); 
}
printf("Got data \n");
status = write (source_fd, buffer, USB_BUFSIZE);
data_received = 0; 
pthread_mutex_unlock(&test_mutex);

} while (status >= 0);
 
 
Read (or Sink Thread )
 
do {
/* original LinuxThreads cancelation didn't work right
* so test for it explicitly.
*/
/* pthread_testcancel ();*/
errno = 0;
/* get mutex as we need to protect buffer and data_sent flag */
pthread_mutex_lock(&test_mutex);


/* Read the data from USB into mmap'ed buffer */
status = read (sink_fd, buffer, USB_BUFSIZE);
if (status < 0) {
/* give up mutex */
pthread_mutex_unlock(&test_mutex);
break;
}
data_received=1;

if (data_received == 1) {
/* signal write task */
printf("broadcast to cond\n");
ret = pthread_cond_broadcast(&test_cond);
printf("read ret= %d\n", ret);
}
/* give up mutex */
pthread_mutex_unlock(&test_mutex);
printf("Read data from buffer\n");
printf("read unlocking mutex\n status = %d", status);


} while (status > 0);
 
 
 
 
 
 


      
_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

Reply via email to