Allow psartial transfers and use them for usbserial

This commit is contained in:
Vladimir 'phcoder' Serbinenko committed 2010-07-19 08:43:01 +02:00
1 parent 824e1447ac
commit 34787305df
10 files changed
+93 -59

No files matched your search

+23
View File
@@ -100,3 +100,26 @@ grub_usbserial_attach (grub_usb_device_t usbdev, int configno, int interfno,
return 1;
}
int
grub_usbserial_fetch (struct grub_serial_port *port, grub_size_t header_size)
{
grub_usb_err_t err;
grub_size_t actual;
if (port->bufstart < port->bufend)
return port->buf[port->bufstart++];
err = grub_usb_bulk_read_extended (port->usbdev, port->in_endp->endp_addr,
sizeof (port->buf), port->buf, 10,
&actual);
if (err != GRUB_USB_ERR_NONE)
return -1;
port->bufstart = header_size;
port->bufend = actual;
if (port->bufstart >= port->bufend)
return -1;
return port->buf[port->bufstart++];
}
+1 -8
View File
@@ -111,16 +111,9 @@ real_config (struct grub_serial_port *port)
static int
ftdi_hw_fetch (struct grub_serial_port *port)
{
char cc[3];
grub_usb_err_t err;
real_config (port);
err = grub_usb_bulk_read (port->usbdev, port->in_endp->endp_addr, 3, cc);
if (err != GRUB_USB_ERR_NONE)
return -1;
return cc[2];
return grub_usbserial_fetch (port, 2);
}
/* Put a character. */
+1 -18
View File
@@ -127,26 +127,9 @@ real_config (struct grub_serial_port *port)
static int
pl2303_hw_fetch (struct grub_serial_port *port)
{
grub_usb_err_t err;
real_config (port);
if (port->bufstart < port->bufend)
return port->buf[port->bufstart++];
err = grub_usb_bulk_read_timeout (port->usbdev, port->in_endp->endp_addr,
sizeof (port->buf), port->buf, 10);
if (err != GRUB_USB_ERR_NONE)
return -1;
port->bufstart = 0;
/* FIXME: nearly always only one byte is transfered.
It happens however that more are transfered.
Setting sizeof (port->buf) to 1 leads code to stop reading after
such transfer. */
port->bufend = 1;
return port->buf[port->bufstart++];
return grub_usbserial_fetch (port, 0);
}
/* Put a character. */