/* Schedule new URB from WAITING to ACTIVE if the endpoint is free  */
void usbd_urb_schedule(usbd_device *dev)
/* Schedule new URB from WAITING to ACTIVE if the endpoint is free  */
void usbd_urb_schedule(usbd_device *dev)
{
	if (dev->urbs.force_all_new_urb_to_waiting) {
		LOG_LN("Could not schedule (force_all_new_urb_to_waiting = true)");
		return;
	}
	usbd_urb *urb = dev->urbs.waiting.head, *prev = NULL, *tmp;
	while (urb != NULL) {
		if (!try_alloc_ep_for_urb(dev, urb)) {
			prev = urb;
			urb = urb->next;
			continue;
		}
		tmp = urb;
		urb = queue_item_detach(&dev->urbs.waiting, prev, tmp);
		queue_item_append(&dev->urbs.active, tmp);
		LOGF_LN("[waiting] URB id=%"PRIu64" is now active", tmp->id);
		dev->backend->urb_submit(dev, tmp);
	}
}