int novacom_usb_transport_start(void) { /*clear auth */ auth_reset(); /* create an event to drive the io worker thread */ platform_event_create(&usb_online_event); platform_event_unsignal(&usb_online_event); /* create a set of events to track the status of the io threads */ platform_event_create(&rx_shutdown_event); platform_event_unsignal(&rx_shutdown_event); platform_event_create(&tx_shutdown_event); platform_event_unsignal(&tx_shutdown_event); /* create a thread to run the control endpoint */ platform_create_thread(NULL, &ep0_thread, NULL); return 0; }
/* main worker thread */ static void *novacom_usb_findandattach_thread(void *arg) { novacom_usb_handle_t *usb; /* init records */ usbrecords_init(); /* initialize records queue */ TAILQ_INIT(&t_recovery_queue); /* device discovery */ while (!novacom_shutdown) { usb = novacom_usb_open(); if (usb ) { usb->shutdown = false; TRACEF("usb_handle 0x%08x, bus=%03d dev=%03d\n", usb->usbll_handle, usb->busnum, usb->devnum); platform_event_create(&usb->tx_startup_event); platform_event_unsignal(&usb->tx_startup_event); usb->tx_startup_wait = 1; platform_event_create(&usb->tx_shutdown_event); platform_event_unsignal(&usb->tx_shutdown_event); platform_create_thread(NULL, &novacom_usb_rx_thread, (void *)usb); platform_create_thread(NULL, &novacom_usb_tx_thread, (void *)usb); } if (!novacom_shutdown) { sleep(1); // dont peg the cpu waiting for usb /* check recovery records, shutdown interface if timeout expired */ (void) usbrecords_update( 1 ); /* assume 1sec delay */ } } /* update records: forcing shutdown of all records */ usbrecords_update(TRANSPORT_RECOVERY_TIMEOUT); return NULL; }