USBv1 code optimization.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8660 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
ac528c28c7
commit
834cea0441
|
@ -212,31 +212,22 @@ static void usb_serve_endpoints(USBDriver *usbp, uint32_t ep) {
|
||||||
const USBEndpointConfig *epcp = usbp->epc[ep];
|
const USBEndpointConfig *epcp = usbp->epc[ep];
|
||||||
|
|
||||||
if (epr & EPR_CTR_TX) {
|
if (epr & EPR_CTR_TX) {
|
||||||
size_t transmitted;
|
|
||||||
/* IN endpoint, transmission.*/
|
/* IN endpoint, transmission.*/
|
||||||
|
USBInEndpointState *isp = epcp->in_state;
|
||||||
|
|
||||||
EPR_CLEAR_CTR_TX(ep);
|
EPR_CLEAR_CTR_TX(ep);
|
||||||
|
|
||||||
/* Double buffering is always enabled for isochronous endpoints, and
|
isp->txcnt += isp->txlast;
|
||||||
although we overlap the two buffers for simplicity, we still need
|
n = isp->txsize - isp->txcnt;
|
||||||
to read from the right counter. The DTOG_TX bit indicates the buffer
|
|
||||||
that is currently in use by the USB peripheral, that is, the buffer
|
|
||||||
from which the next packet will be sent, so we need to read the
|
|
||||||
transmitted bytes from the counter of the OTHER buffer, which is
|
|
||||||
where we stored the last transmitted packet.*/
|
|
||||||
transmitted = (size_t)USB_GET_DESCRIPTOR(ep)->TXCOUNT0;
|
|
||||||
if (EPR_EP_TYPE_IS_ISO(epr) && !(epr & EPR_DTOG_TX))
|
|
||||||
transmitted = (size_t)USB_GET_DESCRIPTOR(ep)->TXCOUNT1;
|
|
||||||
|
|
||||||
epcp->in_state->txcnt += transmitted;
|
|
||||||
n = epcp->in_state->txsize - epcp->in_state->txcnt;
|
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
/* Transfer not completed, there are more packets to send.*/
|
/* Transfer not completed, there are more packets to send.*/
|
||||||
if (n > epcp->in_maxsize)
|
if (n > epcp->in_maxsize)
|
||||||
n = epcp->in_maxsize;
|
n = epcp->in_maxsize;
|
||||||
|
|
||||||
/* Writes the packet from the defined buffer.*/
|
/* Writes the packet from the defined buffer.*/
|
||||||
epcp->in_state->txbuf += transmitted;
|
isp->txbuf += isp->txlast;
|
||||||
usb_packet_write_from_buffer(ep, epcp->in_state->txbuf, n);
|
isp->txlast = n;
|
||||||
|
usb_packet_write_from_buffer(ep, isp->txbuf, n);
|
||||||
|
|
||||||
/* Starting IN operation.*/
|
/* Starting IN operation.*/
|
||||||
EPR_SET_STAT_TX(ep, EPR_STAT_TX_VALID);
|
EPR_SET_STAT_TX(ep, EPR_STAT_TX_VALID);
|
||||||
|
@ -247,26 +238,30 @@ static void usb_serve_endpoints(USBDriver *usbp, uint32_t ep) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (epr & EPR_CTR_RX) {
|
if (epr & EPR_CTR_RX) {
|
||||||
EPR_CLEAR_CTR_RX(ep);
|
|
||||||
/* OUT endpoint, receive.*/
|
/* OUT endpoint, receive.*/
|
||||||
|
|
||||||
|
EPR_CLEAR_CTR_RX(ep);
|
||||||
|
|
||||||
if (epr & EPR_SETUP) {
|
if (epr & EPR_SETUP) {
|
||||||
/* Setup packets handling, setup packets are handled using a
|
/* Setup packets handling, setup packets are handled using a
|
||||||
specific callback.*/
|
specific callback.*/
|
||||||
_usb_isr_invoke_setup_cb(usbp, ep);
|
_usb_isr_invoke_setup_cb(usbp, ep);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
USBOutEndpointState *osp = epcp->out_state;
|
||||||
|
|
||||||
/* Reads the packet into the defined buffer.*/
|
/* Reads the packet into the defined buffer.*/
|
||||||
n = usb_packet_read_to_buffer(ep, epcp->out_state->rxbuf);
|
n = usb_packet_read_to_buffer(ep, osp->rxbuf);
|
||||||
epcp->out_state->rxbuf += n;
|
osp->rxbuf += n;
|
||||||
|
|
||||||
/* Transaction data updated.*/
|
/* Transaction data updated.*/
|
||||||
epcp->out_state->rxcnt += n;
|
osp->rxcnt += n;
|
||||||
epcp->out_state->rxsize -= n;
|
osp->rxsize -= n;
|
||||||
epcp->out_state->rxpkts -= 1;
|
osp->rxpkts -= 1;
|
||||||
|
|
||||||
/* The transaction is completed if the specified number of packets
|
/* The transaction is completed if the specified number of packets
|
||||||
has been received or the current packet is a short packet.*/
|
has been received or the current packet is a short packet.*/
|
||||||
if ((n < epcp->out_maxsize) || (epcp->out_state->rxpkts == 0)) {
|
if ((n < epcp->out_maxsize) || (osp->rxpkts == 0)) {
|
||||||
/* Transfer complete, invokes the callback.*/
|
/* Transfer complete, invokes the callback.*/
|
||||||
_usb_isr_invoke_out_cb(usbp, ep);
|
_usb_isr_invoke_out_cb(usbp, ep);
|
||||||
}
|
}
|
||||||
|
@ -707,6 +702,7 @@ void usb_lld_start_in(USBDriver *usbp, usbep_t ep) {
|
||||||
if (n > (size_t)usbp->epc[ep]->in_maxsize)
|
if (n > (size_t)usbp->epc[ep]->in_maxsize)
|
||||||
n = (size_t)usbp->epc[ep]->in_maxsize;
|
n = (size_t)usbp->epc[ep]->in_maxsize;
|
||||||
|
|
||||||
|
isp->txlast = n;
|
||||||
usb_packet_write_from_buffer(ep, isp->txbuf, n);
|
usb_packet_write_from_buffer(ep, isp->txbuf, n);
|
||||||
|
|
||||||
EPR_SET_STAT_TX(ep, EPR_STAT_TX_VALID);
|
EPR_SET_STAT_TX(ep, EPR_STAT_TX_VALID);
|
||||||
|
|
|
@ -182,6 +182,10 @@ typedef struct {
|
||||||
thread_reference_t thread;
|
thread_reference_t thread;
|
||||||
#endif
|
#endif
|
||||||
/* End of the mandatory fields.*/
|
/* End of the mandatory fields.*/
|
||||||
|
/**
|
||||||
|
* @brief Size of the last transmitted packet.
|
||||||
|
*/
|
||||||
|
size_t txlast;
|
||||||
} USBInEndpointState;
|
} USBInEndpointState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue