Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The ulpt_write_callback function transfers data from user space to the printer (to be printed). Recall that this function is the callback for a bulk OUT endpoint, so it’s executed before and after a bulk OUT transfers data.
The following is the function definition for ulpt_write_callback:
static void
ulpt_write_callback(struct usb_xfer *transfer, usb_error_t error)
{
struct ulpt_softc *sc = usbd_xfer_softc(transfer);
struct usb_fifo *fifo = sc->sc_fifo_open[USB_FIFO_TX];
struct usb_page_cache *pc;
int actual, max;
usbd_xfer_status(transfer, &actual, NULL, NULL, NULL);
if (fifo == NULL)
return;
switch (USB_GET_STATE(transfer)) {
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
setup:
pc = usbd_xfer_get_frame(transfer, 0);
max = usbd_xfer_max_len(transfer);
if (
usb_fifo_get_data(
fifo,
pc, 0,
max,
&actual, 0)) {
usbd_xfer_set_frame_len(transfer, 0,
actual);
usbd_transfer_submit(transfer);
}
break;
default:
if (error != USB_ERR_CANCELLED) {
/* Issue a clear-stall request. */
usbd_xfer_set_stall(transfer);
goto setup;
}
break;
}
}